本文整理汇总了TypeScript中fs-extra.readJSONSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readJSONSync函数的具体用法?TypeScript readJSONSync怎么用?TypeScript readJSONSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readJSONSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getInstalledNpmPkgVersion
export function getInstalledNpmPkgVersion (pkgName: string, basedir: string): string | null {
const pkgPath = getInstalledNpmPkgPath(pkgName, basedir)
if (!pkgPath) {
return null
}
return fs.readJSONSync(pkgPath).version
}
示例2: setTimeout
setTimeout(() => {
const profile = fs.readJSONSync(localProfilePath);
assert.deepEqual(profile.credentials, patch.credentials);
done();
}, 100);
示例3: getAppPackageJsonData
function getAppPackageJsonData(context: BuildContext) {
if (!appPackageJsonData) {
try {
appPackageJsonData = readJSONSync(join(context.rootDir, 'package.json'));
} catch (e) {}
}
return appPackageJsonData;
}
示例4: generateQuickAppManifest
function generateQuickAppManifest () {
const { appConfig, pageConfigs, appPath, outputDir, projectConfig } = getBuildData()
// 生成 router
const pages = (appConfig.pages as string[]).concat()
const routerPages = {}
pages.forEach(element => {
routerPages[path.dirname(element)] = {
component: path.basename(element),
filter: {
view: {
uri: 'https?://.*'
}
}
}
})
const routerEntry = pages.shift()
const router = {
entry: path.dirname(routerEntry as string),
pages: routerPages
}
// 生成 display
const display = JSON.parse(JSON.stringify(appConfig.window || {}))
display.pages = {}
pageConfigs.forEach((item, page) => {
if (item) {
display.pages[path.dirname(page)] = item
}
})
// 读取 project.quickapp.json
const quickappJSONPath = path.join(appPath, 'project.quickapp.json')
let quickappJSON
if (fs.existsSync(quickappJSONPath)) {
quickappJSON = fs.readJSONSync(quickappJSONPath)
} else {
quickappJSON = fs.readJSONSync('../config/manifest.default.json')
}
quickappJSON.router = router
quickappJSON.display = display
quickappJSON.config = Object.assign({}, quickappJSON.config, {
designWidth: projectConfig.designWidth || 750
})
fs.writeFileSync(path.join(outputDir, 'manifest.json'), JSON.stringify(quickappJSON, null, 2))
}
示例5: readFromFile
readFromFile(): any {
this.debug(`Reading config file "${this.configFile}"...`);
try {
return fs.readJSONSync(this.configFile);
} catch (error) {
const schemataKeys = Object.keys(SchemaUpdater.SCHEMATA);
// In case of an error, always use the latest schema with sensible defaults:
return SchemaUpdater.SCHEMATA[schemataKeys[schemataKeys.length - 1]];
}
}
示例6: loadSwaggerDocument
private static loadSwaggerDocument(options: SwaggerOptions) {
let swaggerDocument: any;
if (_.endsWith(options.filePath, '.yml') || _.endsWith(options.filePath, '.yaml')) {
swaggerDocument = YAML.load(options.filePath);
}
else {
swaggerDocument = fs.readJSONSync(options.filePath);
}
return swaggerDocument;
}
示例7: done
repository.updateLocal(update, (err) => {
if (err) {
return done(err);
}
const profileFilePath = repository.getProfileFilePath("local");
const profile = fs.readJSONSync(profileFilePath);
assert.deepEqual(profile.credentials, update.credentials);
assert.deepEqual(profile.activeCredentials, update.activeCredentials)
done();
});
示例8: configure
public static configure() {
try {
const CONFIG_FILE = this.searchConfigFile();
if (CONFIG_FILE && fs.existsSync(CONFIG_FILE)) {
const config = fs.readJSONSync(CONFIG_FILE);
if (config.useIoC) {
Server.useIoC(config.es6);
} else if (config.serviceFactory) {
if (config.serviceFactory.indexOf('.') === 0) {
config.serviceFactory = path.join(process.cwd(), config.serviceFactory);
}
Server.registerServiceFactory(config.serviceFactory);
}
}
} catch (e) {
// tslint:disable-next-line:no-console
console.error(e);
}
}
示例9: writePackageJson
/**
* For a given repo, generate a new package.json and write it to disk.
*/
async function writePackageJson(
repo: WorkspaceRepo,
options: {version: string, flat: boolean, private: boolean}) {
const bowerPackageName = path.basename(repo.dir);
const bowerJsonPath = path.join(repo.dir, 'bower.json');
const bowerJson = fse.readJSONSync(bowerJsonPath) as Partial<BowerConfig>;
const npmPackageName =
lookupNpmPackageName(bowerJsonPath) || bowerPackageName;
const packageJsonPath = path.join(repo.dir, 'package.json');
const existingPackageJson =
await readJsonIfExists<Partial<YarnConfig>>(packageJsonPath);
const packageJson = generatePackageJson(
bowerJson,
{name: npmPackageName, ...options},
undefined,
existingPackageJson);
writeJson(packageJson, packageJsonPath);
}
示例10: lookupNpmPackageName
export function lookupNpmPackageName(bowerJsonPath: string): string|undefined {
let bowerPackageName: string;
// Lookup the official package name via `bower.json`.
try {
const bowerJson = fse.readJSONSync(bowerJsonPath);
bowerPackageName = bowerJson.name as string;
} catch (err) {
console.warn(
`WARNING: "${bowerJsonPath}" not found / could not be read` +
`(${err.message})`);
return;
}
// Check our dependency map for the corresponding package name on npm.
const depInfo = lookupDependencyMapping(bowerPackageName);
if (!depInfo) {
return bowerPackageName;
}
// If lookup was successful, return the correct npm package name.
return depInfo.npm;
}