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


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

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


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

示例1: createSelfSignedCert

export async function createSelfSignedCert(publisher: string) {
  const tmpDir = new TmpDir()
  const targetDir = process.cwd()
  const tempPrefix = path.join(await tmpDir.getTempDir({prefix: "self-signed-cert-creator"}), sanitizeFileName(publisher))
  const cer = `${tempPrefix}.cer`
  const pvk = `${tempPrefix}.pvk`

  log.info(chalk.bold('When asked to enter a password ("Create Private Key Password"), please select "None".'))

  try {
    await ensureDir(path.dirname(tempPrefix))
    const vendorPath = path.join(await getSignVendorPath(), "windows-10", process.arch)
    await exec(path.join(vendorPath, "makecert.exe"),
      ["-r", "-h", "0", "-n", `CN=${quoteString(publisher)}`, "-eku", "1.3.6.1.5.5.7.3.3", "-pe", "-sv", pvk, cer])

    const pfx = path.join(targetDir, `${sanitizeFileName(publisher)}.pfx`)
    await unlinkIfExists(pfx)
    await exec(path.join(vendorPath, "pvk2pfx.exe"), ["-pvk", pvk, "-spc", cer, "-pfx", pfx])
    log.info({file: pfx}, `created. Please see https://electron.build/code-signing how to use it to sign.`)

    const certLocation = "Cert:\\LocalMachine\\TrustedPeople"
    log.info({file: pfx, certLocation}, `importing. Operation will be succeed only if runned from root. Otherwise import file manually.`)
    await spawn("powershell.exe", ["Import-PfxCertificate", "-FilePath", `"${pfx}"`, "-CertStoreLocation", ""])
  }
  finally {
    await tmpDir.cleanup()
  }
}
開發者ID:ledinhphuong,項目名稱:electron-builder,代碼行數:28,代碼來源:create-self-signed-cert.ts

示例2: download

  async download(url: string, destination: string, options?: DownloadOptions | null): Promise<string> {
    if (options == null || !options.skipDirCreation) {
      await ensureDir(path.dirname(destination))
    }

    if (this.httpsAgentPromise == null) {
      this.httpsAgentPromise = createAgent()
    }

    const agent = await this.httpsAgentPromise
    return await new BluebirdPromise<string>((resolve, reject) => {
      const parsedUrl = parseUrl(url)
      this.doDownload(configureRequestOptions({
        hostname: parsedUrl.hostname,
        path: parsedUrl.path,
        headers: (options == null ? null : options.headers) || undefined,
        agent: agent,
      }), destination, 0, options || {}, (error: Error) => {
        if (error == null) {
          resolve(destination)
        }
        else {
          reject(error)
        }
      })
    })
  }
開發者ID:mbrainiac,項目名稱:electron-builder,代碼行數:27,代碼來源:nodeHttpExecutor.ts

示例3: download

  async download(url: string, destination: string, options: DownloadOptions = {cancellationToken: new CancellationToken()}): Promise<string> {
    if (!options.skipDirCreation) {
      await ensureDir(path.dirname(destination))
    }

    if (this.httpsAgentPromise == null) {
      this.httpsAgentPromise = createAgent()
    }

    const agent = await this.httpsAgentPromise
    return await options.cancellationToken.createPromise<string>((resolve, reject, onCancel) => {
      const parsedUrl = parseUrl(url)
      this.doDownload(configureRequestOptions({
        hostname: parsedUrl.hostname,
        path: parsedUrl.path,
        headers: options.headers || undefined,
        agent,
      }), destination, 0, options, (error: Error) => {
        if (error == null) {
          resolve(destination)
        }
        else {
          reject(error)
        }
      }, onCancel)
    })
  }
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:27,代碼來源:nodeHttpExecutor.ts

示例4: prepareWine

  async prepareWine(wineDir: string) {
    await emptyDir(wineDir)
    //noinspection SpellCheckingInspection
    const env = Object.assign({}, process.env, {
      WINEDLLOVERRIDES: "winemenubuilder.exe=d",
      WINEPREFIX: wineDir
    })

    await exec("wineboot", ["--init"], {env: env})

    // regedit often doesn't modify correctly
    let systemReg = await readFile(path.join(wineDir, "system.reg"), "utf8")
    systemReg = systemReg.replace('"CSDVersion"="Service Pack 3"', '"CSDVersion"=" "')
    systemReg = systemReg.replace('"CurrentBuildNumber"="2600"', '"CurrentBuildNumber"="10240"')
    systemReg = systemReg.replace('"CurrentVersion"="5.1"', '"CurrentVersion"="10.0"')
    systemReg = systemReg.replace('"ProductName"="Microsoft Windows XP"', '"ProductName"="Microsoft Windows 10"')
    systemReg = systemReg.replace('"CSDVersion"=dword:00000300', '"CSDVersion"=dword:00000000')
    await writeFile(path.join(wineDir, "system.reg"), systemReg)

    // remove links to host OS
    const desktopDir = path.join(this.userDir, "Desktop")
    await BluebirdPromise.all([
      unlinkIfExists(desktopDir),
      unlinkIfExists(path.join(this.userDir, "My Documents")),
      unlinkIfExists(path.join(this.userDir, "My Music")),
      unlinkIfExists(path.join(this.userDir, "My Pictures")),
      unlinkIfExists(path.join(this.userDir, "My Videos")),
    ])

    await ensureDir(desktopDir)
    return env
  }
開發者ID:mbrainiac,項目名稱:electron-builder,代碼行數:32,代碼來源:wine.ts

示例5: ensureDir

 await BluebirdPromise.each(dirToCreate.get(parentDir)!, (it): any => {
   if (dirToCreate.has(parentDir + path.sep + it)) {
     // already created
     return null
   }
   else {
     return ensureDir(base + path.sep + it)
   }
 })
開發者ID:ledinhphuong,項目名稱:electron-builder,代碼行數:9,代碼來源:unpackDetector.ts

示例6: doFlat

  //noinspection JSMethodCanBeStatic
  protected async doFlat(appPath: string, outFile: string, identity: Identity, keychain: string | n): Promise<any> {
    // productbuild doesn't created directory for out file
    await ensureDir(path.dirname(outFile))

    const args = prepareProductBuildArgs(identity, keychain)
    args.push("--component", appPath, "/Applications")
    args.push(outFile)
    return await exec("productbuild", args)
  }
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:10,代碼來源:macPackager.ts

示例7: doDownload

function doDownload(url: string, destination: string, redirectCount: number, callback: (error: Error) => void) {
  const ensureDirPromise = ensureDir(path.dirname(destination))

  const parsedUrl = parseUrl(url)
  // user-agent must be specified, otherwise some host can return 401 unauthorised
  const request = https.request({
    hostname: parsedUrl.hostname,
    path: parsedUrl.path,
    headers: {
      "User-Agent": "electron-builder"
    }
  }, (response: IncomingMessage) => {
    if (response.statusCode >= 400) {
      callback(new Error("Request error, status " + response.statusCode + ": " + response.statusMessage))
      return
    }

    const redirectUrl = response.headers.location
    if (redirectUrl != null) {
      if (redirectCount < maxRedirects) {
        doDownload(redirectUrl, destination, redirectCount++, callback)
      }
      else {
        callback(new Error("Too many redirects (> " + maxRedirects + ")"))
      }
      return
    }

    ensureDirPromise
      .then(() => {
        const downloadStream = createWriteStream(destination)
        response.pipe(downloadStream)
        downloadStream.on("finish", () => downloadStream.close(callback))
      })
      .catch(callback)

    let ended = false
    response.on("end", () => {
      ended = true
    })

    response.on("close", () => {
      if (!ended) {
        callback(new Error("Request aborted"))
      }
    })
  })
  addTimeOutHandler(request, callback)
  request.on("error", callback)
  request.end()
}
開發者ID:MatthijsvandenBosch,項目名稱:electron-builder,代碼行數:51,代碼來源:httpRequest.ts

示例8: copyAppFiles

export async function copyAppFiles(fileSet: FileSet, packager: Packager) {
  const metadata = fileSet.metadata
  const transformedFiles = fileSet.transformedFiles
  // search auto unpacked dir
  const unpackedDirs = new Set<string>()
  const taskManager = new AsyncTaskManager(packager.cancellationToken)
  const dirToCreateForUnpackedFiles = new Set<string>(unpackedDirs)

  const fileCopier = new FileCopier()
  const links: Array<Link> = []
  for (let i = 0, n = fileSet.files.length; i < n; i++) {
    const file = fileSet.files[i]
    const stat = metadata.get(file)
    if (stat == null) {
      // dir
      continue
    }

    const relativePath = file.replace(fileSet.src, fileSet.destination)
    if (stat.isFile()) {
      const fileParent = path.dirname(file)
      // const dirNode = this.fs.getOrCreateNode(this.getRelativePath(fileParent))

      const newData = transformedFiles == null ? null : transformedFiles[i] as string | Buffer
      if (newData != null) {
        transformedFiles[i] = null
      }

      if (!dirToCreateForUnpackedFiles.has(fileParent)) {
        dirToCreateForUnpackedFiles.add(fileParent)
        await ensureDir(fileParent.replace(fileSet.src, fileSet.destination))
      }

      taskManager.addTask(copyFileOrData(fileCopier, newData, file, relativePath, stat))
      if (taskManager.tasks.length > MAX_FILE_REQUESTS) {
        await taskManager.awaitTasks()
      }
    }
    else if (stat.isSymbolicLink()) {
      links.push({file: relativePath, link: await readlink(file)})
    }
  }

  if (taskManager.tasks.length > MAX_FILE_REQUESTS) {
    await taskManager.awaitTasks()
  }
  if (links.length > 0) {
    BluebirdPromise.map(links, it => symlink(it.link, it.file), CONCURRENCY)
  }
}
開發者ID:yuya-oc,項目名稱:electron-builder,代碼行數:50,代碼來源:appFileCopier.ts

示例9: upload

  // http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-creating-buckets.html
  async upload(task: UploadTask): Promise<any> {
    const fileName = path.basename(task.file)
    const cancellationToken = this.context.cancellationToken

    const target = (this.options.path == null ? "" : `${this.options.path}/`) + fileName

    if (process.env.__TEST_S3_PUBLISHER__ != null) {
      const testFile = path.join(process.env.__TEST_S3_PUBLISHER__!, target)
      await ensureDir(path.dirname(testFile))
      await symlink(task.file, testFile)
      return
    }

    const s3Options: CreateMultipartUploadRequest  = {
      Key: target,
      Bucket: this.getBucketName(),
      ContentType: mime.getType(task.file) || "application/octet-stream"
    }
    this.configureS3Options(s3Options)

    const contentLength = task.fileContent == null ? (await stat(task.file)).size : task.fileContent.length
    const uploader = new Uploader(new S3(this.createClientConfiguration()), s3Options, task.file, contentLength, task.fileContent)

    const progressBar = this.createProgressBar(fileName, uploader.contentLength)
    if (progressBar != null) {
      const callback = new ProgressCallback(progressBar)
      uploader.on("progress", () => {
        if (!cancellationToken.cancelled) {
          callback.update(uploader.loaded, uploader.contentLength)
        }
      })
    }

    return await cancellationToken.createPromise((resolve, reject, onCancel) => {
      onCancel(() => uploader.abort())
      uploader.upload()
        .then(() => {
          try {
            log.debug({provider: this.providerName, file: fileName, bucket: this.getBucketName()}, "uploaded")
          }
          finally {
            resolve()
          }
        })
        .catch(reject)
    })
  }
開發者ID:ledinhphuong,項目名稱:electron-builder,代碼行數:48,代碼來源:BaseS3Publisher.ts


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