-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathstart.js
executable file
·136 lines (116 loc) · 3.83 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env node
'use strict';
require = require('esm')(module);
const _ = require('lodash');
const browserSync = require('browser-sync').create();
const exec = require('child_process').exec;
const CONFIG = require('./_config');
const { copyDist } = require('./_util/copy');
const { generateAll, generateApis } = require('./_generate');
const serverRoutes = {};
serverRoutes[CONFIG.site.baseHref] = CONFIG.publicDir;
// new pipeline functionality
const {
bundleStyles,
bundleBrowsers: bundleBrowserScripts,
} = require('../tasks/bundle');
/**
* 2019-11-01: Disabling Selenium, because it's currently not
* being used and wasting system resources
*/
//browserSync.emitter.on('init', () => {
// console.log('Starting a selenium webdriver instance...');
// exec('yarn webdriver:start', { cwd: CONFIG.testDir }); // don't log anything to the dev server
//});
const lintStylesGlob = `${CONFIG.sourceDir}/**/*.{scss,css}`;
function _regenDocs () {
bundleStyles();
generateAll();
}
function _regenSrc () {
bundleBrowserScripts();
// always regenerate docs when source files change
_regenDocs();
}
browserSync.init({
logLevel: 'debug',
notify: false,
open: false,
reloadOnRestart: true,
reloadDebounce: 250,
server: {
baseDir: CONFIG.publicDir,
routes: serverRoutes
},
watchEvents: ['change'],
files: [
// Reload browser if any file in public directory changes
`${CONFIG.publicDir}/*`,
`${CONFIG.publicDir}/**/*`,
// Regenerate docs if anything changes in the docs directory
// or if any LightDOM CSS changes in the source directory
{
match: [
`${CONFIG.docsDir}/*`,
`${CONFIG.docsDir}/**/*`,
// Ignore raw API data files
`!${CONFIG.docsDir}/api/*`,
`!${CONFIG.docsDir}/api/**/*`,
],
fn: _.debounce(_regenDocs, 1500),
},
{
match: [
// Changes to any source file can modify compiled JS output
`${CONFIG.sourceDir}/**/*`,
// ignore changes to test files
`!${CONFIG.sourceDir}/**/*.spec.js`,
],
fn: _.debounce(_regenSrc, 1500),
},
// Generate API docs when src files change
{
match: [
// ANY JavaScript file in the src/ directory should
// trigger generation of API docs...
`${CONFIG.sourceDir}/**/*.js`,
// ... excluding spec files
`!${CONFIG.sourceDir}/**/*.spec.js`,
],
fn: _.debounce(generateApis, 1500),
},
{
match: [
lintStylesGlob,
],
fn: _.debounce(() => {
let _cmd = `stylelint --color "${lintStylesGlob}"`;
let _proc = exec(_cmd, { cwd: CONFIG.root });
_proc.stdout.pipe(process.stdout);
_proc.stderr.pipe(process.stderr);
}),
},
// Only copy when files change in dist/
{
match: [
`${CONFIG.distDir}/*`,
`${CONFIG.distDir}/**/*`,
],
fn: _.debounce(copyDist, 1500),
},
// Re-transpile test files
// 2019-11-01: temporarily disabled (unused; wasting cpu cycles)
//{
// match: [
// `${CONFIG.testDir}/**/*.ts`,
// `!${CONFIG.testDir}/node_modules/**`,
// `!${CONFIG.testDir}/built/**/*`,
// ],
// fn: _.debounce(() => {
// const tsc = exec('yarn build', { cwd: CONFIG.testDir });
// tsc.stdout.pipe(process.stdout);
// tsc.stderr.pipe(process.stderr);
// }, 1500),
//},
],
});