Skip to content

Commit

Permalink
Merge pull request #798 from pattern-lab/feature/copy-pattern-js
Browse files Browse the repository at this point in the history
Adding routine to copy js along pattern build
  • Loading branch information
bmuenzenmeyer authored Feb 16, 2018
2 parents b18a38d + 351ea5e commit bcf60e4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
32 changes: 26 additions & 6 deletions core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

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

const { concat } = require('lodash');
const copy = require('recursive-copy');
const path = require('path');
const updateNotifier = require('update-notifier');

Expand Down Expand Up @@ -277,14 +279,32 @@ const patternlab_module = function(config) {
p.compileState = CompileState.NEEDS_REBUILD;
}
}

//render all patterns last, so lineageR works
return patternsToBuild
.reduce((previousPromise, pattern) => {
return previousPromise.then(() =>
patternlab.renderSinglePattern(pattern)
const allPatternsPromise = patternsToBuild.map(pattern =>
patternlab.renderSinglePattern(pattern)
);
//copy non-pattern files like JavaScript
const allJS = patternsToBuild.map(pattern => {
const { name, patternPartial, subdir } = pattern;
const {
source: { patterns: sourceDir },
public: { patterns: publicDir },
} = patternlab.config.paths;
const src = path.join(sourceDir, subdir);
const dest = path.join(publicDir, name);
return copy(src, dest, {
overwrite: true,
filter: ['*.js'],
rename: () => {
return `${patternPartial}.js`;
},
}).on(copy.events.COPY_FILE_COMPLETE, () => {
logger.debug(
`Copied JavaScript files from ${src} to ${dest}`
);
}, Promise.resolve())
});
});
return Promise.all(concat(allPatternsPromise, allJS))
.then(() => {
// Saves the pattern graph when all files have been compiled
PatternGraph.storeToFile(patternlab);
Expand Down
1 change: 1 addition & 0 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ module.exports = class PatternLab {
allData = _.merge({}, this.data, pattern.jsonFileData);
allData = _.merge({}, allData, allListItems);
allData.cacheBuster = this.cacheBuster;
allData.patternPartial = pattern.patternPartial;

///////////////
// HEADER
Expand Down

0 comments on commit bcf60e4

Please sign in to comment.