当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fs-extra-p.readJson函数代码示例

本文整理汇总了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
}
开发者ID:mbrainiac,项目名称:electron-builder,代码行数:29,代码来源:readPackageJson.ts

示例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)
  })
开发者ID:TakT,项目名称:electron-builder,代码行数:7,代码来源:BuildTest.ts

示例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
  }
}
开发者ID:jwheare,项目名称:electron-builder,代码行数:7,代码来源:checkDeps.ts

示例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)
}
开发者ID:yuya-oc,项目名称:electron-builder,代码行数:7,代码来源:config.ts

示例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)
}
开发者ID:electron-userland,项目名称:electron-builder,代码行数:8,代码来源:packTester.ts

示例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
}
开发者ID:electron-userland,项目名称:electron-builder,代码行数:9,代码来源:packageMetadata.ts

示例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()
   }
 }
开发者ID:jwheare,项目名称:electron-builder,代码行数:9,代码来源:extraMetadataTest.ts

示例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
}
开发者ID:mbrainiac,项目名称:electron-builder,代码行数:52,代码来源:readInstalled.ts

示例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
   }
 }
开发者ID:jwheare,项目名称:electron-builder,代码行数:13,代码来源:fileTransformer.ts


注:本文中的fs-extra-p.readJson函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。