Skip to content

Commit

Permalink
refactor(generic): replace mkdirp/rimraf calls with equivalent fs-pro…
Browse files Browse the repository at this point in the history
…mise calls
  • Loading branch information
malept committed Dec 17, 2016
1 parent ec0caec commit bb2c6cf
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 29 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/electron-forge-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions src/init/init-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/init/init-starter-files.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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'];
Expand Down
7 changes: 3 additions & 4 deletions src/util/config.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions src/util/ensure-output.js
Original file line number Diff line number Diff line change
@@ -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 };
4 changes: 1 addition & 3 deletions src/util/rebuild.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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();
});
Expand Down
8 changes: 3 additions & 5 deletions test/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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}`]);
});

Expand All @@ -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');
Expand Down Expand Up @@ -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.