• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript fs.readdir函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs.stat函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs.readFileSync函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap