本文整理汇总了TypeScript中fs-extra-p.writeFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript writeFile函数的具体用法?TypeScript writeFile怎么用?TypeScript writeFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writeFile函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: writeFile
projectDirCreated: projectDir => {
return Promise.all([
// writeFile(path.join(projectDir, "build", "license_en.txt"), "Hi"),
writeFile(path.join(projectDir, "build", "license_de.txt"), "Hallo"),
writeFile(path.join(projectDir, "build", "license_ru.txt"), "Привет"),
])
},
示例2: writeFile
projectDirCreated: projectDir => {
return BluebirdPromise.all([
writeFile(path.join(projectDir, "build", "license_en.txt"), "Hi"),
writeFile(path.join(projectDir, "build", "license_ru.txt"), "Привет"),
writeFile(path.join(projectDir, "build", "license_ko.txt"), "Привет"),
writeFile(path.join(projectDir, "build", "license_fi.txt"), "Привет"),
])
},
示例3: 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
}
示例4: 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)
}
示例5: 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
}
}
}
示例6: setPackageVersions
async function setPackageVersions(packageData: Array<any>) {
const versions = await getLatestVersions(packageData)
let publishScript = `#!/usr/bin/env bash
set -e
ln -f README.md packages/electron-builder/README.md
`
for (let i = 0; i < packageData.length; i++) {
const packageMetadata = packageData[i]
const packageName = packageMetadata.name
const versionInfo = versions[i]
const latestVersion = versionInfo.next || versionInfo.latest
if (latestVersion == null || packageMetadata.version === latestVersion || semver.lt(latestVersion, packageMetadata.version)) {
continue
}
packageMetadata.version = latestVersion
console.log(`Set ${packageName} version to ${latestVersion}`)
await writeJson(path.join(packageDir, packageName, "package.json"), packageMetadata, {spaces: 2})
}
for (let i = 0; i < packageData.length; i++) {
const packageMetadata = packageData[i]
const versionInfo = versions[i]
const latestVersion = versionInfo.next || versionInfo.latest
if (latestVersion != null && semver.gt(packageMetadata.version, latestVersion)) {
publishScript += `npm publish packages/${packageMetadata.name}\n`
}
}
await writeFile(path.join(rootDir, "__publish.sh"), publishScript)
}
示例7: createFiles
async function createFiles(appDir: string) {
await BluebirdPromise.all([
outputFile(path.join(appDir, "assets", "file"), "data"),
outputFile(path.join(appDir, "b2", "file"), "data"),
outputFile(path.join(appDir, "do-not-unpack-dir", "file.json"), "{}")
.then(() => writeFile(path.join(appDir, "do-not-unpack-dir", "must-be-not-unpacked"), "{}"))
])
const dir = path.join(appDir, "do-not-unpack-dir", "dir-2", "dir-3", "dir-3")
await mkdirs(dir)
await writeFile(path.join(dir, "file-in-asar"), "{}")
}
示例8: safeLoad
packed: async context => {
const outDir = context.outDir
outDirs.push(outDir)
const targetOutDir = path.join(outDir, "nsis-web")
const updateInfoFile = path.join(targetOutDir, "latest.yml")
const updateInfo: UpdateInfo = safeLoad(await readFile(updateInfoFile, "utf-8"))
const fd = await open(path.join(targetOutDir, `TestApp-${version}-x64.nsis.7z`), "r")
try {
const packageInfo = updateInfo.packages!!.x64
const buffer = Buffer.allocUnsafe(packageInfo.blockMapSize!!)
await read(fd, buffer, 0, buffer.length, packageInfo.size - buffer.length)
const inflateRaw: any = BluebirdPromise.promisify(require("zlib").inflateRaw)
const blockMapData = (await inflateRaw(buffer)).toString()
await writeFile(path.join(outDir, "win-unpacked", BLOCK_MAP_FILE_NAME), blockMapData)
}
finally {
await close(fd)
}
}
示例9: addLicenseToDmg
export async function addLicenseToDmg(packager: PlatformPackager<any>, dmgPath: string) {
// http://www.owsiak.org/?p=700
const licenseFiles = await getLicenseFiles(packager)
if (licenseFiles.length === 0) {
return
}
if (debug.enabled) {
debug(`License files: ${licenseFiles.join(" ")}`)
}
const tempFile = await packager.getTempFile(".r")
let data = await readFile(path.join(__dirname, "..", "..", "templates", "dmg", "license.txt"), "utf8")
let counter = 5000
for (const item of licenseFiles) {
const kind = item.file.toLowerCase().endsWith(".rtf") ? "RTF" : "TEXT"
data += `data '${kind}' (${counter}, "${item.langName} SLA") {\n`
const hex = (await readFile(item.file)).toString("hex").toUpperCase()
for (let i = 0; i < hex.length; i += 32) {
data += '$"' + hex.substring(i, Math.min(i + 32, hex.length)) + '"\n'
}
data += "};\n\n"
// noinspection SpellCheckingInspection
data += `data 'styl' (${counter}, "${item.langName} SLA") {
$"0003 0000 0000 000C 0009 0014 0000 0000"
$"0000 0000 0000 0000 0027 000C 0009 0014"
$"0100 0000 0000 0000 0000 0000 002A 000C"
$"0009 0014 0000 0000 0000 0000 0000"
};`
counter++
}
await writeFile(tempFile, data)
await exec("hdiutil", ["unflatten", dmgPath])
await exec("Rez", ["-a", tempFile, "-o", dmgPath])
await exec("hdiutil", ["flatten", dmgPath])
}
示例10: 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)
}
}