本文整理汇总了TypeScript中builder-util/out/fs.walk函数的典型用法代码示例。如果您正苦于以下问题:TypeScript walk函数的具体用法?TypeScript walk怎么用?TypeScript walk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了walk函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: computeFileSets
export async function computeFileSets(matchers: Array<FileMatcher>, transformer: FileTransformer, packager: Packager, isElectronCompile: boolean): Promise<Array<ResolvedFileSet>> {
const fileSets: Array<ResolvedFileSet> = []
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
}
示例2: encodedZip
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("/")) {
const tempFile = await packager.getTempFile("stub.exe")
await copyFile(path.join(vendorPath, "StubExecutable.exe"), tempFile)
await execWine(path.join(vendorPath, "WriteZipToSetup.exe"), null, ["--copy-stub-resources", file, tempFile])
await packager.sign(tempFile)
archive._append(tempFile, {
name: relativeSafeFilePath.substring(0, relativeSafeFilePath.length - 4) + "_ExecutionStub.exe",
prefix,
stats: await stat(tempFile),
})
}
}
})
archive.finalize()
}
示例3: verifySmartUnpack
async function verifySmartUnpack(resourceDir: string) {
const fs = await readAsar(path.join(resourceDir, "app.asar"))
expect(await fs.readJson("node_modules/debug/package.json")).toMatchObject({
name: "debug"
})
expect(removeUnstableProperties(fs.header)).toMatchSnapshot()
expect((await walk(resourceDir, file => !path.basename(file).startsWith("."))).map(it => it.substring(resourceDir.length + 1))).toMatchSnapshot()
}
示例4: verifySmartUnpack
async function verifySmartUnpack(resourceDir: string) {
const fs = await readAsar(path.join(resourceDir, "app.asar"))
expect(await fs.readJson("node_modules/debug/package.json")).toMatchObject({
name: "debug"
})
expect(removeUnstableProperties(fs.header)).toMatchSnapshot()
const files = (await walk(resourceDir, file => !path.basename(file).startsWith(".")))
.map(it => {
const name = it.substring(resourceDir.length + 1)
if (it.endsWith("package.json")) {
return {name, content: readFileSync(it, "utf-8")}
}
return name
})
expect(files).toMatchSnapshot()
}
示例5: compileUsingElectronCompile
async function compileUsingElectronCompile(mainFileSet: ResolvedFileSet, packager: Packager): Promise<ResolvedFileSet> {
log("Compiling using electron-compile")
const electronCompileCache = await packager.tempDirManager.getTempDir({prefix: "electron-compile-cache"})
const cacheDir = path.join(electronCompileCache, ".cache")
// clear and create cache dir
await ensureDir(cacheDir)
const compilerHost = await createElectronCompilerHost(mainFileSet.src, cacheDir)
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((it: any) => null)
}, CONCURRENCY)
await compilerHost.saveConfiguration()
const metadata = new Map<string, Stats>()
const cacheFiles = await walk(cacheDir, (file, stat) => !file.startsWith("."), {
consume: (file, fileStat) => {
if (fileStat.isFile()) {
metadata.set(file, fileStat)
}
return null
}
})
// add shim
const shimPath = `${mainFileSet.src}/${ELECTRON_COMPILE_SHIM_FILENAME}`
cacheFiles.push(shimPath)
metadata.set(shimPath, {isFile: () => true, isDirectory: () => false} as any)
const transformedFiles = new Array(cacheFiles.length)
transformedFiles[cacheFiles.length - 1] = `
'use strict';
require('electron-compile').init(__dirname, require('path').resolve(__dirname, '${packager.metadata.main || "index"}'), true);
`
// cache files should be first (better IO)
return {src: electronCompileCache, files: cacheFiles, transformedFiles, metadata, destination: mainFileSet.destination}
}
示例6: computeFileSets
export async function computeFileSets(matchers: Array<FileMatcher>, transformer: FileTransformer | null, platformPackager: PlatformPackager<any>, isElectronCompile: boolean): Promise<Array<ResolvedFileSet>> {
const fileSets: Array<ResolvedFileSet> = []
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
}
示例7: listFiles
function listFiles() {
return walk(driveC, null, {consume: walkFilter})
}
示例8: checkDirContents
export async function checkDirContents(dir: string) {
expect((await walk(dir, file => !path.basename(file).startsWith("."))).map(it => it.substring(dir.length + 1))).toMatchSnapshot()
}
示例9: computeFileSets
export async function computeFileSets(matchers: Array<FileMatcher>, transformer: FileTransformer, packager: Packager, isElectronCompile: boolean): Promise<Array<ResolvedFileSet>> {
const fileSets: Array<ResolvedFileSet> = []
let hoistedNodeModuleFileSets: Array<ResolvedFileSet> | null = null
let isHoistedNodeModuleChecked = false
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
// https://github.com/electron-userland/electron-builder/issues/2205 Support for hoisted node_modules (lerna + yarn workspaces)
// if no node_modules in the app dir, it means that probably dependencies are hoisted
// check that main node_modules doesn't exist in addition to isNodeModulesHandled because isNodeModulesHandled will be false if node_modules dir is ignored by filter
// here isNodeModulesHandled is required only because of performance reasons (avoid stat call)
if (!isHoistedNodeModuleChecked && matcher.from === packager.appDir && !fileWalker.isNodeModulesHandled) {
isHoistedNodeModuleChecked = true
if ((await statOrNull(path.join(packager.appDir, "node_modules"))) == null) {
// in the prepacked mode no package.json
const packageJsonStat = await statOrNull(path.join(packager.appDir, "package.json"))
if (packageJsonStat != null && packageJsonStat.isFile()) {
hoistedNodeModuleFileSets = await copyHoistedNodeModules(packager, matcher)
}
}
}
const transformedFiles = new Map<number, string | Buffer>()
await BluebirdPromise.filter(files, (it, index) => {
const fileStat = metadata.get(it)
if (fileStat == null || !fileStat.isFile()) {
return false
}
const transformedValue = transformer(it)
if (transformedValue == null) {
return false
}
if (typeof transformedValue === "object" && "then" in transformedValue) {
return (transformedValue as BluebirdPromise<any>)
.then(it => {
if (it != null) {
transformedFiles.set(index, it)
}
return false
})
}
transformedFiles.set(index, transformedValue as string | Buffer)
return false
}, CONCURRENCY)
fileSets.push({src: matcher.from, files, metadata, transformedFiles, destination: matcher.to})
}
if (isElectronCompile) {
// cache files should be first (better IO)
fileSets.unshift(await compileUsingElectronCompile(fileSets[0], packager))
}
if (hoistedNodeModuleFileSets != null) {
return fileSets.concat(hoistedNodeModuleFileSets)
}
return fileSets
}