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