Skip to content

Commit dda2055

Browse files
committed
finish up copy
closes #706
1 parent 52e6d3e commit dda2055

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

core/lib/asset_copy.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const asset_copier = () => {
1111
const transform_paths = (directories) => {
1212
//create array with all source keys minus our blacklist
1313
const dirs = {};
14-
const blackList = ['root', 'patterns', 'data', 'meta', 'annotations', 'styleguide', 'patternlabFiles'];
14+
const blackList = ['root', 'patterns', 'data', 'meta', 'annotations', 'patternlabFiles'];
1515
_.each(directories.source, (dir, key) => {
1616

1717
if (blackList.includes(key)) {
@@ -66,13 +66,18 @@ const asset_copier = () => {
6666
};
6767

6868
//loop through each directory asset object (source / public pairing)
69-
_.each(dirs, (dir) => {
69+
_.each(dirs, (dir, key) => {
7070

7171
//if we want to watch files, do so, otherwise just copy each file
7272
if (options.watch) {
7373
if (patternlab.config.debug) {
7474
console.log(`Pattern Lab is watching ${path.resolve(basePath, dir.source)} for changes`);
7575
}
76+
77+
if (patternlab.watchers[key]) {
78+
patternlab.watchers[key].close();
79+
}
80+
7681
const assetWatcher = chokidar.watch(
7782
path.resolve(basePath, dir.source),
7883
{
@@ -97,13 +102,21 @@ const asset_copier = () => {
97102
copyFile(p, destination, copyOptions);
98103
});
99104

105+
patternlab.watchers[key] = assetWatcher;
106+
100107
} else {
101108
//just copy
102109
const destination = path.resolve(basePath, dir.public);
103110
copyFile(dir.source, destination, copyOptions);
104111
}
105112
});
106113

114+
// copy the styleguide
115+
copyFile(assetDirectories.source.styleguide, assetDirectories.public.root, copyOptions);
116+
117+
// copy the favicon
118+
copyFile(`${assetDirectories.source.root}/favicon.ico`, `${assetDirectories.public.root}/favicon.ico`, copyOptions);
119+
107120
//we need to special case patterns/**/*.md|.json|.pattern-extensions as well as the global structures
108121
if (options.watch) {
109122

@@ -121,6 +134,10 @@ const asset_copier = () => {
121134
console.log(`Pattern Lab is watching ${globalPath} for changes`);
122135
}
123136

137+
if (patternlab.watchers[globalPath]) {
138+
patternlab.watchers[globalPath].close();
139+
}
140+
124141
const globalWatcher = chokidar.watch(
125142
path.resolve(globalPath),
126143
{
@@ -150,6 +167,8 @@ const asset_copier = () => {
150167
});
151168
});
152169

170+
patternlab.watchers[globalPath] = globalWatcher;
171+
153172
});
154173

155174
// watch patterns

core/lib/patternlab.js

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ const patternlab_engine = function (config) {
200200
patternlab.package = fs.readJSONSync(path.resolve(__dirname, '../../package.json'));
201201
patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../../patternlab-config.json'));
202202
patternlab.events = new PatternLabEventEmitter();
203+
patternlab.watchers = {};
203204

204205
// Initialized when building
205206
patternlab.graph = null;

core/lib/serve.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const serve = (patternlab) => {
1010
open: true,
1111
ignore: path.join(path.resolve(patternlab.config.paths.public.root)),
1212
file: 'index.html',
13-
logLevel: 0 // errors only
13+
logLevel: 0, // errors only
14+
wait: 1000
1415
};
1516

1617
// allow for overrides should they exist inside patternlab-config.json

0 commit comments

Comments
 (0)