diff --git a/package.json b/package.json index 7770ffd..c7674bf 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "devDependencies": { "@types/debug": "0.0.29", "@types/es6-shim": "^0.31.32", - "@types/fs-extra-promise": "0.0.32", + "@types/fs-extra": "^3.0.0", "@types/node": "^7.0.5", "@types/progress": "^1.1.28", "@types/request": "0.0.41", @@ -46,7 +46,7 @@ "7zip-bin": "^2.0.4", "debug": "^2.6.1", "dir-compare": "^1.3.0", - "fs-extra-promise": "^0.4.1", + "fs-extra": "^3.0.1", "globby": "^6.1.0", "plist": "^2.0.1", "progress": "^1.1.8", diff --git a/src/lib/Builder.ts b/src/lib/Builder.ts index fdca595..6d75174 100644 --- a/src/lib/Builder.ts +++ b/src/lib/Builder.ts @@ -2,7 +2,7 @@ import { dirname, basename, resolve } from 'path'; import * as semver from 'semver'; -import { ensureDirAsync, emptyDir, readFileAsync, readJsonAsync, writeFileAsync, copyAsync, removeAsync, createReadStream, createWriteStream, renameAsync } from 'fs-extra-promise'; +import { ensureDir, emptyDir, readFile, readJson, writeFile, copy, remove, createReadStream, createWriteStream, rename } from 'fs-extra'; import * as Bluebird from 'bluebird'; const debug = require('debug')('build:builder'); @@ -107,7 +107,7 @@ export class Builder { } else { - const pkg: any = await readJsonAsync(resolve(this.dir, this.options.chromeApp ? 'manifest.json' : 'package.json')); + const pkg: any = await readJson(resolve(this.dir, this.options.chromeApp ? 'manifest.json' : 'package.json')); const config = new BuildConfig(pkg); debug('in build', 'config', config); @@ -155,14 +155,14 @@ export class Builder { } protected readPlist(path: string): Promise { - return readFileAsync(path, { + return readFile(path, { encoding: 'utf-8', }) .then(data => plist.parse(data)); } protected writePlist(path: string, p: any) { - return writeFileAsync(path, plist.build(p)); + return writeFile(path, plist.build(p)); } protected updateWinResources(targetDir: string, appRoot: string, pkg: any, config: BuildConfig) { @@ -190,7 +190,7 @@ export class Builder { const src = resolve(targetDir, 'nw.exe'); const dest = resolve(targetDir, `${ config.win.versionStrings.ProductName }.exe`); - return renameAsync(src, dest); + return rename(src, dest); } @@ -218,7 +218,7 @@ export class Builder { return; } - await copyAsync(resolve(this.dir, config.mac.icon), path); + await copy(resolve(this.dir, config.mac.icon), path); } @@ -234,7 +234,7 @@ export class Builder { // Different versions has different encodings for `InforPlist.strings`. // We determine encoding by evaluating bytes of `CF` here. - const data = await readFileAsync(path); + const data = await readFile(path); const encoding = data.indexOf(Buffer.from('43004600', 'hex')) >= 0 ? 'ucs2' : 'utf-8'; @@ -257,7 +257,7 @@ export class Builder { } }); - await writeFileAsync(path, Buffer.from(newStrings, encoding)); + await writeFile(path, Buffer.from(newStrings, encoding)); } @@ -268,7 +268,7 @@ export class Builder { const src = resolve(targetDir, 'nwjs.app'); const dest = resolve(targetDir, `${ config.mac.displayName }.app`); - return renameAsync(src, dest); + return rename(src, dest); } @@ -277,7 +277,7 @@ export class Builder { const src = resolve(targetDir, 'nw'); const dest = resolve(targetDir, `${ pkg.name }`); - return renameAsync(src, dest); + return rename(src, dest); } @@ -349,7 +349,7 @@ export class Builder { await compress(this.dir, files, 'zip', nwFile); const executable = await findExecutable(platform, targetDir); await this.combineExecutable(executable, nwFile); - await removeAsync(nwFile); + await remove(nwFile); break; case 'darwin': case 'osx': @@ -373,7 +373,7 @@ export class Builder { // Here we overwrite `package.json` with a stripped one. - await writeFileAsync(resolve(appRoot, 'package.json'), (() => { + await writeFile(resolve(appRoot, 'package.json'), (() => { const json: any = {}; @@ -411,7 +411,7 @@ export class Builder { const src = await findFFmpeg(platform, ffmpegDir); const dest = await findFFmpeg(platform, targetDir); - await copyAsync(src, dest); + await copy(src, dest); } @@ -447,13 +447,13 @@ export class Builder { })).make(); const script = await tmpName(); - await writeFileAsync(script, data); + await writeFile(script, data); await nsisBuild(toDir, script, { mute: this.options.mute, }); - await removeAsync(script); + await remove(script); await versionInfo.addUpdater(toVersion, fromVersion, arch, diffNsis); @@ -478,11 +478,9 @@ export class Builder { } })()); - await new Promise((resolve, reject) => { - emptyDir(targetDir, err => err ? reject(err) : resolve()); - }); + await emptyDir(targetDir); - await copyAsync(runtimeRoot, targetDir, { + await copy(runtimeRoot, targetDir, { //dereference: true, }); @@ -490,7 +488,7 @@ export class Builder { await this.integrateFFmpeg(platform, arch, targetDir, pkg, config); } - await ensureDirAsync(appRoot); + await ensureDir(appRoot); // Copy before refining might void the effort. @@ -525,7 +523,7 @@ export class Builder { const targetArchive = resolve(dirname(sourceDir), `${ basename(sourceDir) }.${ type }`); - await removeAsync(targetArchive); + await remove(targetArchive); const files = await globby([ '**/*' ], { cwd: sourceDir, @@ -575,13 +573,13 @@ export class Builder { })).make(); const script = await tmpName(); - await writeFileAsync(script, data); + await writeFile(script, data); await nsisBuild(sourceDir, script, { mute: this.options.mute, }); - await removeAsync(script); + await remove(script); await versionInfo.addVersion(pkg.version, '', sourceDir); await versionInfo.addInstaller(pkg.version, arch, targetNsis); @@ -640,13 +638,13 @@ export class Builder { })).make(); const script = await tmpName(); - await writeFileAsync(script, data); + await writeFile(script, data); await nsisBuild(sourceDir, script, { mute: this.options.mute, }); - await removeAsync(script); + await remove(script); await versionInfo.addVersion(pkg.version, '', sourceDir); await versionInfo.addInstaller(pkg.version, arch, targetNsis); diff --git a/src/lib/FFmpegDownloader.ts b/src/lib/FFmpegDownloader.ts index 1f05831..0356eec 100644 --- a/src/lib/FFmpegDownloader.ts +++ b/src/lib/FFmpegDownloader.ts @@ -3,7 +3,6 @@ import { dirname, basename, resolve } from 'path'; import * as request from 'request'; import * as ProgressBar from 'progress'; -import { ensureDirSync, exists, writeFile } from 'fs-extra-promise'; const debug = require('debug')('build:ffmpegDownloader'); const progress = require('request-progress'); diff --git a/src/lib/Runner.ts b/src/lib/Runner.ts index f4e63e4..565b144 100644 --- a/src/lib/Runner.ts +++ b/src/lib/Runner.ts @@ -2,7 +2,7 @@ import { resolve } from 'path'; import { spawn } from 'child_process'; -import { copyAsync, readJsonAsync, chmodAsync } from 'fs-extra-promise'; +import { copy, readJson, chmod } from 'fs-extra'; const debug = require('debug')('build:runner'); @@ -49,7 +49,7 @@ export class Runner { ? (this.options.x86 ? 'ia32' : 'x64') : process.arch; - const pkg: any = await readJsonAsync(resolve(this.args[0], this.options.chromeApp ? 'manifest.json' : 'package.json')); + const pkg: any = await readJson(resolve(this.args[0], this.options.chromeApp ? 'manifest.json' : 'package.json')); const config = new BuildConfig(pkg); debug('in run', 'config', config); @@ -87,7 +87,7 @@ export class Runner { const executable = await findExecutable(platform, runtimeDir); - await chmodAsync(executable, 0o555); + await chmod(executable, 0o555); if(!this.options.mute) { console.info('Launching NW.js app...'); @@ -138,7 +138,7 @@ export class Runner { const src = await findFFmpeg(platform, ffmpegDir); const dest = await findFFmpeg(platform, runtimeDir); - await copyAsync(src, dest); + await copy(src, dest); } diff --git a/src/lib/common/DownloaderBase.ts b/src/lib/common/DownloaderBase.ts index 7a05790..258691e 100644 --- a/src/lib/common/DownloaderBase.ts +++ b/src/lib/common/DownloaderBase.ts @@ -3,7 +3,7 @@ import { dirname, basename, resolve } from 'path'; import * as request from 'request'; import * as ProgressBar from 'progress'; -import { ensureDirSync, exists, lstatAsync, writeFile } from 'fs-extra-promise'; +import { ensureDirSync, exists, lstat, writeFile } from 'fs-extra'; const debug = require('debug')('build:downloader'); const progress = require('request-progress'); @@ -100,7 +100,7 @@ export abstract class DownloaderBase { } protected getLocalSize(path: string): Promise { - return lstatAsync(path) + return lstat(path) .then(stat => stat.size); } diff --git a/src/lib/common/NsisVersionInfo.ts b/src/lib/common/NsisVersionInfo.ts index df9584c..32ccd19 100644 --- a/src/lib/common/NsisVersionInfo.ts +++ b/src/lib/common/NsisVersionInfo.ts @@ -2,7 +2,7 @@ import { basename, dirname, relative } from 'path'; import { createHash } from 'crypto'; -import { exists, readJsonAsync, writeJsonAsync, createReadStream } from 'fs-extra-promise'; +import { exists, readJson, writeJson, createReadStream } from 'fs-extra'; import * as semver from 'semver'; interface IInstaller { @@ -134,14 +134,14 @@ export class NsisVersionInfo { } public async save() { - await writeJsonAsync(this.path, this.data); + await writeJson(this.path, this.data); } protected async getData() { if(!this.data) { this.data = (await new Promise((resolve, reject) => exists(this.path, resolve))) - ? await readJsonAsync(this.path) + ? await readJson(this.path) : { latest: undefined, versions: [], diff --git a/src/lib/nsis-gen/NsisComposer.ts b/src/lib/nsis-gen/NsisComposer.ts index c27161d..316dba6 100644 --- a/src/lib/nsis-gen/NsisComposer.ts +++ b/src/lib/nsis-gen/NsisComposer.ts @@ -1,7 +1,7 @@ import { relative, resolve, win32 } from 'path'; -import { readdirAsync, lstatAsync } from 'fs-extra-promise'; +import { readdir, lstat } from 'fs-extra'; import { fixWindowsVersion } from '../util'; diff --git a/src/lib/util/archive.ts b/src/lib/util/archive.ts index ea124c9..4c69319 100644 --- a/src/lib/util/archive.ts +++ b/src/lib/util/archive.ts @@ -1,7 +1,7 @@ import { dirname, basename, join, resolve, normalize } from 'path'; -import { removeAsync, writeFileAsync } from 'fs-extra-promise'; +import { remove, writeFile } from 'fs-extra'; import { path7za } from '7zip-bin'; const debug = require('debug')('build:archive'); @@ -43,7 +43,7 @@ async function extractTarGz(archive: string, dest: string = dirname(archive), op await extract(tar, dest); - await removeAsync(tar); + await remove(tar); return dest; @@ -80,7 +80,7 @@ export async function compress(dir: string, files: string[], type: string, archi debug('in compress', 'listfiles', listfiles); - await writeFileAsync(listfiles, files.map(file => normalize(file)).join('\r\n')); + await writeFile(listfiles, files.map(file => normalize(file)).join('\r\n')); const { code, signal } = await spawnAsync(path7za, [ 'a', `-t${ type }`, resolve(archive), `@${ resolve(listfiles) }` ], { cwd: dir, diff --git a/src/lib/util/index.ts b/src/lib/util/index.ts index 5227051..6e857b2 100644 --- a/src/lib/util/index.ts +++ b/src/lib/util/index.ts @@ -4,7 +4,7 @@ import { spawn, exec } from 'child_process'; import * as tmp from 'tmp'; tmp.setGracefulCleanup(); -import { lstatAsync, ensureDirAsync, readFileAsync, outputFileAsync } from 'fs-extra-promise'; +import { lstat, ensureDir, readFile, outputFile } from 'fs-extra'; const debug = require('debug')('build:util'); const globby = require('globby'); @@ -231,13 +231,13 @@ export function fixWindowsVersion(version: string, build: number = 0) { export async function copyFileAsync(src: string, dest: string) { - const stats = await lstatAsync(src); + const stats = await lstat(src); if(stats.isDirectory() || stats.isSymbolicLink()) { //await ensureDirAsync(dest); } else { - await outputFileAsync(dest, await readFileAsync(src)); + await outputFile(dest, await readFile(src)); } } diff --git a/test/nsis-gen.js b/test/nsis-gen.js index f4ca944..753de50 100644 --- a/test/nsis-gen.js +++ b/test/nsis-gen.js @@ -1,7 +1,7 @@ import { test } from 'ava'; -import { writeFileAsync, removeAsync } from 'fs-extra-promise'; +import { writeFile, remove } from 'fs-extra'; import { NsisComposer, NsisDiffer, nsisBuild } from '../dist/lib/nsis-gen'; import { tmpName, tmpFile, tmpDir } from '../dist/lib/util'; @@ -40,11 +40,11 @@ test('build', async (t) => { postfix: '.nsi', }); - await writeFileAsync(script, data); + await writeFile(script, data); await nsisBuild('./src/', script); - await removeAsync(output); - await removeAsync(script); + await remove(output); + await remove(script); }); @@ -63,10 +63,10 @@ test('diff', async (t) => { postfix: '.nsi', }); - await writeFileAsync(script, data); + await writeFile(script, data); await nsisBuild('./dist/', script); - await removeAsync(output); - await removeAsync(script); + await remove(output); + await remove(script); }); diff --git a/test/util.js b/test/util.js index 6e0fdce..9248253 100644 --- a/test/util.js +++ b/test/util.js @@ -1,7 +1,7 @@ import { test } from 'ava'; -import { removeAsync } from 'fs-extra-promise'; +import { remove } from 'fs-extra'; import { mergeOptions, tmpName, tmpFile, tmpDir, compress } from '../dist/lib/util'; @@ -34,6 +34,6 @@ test('compress', async (t) => { const code = await compress('./assets/', [ './project/index.html', './project/package.json' ], 'zip', path); t.is(code, 0); - await removeAsync(path); + await remove(path); });