Skip to content
Permalink
Browse files

refactor(generic): replace mkdirp/rimraf calls with equivalent fs-pro…

…mise calls
  • Loading branch information
malept committed Dec 17, 2016
1 parent ec0caec commit bb2c6cf3b52ad487fcd5cf9822d5f006bb207a85
@@ -68,11 +68,9 @@
"fs-promise": "^1.0.0",
"inquirer": "^2.0.0",
"log-symbols": "^1.0.2",
"mkdirp": "^0.5.1",
"node-gyp": "^3.4.0",
"ora": "^0.3.0",
"pify": "^2.3.0",
"rimraf": "^2.5.4",
"semver": "^5.3.0",
"username": "^2.2.2",
"yarn-or-npm": "^2.0.2",
@@ -5,7 +5,6 @@ import pify from 'pify';
import packager from 'electron-packager';
import program from 'commander';
import ora from 'ora';
import rimraf from 'rimraf';

import './util/terminate';
import electronHostArch from './util/electron-host-arch';
@@ -64,7 +63,7 @@ const main = async () => {
prepareCounter += 1;
prepareSpinner = ora.ora(`Preparing to Package Application for arch: ${(prepareCounter === 2 ? 'armv7l' : 'x64').cyan}`).start();
}
await pify(rimraf)(path.resolve(buildPath, 'node_modules/electron-compile/test'));
await fs.remove(path.resolve(buildPath, 'node_modules/electron-compile/test'));
done();
}, async (...args) => {
prepareSpinner.succeed();
@@ -2,17 +2,15 @@ import debug from 'debug';
import fs from 'fs-promise';
import inquirer from 'inquirer';
import logSymbols from 'log-symbols';
import mkdirp from 'mkdirp';
import ora from 'ora';
import pify from 'pify';

const d = debug('electron-forge:init:directory');

export default async (dir) => {
const initSpinner = ora.ora('Initializing Project Directory').start();

d('creating directory:', dir);
await pify(mkdirp)(dir);
await fs.mkdirs(dir);

const files = await fs.readdir(dir);
if (files.length !== 0) {
@@ -1,9 +1,7 @@
import debug from 'debug';
import fs from 'fs-promise';
import mkdirp from 'mkdirp';
import ora from 'ora';
import path from 'path';
import pify from 'pify';

const d = debug('electron-forge:init:starter-files');

@@ -30,7 +28,7 @@ export default async (dir, lintStyle) => {
const tmplPath = path.resolve(__dirname, '../../tmpl');

d('creating directory:', path.resolve(dir, 'src'));
await pify(mkdirp)(path.resolve(dir, 'src'));
await fs.mkdirs(path.resolve(dir, 'src'));
const rootFiles = ['_gitignore'];
if (lintStyle === 'airbnb') rootFiles.push('_eslintrc');
const srcFiles = ['index.js', 'index.html'];
@@ -1,21 +1,20 @@
import debug from 'debug';
import fs from 'fs';
import mkdirp from 'mkdirp';
import fs from 'fs-promise';
import os from 'os';
import path from 'path';

const d = debug('electron-forge:runtime-config');

/*
* Let's be real sharing config accross spawned process's must be easier than
* Let's be real: sharing config across spawned processes must be easier than
* this...
*/
class BasicConfigStore {
constructor() {
this._store = {};
this._dir = path.resolve(os.tmpdir(), 'electron-forge');
this._path = path.resolve(this._dir, '.runtime.config');
mkdirp.sync(this._dir);
fs.mkdirsSync(this._dir);
}

get(key) {
@@ -1,21 +1,22 @@
import fs from 'fs-promise';
import mkdirp from 'mkdirp';
import path from 'path';
import pify from 'pify';
import rimraf from 'rimraf';

// This is different from fs-extra's ensureDir because it wipes out the existing directory,
// if it's found.
async function ensureDirectory(dir) {
if (await fs.exists(dir)) {
await pify(rimraf)(dir);
await fs.remove(dir);
}
return pify(mkdirp)(dir);
return fs.mkdirs(dir);
}

// This is different from fs-extra's ensureFile because it wipes out the existing file,
// if it's found.
async function ensureFile(file) {
if (await fs.exists(file)) {
await pify(rimraf)(file);
await fs.remove(file);
}
await pify(mkdirp)(path.dirname(file));
await fs.mkdirs(path.dirname(file));
}

export { ensureDirectory, ensureFile };
@@ -1,11 +1,9 @@
import { spawn } from 'child_process';
import debug from 'debug';
import fs from 'fs-promise';
import mkdirp from 'mkdirp';
import ora from 'ora';
import os from 'os';
import path from 'path';
import pify from 'pify';

const d = debug('electron-forge:rebuild');

@@ -59,7 +57,7 @@ export default async (buildPath, electronVersion, pPlatform, pArch) => {
child.on('exit', async (code) => {
d('built:', path.basename(modulePath));
if (code !== 0) return reject(new Error(`Failed to rebuild: ${modulePath}\n\n${output}`));
await pify(mkdirp)(path.dirname(metaPath));
await fs.mkdirs(path.dirname(metaPath));
await fs.writeFile(metaPath, pArch);
resolve();
});
@@ -2,8 +2,6 @@ import { spawn } from 'child_process';
import fs from 'fs-promise';
import os from 'os';
import path from 'path';
import pify from 'pify';
import rimraf from 'rimraf';

import { expect } from 'chai';

@@ -44,7 +42,7 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
before(async () => {
dir = path.resolve(os.tmpdir(), `electron-forge-test-${dirID}`);
dirID += 1;
await pify(rimraf)(dir);
await fs.remove(dir);
await pSpawn(['init', dir, `--lintstyle=${lintStyle}`]);
});

@@ -67,7 +65,7 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
it('should initially pass the linting process', () => pSpawn(['lint', dir]));
});

after(done => rimraf(dir, done));
after(() => fs.remove(dir));
});
};
forLintingMethod('airbnb');
@@ -113,6 +111,6 @@ describe(`electron-forge CLI (with installer=${installer.substr(12)})`, () => {
});
});

after(done => rimraf(dir, done));
after(() => fs.remove(dir));
});
});

0 comments on commit bb2c6cf

Please sign in to comment.
You can’t perform that action at this time.