Skip to content

Commit 26a8b95

Browse files
committed
Merge pull request #32 from doapp-ryanp/patch-1
includePaths needs to support files
2 parents 3501e54 + 8692579 commit 26a8b95

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

index.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
module.exports = function(S) {
88

9-
const path = require('path'),
10-
_ = require('lodash'),
11-
fs = require('fs'),
12-
browserify = require('browserify'),
13-
UglifyJS = require('uglify-js'),
14-
wrench = require('wrench'),
15-
BbPromise = require('bluebird');
9+
const path = require('path'),
10+
_ = require('lodash'),
11+
fs = require('fs'),
12+
browserify = require('browserify'),
13+
UglifyJS = require('uglify-js'),
14+
wrench = require('wrench'),
15+
BbPromise = require('bluebird');
1616

1717
/**
1818
* ServerlessOptimizer
@@ -44,7 +44,7 @@ module.exports = function(S) {
4444

4545
S.addHook(this._optimize.bind(this), {
4646
action: 'codeDeployLambda',
47-
event: 'pre'
47+
event: 'pre'
4848
});
4949

5050
return BbPromise.resolve();
@@ -63,8 +63,8 @@ module.exports = function(S) {
6363
}
6464

6565
// Get function
66-
let func = S.getProject().getFunction(evt.options.name),
67-
optimizer;
66+
let func = S.getProject().getFunction(evt.options.name),
67+
optimizer;
6868

6969
// Skip if no optimization is set on function
7070
if (!func.custom || !func.custom.optimize) {
@@ -140,8 +140,8 @@ module.exports = function(S) {
140140
class OptimizeNodejs {
141141

142142
constructor(S, evt, func) {
143-
this.evt = evt;
144-
this.function = func;
143+
this.evt = evt;
144+
this.function = func;
145145
}
146146

147147
optimize() {
@@ -177,8 +177,8 @@ module.exports = function(S) {
177177

178178
browserify() {
179179

180-
let _this = this;
181-
let uglyOptions = {
180+
let _this = this;
181+
let uglyOptions = {
182182
mangle: true, // @see http://lisperator.net/uglifyjs/compress
183183
compress: {}
184184
};
@@ -197,7 +197,7 @@ module.exports = function(S) {
197197
insertGlobalVars: { // Handle process https://github.com/substack/node-browserify/issues/1277
198198
//__filename: insertGlobals.lets.__filename,
199199
//__dirname: insertGlobals.lets.__dirname,
200-
process: function () {
200+
process: function() {
201201
}
202202
}
203203
});
@@ -227,9 +227,9 @@ module.exports = function(S) {
227227
_this.config.ignore.forEach(file => b.ignore(file));
228228

229229
// Perform Bundle
230-
return new BbPromise(function (resolve, reject) {
230+
return new BbPromise(function(resolve, reject) {
231231

232-
b.bundle(function (err, bundledBuf) {
232+
b.bundle(function(err, bundledBuf) {
233233

234234
// Reset pathDist
235235
_this.optimizedDistPath = path.join(_this.evt.options.pathDist, 'optimized');
@@ -267,14 +267,20 @@ module.exports = function(S) {
267267

268268
if (includePaths && includePaths.length) {
269269
includePaths.forEach(function(p) {
270+
let destPath = path.join(_this.optimizedDistPath, p);
270271

271-
wrench.mkdirSyncRecursive(path.join(_this.optimizedDistPath, p), '0777');
272-
wrench.copyDirSyncRecursive(
272+
if (fs.lstatSync(p).isDirectory()) {
273+
wrench.mkdirSyncRecursive(destPath, '0777');
274+
wrench.copyDirSyncRecursive(
273275
path.join(_this.evt.options.pathDist, p),
274-
path.join(_this.optimizedDistPath, p), {
275-
forceDelete: true
276+
destPath, {
277+
forceDelete: true
276278
}
277-
);
279+
);
280+
} else {
281+
wrench.mkdirSyncRecursive(path.dirname(destPath), '0777');
282+
S.utils.writeFileSync(destPath, S.utils.readFileSync(p));
283+
}
278284
});
279285
}
280286

0 commit comments

Comments
 (0)