當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。