From 28ad6f9c815dc885b7d871c9f3cf0c0066a19bdf Mon Sep 17 00:00:00 2001 From: shmyga Date: Sat, 28 Apr 2018 17:08:22 +0300 Subject: [PATCH] replace 'mkdirp' and 'rmdir' usage with 'fs-extra' --- haxetool/haxe.js | 18 ++++++++---------- haxetool/project.js | 3 +-- haxetool/sdk.js | 6 +++--- package.json | 2 -- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/haxetool/haxe.js b/haxetool/haxe.js index 4ebfc61..d7dd610 100755 --- a/haxetool/haxe.js +++ b/haxetool/haxe.js @@ -1,18 +1,13 @@ const os = require('os'); const fs = require('fs'); +const fse = require('fs-extra'); const path = require('path'); -const tmp = require('tmp-file'); const exec = require('./exec'); -const through = require('through2'); const Sdk = require('./sdk'); -const Vinyl = require('vinyl'); -const PluginError = require('plugin-error'); const colors = require('ansi-colors'); const log = require('fancy-log'); const vfs = require('vinyl-fs'); -const rmdir = require('rmdir'); const template = require('lodash.template'); -const mkdirp = require('mkdirp'); class Haxe extends Sdk { @@ -87,7 +82,7 @@ class Haxe extends Sdk { openfl(command, platform, config, debug=false) { log(this.tag, colors.cyan(`openfl build ${platform}`)); const buildDir = path.join(os.tmpdir(), 'build', config.name); - mkdirp.sync(buildDir); + fse.ensureDirSync(buildDir); const projectTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/project.xml'))); const project = projectTemplate({...config, buildDir: buildDir}); @@ -98,14 +93,14 @@ class Haxe extends Sdk { args.push('-debug'); } const target = path.resolve(buildDir, platform, 'bin'); - rmdir(target); + fse.emptyDirSync(target); return this.haxelib(args).then(() => vfs.src(`${target}/**/*`)); } build(platform, config, debug=false) { log(this.tag, colors.cyan(`build ${platform}`)); const buildDir = path.join(os.tmpdir(), 'build', config.name); - mkdirp.sync(buildDir); + fse.ensureDirSync(buildDir); const projectTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/project.hxml'))); @@ -127,7 +122,10 @@ class Haxe extends Sdk { args.push('-debug'); } const target = path.resolve(buildDir, platform, 'bin'); - rmdir(target); + fse.emptyDirSync(target) + for (const asset of config.assets) { + fse.copySync(asset, path.join(target, asset.split(path.sep).pop())); + } return this.haxe(args).then(() => vfs.src(`${target}/**/*`)); } diff --git a/haxetool/project.js b/haxetool/project.js index 96e67ee..c947f49 100644 --- a/haxetool/project.js +++ b/haxetool/project.js @@ -14,7 +14,6 @@ const {BuildSystem, Platform, Config} = require('./core'); const vfs = require('vinyl-fs'); const rename = require('gulp-rename'); const template = require('lodash.template'); -const mkdirp = require('mkdirp'); const through = require('through2'); const Vinyl = require('vinyl'); @@ -168,7 +167,7 @@ class LinuxPacker extends Packer { const buildDir = path.join(os.tmpdir(), 'build', this.config.name, 'debian'); const desktopTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/linux/app.desktop'))); const desktop = desktopTemplate(this.config); - mkdirp.sync(`${buildDir}/usr/share/applications`); + fse.ensureDirSync(`${buildDir}/usr/share/applications`); fs.writeFileSync(`${buildDir}/usr/share/applications/${this.config.meta.filename}.desktop`, desktop); fse.copySync(`${target}`, `${buildDir}/usr/share/${this.config.meta.filename}/`); return gulp.src(`${buildDir}/*`) diff --git a/haxetool/sdk.js b/haxetool/sdk.js index 1a1f8d8..7b0b5ff 100755 --- a/haxetool/sdk.js +++ b/haxetool/sdk.js @@ -8,7 +8,7 @@ const tar = require('tar'); const ProgressBar = require('progress'); const colors = require('ansi-colors'); const log = require('fancy-log'); -const mkdirp = require('mkdirp'); +const fse = require('fs-extra'); class System { @@ -81,7 +81,7 @@ class Sdk { if (this.prepared) { return Promise.resolve(); } else { - mkdirp.sync(this.path); + fse.ensureDirSync(this.path); const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true}); let stream = got.stream(this.link); stream = stream.on('downloadProgress', (p) => bar.update(p.percent)); @@ -90,7 +90,7 @@ class Sdk { const filePath = entry.path.split('/').slice(1).join(path.sep); if (filePath.length > 0) { if (entry.type === 'Directory') { - mkdirp(path.join(this.path, path.normalize(filePath))); + fse.ensureDirSync(path.join(this.path, path.normalize(filePath))); } else if (entry.type === 'File') { entry.pipe(fs.createWriteStream(path.join(this.path, path.normalize(filePath)))); } diff --git a/package.json b/package.json index 2c82622..42ab04f 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,9 @@ "gulp-webserver": "^0.9.1", "lodash.defaults": "^4.2.0", "lodash.template": "^4.4.0", - "mkdirp": "^0.5.1", "plugin-error": "^1.0.1", "progress": "^2.0.0", "promise-streams": "^2.1.1", - "rmdir": "^1.2.0", "tail": "^1.2.3", "tar": "^4.4.1", "through2": "^2.0.3",