Skip to content
Permalink
Browse files

refactor(maker): create ensure{Directory,File} to rimraf+mkdirp the g…

…iven output
  • Loading branch information
malept authored and MarshallOfSound committed Dec 4, 2016
1 parent aaceb3f commit b3b616a03e12f2af5e5f4e2106097149c8fb92d2
Showing with 31 additions and 22 deletions.
  1. +3 −7 src/makers/darwin/dmg.js
  2. +3 −7 src/makers/generic/zip.js
  3. +4 −8 src/makers/win32/squirrel.js
  4. +21 −0 src/util/ensure-output.js
@@ -1,16 +1,12 @@
import electronDMG from 'electron-installer-dmg';
import fs from 'fs-promise';
import mkdirp from 'mkdirp';
import path from 'path';
import pify from 'pify';
import rimraf from 'rimraf';

import { ensureFile } from '../../util/ensure-output';

export default async (dir, appName, forgeConfig) => {
const outPath = path.resolve(dir, '../make', `${path.basename(dir)}.dmg`);
if (await fs.exists(outPath)) {
await pify(rimraf)(outPath);
}
await pify(mkdirp)(path.dirname(outPath));
await ensureFile(outPath);
const dmgConfig = Object.assign({
overwrite: true,
}, forgeConfig.electronInstallerDMG, {
@@ -1,11 +1,10 @@
import { spawn } from 'child_process';
import fs from 'fs-promise';
import mkdirp from 'mkdirp';
import path from 'path';
import pify from 'pify';
import rimraf from 'rimraf';
import zipFolder from 'zip-folder';

import { ensureFile } from '../../util/ensure-output';

const zipPromise = (from, to) =>
new Promise((resolve, reject) => {
const child = spawn('zip', ['-r', '-y', to, from]);
@@ -21,10 +20,7 @@ const zipPromise = (from, to) =>

export default async (dir, appName, forgeConfig) => { // eslint-disable-line
const zipPath = path.resolve(dir, '../make', `${path.basename(dir)}.zip`);
await pify(mkdirp)(path.dirname(zipPath));
if (await fs.exists(zipPath)) {
await pify(rimraf)(zipPath);
}
await ensureFile(zipPath);
switch (process.platform) {
case 'win32':
await pify(zipFolder)(dir, zipPath);
@@ -1,16 +1,12 @@
import { createWindowsInstaller } from 'electron-winstaller';
import fs from 'fs-promise';
import mkdirp from 'mkdirp';
import path from 'path';
import pify from 'pify';
import rimraf from 'rimraf';

import { ensureDirectory } from '../../util/ensure-output';

export default async (dir, appName, forgeConfig) => {
const outPath = path.resolve(dir, '../make/squirrel.windows');
if (await fs.exists(outPath)) {
await pify(rimraf)(outPath);
}
await pify(mkdirp)(outPath);
await ensureDirectory(outPath);

const winstallerConfig = Object.assign({
description: 'This is the default electron-forge description, you can override it in your config',
}, forgeConfig.electronWinstallerConfig, {
@@ -0,0 +1,21 @@
import fs from 'fs-promise';
import mkdirp from 'mkdirp';
import path from 'path';
import pify from 'pify';
import rimraf from 'rimraf';

async function ensureDirectory(dir) {
if (await fs.exists(dir)) {
await pify(rimraf)(dir);
}
return pify(mkdirp)(dir);
}

async function ensureFile(file) {
if (await fs.exists(file)) {
await pify(rimraf)(file);
}
await pify(mkdirp)(path.dirname(file));
}

export { ensureDirectory, ensureFile };

0 comments on commit b3b616a

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