Skip to content

Commit bcf60e4

Browse files
Merge pull request #798 from pattern-lab/feature/copy-pattern-js
Adding routine to copy js along pattern build
2 parents b18a38d + 351ea5e commit bcf60e4

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

core/index.js

Lines changed: 26 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,32 @@ 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, patternPartial, 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+
rename: () => {
299+
return `${patternPartial}.js`;
300+
},
301+
}).on(copy.events.COPY_FILE_COMPLETE, () => {
302+
logger.debug(
303+
`Copied JavaScript files from ${src} to ${dest}`
286304
);
287-
}, Promise.resolve())
305+
});
306+
});
307+
return Promise.all(concat(allPatternsPromise, allJS))
288308
.then(() => {
289309
// Saves the pattern graph when all files have been compiled
290310
PatternGraph.storeToFile(patternlab);

core/lib/patternlab.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ module.exports = class PatternLab {
380380
allData = _.merge({}, this.data, pattern.jsonFileData);
381381
allData = _.merge({}, allData, allListItems);
382382
allData.cacheBuster = this.cacheBuster;
383+
allData.patternPartial = pattern.patternPartial;
383384

384385
///////////////
385386
// HEADER

0 commit comments

Comments
 (0)