How to use the builder-util/out/fs.walk function in builder-util

To help you get started, we’ve selected a few builder-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github electron-userland / electron-builder / packages / app-builder-lib / src / util / appFileCopier.ts View on Github external
export async function computeFileSets(matchers: Array, transformer: FileTransformer | null, platformPackager: PlatformPackager, isElectronCompile: boolean): Promise> {
  const fileSets: Array = []
  const packager = platformPackager.info

  for (const matcher of matchers) {
    const fileWalker = new AppFileWalker(matcher, packager)

    const fromStat = await statOrNull(matcher.from)
    if (fromStat == null) {
      log.debug({directory: matcher.from, reason: "doesn't exist"}, `skipped copying`)
      continue
    }

    const files = await walk(matcher.from, fileWalker.filter, fileWalker)
    const metadata = fileWalker.metadata
    fileSets.push(validateFileSet({src: matcher.from, files, metadata, destination: matcher.to}))
  }

  if (isElectronCompile) {
    // cache files should be first (better IO)
    fileSets.unshift(await compileUsingElectronCompile(fileSets[0], packager))
  }
  return fileSets
}
github electron-userland / electron-builder / packages / electron-builder-squirrel-windows / src / squirrelPack.ts View on Github external
async function encodedZip(archive: any, dir: string, prefix: string, vendorPath: string, packager: WinPackager) {
  await walk(dir, null, {
    isIncludeDir: true,
    consume: async (file, stats) => {
      if (stats.isDirectory()) {
        return
      }

      const relativeSafeFilePath = file.substring(dir.length + 1).replace(/\\/g, "/")
      archive._append(file, {
        name: relativeSafeFilePath,
        prefix,
        stats,
      })

      // createExecutableStubForExe
      // https://github.com/Squirrel/Squirrel.Windows/pull/1051 Only generate execution stubs for the top-level executables
      if (file.endsWith(".exe") && !file.includes("squirrel.exe") && !relativeSafeFilePath.includes("/")) {
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / AppxTarget.ts View on Github external
const vendorPath = await getSignVendorPath()
    const vm = await packager.vm.value

    const stageDir = await createStageDir(this, packager, arch)

    const mappingFile = stageDir.getTempFile("mapping.txt")
    const makeAppXArgs = ["pack", "/o" /* overwrite the output file if it exists */,
      "/f", vm.toVmFile(mappingFile),
      "/p", vm.toVmFile(artifactPath),
    ]
    if (packager.compression === "store") {
      makeAppXArgs.push("/nc")
    }

    const mappingList: Array> = []
    mappingList.push(await BluebirdPromise.map(walk(appOutDir), file => {
      let appxPath = file.substring(appOutDir.length + 1)
      if (path.sep !== "\\") {
        appxPath = appxPath.replace(/\//g, "\\")
      }
      return `"${vm.toVmFile(file)}" "app\\${appxPath}"`
    }))

    const userAssetDir = await this.packager.getResource(undefined, APPX_ASSETS_DIR_NAME)
    const assetInfo = await AppXTarget.computeUserAssets(vm, vendorPath, userAssetDir)
    const userAssets = assetInfo.userAssets

    const manifestFile = stageDir.getTempFile("AppxManifest.xml")
    await this.writeManifest(manifestFile, arch, await this.computePublisherName(), userAssets)
    mappingList.push(assetInfo.mappings)
    mappingList.push([`"${vm.toVmFile(manifestFile)}" "AppxManifest.xml"`])
github electron-userland / electron-builder / packages / electron-builder-lib / src / util / AppFileCopierHelper.ts View on Github external
const nextSlashIndex = mainFileSet.src.length + 1
  // pre-compute electron-compile to cache dir - we need to process only subdirectories, not direct files of app dir
  await BluebirdPromise.map(mainFileSet.files, file => {
    if (file.includes(NODE_MODULES_PATTERN) || file.includes(BOWER_COMPONENTS_PATTERN)
      || !file.includes(path.sep, nextSlashIndex) // ignore not root files
      || !mainFileSet.metadata.get(file)!.isFile()) {
      return null
    }
    return compilerHost.compile(file)
      .then(() => null)
  }, CONCURRENCY)

  await compilerHost.saveConfiguration()

  const metadata = new Map()
  const cacheFiles = await walk(cacheDir, file => !file.startsWith("."), {
    consume: (file, fileStat) => {
      if (fileStat.isFile()) {
        metadata.set(file, fileStat)
      }
      return null
    }
  })

  // add shim
  const shimPath = `${mainFileSet.src}${path.sep}${ELECTRON_COMPILE_SHIM_FILENAME}`
  mainFileSet.files.push(shimPath)
  mainFileSet.metadata.set(shimPath, {isFile: () => true, isDirectory: () => false, isSymbolicLink: () => false} as any)
  if (mainFileSet.transformedFiles == null) {
    mainFileSet.transformedFiles = new Map()
  }
  mainFileSet.transformedFiles.set(mainFileSet.files.length - 1, `
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / MsiTarget.ts View on Github external
private async computeFileDeclaration(appOutDir: string) {
    const appInfo = this.packager.appInfo
    let isRootDirAddedToRemoveTable = false
    const dirNames = new Set()
    const dirs: Array = []
    const fileSpace = " ".repeat(6)
    const commonOptions = getEffectiveOptions(this.options, this.packager)
    const files = await BluebirdPromise.map(walk(appOutDir), file => {
      const packagePath = file.substring(appOutDir.length + 1)

      const lastSlash = packagePath.lastIndexOf(path.sep)
      const fileName = lastSlash > 0 ? packagePath.substring(lastSlash + 1) : packagePath
      let directoryId: string | null = null
      let dirName = ""
      // Wix Directory.FileSource doesn't work - https://stackoverflow.com/questions/21519388/wix-filesource-confusion
      if (lastSlash > 0) {
        // This Name attribute may also define multiple directories using the inline directory syntax.
        // For example, "ProgramFilesFolder:\My Company\My Product\bin" would create a reference to a Directory element with Id="ProgramFilesFolder" then create directories named "My Company" then "My Product" then "bin" nested beneath each other.
        // This syntax is a shortcut to defining each directory in an individual Directory element.
        dirName = packagePath.substring(0, lastSlash)
        // https://github.com/electron-userland/electron-builder/issues/3027
        directoryId = "d" + createHash("md5").update(dirName).digest("base64").replace(/\//g, "_").replace(/\+/g, ".").replace(/=+$/, "")
        if (!dirNames.has(dirName)) {
          dirNames.add(dirName)
github electron-userland / electron-builder / packages / app-builder-lib / src / util / appFileCopier.ts View on Github external
const nextSlashIndex = mainFileSet.src.length + 1
  // pre-compute electron-compile to cache dir - we need to process only subdirectories, not direct files of app dir
  await BluebirdPromise.map(mainFileSet.files, file => {
    if (file.includes(NODE_MODULES_PATTERN) || file.includes(BOWER_COMPONENTS_PATTERN)
      || !file.includes(path.sep, nextSlashIndex) // ignore not root files
      || !mainFileSet.metadata.get(file)!.isFile()) {
      return null
    }
    return compilerHost.compile(file)
      .then(() => null)
  }, CONCURRENCY)

  await compilerHost.saveConfiguration()

  const metadata = new Map()
  const cacheFiles = await walk(cacheDir, file => !file.startsWith("."), {
    consume: (file, fileStat) => {
      if (fileStat.isFile()) {
        metadata.set(file, fileStat)
      }
      return null
    }
  })

  // add shim
  const shimPath = `${mainFileSet.src}${path.sep}${ELECTRON_COMPILE_SHIM_FILENAME}`
  mainFileSet.files.push(shimPath)
  mainFileSet.metadata.set(shimPath, {isFile: () => true, isDirectory: () => false, isSymbolicLink: () => false} as any)
  if (mainFileSet.transformedFiles == null) {
    mainFileSet.transformedFiles = new Map()
  }
  mainFileSet.transformedFiles.set(mainFileSet.files.length - 1, `
github electron-userland / electron-builder / packages / electron-builder-lib / src / util / AppFileCopierHelper.ts View on Github external
export async function computeFileSets(matchers: Array, transformer: FileTransformer | null, platformPackager: PlatformPackager, isElectronCompile: boolean): Promise> {
  const fileSets: Array = []
  const packager = platformPackager.info

  for (const matcher of matchers) {
    const fileWalker = new AppFileWalker(matcher, packager)

    const fromStat = await statOrNull(matcher.from)
    if (fromStat == null) {
      log.debug({directory: matcher.from, reason: "doesn't exist"}, `skipped copying`)
      continue
    }

    const files = await walk(matcher.from, fileWalker.filter, fileWalker)
    const metadata = fileWalker.metadata
    fileSets.push(validateFileSet({src: matcher.from, files, metadata, transformedFiles: await transformFiles(transformer, files, metadata), destination: matcher.to}))
  }

  if (isElectronCompile) {
    // cache files should be first (better IO)
    fileSets.unshift(await compileUsingElectronCompile(fileSets[0], packager))
  }
  return fileSets
}
github electron-userland / electron-builder / test / src / helpers / winHelper.ts View on Github external
function listFiles() {
    return walk(driveC, null, {consume: walkFilter})
  }
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / nsis / NsisTarget.ts View on Github external
async function generateForPreCompressed(preCompressedFileExtensions: Array, dir: string, arch: Arch, scriptGenerator: NsisScriptGenerator) {
  const resourcesDir = path.join(dir, "resources")
  const dirInfo = await statOrNull(resourcesDir)
  if (dirInfo == null || !dirInfo.isDirectory()) {
    return
  }

  const nodeModules = `${path.sep}node_modules`
  const preCompressedAssets = await walk(resourcesDir, (file, stat) => {
    if (stat.isDirectory()) {
      return !file.endsWith(nodeModules)
    }
    else {
      return preCompressedFileExtensions.some(it => file.endsWith(it))
    }
  })

  if (preCompressedAssets.length !== 0) {
    const macro = new NsisScriptGenerator()
    for (const file of preCompressedAssets) {
      macro.file(`$INSTDIR\\${path.relative(dir, file).replace(/\//g, "\\")}`, file)
    }
    scriptGenerator.macro(`customFiles_${Arch[arch]}`, macro)
  }
}