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


TypeScript fs.statOrNull函數代碼示例

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


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

示例1: computeDefaultAppDirectory

export async function computeDefaultAppDirectory(projectDir: string, userAppDir: string | null | undefined): Promise<string> {
  if (userAppDir != null) {
    const absolutePath = path.resolve(projectDir, userAppDir)
    const stat = await statOrNull(absolutePath)
    if (stat == null) {
      throw new Error(`Application directory ${userAppDir} doesn't exists`)
    }
    else if (!stat.isDirectory()) {
      throw new Error(`Application directory ${userAppDir} is not a directory`)
    }
    else if (projectDir === absolutePath) {
      warn(`Specified application directory "${userAppDir}" equals to project dir — superfluous or wrong configuration`)
    }
    return absolutePath
  }

  for (const dir of DEFAULT_APP_DIR_NAMES) {
    const absolutePath = path.join(projectDir, dir)
    const packageJson = path.join(absolutePath, "package.json")
    const stat = await statOrNull(packageJson)
    if (stat != null && stat.isFile()) {
      return absolutePath
    }
  }
  return projectDir
}
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:26,代碼來源:config.ts

示例2: computeFileSets

export async function computeFileSets(matchers: Array<FileMatcher>, transformer: FileTransformer, packager: Packager, isElectronCompile: boolean): Promise<Array<FileSet>> {
  const fileSets: Array<FileSet> = []
  for (const matcher of matchers) {
    const fileWalker = new AppFileWalker(matcher, packager)

    const fromStat = await statOrNull(fileWalker.matcher.from)
    if (fromStat == null) {
      debug(`Directory ${fileWalker.matcher.from} doesn't exists, skip file copying`)
      continue
    }

    const files = await walk(fileWalker.matcher.from, fileWalker.filter, fileWalker)
    const metadata = fileWalker.metadata

    const transformedFiles = await BluebirdPromise.map(files, it => {
      const fileStat = metadata.get(it)
      return fileStat != null && fileStat.isFile() ? transformer(it) : null
    }, CONCURRENCY)

    fileSets.push({src: fileWalker.matcher.from, files, metadata: fileWalker.metadata, transformedFiles, destination: fileWalker.matcher.to})
  }

  const mainFileSet = fileSets[0]
  if (isElectronCompile) {
    // cache should be first in the asar
    fileSets.unshift(await compileUsingElectronCompile(mainFileSet, packager))
  }
  return fileSets
}
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:29,代碼來源:AppFileCopierHelper.ts

示例3: reactCra

export async function reactCra(projectDir: string): Promise<Config> {
  if ((await statOrNull(path.join(projectDir, "public", "electron.js"))) == null) {
    warn("public/electron.js not found. Please see https://medium.com/@kitze/%EF%B8%8F-from-react-to-an-electron-app-ready-for-production-a0468ecb1da3")
  }

  return {
    directories: {
      buildResources: "assets"
    },
    files: ["build/**/*"],
    extraMetadata: {
      main: "build/electron.js"
    }
  }}
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:14,代碼來源:rectCra.ts

示例4: downloadCertificate

export async function downloadCertificate(urlOrBase64: string, tmpDir: TmpDir, currentDir: string): Promise<string> {
  urlOrBase64 = urlOrBase64.trim()

  let file: string | null = null
  if ((urlOrBase64.length > 3 && urlOrBase64[1] === ":") || urlOrBase64.startsWith("/") || urlOrBase64.startsWith(".")) {
    file = urlOrBase64
  }
  else if (urlOrBase64.startsWith("file://")) {
    file = urlOrBase64.substring("file://".length)
  }
  else if (urlOrBase64.startsWith("~/")) {
    file = path.join(homedir(), urlOrBase64.substring("~/".length))
  }
  else {
    const isUrl = urlOrBase64.startsWith("https://")
    if (isUrl || urlOrBase64.length > 2048 || urlOrBase64.endsWith("=")) {
      const tempFile = await tmpDir.getTempFile(".p12")
      if (isUrl) {
        await httpExecutor.download(urlOrBase64, tempFile)
      }
      else {
        await outputFile(tempFile, new Buffer(urlOrBase64, "base64"))
      }
      return tempFile
    }
    else {
      file = urlOrBase64
    }
  }

  file = path.resolve(currentDir, file)
  const stat = await statOrNull(file)
  if (stat == null) {
    throw new Error(`${file} doesn't exist`)
  }
  else if (!stat.isFile()) {
    throw new Error(`${file} not a file`)
  }
  else {
    return file
  }
}
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:42,代碼來源:codeSign.ts

示例5: unpack

async function unpack(packager: PlatformPackager<any>, out: string, platform: string, options: InternalElectronDownloadOptions) {
  let dist: string | null | undefined = packager.config.electronDist
  if (dist != null) {
    const zipFile = `electron-v${options.version}-${platform}-${options.arch}.zip`
    const resolvedDist = path.resolve(packager.projectDir, dist)
    if ((await statOrNull(path.join(resolvedDist, zipFile))) != null) {
      options.cache = resolvedDist
      dist = null
    }
  }

  if (dist == null) {
    const zipPath = (await BluebirdPromise.all<any>([
      downloadElectron(options),
      emptyDir(out)
    ]))[0]

    await spawn(path7za, debug7zArgs("x").concat(zipPath, `-o${out}`))
  }
  else {
    const source = packager.getElectronSrcDir(dist)
    const destination = packager.getElectronDestinationDir(out)
    log(`Copying Electron from "${source}" to "${destination}"`)
    await emptyDir(out)
    await copyDir(source, destination, null, null, DO_NOT_USE_HARD_LINKS)
  }

  if (platform === "linux") {
    // https://github.com/electron-userland/electron-builder/issues/786
    // fix dir permissions — opposite to extract-zip, 7za creates dir with no-access for other users, but dir must be readable for non-root users
    await BluebirdPromise.all([
      chmod(path.join(out, "locales"), "0755"),
      chmod(path.join(out, "resources"), "0755")
    ])
  }
}
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:36,代碼來源:dirPackager.ts


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