本文整理汇总了TypeScript中sander.readFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readFile函数的具体用法?TypeScript readFile怎么用?TypeScript readFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readFile函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: installCommand
export async function installCommand(config: Config, args) {
const path = args["p"] || args["path"] || process.cwd();
const fname = args["f"] || args["fetcher"] || "default";
const FETCHER = config.fetchers[fname];
let ledeModulesToInstall: string[] = args["_"];
let addToPackageJson = true;
const workingDir = await searchForProjectDir(path);
if (ledeModulesToInstall.length === 0) {
ledeModulesToInstall = await loadFromPackage(workingDir);
addToPackageJson = false;
}
await Promise.all(ledeModulesToInstall.map(install.bind({ fetcher: FETCHER, workingDir: join(workingDir, config.caches.DEP_CACHE) })))
if (addToPackageJson) {
let p = await sander.readFile(join(workingDir, "package.json"), {encoding: "utf8"});
p = JSON.parse(p);
if (p.ledeModules && Array.isArray(p.ledeModules)) {
p.ledeModules.concat(ledeModulesToInstall)
} else {
p.ledeModules = ledeModulesToInstall;
}
await sander.writeFile(join(workingDir, "package.json"), JSON.stringify(p, null, 2));
}
ledeModulesToInstall.forEach(m => config.logger.info(`Finished installing ${m}`));
}
示例2: Promise
return new Promise((res, rej) => {
Promise.all([
Promise.resolve(bitToSettingsString(bit)),
sander.readFile(bit.script, {encoding: "utf8"}),
sander.readFile(bit.style, {encoding: "utf8"}),
sander.readFile(bit.html, {encoding: "utf8"})
])
.then(([settings, script, style, html]) => {
const bitDetail = {
settings,
script: { file: basename(bit.script), contents: script },
style: { file: basename(bit.style), contents: style },
html: { file: basename(bit.html), contents: html }
};
return Object.assign({}, bit, bitDetail)
})
.then(res)
})
示例3: loadFromPackage
async function loadFromPackage(workingDir: string) {
const location = join(workingDir, "package.json");
const pack = await sander.readFile(location, {encoding: "utf8"});
return JSON.parse(pack).ledeModules;
}
示例4:
preBlocks.map(block => sander.readFile(join(workingDir, "blocks", block), {encoding: "utf8"}))