replace 'mkdirp' and 'rmdir' usage with 'fs-extra'
This commit is contained in:
@@ -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}/**/*`));
|
||||
}
|
||||
|
||||
|
||||
@@ -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}/*`)
|
||||
|
||||
@@ -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))));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user