@dbx-tools/路径
发现、匹配、忽略、扫描和监视同样规则的文件系统路径 由CLI、Projen、枪管生成、代码生成和文档使用 用于工具.
查找文件
import { find, ignore } from "@dbx-tools/path";
for await (const file of find.findFiles(["packages/**/src/**/*.ts"], {
ignore: ignore.ignorePatterns(),
})) {
await processFile(file);
}
const files = find.findFilesSync(["packages/**/src/**/*.ts"]).toArray();
find.findFiles() 溪流同步匹配 . find.findFilesSync()
返回懒惰 Sequence<string> 从
@dbx-tools/ 共享核心,所以呼叫者可以不使用
立即实现.
软件包还提供了 glob 匹配器、 共享忽略规则、 工作空间软件包 扫描 和Chokidar制表助手.
使用此软件包而不是直接 glob 或者说 chokidar 在结果出现时打电话
应同意软件包的发现、桶的生成或清理逻辑.
编译匹配者
import { match } from "@dbx-tools/path";
const isTest = match.toPathMatcher("**/*.test.ts");
if (isTest("packages/shared/model/test/classify.test.ts")) {
skip();
}
match.toPathMatcher() 返回可堆叠的共享核心上游。 使用
match.pathMatchTests() 当您需要检查所编译的包含/不包括
测试.
重用忽略规则
import { ignore } from "@dbx-tools/path";
const matcher = ignore.ignorePathMatcher({
defaults: true,
dot: true,
test: false,
lock: "auto",
});
被忽略的帮助者集中重放全局的排除,例如 node_modules, (中文(简体) ),
生成文件,构建输出,VCS元数据,以及包管理输出.
扫描工作空间包
import { scan } from "@dbx-tools/path";
const options: scan.FileScanOptions = {
cwd: "packages",
ignore: ["generated/**"],
followSymlinks: scan.FOLLOW_SYMLINKS_DEFAULT,
};
scan 导出 projen 引擎使用的共享扫描选项类型 。 用同样的
选项
就像合成一样.
监视文件
import { watch } from "@dbx-tools/path";
const watcher = await watch.watchFiles(["packages/**/src/**/*.ts"], {
ignoreInitial: true,
});
watcher.on("change", (file) => rebuild(file));
watch.watchFiles() 用同样的路径包裹chokidar,忽略期望
用于其他回波工具.
构建图案
import { pattern } from "@dbx-tools/path";
const nodeModulesPattern = pattern.directoryNamePattern("node_modules");
const tsPattern = pattern.fileExtensionPattern("ts");
模式帮助者使生成的光子碎片得以逃脱并保持一致.
模块
find- 被蒙蔽了的懒惰档案.match- 闪闪发光的选手.ignore- 标准忽略模式和匹配者构建.scan- 包扫描选项类型和默认值.watch- chokidar的档案包.pattern- 逃脱的目录名称和扩展名光子碎片.
Projen 引擎在 @dbx-tools/ projen (英语)。 。 。 .