本文整理汇总了TypeScript中walk-sync.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: generateFileTree
export async function generateFileTree(parentDirectory: string) {
const fileTree: FileTree = {
dirs: {},
files: []
};
const paths: string[] = walkSync(parentDirectory, { ignore: ['.git'] });
for (let path of paths) {
let segments: string[] = path.split('/');
let obj: FileTree = fileTree;
// 遍历每一段路径
for (let segment of segments) {
if (segment.endsWith('.md')) {
// 这里的 segment 等价于文件名
let h1s: string[] = await readMarkdownHeadersFromFile(
parentDirectory + '/' + path
);
obj.files.push({
path,
name: segment,
h1s,
html_url: `./${path}`
});
} else {
// 如果是文件目录,则创建新的结点
if (ignoreFilesOrDirs.includes(segment)) {
continue;
}
// 如果当前树中不存在结点,则创建空结点
if (!obj.hasOwnProperty('dirs')) {
obj['dirs'] = {};
}
// 判断是否存在目录结点
if (!obj['dirs'][segment]) {
obj['dirs'][segment] = {
dirs: {},
files: []
};
}
// 将子字典赋值给当前对象
obj = obj['dirs'][segment];
}
}
}
return fileTree;
}
示例2: function
return function () {
let blueprintPath = path.join(root, dir, 'files');
let expected = walkSync(blueprintPath);
let actual = walkSync('.').sort();
let directory = path.basename(process.cwd());
forEach(Blueprint.renamedFiles, function (destFile, srcFile) {
expected[expected.indexOf(srcFile)] = destFile;
});
expected.forEach(function (file, index) {
expected[index] = file.replace(/__name__/g, 'angular-cli');
});
expected.sort();
expect(directory).to.equal('foo');
expect(expected).to.deep.equal(
actual,
EOL + ' expected: ' + util.inspect(expected) + EOL + ' but got: ' + util.inspect(actual));
};
示例3: generateToc
export async function generateToc(repoName = 'Awesome-Reference') {
// 获取仓库的配置信息
const repo: ReposityConfig = repos[repoName];
const files = walkSync(repo.localPath).filter(
path => path.endsWith('.md') && path !== 'README.md'
);
// 暂时不进行文件头添加操作
// for (let file of files) {
// const absoluteFile = `${repo.localPath}/${file}`;
// // 读取文件内容
// let content = await readFileAsync(absoluteFile, { encoding: 'utf8' });
// const header = `[![返回目录](${repo.chapterHeader})](${repo.sUrl}) \n`;
// // 替换已经存在的图片
// content = content.replace(/\[!\[返回目录\]\(.*\)\]\(.*\)/g, '');
// content = header + content;
// fs.outputFile(absoluteFile, content);
// }
let fileTree = await generateFileTree(repo.localPath);
let toc;
if (repo.depth === 1) {
toc = generateTocFromFileTree(fileTree);
} else {
toc = generateTocFromFileTreeWithSubHeader(fileTree, 0);
}
fs.outputFile('toc.md', toc);
}