Skip to content

Commit 60ebb6e

Browse files
committed
Adding routine to copy js along pattern build
1 parent 98b24fa commit 60ebb6e

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

core/index.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
const packageInfo = require('../package.json');
1414

15+
const { concat } = require('lodash');
16+
const copy = require('recursive-copy');
1517
const path = require('path');
1618
const updateNotifier = require('update-notifier');
1719

@@ -277,14 +279,29 @@ const patternlab_module = function(config) {
277279
p.compileState = CompileState.NEEDS_REBUILD;
278280
}
279281
}
280-
281282
//render all patterns last, so lineageR works
282-
return patternsToBuild
283-
.reduce((previousPromise, pattern) => {
284-
return previousPromise.then(() =>
285-
patternlab.renderSinglePattern(pattern)
283+
const allPatternsPromise = patternsToBuild.map(pattern =>
284+
patternlab.renderSinglePattern(pattern)
285+
);
286+
//copy non-pattern files like JavaScript
287+
const allJS = patternsToBuild.map(pattern => {
288+
const { name, subdir } = pattern;
289+
const {
290+
source: { patterns: sourceDir },
291+
public: { patterns: publicDir },
292+
} = patternlab.config.paths;
293+
const src = path.join(sourceDir, subdir);
294+
const dest = path.join(publicDir, name);
295+
return copy(src, dest, {
296+
overwrite: true,
297+
filter: ['*.js'],
298+
}).on(copy.events.COPY_FILE_COMPLETE, () => {
299+
logger.debug(
300+
`Copied JavaScript files from ${src} to ${dest}`
286301
);
287-
}, Promise.resolve())
302+
});
303+
});
304+
return Promise.all(concat(allPatternsPromise, allJS))
288305
.then(() => {
289306
// Saves the pattern graph when all files have been compiled
290307
PatternGraph.storeToFile(patternlab);

0 commit comments

Comments
 (0)