feat(build): add general copy/multicopy method

This commit is contained in:
Tobias Bosch 2015-02-23 17:56:47 -08:00
parent cfe71def7e
commit 3f25f5a356
11 changed files with 274 additions and 207 deletions

View File

@ -5,21 +5,21 @@ var merge = require('merge');
var gulpTraceur = require('./tools/transpiler/gulp-traceur');
var clean = require('./tools/build/clean');
var deps = require('./tools/build/deps');
var transpile = require('./tools/build/transpile');
var html = require('./tools/build/html');
var pubspec = require('./tools/build/pubspec');
var pubget = require('./tools/build/pubget');
var linknodemodules = require('./tools/build/linknodemodules');
var pubbuild = require('./tools/build/pubbuild');
var dartanalyzer = require('./tools/build/dartanalyzer');
var jsserve = require('./tools/build/jsserve');
var pubserve = require('./tools/build/pubserve');
var rundartpackage = require('./tools/build/rundartpackage');
var multicopy = require('./tools/build/multicopy');
var copy = require('./tools/build/copy');
var karma = require('karma').server;
var minimist = require('minimist');
var es5build = require('./tools/build/es5build');
var runServerDartTests = require('./tools/build/run_server_dart_tests');
var util = require('./tools/build/util');
var DART_SDK = require('./tools/build/dartdetect')(gulp);
// -----------------------
@ -35,14 +35,13 @@ var _COMPILER_CONFIG_JS_DEFAULT = {
};
var _HTLM_DEFAULT_SCRIPTS_JS = [
{src: '/deps/traceur-runtime.js', mimeType: 'text/javascript'},
{src: '/rtts_assert/rtts_assert.js', mimeType: 'text/javascript'},
{src: '/deps/es6-module-loader-sans-promises.src.js', mimeType: 'text/javascript'},
{src: '/deps/zone.js', mimeType: 'text/javascript'},
{src: '/deps/long-stack-trace-zone.js', mimeType: 'text/javascript'},
{src: '/deps/system.src.js', mimeType: 'text/javascript'},
{src: '/deps/extension-register.js', mimeType: 'text/javascript'},
{src: '/deps/runtime_paths.js', mimeType: 'text/javascript'},
{src: '../../traceur-runtime.js', mimeType: 'text/javascript'},
{src: '../../es6-module-loader-sans-promises.src.js', mimeType: 'text/javascript'},
{src: '../../zone.js', mimeType: 'text/javascript'},
{src: '../../long-stack-trace-zone.js', mimeType: 'text/javascript'},
{src: '../../system.src.js', mimeType: 'text/javascript'},
{src: '../../extension-register.js', mimeType: 'text/javascript'},
{src: '../../runtime_paths.js', mimeType: 'text/javascript'},
{
inline: 'System.import(\'$MODULENAME$\').then(function(m) { m.main(); }, console.log.bind(console))',
mimeType: 'text/javascript'
@ -54,6 +53,52 @@ var _HTML_DEFAULT_SCRIPTS_DART = [
{src: 'packages/browser/dart.js', mimeType: 'text/javascript'}
];
var BASE_PACKAGE_JSON = require('./package.json');
var COMMON_PACKAGE_JSON = {
version: BASE_PACKAGE_JSON.version,
homepage: BASE_PACKAGE_JSON.homepage,
bugs: BASE_PACKAGE_JSON.bugs,
license: BASE_PACKAGE_JSON.license,
contributors: BASE_PACKAGE_JSON.contributors,
dependencies: BASE_PACKAGE_JSON.dependencies,
devDependencies: {
"yargs": BASE_PACKAGE_JSON.devDependencies['yargs'],
"gulp-sourcemaps": BASE_PACKAGE_JSON.devDependencies['gulp-sourcemaps'],
"gulp-traceur": BASE_PACKAGE_JSON.devDependencies['gulp-traceur'],
"gulp": BASE_PACKAGE_JSON.devDependencies['gulp'],
"gulp-rename": BASE_PACKAGE_JSON.devDependencies['gulp-rename'],
"through2": BASE_PACKAGE_JSON.devDependencies['through2']
}
};
var SRC_FOLDER_INSERTION = {
js: {
'**': ''
},
dart: {
'**': 'lib',
'*/test/**': '',
'benchmarks/**': 'web',
'benchmarks/test/**': '',
'benchmarks_external/**': 'web',
'benchmarks_external/test/**': '',
'example*/**': 'web',
'example*/test/**': ''
}
};
var ES5_DEPS = [
gulpTraceur.RUNTIME_PATH,
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/systemjs/lib/extension-register.js',
'node_modules/zone.js/zone.js',
'node_modules/zone.js/long-stack-trace-zone.js',
'tools/build/snippets/runtime_paths.js',
'tools/build/snippets/url_params_to_form.js',
'node_modules/angular/angular.js'
];
var CONFIG = {
dest: {
js: {
@ -72,46 +117,12 @@ var CONFIG = {
dart: 'dist/dart',
docs: 'dist/docs'
},
srcFolderInsertion: {
js: {
'**': ''
},
dart: {
'**': 'lib',
'*/test/**': '',
'benchmarks/**': 'web',
'benchmarks/test/**': '',
'benchmarks_external/**': 'web',
'benchmarks_external/test/**': '',
'example*/**': 'web',
'example*/test/**': ''
}
},
deps: {
js: [
gulpTraceur.RUNTIME_PATH,
"node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js",
"node_modules/systemjs/dist/system.src.js",
"node_modules/systemjs/lib/extension-register.js",
"node_modules/zone.js/zone.js",
"node_modules/zone.js/long-stack-trace-zone.js",
"tools/build/snippets/runtime_paths.js",
"tools/build/snippets/url_params_to_form.js",
"node_modules/angular/angular.js"
],
dart: [
"tools/build/snippets/url_params_to_form.js"
]
},
srcFolderInsertion: SRC_FOLDER_INSERTION,
transpile: {
src: {
js: ['modules/**/*.js', 'modules/**/*.es6'],
dart: ['modules/**/*.js'],
},
copy: {
js: ['modules/**/*.es5'],
dart: ['modules/**/*.dart', '!modules/**/e2e_test/**'],
},
options: {
js: {
dev: merge(true, _COMPILER_CONFIG_JS_DEFAULT, {
@ -140,13 +151,67 @@ var CONFIG = {
}
},
copy: {
js: ['modules/**/README.md', 'modules/**/package.json'],
dart: []
js: {
cjs: {
src: ['modules/**/README.js.md', 'modules/**/package.json', 'modules/**/*.cjs'],
pipes: {
'**/*.cjs': gulpPlugins.rename({extname: '.js'}),
'**/*.js.md': gulpPlugins.rename(function(file) {
file.basename = file.basename.substring(0, file.basename.lastIndexOf('.'));
}),
'**/package.json': gulpPlugins.template({ 'packageJson': COMMON_PACKAGE_JSON })
}
}
},
dart: {
src: ['modules/**/README.dart.md', 'modules/**/*.dart', 'modules/*/pubspec.yaml', '!modules/**/e2e_test/**'],
pipes: {
'**/*.dart': util.insertSrcFolder(gulpPlugins, SRC_FOLDER_INSERTION.dart),
'**/*.dart.md': gulpPlugins.rename(function(file) {
file.basename = file.basename.substring(0, file.basename.lastIndexOf('.'));
}),
'**/pubspec.yaml': gulpPlugins.template({ 'packageJson': COMMON_PACKAGE_JSON })
}
}
},
multicopy: {
src: {
dart: ['LICENSE'],
js: ['LICENSE', 'tools/build/es5build.js']
js: {
cjs: {
src: [
'LICENSE'
],
pipes: {}
},
dev: {
es6: {
src: ['tools/build/es5build.js'],
pipes: {}
},
es5: {
src: ES5_DEPS,
pipes: {}
}
},
prod: {
es6: {
src: ['tools/build/es5build.js'],
pipes: {}
},
es5: {
src: ES5_DEPS,
pipes: {}
}
},
dart2js: {
src: ['tools/build/snippets/url_params_to_form.js'],
exclude: ['rtts_assert/'],
pipes: {}
}
},
dart: {
src: ['LICENSE'],
exclude: ['rtts_assert/'],
pipes: {}
}
},
html: {
@ -159,26 +224,23 @@ var CONFIG = {
'**': _HTLM_DEFAULT_SCRIPTS_JS,
'benchmarks/**':
[
{ src: '/deps/url_params_to_form.js', mimeType: 'text/javascript' }
{ src: '../../url_params_to_form.js', mimeType: 'text/javascript' }
].concat(_HTLM_DEFAULT_SCRIPTS_JS),
'benchmarks_external/**':
[
{ src: '/deps/angular.js', mimeType: 'text/javascript' },
{ src: '/deps/url_params_to_form.js', mimeType: 'text/javascript' }
{ src: '../../angular.js', mimeType: 'text/javascript' },
{ src: '../../url_params_to_form.js', mimeType: 'text/javascript' }
].concat(_HTLM_DEFAULT_SCRIPTS_JS)
},
dart: {
'**': _HTML_DEFAULT_SCRIPTS_DART,
'benchmarks*/**':
[
{ src: '/deps/url_params_to_form.js', mimeType: 'text/javascript' }
{ src: '../../url_params_to_form.js', mimeType: 'text/javascript' }
].concat(_HTML_DEFAULT_SCRIPTS_DART)
}
}
},
pubspec: {
src: 'modules/*/pubspec.yaml'
},
formatDart: {
packageName: 'dart_style',
args: ['dart_style:format', '-w', 'dist/dart']
@ -201,30 +263,11 @@ gulp.task('build/clean.docs', clean(gulp, gulpPlugins, {
}));
// ------------
// deps
gulp.task('build/deps.js.dev', deps(gulp, gulpPlugins, {
src: CONFIG.deps.js,
dest: CONFIG.dest.js.dev.es5
}));
gulp.task('build/deps.js.prod', deps(gulp, gulpPlugins, {
src: CONFIG.deps.js,
dest: CONFIG.dest.js.prod.es5
}));
gulp.task('build/deps.js.dart2js', deps(gulp, gulpPlugins, {
src: CONFIG.deps.dart,
dest: CONFIG.dest.js.dart2js
}));
// ------------
// transpile
gulp.task('build/transpile.js.dev.es6', transpile(gulp, gulpPlugins, {
src: CONFIG.transpile.src.js,
copy: CONFIG.transpile.copy.js,
dest: CONFIG.dest.js.dev.es6,
outputExt: 'es6',
options: CONFIG.transpile.options.js.dev,
@ -249,7 +292,6 @@ gulp.task('build/transpile.js.dev', function(done) {
gulp.task('build/transpile.js.prod.es6', transpile(gulp, gulpPlugins, {
src: CONFIG.transpile.src.js,
copy: CONFIG.transpile.copy.js,
dest: CONFIG.dest.js.prod.es6,
outputExt: 'es6',
options: CONFIG.transpile.options.js.prod,
@ -274,7 +316,6 @@ gulp.task('build/transpile.js.prod', function(done) {
gulp.task('build/transpile.js.cjs', transpile(gulp, gulpPlugins, {
src: CONFIG.transpile.src.js,
copy: CONFIG.transpile.copy.js,
dest: CONFIG.dest.js.cjs,
outputExt: 'js',
options: CONFIG.transpile.options.js.cjs,
@ -283,7 +324,6 @@ gulp.task('build/transpile.js.cjs', transpile(gulp, gulpPlugins, {
gulp.task('build/transpile.dart', transpile(gulp, gulpPlugins, {
src: CONFIG.transpile.src.dart,
copy: CONFIG.transpile.copy.dart,
dest: CONFIG.dest.dart,
outputExt: 'dart',
options: CONFIG.transpile.options.dart,
@ -317,49 +357,77 @@ gulp.task('build/html.dart', html(gulp, gulpPlugins, {
// ------------
// copy
gulp.task('build/copy.js.dev', function() {
return gulp.src(CONFIG.copy.js)
.pipe(gulpPlugins.template({
'channel': 'dev',
'packageJson': require('./package.json')
}))
.pipe(gulp.dest(CONFIG.dest.js.dev.es6));
});
gulp.task('build/copy.js.cjs', copy.copy(gulp, gulpPlugins, {
src: CONFIG.copy.js.cjs.src,
pipes: CONFIG.copy.js.cjs.pipes,
dest: CONFIG.dest.js.cjs
}));
gulp.task('build/copy.dart', copy.copy(gulp, gulpPlugins, {
src: CONFIG.copy.dart.src,
pipes: CONFIG.copy.dart.pipes,
dest: CONFIG.dest.dart
}));
gulp.task('build/copy.js.prod', function() {
return gulp.src(CONFIG.copy.js)
.pipe(gulpPlugins.template({
'channel': 'prod',
'packageJson': require('./package.json')
}))
.pipe(gulp.dest(CONFIG.dest.js.prod.es6));
});
// ------------
// multicopy
gulp.task('build/multicopy.js.dev', multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.src.js,
gulp.task('build/multicopy.js.cjs', copy.multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.js.cjs.src,
pipes: CONFIG.multicopy.js.cjs.pipes,
exclude: CONFIG.multicopy.js.cjs.exclude,
dest: CONFIG.dest.js.cjs
}));
gulp.task('build/multicopy.js.dev.es6', copy.multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.js.dev.es6.src,
pipes: CONFIG.multicopy.js.dev.es6.pipes,
exclude: CONFIG.multicopy.js.dev.es6.exclude,
dest: CONFIG.dest.js.dev.es6
}));
gulp.task('build/multicopy.js.prod', multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.src.js,
gulp.task('build/multicopy.js.dev.es5', copy.multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.js.dev.es5.src,
pipes: CONFIG.multicopy.js.dev.es5.pipes,
exclude: CONFIG.multicopy.js.dev.es5.exclude,
dest: CONFIG.dest.js.dev.es5
}));
gulp.task('build/multicopy.js.prod.es6', copy.multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.js.prod.es6.src,
pipes: CONFIG.multicopy.js.prod.es6.pipes,
exclude: CONFIG.multicopy.js.prod.es6.exclude,
dest: CONFIG.dest.js.prod.es6
}));
gulp.task('build/multicopy.dart', multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.src.dart,
gulp.task('build/multicopy.js.prod.es5', copy.multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.js.prod.es5.src,
pipes: CONFIG.multicopy.js.prod.es5.pipes,
exclude: CONFIG.multicopy.js.prod.es5.exclude,
dest: CONFIG.dest.js.prod.es5
}));
gulp.task('build/multicopy.dart', copy.multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.dart.src,
pipes: CONFIG.multicopy.dart.pipes,
exclude: CONFIG.multicopy.dart.exclude,
dest: CONFIG.dest.dart
}));
gulp.task('build/multicopy.js.dart2js', copy.multicopy(gulp, gulpPlugins, {
src: CONFIG.multicopy.js.dart2js.src,
pipes: CONFIG.multicopy.js.dart2js.pipes,
exclude: CONFIG.multicopy.js.dart2js.exclude,
dest: CONFIG.dest.js.dart2js
}));
// ------------
// pubspec
gulp.task('build/pubspec.dart', pubspec(gulp, gulpPlugins, {
src: CONFIG.pubspec.src,
dest: CONFIG.dest.dart,
gulp.task('build/pubspec.dart', pubget(gulp, gulpPlugins, {
dir: CONFIG.dest.dart,
command: DART_SDK.PUB
}));
@ -534,12 +602,14 @@ gulp.task('tests/transform.dart', function() {
// orchestrated targets
gulp.task('build.dart', function(done) {
runSequence(
['build/deps.js.dart2js', 'build/transpile.dart', 'build/html.dart'],
['build/transpile.dart', 'build/html.dart', 'build/copy.dart', 'build/multicopy.dart'],
'tests/transform.dart',
'build/format.dart',
'build/pubspec.dart',
'build/multicopy.dart',
'build/pubbuild.dart',
// Note: pubbuild.dart will clear the dart2js folder, so we need to copy
// our files after this :-(
'build/multicopy.js.dart2js',
'build/analyze.dart',
done
);
@ -547,24 +617,22 @@ gulp.task('build.dart', function(done) {
gulp.task('build.js.dev', function(done) {
runSequence(
['build/deps.js.dev', 'build/transpile.js.dev', 'build/html.js.dev', 'build/copy.js.dev'],
'build/multicopy.js.dev',
['build/transpile.js.dev', 'build/html.js.dev', 'build/multicopy.js.dev.es6', 'build/multicopy.js.dev.es5'],
done
);
});
gulp.task('build.js.prod', function(done) {
runSequence(
['build/deps.js.prod', 'build/transpile.js.prod', 'build/html.js.prod', 'build/copy.js.prod'],
'build/multicopy.js.prod',
['build/transpile.js.prod', 'build/html.js.prod', 'build/multicopy.js.prod.es6', 'build/multicopy.js.prod.es5'],
done
);
});
gulp.task('build.js.cjs', function(done) {
runSequence(
'build/transpile.js.cjs',
'build/linknodemodules.js.cjs',
['build/transpile.js.cjs', 'build/copy.js.cjs', 'build/multicopy.js.cjs'],
['build/linknodemodules.js.cjs'],
done
);;
});

View File

@ -67,6 +67,7 @@
"run-sequence": "^0.3.6",
"source-map": "^0.3.0",
"sprintf-js": "1.0.*",
"ternary-stream": "^1.2.3",
"through2": "^0.6.1",
"yargs": "2.3.*"
}

46
tools/build/copy.js Normal file
View File

@ -0,0 +1,46 @@
/**
* A utility that allows copying one file to multiple directories, such
* as the LICENSE file.
*/
var path = require('path');
var util = require('./util');
var ternaryStream = require('ternary-stream');
var minimatch = require('minimatch');
module.exports = {
multicopy: multicopy,
copy: copy
};
function createCopyPipe(gulp, plugins, config) {
var pipe = gulp.src(config.src);
Object.keys(config.pipes).forEach(function(pattern) {
pipe = pipe.pipe(ternaryStream(function(file) {
return minimatch(file.relative, pattern);
}, config.pipes[pattern]));
});
return pipe;
}
function copy(gulp, plugins, config) {
return function() {
return createCopyPipe(gulp, plugins, config)
.pipe(gulp.dest(config.dest));
}
}
function multicopy(gulp, plugins, config) {
return function() {
var pipe = createCopyPipe(gulp, plugins, config);
var modules = util.subDirs('modules');
if (config.exclude) {
modules = modules.filter(function(module) {
return config.exclude.indexOf(module) === -1;
});
}
modules.map(function(module) {
pipe = pipe.pipe(gulp.dest(path.join(config.dest, module)));
});
return pipe;
};
}

View File

@ -9,7 +9,7 @@ var util = require('./util');
module.exports = function(gulp, plugins, config) {
return function() {
var tempFile = '_analyzer.dart';
return util.forEachSubDir(
return util.forEachSubDirSequential(
config.dest,
function(dir) {
var srcFiles = [].slice.call(glob.sync('{/lib,/web}/**/*.dart', {

View File

@ -1,8 +0,0 @@
var path = require('path');
module.exports = function(gulp, plugins, config) {
return function() {
return gulp.src(config.src)
.pipe(gulp.dest(path.join(config.dest, 'deps')));
};
};

View File

@ -1,29 +0,0 @@
/**
* A utility that allows copying one file to multiple directories, such
* as the LICENSE file.
*/
var path = require('path');
var fs = require('fs');
module.exports = function(gulp, plugins, config) {
return function() {
var subDirs = getSubdirs(config.dest);
config.src.forEach(function(srcFile) {
var content = fs.readFileSync(srcFile);
subDirs.forEach(function(subDir) {
var destFile = path.join(config.dest, subDir, path.basename(srcFile));
fs.writeFileSync(destFile, content);
});
});
};
};
function getSubdirs(rootDir) {
return fs.readdirSync(rootDir).filter(function(file) {
if (file[0] === '.') {
return false;
}
var dirPath = path.join(rootDir, file);
return fs.statSync(dirPath).isDirectory();
});
}

17
tools/build/pubget.js Normal file
View File

@ -0,0 +1,17 @@
var util = require('./util');
var spawn = require('child_process').spawn;
var path = require('path');
module.exports = function(gulp, plugins, config) {
return function() {
// We need to execute pubspec serially as otherwise we can get into trouble
// with the pub cache...
return util.forEachSubDirSequential(config.dir, function(subDir) {
return util.processToPromise(spawn(config.command, ['get'], {
stdio: 'inherit',
cwd: subDir
}));
});
};
};

View File

@ -1,40 +0,0 @@
var util = require('./util');
var Q = require('q');
var spawn = require('child_process').spawn;
var through2 = require('through2');
var path = require('path');
module.exports = function(gulp, plugins, config) {
return function() {
var files = [];
var pubSpecCopy = util.streamToPromise(gulp.src(config.src)
.pipe(plugins.changed(config.dest)) // Only forward files that changed.
.pipe(plugins.template({
'packageJson': require('../../package.json')
}))
.pipe(through2.obj(function(file, enc, done) {
files.push(path.resolve(process.cwd(), config.dest, file.relative));
this.push(file);
done();
}))
.pipe(gulp.dest(config.dest)));
// We need to wait for all pubspecs to be present before executing
// `pub get` as it checks the folders of the dependencies!
// We need to execute pubspec serially as otherwise we can get into trouble
// with the pub cache...
return pubSpecCopy.then(nextFile);
function nextFile() {
if (!files.length) {
return;
}
var file = files.shift();
return util.processToPromise(spawn(config.command, ['get'], {
stdio: 'inherit',
cwd: path.dirname(file)
})).then(nextFile);
}
};
};

View File

@ -8,7 +8,7 @@ var util = require('./util');
module.exports = function(gulp, plugins, config) {
return function() {
return util.forEachSubDir(
return util.forEachSubDirSequential(
config.dest,
function(dir) {
var testDir = path.join(dir, 'test');
@ -18,7 +18,7 @@ module.exports = function(gulp, plugins, config) {
}));
if (testFiles.length == 0) {
// No test files found
return;
return Q.resolve();
}
var header = ['library _all_tests;', ''];
var main = ['main() {'];

View File

@ -1,24 +1,16 @@
var util = require('./util');
var gulpTraceur = require('../transpiler/gulp-traceur');
var file2moduleName = require('./file2modulename');
var mergeStreams = require('event-stream').merge;
module.exports = function(gulp, plugins, config) {
return function() {
var transpile = gulp.src(config.src)
return gulp.src(config.src)
.pipe(plugins.rename({extname: '.'+config.outputExt}))
.pipe(util.insertSrcFolder(plugins, config.srcFolderInsertion, config.modulesFolder))
.pipe(util.insertSrcFolder(plugins, config.srcFolderInsertion))
.pipe(gulpTraceur(
config.options,
file2moduleName)
)
.pipe(gulp.dest(config.dest));
var copy = gulp.src(config.copy)
.pipe(plugins.rename({extname: '.'+config.outputExt}))
.pipe(util.insertSrcFolder(plugins, config.srcFolderInsertion, config.modulesFolder))
.pipe(gulp.dest(config.dest));
return mergeStreams(transpile, copy);
};
};

View File

@ -8,17 +8,37 @@ module.exports = {
streamToPromise: streamToPromise,
insertSrcFolder: insertSrcFolder,
filterByFile: filterByFile,
forEachSubDir: forEachSubDir
subDirs: subDirs,
forEachSubDir: forEachSubDir,
forEachSubDirSequential: forEachSubDirSequential
};
function subDirs(dir) {
return [].slice.call(glob.sync('*/', {cwd: dir}));
}
function forEachSubDir(dir, callback) {
var moduleFolders = [].slice.call(glob.sync(dir + '/*'));
return Q.all(moduleFolders.map(function(subDir) {
return callback(subDir);
var dirs = subDirs(dir);
return Q.all(dirs.map(function(subdir) {
return callback(path.join(dir, subdir));
}));
};
function forEachSubDirSequential(dir, callback) {
var dirs = subDirs(dir);
return next(0);
function next(index) {
if (index < dirs.length) {
return callback(path.join(dir, dirs[index])).then(function() {
return next(index+1);
});
} else {
return true;
}
}
}
function processToPromise(process) {
var defer = Q.defer();
process.on('close', function(code) {