當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fs-extra-p.readFile函數代碼示例

本文整理匯總了TypeScript中fs-extra-p.readFile函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript readFile函數的具體用法?TypeScript readFile怎麽用?TypeScript readFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了readFile函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: async

 packed: async(context) => {
   expect(safeLoad(await readFile(path.join(context.getResources(Platform.WINDOWS, archFromString(process.arch)), "app-update.yml"), "utf-8"))).toMatchSnapshot()
   const updateInfo = safeLoad(await readFile(path.join(context.outDir, "latest.yml"), "utf-8"))
   expect(updateInfo.sha2).not.toEqual("")
   expect(updateInfo.releaseDate).not.toEqual("")
   delete updateInfo.sha2
   delete updateInfo.releaseDate
   expect(updateInfo).toMatchSnapshot()
   await doTest(context.outDir, false)
 }
開發者ID:mbrainiac,項目名稱:electron-builder,代碼行數:10,代碼來源:nsisTest.ts

示例2: async

 packed: async(context) => {
   assertThat(safeLoad(await readFile(path.join(context.getResources(Platform.WINDOWS, Arch.ia32), "app-update.yml"), "utf-8"))).hasProperties({
         provider: "generic",
         url: "https://develar.s3.amazonaws.com/test",
       })
   const updateInfo = safeLoad(await readFile(path.join(context.outDir, "latest.yml"), "utf-8"))
   assertThat(updateInfo).hasProperties({
         version: "1.1.0",
         path: "TestApp Setup 1.1.0.exe",
       })
   assertThat(updateInfo.sha2).isNotEmpty()
   await doTest(context.outDir, false)
 },
開發者ID:Icenium,項目名稱:electron-builder,代碼行數:13,代碼來源:nsisTest.ts

示例3: pathSorter

  packed: async context => {
    const pkgPath = path.join(context.outDir, "Test App ßW-1.1.0.pkg")
    const fileList = pathSorter(parseFileList(await exec("pkgutil", ["--payload-files", pkgPath]), false))
    expect(fileList).toMatchSnapshot()

    const unpackedDir = path.join(context.outDir, "pkg-unpacked")
    await exec("pkgutil", ["--expand", pkgPath, unpackedDir])

    const m: any = BluebirdPromise.promisify(parseString)
    const info = await m(await readFile(path.join(unpackedDir, "Distribution"), "utf8"), {
      explicitRoot: false,
      explicitArray: false,
      mergeAttrs: true,
    })
    delete info["pkg-ref"][0]["bundle-version"].bundle.CFBundleVersion
    delete info["pkg-ref"][1].installKBytes
    delete info.product.version
    expect(info).toMatchSnapshot()

    const scriptDir = path.join(unpackedDir, "org.electron-builder.testApp.pkg", "Scripts")
    await BluebirdPromise.all([
      assertThat(path.join(scriptDir, "postinstall")).isFile(),
      assertThat(path.join(scriptDir, "preinstall")).isFile(),
    ])
  }
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:25,代碼來源:macArchiveTest.ts

示例4: checkOsXResult

async function checkOsXResult(packager: Packager, packagerOptions: PackagerOptions, checkOptions: AssertPackOptions, artifacts: Array<ArtifactCreated>) {
  const productName = getProductName(packager.metadata, packager.devMetadata)
  const packedAppDir = path.join(path.dirname(artifacts[0].file), (productName || packager.metadata.name) + ".app")
  const info = parsePlist(await readFile(path.join(packedAppDir, "Contents", "Info.plist"), "utf8"))
  assertThat(info).has.properties({
    CFBundleDisplayName: productName,
    CFBundleIdentifier: "your.id",
    LSApplicationCategoryType: "your.app.category.type",
    CFBundleVersion: "1.1.0" + "." + (process.env.TRAVIS_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM)
  })

  if (packagerOptions.csaLink != null) {
    const result = await exec("codesign", ["--verify", packedAppDir])
    assertThat(result[0].toString()).not.match(/is not signed at all/)
  }

  const actualFiles = artifacts.map(it => path.basename(it.file)).sort()
  if (checkOptions != null && checkOptions.expectedContents != null) {
    assertThat(actualFiles).deepEqual(checkOptions.expectedContents)
  }
  else {
    assertThat(actualFiles).deepEqual([
      `${productName}-1.1.0-mac.zip`,
      `${productName}-1.1.0.dmg`,
    ].sort())

    assertThat(artifacts.map(it => it.artifactName).sort()).deepEqual([
      "TestApp-1.1.0-mac.zip",
      "TestApp-1.1.0.dmg",
    ].sort())
  }
}
開發者ID:GabeIsman,項目名稱:electron-builder,代碼行數:32,代碼來源:packTester.ts

示例5: getLicenseButtons

export async function getLicenseButtons(licenseButtonFiles: Array<LicenseButtonsFile>, langWithRegion: string, id: number, name: string) {
  let data = getDefaultButtons(langWithRegion, id, name)

  for (const item of licenseButtonFiles) {
    if (item.langWithRegion !== langWithRegion) {
      continue
    }

    try {
      const fileData = safeLoad(await readFile(item.file, "utf-8")) as any
      const buttonsStr = labelToHex(fileData.lang, item.lang, item.langWithRegion) +
        labelToHex(fileData.agree, item.lang, item.langWithRegion) +
        labelToHex(fileData.disagree, item.lang, item.langWithRegion) +
        labelToHex(fileData.print, item.lang, item.langWithRegion) +
        labelToHex(fileData.save, item.lang, item.langWithRegion) +
        labelToHex(fileData.description, item.lang, item.langWithRegion)

      data = `data 'STR#' (${id}, "${name}") {\n`
      data += serializeString("0006" + buttonsStr)
      data += `\n};`

      if (log.isDebugEnabled) {
        log.debug({lang: item.langName, data}, `overwriting license buttons`)
      }
      return data
    }
    catch (e) {
      log.debug({error: e}, "cannot overwrite license buttons")
      return data
    }
  }

  return data
}
開發者ID:electron-userland,項目名稱:electron-builder,代碼行數:34,代碼來源:licenseButtons.ts

示例6: pathSorter

  packed: async context => {
    const pkgPath = path.join(context.outDir, "Test App ßW-1.1.0.pkg")
    console.log("CALL")
    const fileList = pathSorter(parseFileList(await exec("pkgutil", ["--payload-files", pkgPath]), false))
    expect(fileList).toMatchSnapshot()

    const unpackedDir = path.join(context.outDir, "pkg-unpacked")
    await exec("pkgutil", ["--expand", pkgPath, unpackedDir])

    const info = parseXml(await readFile(path.join(unpackedDir, "Distribution"), "utf8"))
    for (const element of info.getElements("pkg-ref")) {
      element.removeAttribute("installKBytes")
      const bundleVersion = element.elementOrNull("bundle-version")
      if (bundleVersion != null) {
        bundleVersion.element("bundle").removeAttribute("CFBundleVersion")
      }
    }

    // delete info.product.version
    info.element("product").removeAttribute("version")

    expect(info).toMatchSnapshot()

    const scriptDir = path.join(unpackedDir, "org.electron-builder.testApp.pkg", "Scripts")
    await Promise.all([
      assertThat(path.join(scriptDir, "postinstall")).isFile(),
      assertThat(path.join(scriptDir, "preinstall")).isFile(),
    ])
  }
開發者ID:electron-userland,項目名稱:electron-builder,代碼行數:29,代碼來源:macArchiveTest.ts

示例7: checkOsXResult

async function checkOsXResult(packager: Packager, packagerOptions: PackagerOptions, checkOptions: AssertPackOptions, artifacts: Array<ArtifactCreated>) {
  const appInfo = packager.appInfo
  const packedAppDir = path.join(path.dirname(artifacts[0].file), `${appInfo.productFilename}.app`)
  const info = parsePlist(await readFile(path.join(packedAppDir, "Contents", "Info.plist"), "utf8"))
  assertThat2(info).has.properties({
    CFBundleDisplayName: appInfo.productName,
    CFBundleIdentifier: "org.electron-builder.testApp",
    LSApplicationCategoryType: "your.app.category.type",
    CFBundleVersion: `${appInfo.version}.${(process.env.TRAVIS_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM)}`
  })

  if (packagerOptions.cscLink != null) {
    const result = await exec("codesign", ["--verify", packedAppDir])
    assertThat2(result).not.match(/is not signed at all/)
  }

  const actualFiles = artifacts.map(it => path.basename(it.file)).sort()
  if (checkOptions != null && checkOptions.expectedContents != null) {
    assertThat(actualFiles).isEqualTo(checkOptions.expectedContents)
  }
  else {
    assertThat(actualFiles).isEqualTo([
      `${appInfo.productFilename}-${appInfo.version}-mac.zip`,
      `${appInfo.productFilename}-${appInfo.version}.dmg`,
    ].sort())

    assertThat(artifacts.map(it => it.artifactName).sort()).isEqualTo([
      `TestApp-${appInfo.version}-mac.zip`,
      `TestApp-${appInfo.version}.dmg`,
    ].sort())
  }
}
開發者ID:SimplyAhmazing,項目名稱:electron-builder,代碼行數:32,代碼來源:packTester.ts

示例8: getGitUrlFromGitConfig

async function getGitUrlFromGitConfig(): Promise<string | null> {
  let data: string | null = null
  try {
    data = await readFile(path.join(".git", "config"), "utf8")
  }
  catch (e) {
    if (e.code === "ENOENT") {
      return null
    }

    throw e
  }

  const conf = data.split(/\r?\n/)
  const i = conf.indexOf('[remote "origin"]')
  if (i !== -1) {
    let u = conf[i + 1]
    if (!u.match(/^\s*url =/)) {
      u = conf[i + 2]
    }

    if (u.match(/^\s*url =/)) {
      return u.replace(/^\s*url = /, "")
    }
  }
  return null
}
開發者ID:ArchMa9e,項目名稱:electron-builder,代碼行數:27,代碼來源:repositoryInfo.ts

示例9: exec

  packed: async context => {
    const pkgPath = path.join(context.outDir, "Test App ßW-1.1.0.pkg")
    const unpackedDir = path.join(context.outDir, "pkg-unpacked")
    await exec("pkgutil", ["--expand", pkgPath, unpackedDir])

    const packageInfoFile = path.join(unpackedDir, "org.electron-builder.testApp.pkg", "PackageInfo")
    const info = parseXml(await readFile(packageInfoFile, "utf8"))

    const relocateElement = info.elementOrNull("relocate")
    if (relocateElement) {
      expect(relocateElement.elements).toBeNull()
    }

    const upgradeBundleElement = info.elementOrNull("upgrade-bundle")
    if (upgradeBundleElement) {
      expect(upgradeBundleElement.elements).toBeNull()
    }

    const updateBundleElement = info.elementOrNull("update-bundle")
    if (updateBundleElement) {
      expect(updateBundleElement.elements).toHaveLength(1)
    }

    const strictIdentifierElement = info.elementOrNull("strict-identifier")
    if (strictIdentifierElement) {
      expect(strictIdentifierElement.elements).toBeNull()
    }
  }
開發者ID:electron-userland,項目名稱:electron-builder,代碼行數:28,代碼來源:macArchiveTest.ts

示例10: assertThat

    packed: async context => {
      const base = path.join(context.outDir, `${platform.buildConfigurationKey}-unpacked`)
      let resourcesDir = path.join(base, "resources")
      if (platform === Platform.MAC) {
        resourcesDir = path.join(base, "TestApp.app", "Contents", "Resources")
      }
      const appDir = path.join(resourcesDir, "app")

      await BluebirdPromise.all([
        assertThat(path.join(resourcesDir, "foo")).isDirectory(),
        assertThat(path.join(appDir, "foo")).doesNotExist(),

        assertThat(path.join(resourcesDir, "foo", "nameWithoutDot")).isFile(),
        assertThat(path.join(appDir, "foo", "nameWithoutDot")).doesNotExist(),

        assertThat(path.join(resourcesDir, "bar", "hello.txt")).isFile(),
        assertThat(path.join(resourcesDir, "bar", `${process.arch}.txt`)).isFile(),
        assertThat(path.join(appDir, "bar", `${process.arch}.txt`)).doesNotExist(),

        assertThat(path.join(resourcesDir, osName, `${process.arch}.txt`)).isFile(),
        assertThat(path.join(resourcesDir, "platformSpecificR")).isFile(),
        assertThat(path.join(resourcesDir, "ignoreMe.txt")).doesNotExist(),

        allCan(path.join(resourcesDir, "executable"), true),
        allCan(path.join(resourcesDir, "executableOnlyOwner"), true),

        allCan(path.join(resourcesDir, "bar", "hello.txt"), false),
      ])

      expect(await readFile(path.join(resourcesDir, "bar", "hello.txt"), "utf-8")).toEqual("data")
    },
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:31,代碼來源:filesTest.ts


注:本文中的fs-extra-p.readFile函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。