From bdc8c46362a3fa0639dac5b32ec47d2b0d9faa47 Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Tue, 9 Jun 2015 19:30:43 -0700 Subject: [PATCH] Move prune to common module --- common.js | 12 ++++++++++++ linux.js | 14 +------------- mac.js | 15 ++------------- win32.js | 16 ++-------------- 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/common.js b/common.js index 19172fc..24fd323 100644 --- a/common.js +++ b/common.js @@ -1,4 +1,5 @@ var asar = require('asar') +var child = require('child_process') var path = require('path') var rimraf = require('rimraf') @@ -15,6 +16,17 @@ module.exports = { }) }, + prune: function prune (opts, cwd, cb, nextStep) { + if (opts.prune) { + child.exec('npm prune --production', { cwd: cwd }, function pruned (err) { + if (err) return cb(err) + nextStep() + }) + } else { + nextStep() + } + }, + userIgnoreFilter: function userIgnoreFilter (opts, is_win32, finalDir) { return function filter (file) { if (is_win32) { diff --git a/linux.js b/linux.js index fa37391..83426c6 100644 --- a/linux.js +++ b/linux.js @@ -1,6 +1,5 @@ var path = require('path') var fs = require('fs') -var child = require('child_process') var mkdirp = require('mkdirp') var ncp = require('ncp').ncp var common = require('./common') @@ -29,14 +28,7 @@ module.exports = { function copyUserApp () { ncp(opts.dir, userAppDir, {filter: common.userIgnoreFilter(opts, false, finalDir), dereference: true}, function copied (err) { if (err) return cb(err) - if (opts.prune) { - prune(function pruned (err) { - if (err) return cb(err) - renameElectronBinary() - }) - } else { - renameElectronBinary() - } + common.prune(opts, userAppDir, cb, renameElectronBinary) }) } @@ -51,10 +43,6 @@ module.exports = { }) } - function prune (cb) { - child.exec('npm prune --production', { cwd: userAppDir }, cb) - } - function appFilter (file) { return file.match(/default_app/) === null } diff --git a/mac.js b/mac.js index b22b110..b125c74 100644 --- a/mac.js +++ b/mac.js @@ -72,19 +72,6 @@ function buildMacApp (opts, cb, newApp) { ncp(opts.dir, paths.app, {filter: common.userIgnoreFilter(opts), dereference: true}, function copied (err) { if (err) return cb(err) - if (opts.prune) { - prune(function pruned (err) { - if (err) return cb(err) - moveApp() - }) - } else { - moveApp() - } - - function prune (cb) { - child.exec('npm prune --production', { cwd: paths.app }, cb) - } - function moveApp () { // finally, move app into cwd var outdir = opts.out || process.cwd() @@ -134,5 +121,7 @@ function buildMacApp (opts, cb, newApp) { cb(err, appPath) }) } + + common.prune(opts, paths.app, cb, moveApp) }) } diff --git a/win32.js b/win32.js index e5d7ab7..bc3eb81 100644 --- a/win32.js +++ b/win32.js @@ -1,6 +1,5 @@ var os = require('os') var path = require('path') -var child = require('child_process') var mkdirp = require('mkdirp') var rimraf = require('rimraf') @@ -54,19 +53,6 @@ function buildWinApp (opts, cb, newApp) { ncp(opts.dir, paths.app, {filter: common.userIgnoreFilter(opts, true), dereference: true}, function copied (err) { if (err) return cb(err) - if (opts.prune) { - prune(function pruned (err) { - if (err) return cb(err) - moveApp() - }) - } else { - moveApp() - } - - function prune (cb) { - child.exec('npm prune --production', { cwd: paths.app }, cb) - } - function moveApp () { // finally, move app into cwd var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32') @@ -97,5 +83,7 @@ function buildWinApp (opts, cb, newApp) { cb(err, finalPath) }) } + + common.prune(opts, paths.app, cb, moveApp) }) }