本文整理汇总了TypeScript中mz/fs.stat函数的典型用法代码示例。如果您正苦于以下问题:TypeScript stat函数的具体用法?TypeScript stat怎么用?TypeScript stat使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stat函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: requireDir
export async function requireDir(path: string, iterator: (mod: any, path?: string) => Promise<any>): Promise<void> {
if (!Path.isAbsolute(path)) {
path = Path.resolve(path);
}
let files = await fs.readdir(path);
files.sort();
for (let i = 0, ii = files.length; i < ii; i++) {
let fp = Path.join(path, files[i])
let stat = await fs.stat(fp);
if (stat.isDirectory()) {
await requireDir(fp, iterator);
continue;
}
let mod;
try {
mod = require(fp);
} catch (e) {
e.path = fp;
throw e
}
await iterator(mod, fp);
}
}
示例2: buildDirectory
async function buildDirectory(
srcDirPath: string,
outDirPath: string,
options: CLIOptions,
): Promise<void> {
const extension = options.sucraseOptions.transforms.includes("typescript") ? ".ts" : ".js";
if (!(await exists(outDirPath))) {
await mkdir(outDirPath);
}
for (const child of await readdir(srcDirPath)) {
if (["node_modules", ".git"].includes(child) || options.excludeDirs.includes(child)) {
continue;
}
const srcChildPath = join(srcDirPath, child);
const outChildPath = join(outDirPath, child);
if ((await stat(srcChildPath)).isDirectory()) {
await buildDirectory(srcChildPath, outChildPath, options);
} else if (srcChildPath.endsWith(extension)) {
const outPath = `${outChildPath.substr(0, outChildPath.length - extension.length)}.${
options.outExtension
}`;
await buildFile(srcChildPath, outPath, options);
}
}
}
示例3: processPath
async function processPath(path: string): Promise<void> {
let info = await stat(path);
if (info.isDirectory()) {
await processDirectory(path);
} else {
await processFile(path);
}
}
示例4: getSubdirectoriesAsync
/**
* Gets all subdirectories (not files) under a directory.
*/
protected static async getSubdirectoriesAsync(directoryPath: string): Promise<string[]> {
let directoryNames: string[] = [];
let childNames: string[] = await fs.readdir(directoryPath);
for (let i = 0; i < childNames.length; i++) {
if ((await fs.stat(path.join(directoryPath, childNames[i]))).isDirectory()) {
directoryNames.push(childNames[i]);
}
}
return directoryNames;
}
示例5:
static async $rmr(node?: string): Promise<void> {
if (node) {
if ((await fs.stat(node)).isDirectory()) {
for (const file of await fs.readdir(node)) {
await Engine.$rmr(path.join(node, file));
}
await fs.rmdir(node);
}
else {
await fs.unlink(node);
}
}
}
示例6: handleClient
async function handleClient(assets:Assets, req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {
let stream, mime = "text/html", stats;
let path: string;
switch (req.url) {
case '/js/assets-gallery.js':
path = Path.join(ASSETS_PATH, 'js', 'assets-gallery.js')
mime = 'application/javascript';
break;
case '/css/assets-gallery.css':
path = Path.join(ASSETS_PATH, 'css', 'assets-gallery.css');
mime = 'text/css';
break;
case '/images/assets-mimetypes.png':
path = Path.join(ASSETS_PATH, 'images', 'assets-mimetypes.png')
mime = 'image/png';
break;
case '/images/assets-mimetypes@2x.png':
path = Path.join(ASSETS_PATH, 'images', 'assets-mimetypes@2x.png')
mime = 'image/png';
break;
case '/images/assets-loader.gif':
path = Path.join(ASSETS_PATH, 'images', 'assets-loader.gif');
mime = 'image/gif';
break;
case '/images/assets-remove.png':
path = Path.join(ASSETS_PATH, 'images', 'assets-remove.png');
mime = 'image/png';
break;
default:
path = Path.resolve(__dirname, '../../resources/index.html');
mime = 'text/html';
}
stats = await fs.stat(path);
stream = fs.createReadStream(path);
res.writeHead(200, {
'Content-Type': mime,
'Content-Length': stats.size,
//'ETag': etag(stats)
});
stream.pipe(res);
}
示例7: mergeDirectoryContents
export default async function mergeDirectoryContents(
srcDirPath: string,
destDirPath: string,
): Promise<void> {
if (!(await exists(destDirPath))) {
await mkdir(destDirPath);
}
for (const child of await readdir(srcDirPath)) {
const srcChildPath = join(srcDirPath, child);
const destChildPath = join(destDirPath, child);
if ((await stat(srcChildPath)).isDirectory()) {
await mergeDirectoryContents(srcChildPath, destChildPath);
} else {
await copyFile(srcChildPath, destChildPath);
}
}
}
示例8: processDirectory
async function processDirectory(path: string): Promise<void> {
let children = await readdir(path);
for (let child of children) {
let childPath = join(path, child);
let childStat = await stat(childPath);
if (childStat.isDirectory()) {
await processDirectory(childPath);
} else if (options.modernizeJS) {
if (child.endsWith('.js')) {
await processPath(childPath);
}
} else if (child.endsWith('.coffee') || child.endsWith('.litcoffee') || child.endsWith('.coffee.md')) {
await processPath(childPath);
}
}
}
示例9: visit
async function visit(path: string): Promise<void> {
for (const child of await readdir(path)) {
if (["node_modules", ".git"].includes(child)) {
continue;
}
const childPath = join(path, child);
if ((await stat(childPath)).isDirectory()) {
await visit(childPath);
} else if (
childPath.endsWith(".js") ||
childPath.endsWith(".jsx") ||
childPath.endsWith(".ts") ||
childPath.endsWith(".tsx")
) {
const code = (await readFile(childPath)).toString();
results.push({code, path: childPath});
}
}
}
示例10: setupConfig
async setupConfig (configPath: string): Promise<any> {
let config = {}
try {
await fs.stat(configPath)
config = requireAll(configPath)
} catch (err) {
if (err.code === 'ENOENT') {
this.log.warn(err)
} else {
this.log.error(err)
}
return {}
}
try {
for (let [key, conf] of entries(config)) {
if (key === 'index') continue
conf = conf.default || conf
key = key.replace('-', '_')
if (isFunction(conf)) {
config[key] = conf(this.app)
if (isPromise(config[key])) {
config[key] = await config[key]
}
} else {
config[key] = conf
}
}
return config
} catch (err) {
this.app.log.error(err)
return {}
}
}