replace 'mkdirp' and 'rmdir' usage with 'fs-extra'

This commit is contained in:
2018-04-28 17:08:22 +03:00
parent 00d9ec5c0e
commit 28ad6f9c81
4 changed files with 12 additions and 17 deletions

View File

@@ -1,18 +1,13 @@
const os = require('os'); const os = require('os');
const fs = require('fs'); const fs = require('fs');
const fse = require('fs-extra');
const path = require('path'); const path = require('path');
const tmp = require('tmp-file');
const exec = require('./exec'); const exec = require('./exec');
const through = require('through2');
const Sdk = require('./sdk'); const Sdk = require('./sdk');
const Vinyl = require('vinyl');
const PluginError = require('plugin-error');
const colors = require('ansi-colors'); const colors = require('ansi-colors');
const log = require('fancy-log'); const log = require('fancy-log');
const vfs = require('vinyl-fs'); const vfs = require('vinyl-fs');
const rmdir = require('rmdir');
const template = require('lodash.template'); const template = require('lodash.template');
const mkdirp = require('mkdirp');
class Haxe extends Sdk { class Haxe extends Sdk {
@@ -87,7 +82,7 @@ class Haxe extends Sdk {
openfl(command, platform, config, debug=false) { openfl(command, platform, config, debug=false) {
log(this.tag, colors.cyan(`openfl build ${platform}`)); log(this.tag, colors.cyan(`openfl build ${platform}`));
const buildDir = path.join(os.tmpdir(), 'build', config.name); 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 projectTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/project.xml')));
const project = projectTemplate({...config, buildDir: buildDir}); const project = projectTemplate({...config, buildDir: buildDir});
@@ -98,14 +93,14 @@ class Haxe extends Sdk {
args.push('-debug'); args.push('-debug');
} }
const target = path.resolve(buildDir, platform, 'bin'); const target = path.resolve(buildDir, platform, 'bin');
rmdir(target); fse.emptyDirSync(target);
return this.haxelib(args).then(() => vfs.src(`${target}/**/*`)); return this.haxelib(args).then(() => vfs.src(`${target}/**/*`));
} }
build(platform, config, debug=false) { build(platform, config, debug=false) {
log(this.tag, colors.cyan(`build ${platform}`)); log(this.tag, colors.cyan(`build ${platform}`));
const buildDir = path.join(os.tmpdir(), 'build', config.name); 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'))); const projectTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/project.hxml')));
@@ -127,7 +122,10 @@ class Haxe extends Sdk {
args.push('-debug'); args.push('-debug');
} }
const target = path.resolve(buildDir, platform, 'bin'); 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}/**/*`)); return this.haxe(args).then(() => vfs.src(`${target}/**/*`));
} }

View File

@@ -14,7 +14,6 @@ const {BuildSystem, Platform, Config} = require('./core');
const vfs = require('vinyl-fs'); const vfs = require('vinyl-fs');
const rename = require('gulp-rename'); const rename = require('gulp-rename');
const template = require('lodash.template'); const template = require('lodash.template');
const mkdirp = require('mkdirp');
const through = require('through2'); const through = require('through2');
const Vinyl = require('vinyl'); const Vinyl = require('vinyl');
@@ -168,7 +167,7 @@ class LinuxPacker extends Packer {
const buildDir = path.join(os.tmpdir(), 'build', this.config.name, 'debian'); const buildDir = path.join(os.tmpdir(), 'build', this.config.name, 'debian');
const desktopTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/linux/app.desktop'))); const desktopTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/linux/app.desktop')));
const desktop = desktopTemplate(this.config); 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); fs.writeFileSync(`${buildDir}/usr/share/applications/${this.config.meta.filename}.desktop`, desktop);
fse.copySync(`${target}`, `${buildDir}/usr/share/${this.config.meta.filename}/`); fse.copySync(`${target}`, `${buildDir}/usr/share/${this.config.meta.filename}/`);
return gulp.src(`${buildDir}/*`) return gulp.src(`${buildDir}/*`)

View File

@@ -8,7 +8,7 @@ const tar = require('tar');
const ProgressBar = require('progress'); const ProgressBar = require('progress');
const colors = require('ansi-colors'); const colors = require('ansi-colors');
const log = require('fancy-log'); const log = require('fancy-log');
const mkdirp = require('mkdirp'); const fse = require('fs-extra');
class System { class System {
@@ -81,7 +81,7 @@ class Sdk {
if (this.prepared) { if (this.prepared) {
return Promise.resolve(); return Promise.resolve();
} else { } else {
mkdirp.sync(this.path); fse.ensureDirSync(this.path);
const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true}); const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
let stream = got.stream(this.link); let stream = got.stream(this.link);
stream = stream.on('downloadProgress', (p) => bar.update(p.percent)); 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); const filePath = entry.path.split('/').slice(1).join(path.sep);
if (filePath.length > 0) { if (filePath.length > 0) {
if (entry.type === 'Directory') { 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') { } else if (entry.type === 'File') {
entry.pipe(fs.createWriteStream(path.join(this.path, path.normalize(filePath)))); entry.pipe(fs.createWriteStream(path.join(this.path, path.normalize(filePath))));
} }

View File

@@ -16,11 +16,9 @@
"gulp-webserver": "^0.9.1", "gulp-webserver": "^0.9.1",
"lodash.defaults": "^4.2.0", "lodash.defaults": "^4.2.0",
"lodash.template": "^4.4.0", "lodash.template": "^4.4.0",
"mkdirp": "^0.5.1",
"plugin-error": "^1.0.1", "plugin-error": "^1.0.1",
"progress": "^2.0.0", "progress": "^2.0.0",
"promise-streams": "^2.1.1", "promise-streams": "^2.1.1",
"rmdir": "^1.2.0",
"tail": "^1.2.3", "tail": "^1.2.3",
"tar": "^4.4.1", "tar": "^4.4.1",
"through2": "^2.0.3", "through2": "^2.0.3",