Skip to content

Commit c2b089c

Browse files
author
mgoria
committed
Merge branch 'dev' of github.com:MitocGroup/deepify into dev
2 parents bbd2642 + 897b394 commit c2b089c

38 files changed

+1078
-3008
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ lib-cov
8888
# Coverage directory used by tools like istanbul
8989
coverage
9090
coverages
91-
compile
9291

9392
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
9493
.grunt

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sudo: false
33
node_js:
44
- '4.3'
55
- '6.10'
6-
- '7.7'
6+
- '7.8'
77
cache:
88
edge: true
99
directories:

src/bin/commands/bin/compile-es6.sh

-25
This file was deleted.

src/bin/commands/compile/es6.js

+29-10
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,52 @@
77

88
module.exports = function(mainPath) {
99
let path = require('path');
10+
let esPreset = require('./helper/es-preset');
1011
let Exec = require('../../../lib.compiled/Helpers/Exec').Exec;
1112

1213
mainPath = this.normalizeInputPath(mainPath);
1314
let extension = this.opts.locate('extension').value || '.es6';
1415
let outDirectory = this.opts.locate('out-dir').value || mainPath;
15-
let compileEs5 = this.opts.locate('es5').exists;
16+
let compileES5 = this.opts.locate('es5').exists;
1617
let pipeSource = this.opts.locate('source').exists;
1718
let nodeModules = path.join(__dirname, '../../../node_modules');
1819

1920
let babelCompileCommand = () => {
2021
let babelCmd = path.join(nodeModules, 'babel-cli/bin/babel.js');
21-
let presets = [path.join(nodeModules, `babel-preset-es2015${ compileEs5 ? '' : '-node4' }`)];
22-
let plugins = [
23-
path.join(nodeModules, 'babel-plugin-transform-es2015-classes'),
24-
path.join(nodeModules, 'babel-plugin-add-module-exports'),
25-
];
22+
let presets = [];
23+
let babelES6Preset = null;
24+
let plugins = [ path.join(nodeModules, 'babel-plugin-add-module-exports') ];
25+
26+
if (compileES5) {
27+
presets.push(path.join(nodeModules, 'babel-preset-es2015'));
28+
} else {
29+
babelES6Preset = esPreset();
30+
31+
presets.push(path.join(nodeModules, babelES6Preset));
32+
}
33+
34+
if (compileES5 || babelES6Preset === 'babel-preset-es2015-node4') {
35+
plugins.push(path.join(nodeModules, 'babel-plugin-transform-es2015-classes'));
36+
}
2637

2738
let compileCmd = new Exec(
2839
this.nodeBinary,
2940
babelCmd,
3041
mainPath
3142
);
3243

33-
compileCmd
34-
.addArg(`--extensions=${extension}`)
35-
.addArg(`--presets=${presets.join(',')}`)
36-
.addArg(`--plugins=${plugins.join(',')}`);
44+
console.log(`Plugins: ${plugins.map(p => path.basename(p)).join(', ')}`);
45+
console.log(`Presets: ${presets.map(p => path.basename(p)).join(', ')}`);
46+
47+
compileCmd.addArg(`--extensions=${extension}`);
48+
49+
if (presets.length > 0) {
50+
compileCmd.addArg(`--presets=${presets.join(',')}`);
51+
}
52+
53+
if (plugins.length > 0) {
54+
compileCmd.addArg(`--plugins=${plugins.join(',')}`);
55+
}
3756

3857
if (!pipeSource) {
3958
compileCmd.addArg(`--out-dir=${outDirectory}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* Created by AlexanderC on 8/4/15.
3+
*/
4+
5+
'use strict';
6+
7+
const NpmChain = require('../../../../lib.compiled/NodeJS/NpmChain').NpmChain;
8+
const Hash = require('deep-package-manager').Helpers_Hash;
9+
const helpers = require('./compile-prod');
10+
const tmp = require('tmp');
11+
const path = require('path');
12+
const webpackConfig = require('./webpack.prod');
13+
const fse = require('fs-extra');
14+
const pify = require('pify');
15+
16+
module.exports = function (lambdaPath, debug, purge, libsToLink) {
17+
const dry = debug ? '[DRY] ' : '';
18+
19+
console.log(`Compiling lambda "${lambdaPath}" (purge=${purge ? 'true' : 'false'})`);
20+
console.debug(`${dry}Purge "node_modules" in "${lambdaPath}"`);
21+
22+
const prepare = (purge && !debug)
23+
? pify(fse.remove)(path.join(lambdaPath, 'node_modules'))
24+
: Promise.resolve();
25+
26+
return prepare
27+
.then(() => {
28+
if (libsToLink.length <= 0) {
29+
console.debug(`No global libraries available to link for "${lambdaPath}"`);
30+
31+
return Promise.resolve();
32+
}
33+
34+
console.debug(`${dry}Linking global libraries in "${lambdaPath}" (${libsToLink.join(', ')})`);
35+
36+
return Promise.all(libsToLink.map(lib => {
37+
return helpers.hasDependency(lambdaPath, lib)
38+
.then(hasLib => {
39+
if (!hasLib) {
40+
console.debug(`Skip linking extraneous library "${lib}" in "${lambdaPath}"`);
41+
}
42+
43+
return Promise.resolve(hasLib);
44+
});
45+
})).then(libsVector => {
46+
const libs = libsToLink.filter((lib, i) => {
47+
return libsVector[i];
48+
});
49+
50+
if (libs.length <= 0) {
51+
return Promise.resolve();
52+
}
53+
54+
return helpers.npmLink(lambdaPath, libs, debug);
55+
});
56+
})
57+
.then(() => {
58+
console.debug(`${dry}Running "npm install" on "${lambdaPath}"`);
59+
60+
return helpers.npmInstall(lambdaPath, debug);
61+
})
62+
.then(() => {
63+
const buildPath = path.join(
64+
tmp.dirSync().name,
65+
`${Hash.md5(lambdaPath)}_${new Date().getTime()}`
66+
);
67+
const configFile = path.join(buildPath, 'webpack.prod.js');
68+
const bundlePath = path.join(buildPath, 'bundle');
69+
70+
console.debug(`Ensure working env in "${buildPath}"`);
71+
72+
return pify(fse.ensureDir)(bundlePath)
73+
.then(() => {
74+
return webpackConfig(lambdaPath, bundlePath, libsToLink, debug)
75+
.then(webpackConfig => {
76+
const { rawConfig, tmpBootstrapJs } = webpackConfig;
77+
78+
return pify(fse.outputFile)(configFile, rawConfig)
79+
.then(() => Promise.resolve(tmpBootstrapJs));
80+
});
81+
})
82+
.then(tmpBootstrapJs => {
83+
console.debug(`Bundle "${lambdaPath}" using Webpack to "${bundlePath}"`);
84+
85+
const removeTmpBootstrap = () => {
86+
console.debug(`Removing temporary bootstrap file "${tmpBootstrapJs}"`);
87+
88+
return pify(fse.remove)(tmpBootstrapJs)
89+
.catch(() => Promise.resolve());
90+
};
91+
92+
return helpers.bundle(configFile, debug)
93+
.then(() => removeTmpBootstrap())
94+
.catch(error => {
95+
return removeTmpBootstrap()
96+
.then(() => Promise.reject(error));
97+
});
98+
})
99+
.then(() => Promise.resolve({ bundlePath, buildPath }));
100+
})
101+
.then(result => {
102+
const { bundlePath, buildPath } = result;
103+
const bundleDestination = path.join(
104+
lambdaPath,
105+
'..',
106+
`${path.basename(lambdaPath)}.zip`
107+
);
108+
109+
console.info(`Archive "${lambdaPath}" build to "${bundleDestination}"`);
110+
111+
return pify(fse.remove)(bundleDestination)
112+
.catch(() => Promise.resolve())
113+
.then(() => helpers.zip(bundlePath, bundleDestination))
114+
.then(() => Promise.resolve(buildPath));
115+
})
116+
.then(buildPath => {
117+
console.debug(`Cleanup temporary data for "${lambdaPath}"`);
118+
119+
return pify(fse.remove)(buildPath);
120+
});
121+
};

0 commit comments

Comments
 (0)