本文整理汇总了TypeScript中fs-extra.readJson函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readJson函数的具体用法?TypeScript readJson怎么用?TypeScript readJson使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readJson函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
async () => {
const scanResultJson =
await readJson(path.join(manifestsDir, 'simple_expected.json'));
const expectedManifestResult =
await readJson(path.join(manifestsDir, 'simple_source.json'));
const actualResult = serializePackageScanResult(
new Map(scanResultJson[0]),
new Map(scanResultJson[1]),
urlHandler);
assert.deepEqual(actualResult, expectedManifestResult);
});
示例2: downloadSeriesAsync
await mio.usingAsync(mio.Browser.createAsync(), async browser => {
let fileNames = await fs.readdir(shared.path.normal());
for (let fileName of fileNames) {
let fileExtension = path.extname(fileName);
if (fileExtension === shared.extension.json) {
let metaProviderPath = shared.path.normal(fileName);
let metaProvider = await fs.readJson(metaProviderPath) as shared.IMetaProvider;
for (let url in metaProvider) {
let timer = new mio.Timer();
let awaiter = mio.scrapeAsync(browser, url);
if (awaiter) {
console.log(`Awaiting ${url}`);
await mio.usingAsync(awaiter, async series => {
if (series.title !== metaProvider[url]) throw new Error(`Series at ${url} property changed: title`)
if (series.url !== url) throw new Error(`Series at ${url} property changed: url`);
console.log(`Fetching ${series.title}`);
await mio.commands.updateSeriesAsync(series);
await downloadSeriesAsync(series);
console.log(`Finished ${series.title} (${timer})`);
});
} else {
console.log(`Rejected ${url}`);
}
}
}
}
});
示例3: found
(async () => {
const dirsToCheck = [];
for (const subDir of await fs.readdir(PACKAGES_DIR)) {
for (const packageDir of await fs.readdir(path.resolve(PACKAGES_DIR, subDir))) {
dirsToCheck.push(path.resolve(PACKAGES_DIR, subDir, packageDir));
}
}
let bad = false;
for (const dir of dirsToCheck) {
const pj = await fs.readJson(path.resolve(dir, 'package.json'));
if (pj.name === '@electron-forge/cli') continue;
if (!await fs.pathExists(path.resolve(dir, pj.main))) {
console.error(`${`[${pj.name}]`.cyan}:`, `Main entry not found (${pj.main})`.red);
bad = true;
}
if (!pj.typings || !await fs.pathExists(path.resolve(dir, pj.typings))) {
console.error(`${`[${pj.name}]`.cyan}:`, `Typings entry not found (${pj.typings})`.red);
bad = true;
}
}
if (bad) {
process.exit(1);
}
})().catch(console.error);
示例4: Promise
return new Promise((resolve, reject) => {
readJson(path, (err, r: any) => {
if (err) {
return reject(err);
}
return resolve(r)
})
});
示例5: createSeriesAsync
export async function createSeriesAsync(series: mio.IScraperSeries) {
let metaProviderPath = shared.path.normal(series.providerName + shared.extension.json);
let metaProviderExists = await fs.pathExists(metaProviderPath);
let metaProvider = metaProviderExists ? await fs.readJson(metaProviderPath) as shared.IMetaProvider : {};
metaProvider[series.url] = series.title;
await mio.commands.updateSeriesAsync(series);
await fs.writeJson(metaProviderPath, metaProvider, {spaces: 2});
}
示例6: execAsync
export async function execAsync(argv: string[]) {
let packageData = await fs.readJson(packagePath);
commander.version(packageData.version);
commander.option('--no-webpack', 'disables webpack middleware');
commander.option('-p, --port <n>', 'sets the port', parseInt);
commander.parse(argv);
await mio.serveAsync(commander.port || mio.settings.serverPort, commander.webpack);
}
示例7: getPackageJSON
/**
* Return package.json object
*
* @param {string} projectPath
* @returns
*/
async function getPackageJSON(projectPath: string) {
const packageJSONPath = path.join(projectPath, 'package.json');
const fileExists = await fs.exists(packageJSONPath);
if (!fileExists) {
throw new Error(`The project doesn't have a package.json.`);
}
return fs.readJson(packageJSONPath);
}
示例8: readPackageJson
export async function readPackageJson(dir: string, safe = false) {
try {
return await fs.readJson(path.resolve(dir, 'package.json'));
} catch (err) {
if (safe) {
return {};
} else {
throw err;
}
}
}