Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit efbb1f0

Browse files
committed
feat(gulpfile): distill core bahavior
1 parent 5de7df8 commit efbb1f0

File tree

1 file changed

+40
-92
lines changed

1 file changed

+40
-92
lines changed

gulpfile.js

+40-92
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,70 @@
11
/******************************************************
22
* PATTERN LAB NODE
33
* EDITION-NODE-GULP
4-
* The gulp wrapper around patternlab-node core, providing tasks to interact with the core library and move supporting frontend assets.
4+
* The gulp wrapper around patternlab-node core, providing tasks to interact with the core library.
55
******************************************************/
6-
var gulp = require('gulp'),
7-
path = require('path'),
8-
argv = require('minimist')(process.argv.slice(2)),
9-
_ = require('lodash');
10-
11-
/**
12-
* Normalize all paths to be plain, paths with no leading './',
13-
* relative to the process root, and with backslashes converted to
14-
* forward slashes. Should work regardless of how the path was
15-
* written. Accepts any number of parameters, and passes them along to
16-
* path.resolve().
17-
*
18-
* This is intended to avoid all known limitations of gulp.watch().
19-
*
20-
* @param {...string} pathFragment - A directory, filename, or glob.
21-
*/
22-
function normalizePath() {
23-
return path
24-
.relative(
25-
process.cwd(),
26-
path.resolve.apply(this, arguments)
27-
)
28-
.replace(/\\/g, "/");
29-
}
6+
const gulp = require('gulp');
7+
const argv = require('minimist')(process.argv.slice(2));
308

319
/******************************************************
32-
* PATTERN LAB CONFIGURATION - API with core library
10+
* PATTERN LAB NODE WRAPPER TASKS with core library
3311
******************************************************/
34-
//read all paths from our namespaced config file
35-
var config = require('./patternlab-config.json'),
36-
patternlab = require('patternlab-node')(config);
37-
38-
function paths() {
39-
return config.paths;
40-
}
41-
42-
function getConfiguredCleanOption() {
43-
return config.cleanPublic;
44-
}
45-
46-
function getPathsToCopy() {
47-
const pathsToCopy = _.cloneDeep(paths());
48-
delete pathsToCopy.source.root;
49-
delete pathsToCopy.source.patterns;
50-
delete pathsToCopy.source.data;
51-
delete pathsToCopy.source.meta;
52-
delete pathsToCopy.source.annotations;
53-
delete pathsToCopy.source.styleguide;
54-
delete pathsToCopy.source.patternlabFiles;
55-
return pathsToCopy;
12+
const config = require('./patternlab-config.json');
13+
const patternlab = require('@pattern-lab/patternlab-node')(config);
14+
15+
function build() {
16+
return patternlab.build({
17+
watch: argv.watch,
18+
cleanPublic: config.cleanPublic
19+
}).then(() =>{
20+
// do something else when this promise resolves
21+
});
5622
}
5723

58-
/**
59-
* Performs the actual build step. Accomodates both async and sync
60-
* versions of Pattern Lab.
61-
* @param {function} done - Gulp done callback
62-
*/
63-
function build(done) {
64-
//const buildResult = patternlab.build(
65-
const buildResult = patternlab.serve(
66-
() => {}, {
67-
cleanPublic: getConfiguredCleanOption(),
68-
watch: true
69-
}
70-
);
71-
72-
patternlab.events.on('patternlab-asset-change', (data) => {
73-
console.log(126, 'EDITION EVENT! ', data);
74-
})
75-
76-
// handle async version of Pattern Lab
77-
if (buildResult instanceof Promise) {
78-
return buildResult.then(done);
24+
function serve() {
25+
return patternlab.serve({
26+
cleanPublic: config.cleanPublic
7927
}
80-
81-
// handle sync version of Pattern Lab
82-
done();
83-
return null;
28+
).then(() => {
29+
// do something else when this promise resolves
30+
});
8431
}
8532

86-
gulp.task('patternlab:version', function (done) {
33+
gulp.task('patternlab:version', function () {
8734
patternlab.version();
88-
done();
8935
});
9036

91-
gulp.task('patternlab:help', function (done) {
37+
gulp.task('patternlab:help', function () {
9238
patternlab.help();
93-
done();
9439
});
9540

96-
gulp.task('patternlab:patternsonly', function (done) {
97-
patternlab.patternsonly(done, getConfiguredCleanOption());
41+
gulp.task('patternlab:patternsonly', function () {
42+
patternlab.patternsonly(config.cleanPublic);
9843
});
9944

100-
gulp.task('patternlab:liststarterkits', function (done) {
45+
gulp.task('patternlab:liststarterkits', function () {
10146
patternlab.liststarterkits();
102-
done();
10347
});
10448

105-
gulp.task('patternlab:loadstarterkit', function (done) {
49+
gulp.task('patternlab:loadstarterkit', function () {
10650
patternlab.loadstarterkit(argv.kit, argv.clean);
107-
done();
10851
});
10952

110-
gulp.task('patternlab:build', gulp.series(build));
53+
gulp.task('patternlab:build', function () {
54+
build().then(() => {
55+
// do something else when this promise resolves
56+
});
57+
});
58+
59+
gulp.task('patternlab:serve', function () {
60+
serve().then(() => {
61+
// do something else when this promise resolves
62+
});
63+
});
11164

112-
gulp.task('patternlab:installplugin', function (done) {
65+
gulp.task('patternlab:installplugin', function () {
11366
patternlab.installplugin(argv.plugin);
114-
done();
11567
});
11668

117-
/******************************************************
118-
* COMPOUND TASKS
119-
******************************************************/
120-
gulp.task('default', gulp.series('patternlab:build'));
121-
gulp.task('patternlab:watch', gulp.series('patternlab:build', watch));
122-
gulp.task('patternlab:serve', gulp.series('patternlab:build', 'patternlab:connect', watch));
69+
gulp.task('default', ['patternlab:help']);
70+

0 commit comments

Comments
 (0)