本文整理汇总了TypeScript中builder-util/out/fs.statOrNull函数的典型用法代码示例。如果您正苦于以下问题:TypeScript statOrNull函数的具体用法?TypeScript statOrNull怎么用?TypeScript statOrNull使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了statOrNull函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 InvalidConfigurationError(`Application directory ${userAppDir} doesn't exist`)
}
else if (!stat.isDirectory()) {
throw new InvalidConfigurationError(`Application directory ${userAppDir} is not a directory`)
}
else if (projectDir === absolutePath) {
log.warn({appDirectory: userAppDir}, `Specified application directory 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:electron-userland,项目名称:electron-builder,代码行数:26,代码来源:config.ts
示例2: 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
}
开发者ID:jwheare,项目名称:electron-builder,代码行数:29,代码来源:AppFileCopierHelper.ts
示例3: checkFileInArchive
export async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) {
function error(text: string) {
return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`)
}
let fs
try {
fs = await readAsar(asarFile)
}
catch (e) {
throw error(`is corrupted: ${e}`)
}
let stat: Node | null
try {
stat = fs.getFile(relativeFile)
}
catch (e) {
const fileStat = await statOrNull(asarFile)
if (fileStat == null) {
throw error(`does not exist. Seems like a wrong configuration.`)
}
// asar throws error on access to undefined object (info.link)
stat = null
}
if (stat == null) {
throw error(`does not exist. Seems like a wrong configuration.`)
}
if (stat.size === 0) {
throw error(`is corrupted: size 0`)
}
}
开发者ID:electron-userland,项目名称:electron-builder,代码行数:34,代码来源:asarFileChecker.ts
示例4: isFile
async isFile() {
const info = await statOrNull(this.actual)
if (info == null) {
throw new Error(`Path ${this.actual} doesn't exist`)
}
if (!info.isFile()) {
throw new Error(`Path ${this.actual} is not a file`)
}
}
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:9,代码来源:fileAssert.ts
示例5: isDirectory
async isDirectory() {
const file = this.actual
const info = await statOrNull(file)
if (info == null) {
throw new Error(`Path ${file} doesn't exist`)
}
if (!info.isDirectory()) {
throw new Error(`Path ${file} is not a directory`)
}
}
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:10,代码来源:fileAssert.ts
示例6: reactCra
export async function reactCra(projectDir: string): Promise<Configuration> {
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:jwheare,项目名称:electron-builder,代码行数:14,代码来源:rectCra.ts
示例7: 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>([
packager.info.electronDownloader(options),
emptyDir(out)
]))[0]
if (process.platform === "darwin" || isEnvTrue(process.env.USE_UNZIP)) {
// on mac unzip faster than 7za (1.1 sec vs 1.6 see)
await exec("unzip", ["-oqq", "-d", out, zipPath])
}
else {
await spawn(path7za, debug7zArgs("x").concat(zipPath, "-aoa", `-o${out}`))
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")
])
}
}
}
else {
const source = packager.getElectronSrcDir(dist)
const destination = packager.getElectronDestinationDir(out)
log.info({source, destination}, "copying Electron")
await emptyDir(out)
await copyDir(source, destination, {
isUseHardLink: DO_NOT_USE_HARD_LINKS,
})
}
}
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:43,代码来源:dirPackager.ts
示例8: 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({suffix: ".p12"})
if (isUrl) {
await download(urlOrBase64, tempFile)
}
else {
await outputFile(tempFile, Buffer.from(urlOrBase64, "base64"))
}
return tempFile
}
else {
file = urlOrBase64
}
}
file = path.resolve(currentDir, file)
const stat = await statOrNull(file)
if (stat == null) {
throw new InvalidConfigurationError(`${file} doesn't exist`)
}
else if (!stat.isFile()) {
throw new InvalidConfigurationError(`${file} not a file`)
}
else {
return file
}
}
开发者ID:electron-userland,项目名称:electron-builder,代码行数:42,代码来源:codesign.ts
示例9: 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
}
开发者ID:electron-userland,项目名称:electron-builder,代码行数:24,代码来源:appFileCopier.ts
示例10: 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, "-aoa", `-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:jwheare,项目名称:electron-builder,代码行数:36,代码来源:dirPackager.ts
示例11: 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
}
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:68,代码来源:AppFileCopierHelper.ts
注:本文中的builder-util/out/fs.statOrNull函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论