本文整理匯總了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);
}