本文整理匯總了TypeScript中fs-extra-p.Stats類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Stats類的具體用法?TypeScript Stats怎麽用?TypeScript Stats使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Stats類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: copy
async copy(src: string, dest: string, stat: Stats | undefined) {
if (this.transformer != null && stat != null && stat.isFile()) {
let data = this.transformer(src)
if (data != null) {
if (typeof (data as any).then === "function") {
data = await data
}
if (data != null) {
await writeFile(dest, data)
return
}
}
}
const isUseHardLink = (!this.isUseHardLink || this.isUseHardLinkFunction == null) ? this.isUseHardLink : this.isUseHardLinkFunction(dest)
await copyOrLinkFile(src, dest, stat, isUseHardLink, isUseHardLink ? () => {
// files are copied concurrently, so, we must not check here currentIsUseHardLink — our code can be executed after that other handler will set currentIsUseHardLink to false
if (this.isUseHardLink) {
this.isUseHardLink = false
return true
}
else {
return false
}
} : null)
}
示例2: copy
async copy(src: string, dest: string, stat: Stats | undefined) {
try {
if (this.transformer != null && stat != null && stat.isFile()) {
let data = this.transformer(src)
if (data != null) {
if (typeof (data as any).then === "function") {
data = await data
}
if (data != null) {
await writeFile(dest, data)
return
}
}
}
await copyOrLinkFile(src, dest, stat, (!this.isUseHardLink || this.isUseHardLinkFunction == null) ? this.isUseHardLink : this.isUseHardLinkFunction(dest))
}
catch (e) {
// files are copied concurrently, so, we must not check here currentIsUseHardLink — our code can be executed after that other handler will set currentIsUseHardLink to false
if (e.code === "EXDEV") {
// ...but here we want to avoid excess debug log message
if (this.isUseHardLink) {
debug(`Cannot copy using hard link: ${e}`)
this.isUseHardLink = false
}
await copyOrLinkFile(src, dest, stat, false)
}
else {
throw e
}
}
}
示例3: minimatchAll
// https://github.com/joshwnj/minimatch-all/blob/master/index.js
function minimatchAll(path: string, patterns: Array<Minimatch>, stat: Stats): boolean {
let match = false
for (const pattern of patterns) {
// If we've got a match, only re-test for exclusions.
// if we don't have a match, only re-test for inclusions.
if (match !== pattern.negate) {
continue
}
// partial match — pattern: foo/bar.txt path: foo — we must allow foo
// use it only for non-negate patterns: const m = new Minimatch("!node_modules/@(electron-download|electron)/**/*", {dot: true }); m.match("node_modules", true) will return false, but must be true
match = pattern.match(path, stat.isDirectory() && !pattern.negate)
}
return match
}
示例4: copy
async copy(src: string, dest: string, stat: Stats | undefined) {
let afterCopyTransformer: AfterCopyFileTransformer | null = null
if (this.transformer != null && stat != null && stat.isFile()) {
let data = this.transformer(src)
if (data != null) {
if (typeof data === "object" && "then" in data) {
data = await data
}
if (data != null) {
if (data instanceof CopyFileTransformer) {
afterCopyTransformer = data.afterCopyTransformer
}
else {
await writeFile(dest, data)
return
}
}
}
}
const isUseHardLink = afterCopyTransformer == null && ((!this.isUseHardLink || this.isUseHardLinkFunction == null) ? this.isUseHardLink : this.isUseHardLinkFunction(dest))
await copyOrLinkFile(src, dest, stat, isUseHardLink, isUseHardLink ? () => {
// files are copied concurrently, so, we must not check here currentIsUseHardLink — our code can be executed after that other handler will set currentIsUseHardLink to false
if (this.isUseHardLink) {
this.isUseHardLink = false
return true
}
else {
return false
}
} : null)
if (afterCopyTransformer != null) {
await afterCopyTransformer(dest)
}
}
示例5: isDirectory
async isDirectory() {
const info: Stats = await stat(this.actual)
if (!info.isDirectory()) {
throw new Error(`Path ${this.actual} is not a directory`)
}
}
示例6: isFile
async isFile() {
const info: Stats = await stat(this.actual)
if (!info.isFile()) {
throw new Error(`Path ${this.actual} is not a file`)
}
}
示例7: packageInDistributableFormat
async packageInDistributableFormat(outDir: string, appOutDir: string, arch: string): Promise<any> {
let iconUrl = this.devMetadata.build.iconUrl
if (!iconUrl) {
if (this.customBuildOptions != null) {
iconUrl = this.customBuildOptions.iconUrl
}
if (!iconUrl) {
if (this.info.repositoryInfo != null) {
const info = await this.info.repositoryInfo.getInfo(this)
if (info != null) {
iconUrl = `https://raw.githubusercontent.com/${info.user}/${info.project}/master/${this.relativeBuildResourcesDirname}/icon.ico`
}
}
if (!iconUrl) {
throw new Error("iconUrl is not specified, please see https://github.com/electron-userland/electron-builder#in-short")
}
}
}
const certificateFile = await this.certFilePromise
const version = this.metadata.version
const installerOutDir = WinPackager.computeDistOut(outDir, arch)
const archSuffix = arch === "x64" ? "" : ("-" + arch)
const options = Object.assign({
name: this.metadata.name,
productName: this.appName,
exe: this.appName + ".exe",
title: this.appName,
appDirectory: appOutDir,
outputDirectory: installerOutDir,
version: version,
description: this.metadata.description,
authors: this.metadata.author.name,
iconUrl: iconUrl,
setupIcon: path.join(this.buildResourcesDir, "icon.ico"),
certificateFile: certificateFile,
certificatePassword: this.options.cscKeyPassword,
fixUpPaths: false,
usePackageJson: false,
noMsi: true,
}, this.customBuildOptions)
try {
await require("electron-winstaller-fixed").createWindowsInstaller(options)
}
catch (e) {
if (!e.message.includes("Unable to set icon")) {
throw e
}
else {
let fileInfo: Stats
try {
fileInfo = await stat(options.setupIcon)
}
catch (e) {
throw new Error("Please specify correct setupIcon, file " + options.setupIcon + " not found")
}
if (fileInfo.isDirectory()) {
throw new Error("Please specify correct setupIcon, " + options.setupIcon + " is a directory")
}
}
}
const releasesFile = path.join(installerOutDir, "RELEASES")
const nupkgPathOriginal = this.metadata.name + "-" + version + "-full.nupkg"
const nupkgPathWithArch = this.metadata.name + "-" + version + archSuffix + "-full.nupkg"
async function changeFileNameInTheReleasesFile(): Promise<void> {
const data = (await readFile(releasesFile, "utf8")).replace(new RegExp(" " + nupkgPathOriginal + " ", "g"), " " + nupkgPathWithArch + " ")
await writeFile(releasesFile, data)
}
const promises: Array<Promise<any>> = [
rename(path.join(installerOutDir, "Setup.exe"), path.join(installerOutDir, `${this.appName}Setup-${version}${archSuffix}.exe`))
.then(it => this.dispatchArtifactCreated(it, `${this.metadata.name}Setup-${version}${archSuffix}.exe`)),
]
if (archSuffix === "") {
this.dispatchArtifactCreated(path.join(installerOutDir, nupkgPathOriginal))
this.dispatchArtifactCreated(path.join(installerOutDir, "RELEASES"))
}
else {
promises.push(
rename(path.join(installerOutDir, nupkgPathOriginal), path.join(installerOutDir, nupkgPathWithArch))
.then(it => this.dispatchArtifactCreated(it))
)
promises.push(
changeFileNameInTheReleasesFile()
.then(() => copy(releasesFile, path.join(installerOutDir, "RELEASES-ia32")))
.then(it => this.dispatchArtifactCreated(it))
)
}
await BluebirdPromise.all(promises)
}