本文整理汇总了TypeScript中fs-extra-p.readJson函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readJson函数的具体用法?TypeScript readJson怎么用?TypeScript readJson使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readJson函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getElectronVersion
export async function getElectronVersion(config: Config | null | undefined, projectDir: string, projectMetadata?: any | null): Promise<string> {
// build is required, but this check is performed later, so, we should check for null
if (config != null && config.electronVersion != null) {
return config.electronVersion
}
// projectMetadata passed only for prepacked app asar and in this case no dev deps in the app.asar
if (projectMetadata == null) {
for (const name of ["electron", "electron-prebuilt", "electron-prebuilt-compile"]) {
try {
return (await readJson(path.join(projectDir, "node_modules", name, "package.json"))).version
}
catch (e) {
if (e.code !== "ENOENT") {
warn(`Cannot read electron version from ${name} package.json: ${e.message}`)
}
}
}
}
const packageJsonPath = path.join(projectDir, "package.json")
const electronPrebuiltDep = findFromElectronPrebuilt(projectMetadata || await readJson(packageJsonPath))
if (electronPrebuiltDep == null) {
throw new Error(`Cannot find electron dependency to get electron version in the '${packageJsonPath}'`)
}
const firstChar = electronPrebuiltDep[0]
return firstChar === "^" || firstChar === "~" ? electronPrebuiltDep.substring(1) : electronPrebuiltDep
}
示例2: async
}, true, async (projectDir) => {
const file = path.join(projectDir, "package.json")
const data = await readJson(file)
data.productName = "Test App"
return await writeJson(file, data)
})
示例3: main
async function main(): Promise<void> {
const packages = (await readdir(packageDir)).filter(it => !it.includes(".")).sort()
const devPackageData = await readJson(path.join(rootDir, "package.json"))
if ((await BluebirdPromise.map(packages, it => check(path.join(packageDir, it), devPackageData))).includes(false)) {
process.exitCode = 1
}
}
示例4: createConfigValidator
async function createConfigValidator() {
const ajv = new Ajv({allErrors: true, coerceTypes: true})
ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-04.json"))
require("ajv-keywords")(ajv, ["typeof"])
const schema = await readJson(path.join(__dirname, "..", "..", "scheme.json"))
return ajv.compile(schema)
}
示例5: modifyPackageJson
export async function modifyPackageJson(projectDir: string, task: (data: any) => void, isApp = false): Promise<any> {
const file = isApp ? path.join(projectDir, "app", "package.json") : path.join(projectDir, "package.json")
const data = await readJson(file)
task(data)
// because copied as hard link
await unlink(file)
return await writeJson(file, data)
}
示例6: readPackageJson
export async function readPackageJson(file: string): Promise<any> {
const data = await readJson(file)
await authors(file, data)
normalizeData(data)
// remove not required fields because can be used for remote build
delete data.scripts
delete data.readme
return data
}
示例7: assertThat
packed: async context => {
await assertThat(path.join(context.getContent(Platform.LINUX), "new-name")).isFile()
if (asar) {
expect(await readAsarJson(path.join(context.getResources(Platform.LINUX), "app.asar"), "package.json")).toMatchSnapshot()
}
else {
expect(await readJson(path.join(context.getResources(Platform.LINUX), "app", "package.json"))).toMatchSnapshot()
}
}
示例8: _readInstalled
async function _readInstalled(folder: string, parent: any | null, name: string | null, depth: number, opts: any, realpathSeen: Map<string, Dependency>, findUnmetSeen: Set<any>): Promise<any> {
const realDir = await realpath(folder)
const processed = realpathSeen.get(realDir)
if (processed != null) {
return processed
}
const obj = await readJson(path.resolve(folder, "package.json"))
obj.realPath = realDir
obj.path = obj.path || folder
//noinspection ES6MissingAwait
if ((await lstat(folder)).isSymbolicLink()) {
obj.link = realDir
}
obj.realName = name || obj.name
obj.dependencyNames = obj.dependencies == null ? null : new Set(Object.keys(obj.dependencies))
// Mark as extraneous at this point.
// This will be un-marked in unmarkExtraneous, where we mark as not-extraneous everything that is required in some way from the root object.
obj.extraneous = true
obj.optional = true
if (parent != null && obj.link == null) {
obj.parent = parent
}
realpathSeen.set(realDir, obj)
if (depth > opts.depth) {
return obj
}
const deps = await BluebirdPromise.map(await readScopedDir(path.join(folder, "node_modules")), pkg => _readInstalled(path.join(folder, "node_modules", pkg), obj, pkg, depth + 1, opts, realpathSeen, findUnmetSeen), {concurrency: 8})
if (obj.dependencies != null) {
for (const dep of deps) {
obj.dependencies[dep.realName] = dep
}
// any strings in the obj.dependencies are unmet deps. However, if it's optional, then that's fine, so just delete it.
if (obj.optionalDependencies != null) {
for (const dep of Object.keys(obj.optionalDependencies)) {
if (typeof obj.dependencies[dep] === "string") {
delete obj.dependencies[dep]
}
}
}
}
return obj
}
示例9: modifyMainPackageJson
return file => {
if (file === mainPackageJson) {
return modifyMainPackageJson(file, extraMetadata)
}
else if (file.endsWith("/package.json") && file.includes("/node_modules/")) {
return readJson(file)
.then(it => cleanupPackageJson(it, false))
.catch(e => warn(e))
}
else {
return null
}
}