|
1 | 1 | /******************************************************
|
2 | 2 | * PATTERN LAB NODE
|
3 | 3 | * 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. |
5 | 5 | ******************************************************/
|
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)); |
30 | 8 |
|
31 | 9 | /******************************************************
|
32 |
| - * PATTERN LAB CONFIGURATION - API with core library |
| 10 | + * PATTERN LAB NODE WRAPPER TASKS with core library |
33 | 11 | ******************************************************/
|
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 | + }); |
56 | 22 | }
|
57 | 23 |
|
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 |
79 | 27 | }
|
80 |
| - |
81 |
| - // handle sync version of Pattern Lab |
82 |
| - done(); |
83 |
| - return null; |
| 28 | +).then(() => { |
| 29 | + // do something else when this promise resolves |
| 30 | + }); |
84 | 31 | }
|
85 | 32 |
|
86 |
| -gulp.task('patternlab:version', function (done) { |
| 33 | +gulp.task('patternlab:version', function () { |
87 | 34 | patternlab.version();
|
88 |
| - done(); |
89 | 35 | });
|
90 | 36 |
|
91 |
| -gulp.task('patternlab:help', function (done) { |
| 37 | +gulp.task('patternlab:help', function () { |
92 | 38 | patternlab.help();
|
93 |
| - done(); |
94 | 39 | });
|
95 | 40 |
|
96 |
| -gulp.task('patternlab:patternsonly', function (done) { |
97 |
| - patternlab.patternsonly(done, getConfiguredCleanOption()); |
| 41 | +gulp.task('patternlab:patternsonly', function () { |
| 42 | + patternlab.patternsonly(config.cleanPublic); |
98 | 43 | });
|
99 | 44 |
|
100 |
| -gulp.task('patternlab:liststarterkits', function (done) { |
| 45 | +gulp.task('patternlab:liststarterkits', function () { |
101 | 46 | patternlab.liststarterkits();
|
102 |
| - done(); |
103 | 47 | });
|
104 | 48 |
|
105 |
| -gulp.task('patternlab:loadstarterkit', function (done) { |
| 49 | +gulp.task('patternlab:loadstarterkit', function () { |
106 | 50 | patternlab.loadstarterkit(argv.kit, argv.clean);
|
107 |
| - done(); |
108 | 51 | });
|
109 | 52 |
|
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 | +}); |
111 | 64 |
|
112 |
| -gulp.task('patternlab:installplugin', function (done) { |
| 65 | +gulp.task('patternlab:installplugin', function () { |
113 | 66 | patternlab.installplugin(argv.plugin);
|
114 |
| - done(); |
115 | 67 | });
|
116 | 68 |
|
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