當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fs.readdir函數代碼示例

本文整理匯總了TypeScript中mz/fs.readdir函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript readdir函數的具體用法?TypeScript readdir怎麽用?TypeScript readdir使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了readdir函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
    }
}
開發者ID:kildevaeld,項目名稱:willburg,代碼行數:32,代碼來源:utils.ts

示例2: render

export function render(inputPath) {

    return fs
        .readdir(inputPath)
        .then(files => {

            var rendering = files
                .filter(file => file.endsWith('.md'))
                .map(file => {
                    const pathToFile = path.join(inputPath, file);
                    const pathForHtml = path.join(outputPath, file.replace('.md', '.html'));

                    return fs
                        .readFile(pathToFile, 'utf8')
                        .then(raw => {
                            console.log(pathToFile);

                            const html = marked(raw);
                            return fs.writeFile(pathForHtml, html);
                        });
                });

            return Promise.all(rendering);
        });
};
開發者ID:bennage,項目名稱:pundit,代碼行數:25,代碼來源:markdown.ts

示例3: 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);
    }
  }
}
開發者ID:alangpierce,項目名稱:sucrase,代碼行數:25,代碼來源:cli.ts

示例4: findVariants

// TODO(usergenic): Variants should support the directory naming convention in
// the .bowerrc instead of hardcoded 'bower_components' form seen here.
async function findVariants(options: ServerOptions) {
  const root = options.root || process.cwd();
  const filesInRoot = await fs.readdir(root);
  const variants = filesInRoot
                       .map(f => {
                         const match = f.match(/^bower_components-(.*)/!);
                         return match && {name: match[1], directory: match[0]};
                       })
                       .filter(f => f != null && f.name !== '');
  return variants;
}
開發者ID:iblancasa,項目名稱:polyserve,代碼行數:13,代碼來源:start_server.ts

示例5: 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;
    }
開發者ID:arjun-msft,項目名稱:opent2t,代碼行數:15,代碼來源:LocalPackageSource.ts

示例6:

    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);
            }
        }
    }
開發者ID:LeviticusMB,項目名稱:ghostly,代碼行數:14,代碼來源:ghostly.ts

示例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);
    }
  }
}
開發者ID:alangpierce,項目名稱:sucrase,代碼行數:17,代碼來源:mergeDirectoryContents.ts

示例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);
      }
    }
  }
開發者ID:alangpierce,項目名稱:decaffeinate,代碼行數:18,代碼來源:cli.ts

示例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});
     }
   }
 }
開發者ID:alangpierce,項目名稱:sucrase,代碼行數:19,代碼來源:loadProjectFiles.ts


注:本文中的mz/fs.readdir函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。