sdc-build-wp 4.7.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/index.js +7 -112
- package/lib/build.js +34 -0
- package/lib/components/blocks.js +1 -0
- package/lib/components/errors.js +1 -0
- package/lib/components/fonts.js +1 -0
- package/lib/components/images.js +1 -0
- package/lib/components/php.js +1 -0
- package/lib/components/scripts.js +1 -0
- package/lib/components/server.js +1 -0
- package/lib/components/style.js +1 -0
- package/lib/help.js +30 -0
- package/lib/project.js +76 -0
- package/lib/utils.js +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,4 +16,10 @@ Develop locally with the following command from within the test project director
|
|
|
16
16
|
node ~/sites/sdc/sdc-build-wp/index.js --watch
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
While watch is
|
|
19
|
+
While watch is enabled, use the following keyboard commands to control the build process:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
[r] Restart
|
|
23
|
+
[p] Pause/Resume
|
|
24
|
+
[q] Quit
|
|
25
|
+
````
|
package/index.js
CHANGED
|
@@ -1,116 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import { promises as fs } from 'fs';
|
|
6
|
-
import project from './lib/project.js';
|
|
7
|
-
import log from './lib/logging.js';
|
|
8
|
-
import * as LibComponents from './lib/components/index.js';
|
|
9
|
-
|
|
10
|
-
project.components = Object.fromEntries(Object.entries(LibComponents).map(([name, Class]) => [name, new Class()]));
|
|
11
|
-
|
|
12
|
-
const argv = parseArgs(process.argv.slice(2));
|
|
13
|
-
|
|
14
|
-
if (argv.help || argv.h) {
|
|
15
|
-
console.log(`
|
|
16
|
-
Usage: sdc-build-wp [options] [arguments]
|
|
17
|
-
|
|
18
|
-
Options:
|
|
19
|
-
-h, --help Show help message and exit
|
|
20
|
-
-v, --version Version
|
|
21
|
-
-w, --watch Build and watch
|
|
22
|
-
-b, --builds BUILDS Build with specific components
|
|
23
|
-
|
|
24
|
-
Components:
|
|
25
|
-
|
|
26
|
-
${Object.entries(project.components).map(([key, component]) => {
|
|
27
|
-
return `${key}\t\t${component.description}\r\n`;
|
|
28
|
-
}).join('')}
|
|
29
|
-
Examples:
|
|
30
|
-
|
|
31
|
-
sdc-build-wp
|
|
32
|
-
sdc-build-wp --watch
|
|
33
|
-
sdc-build-wp --watch --builds=style,scripts
|
|
34
|
-
`);
|
|
35
|
-
|
|
36
|
-
process.exit(0);
|
|
37
|
-
} else if (argv.version || argv.v) {
|
|
38
|
-
console.log(JSON.parse(await fs.readFile(path.join(path.dirname(fileURLToPath(import.meta.url)), 'package.json'))).version);
|
|
39
|
-
process.exit(0);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
project.builds = argv.builds ? (Array.isArray(argv.builds) ? argv.builds : argv.builds.split(',')) : Object.keys(project.components);
|
|
2
|
+
import { default as project, init, keypressListen } from './lib/project.js';
|
|
3
|
+
import build from './lib/build.js';
|
|
43
4
|
|
|
44
5
|
(async () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
process.on('SIGINT', function () {
|
|
50
|
-
console.log(`\r`);
|
|
51
|
-
if (process.stdin.isTTY) {
|
|
52
|
-
process.stdin.setRawMode(false);
|
|
53
|
-
process.stdin.pause();
|
|
6
|
+
await init();
|
|
7
|
+
if (project.argv.watch) {
|
|
8
|
+
keypressListen();
|
|
54
9
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
process.exit(0);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
function keypressListen() {
|
|
61
|
-
if (!process.stdin.isTTY) { return; }
|
|
62
|
-
|
|
63
|
-
process.stdin.setRawMode(true);
|
|
64
|
-
process.stdin.resume();
|
|
65
|
-
process.stdin.setEncoding('utf8');
|
|
66
|
-
|
|
67
|
-
process.stdin.on('data', (key) => {
|
|
68
|
-
switch (key) {
|
|
69
|
-
case '\u0003': // Ctrl+C
|
|
70
|
-
case 'q':
|
|
71
|
-
process.emit('SIGINT');
|
|
72
|
-
return;
|
|
73
|
-
case 'r':
|
|
74
|
-
log('info', 'Restart requested...');
|
|
75
|
-
stopActiveComponents()
|
|
76
|
-
setTimeout(() => {
|
|
77
|
-
process.stdout.write('\x1B[2J\x1B[0f'); // Clear screen
|
|
78
|
-
runBuild();
|
|
79
|
-
}, 100);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async function runBuild() {
|
|
86
|
-
if (argv.watch && project.builds.includes('server')) {
|
|
87
|
-
project.builds.splice(project.builds.indexOf('server'), 1);
|
|
88
|
-
project.builds.unshift('server');
|
|
89
|
-
project.components.server.serve(false);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let initialBuildTimerStart = performance.now();
|
|
93
|
-
log('info', `Started initial build [${project.builds.join(', ')}]`);
|
|
94
|
-
let promisesBuilds = [];
|
|
95
|
-
for (let build of project.builds) {
|
|
96
|
-
promisesBuilds.push(project.components[build].init());
|
|
97
|
-
}
|
|
98
|
-
await Promise.all(promisesBuilds);
|
|
99
|
-
log('info', `Finished initial build in ${Math.round((performance.now() - initialBuildTimerStart) / 1000)} seconds`);
|
|
100
|
-
|
|
101
|
-
if (argv.watch && project.builds.includes('server')) {
|
|
102
|
-
project.builds.splice(project.builds.indexOf('server'), 1);
|
|
103
|
-
project.builds.push('server');
|
|
104
|
-
log('info', `Started watching [${project.builds.join(', ')}]`);
|
|
105
|
-
log('info', `[r] to restart, [q] to quit`);
|
|
106
|
-
for (let build of project.builds) {
|
|
107
|
-
await project.components[build].watch();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function stopActiveComponents() {
|
|
113
|
-
if (project.components.server?.server) {
|
|
114
|
-
project.components.server.server.exit();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
10
|
+
await build(project.argv.watch);
|
|
11
|
+
})();
|
package/lib/build.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { default as project } from './project.js';
|
|
2
|
+
import * as utils from './utils.js';
|
|
3
|
+
import log from './logging.js';
|
|
4
|
+
|
|
5
|
+
export default async function(watch = false) {
|
|
6
|
+
if (watch && project.builds.includes('server')) {
|
|
7
|
+
project.builds.splice(project.builds.indexOf('server'), 1);
|
|
8
|
+
project.builds.unshift('server');
|
|
9
|
+
project.components.server.serve(false);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let initialBuildTimerStart = performance.now();
|
|
13
|
+
log('info', `Started initial build [${project.builds.join(', ')}]`);
|
|
14
|
+
let promisesBuilds = [];
|
|
15
|
+
for (let build of project.builds) {
|
|
16
|
+
promisesBuilds.push(project.components[build].init());
|
|
17
|
+
}
|
|
18
|
+
await Promise.all(promisesBuilds);
|
|
19
|
+
utils.clearScreen();
|
|
20
|
+
log('info', `Finished initial build in ${Math.round((performance.now() - initialBuildTimerStart) / 1000)} seconds`);
|
|
21
|
+
|
|
22
|
+
if (watch && project.builds.includes('server')) {
|
|
23
|
+
project.isRunning = true;
|
|
24
|
+
project.builds.splice(project.builds.indexOf('server'), 1);
|
|
25
|
+
project.builds.push('server');
|
|
26
|
+
log('info', `Started watching [${project.builds.join(', ')}]`);
|
|
27
|
+
log('info', `[r] to restart, [p] to pause/resume, [q] to quit`);
|
|
28
|
+
for (let build of project.builds) {
|
|
29
|
+
await project.components[build].watch();
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
process.emit('SIGINT');
|
|
33
|
+
}
|
|
34
|
+
}
|
package/lib/components/blocks.js
CHANGED
|
@@ -88,6 +88,7 @@ export default class BlocksComponent extends BaseComponent {
|
|
|
88
88
|
this.chokidar.watch(`${block}/src`, {
|
|
89
89
|
...this.project.chokidarOpts
|
|
90
90
|
}).on('all', (event, path) => {
|
|
91
|
+
if (!this.project.isRunning) { return; }
|
|
91
92
|
if (!['unlink', 'unlinkDir'].includes(event)) {
|
|
92
93
|
if (path.endsWith('.js')) {
|
|
93
94
|
this.project.components.scripts.lint(path);
|
package/lib/components/errors.js
CHANGED
|
@@ -26,6 +26,7 @@ export default class ErrorsComponent extends BaseComponent {
|
|
|
26
26
|
try {
|
|
27
27
|
await fs.access(this.project.paths.errorLog);
|
|
28
28
|
new Tail(this.project.paths.errorLog).on('line', function(data) {
|
|
29
|
+
if (!component.project.isRunning) { return; }
|
|
29
30
|
component.log('php', data);
|
|
30
31
|
});
|
|
31
32
|
} catch (error) {
|
package/lib/components/fonts.js
CHANGED
package/lib/components/images.js
CHANGED
|
@@ -80,6 +80,7 @@ export default class ImagesComponent extends BaseComponent {
|
|
|
80
80
|
this.watcher = this.chokidar.watch(this.project.paths.images, {
|
|
81
81
|
...this.project.chokidarOpts
|
|
82
82
|
}).on('all', (event, path) => {
|
|
83
|
+
if (!this.project.isRunning) { return; }
|
|
83
84
|
this.process();
|
|
84
85
|
});
|
|
85
86
|
}
|
package/lib/components/php.js
CHANGED
|
@@ -90,6 +90,7 @@ export default class PHPComponent extends BaseComponent {
|
|
|
90
90
|
this.watcher = this.chokidar.watch(this.globs, {
|
|
91
91
|
...this.project.chokidarOpts
|
|
92
92
|
}).on('all', (event, path) => {
|
|
93
|
+
if (!this.project.isRunning) { return; }
|
|
93
94
|
if (!['unlink', 'unlinkDir'].includes(event)) {
|
|
94
95
|
this.process(path);
|
|
95
96
|
}
|
package/lib/components/server.js
CHANGED
|
@@ -78,6 +78,7 @@ export default class ServerComponent extends BaseComponent {
|
|
|
78
78
|
ignored: this.ignoredFiles,
|
|
79
79
|
ignoreInitial: true
|
|
80
80
|
}, (event, file) => {
|
|
81
|
+
if (!this.project.isRunning) { return; }
|
|
81
82
|
if (['add', 'addDir', 'change'].includes(event)) {
|
|
82
83
|
this.server.reload(file);
|
|
83
84
|
if (file.split('.').pop() == 'css') {
|
package/lib/components/style.js
CHANGED
|
@@ -181,6 +181,7 @@ export default class StyleComponent extends BaseComponent {
|
|
|
181
181
|
], {
|
|
182
182
|
...this.project.chokidarOpts
|
|
183
183
|
}).on('all', (event, path) => {
|
|
184
|
+
if (!this.project.isRunning) { return; }
|
|
184
185
|
let hasRanSingle = false;
|
|
185
186
|
for (let group of this.files) {
|
|
186
187
|
if (path == group.file || this.utils.getImportedSASSFiles(group.file).includes(path)) {
|
package/lib/help.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import project from './project.js';
|
|
2
|
+
|
|
3
|
+
export default function() {
|
|
4
|
+
console.log(`
|
|
5
|
+
Usage: sdc-build-wp [options] [arguments]
|
|
6
|
+
|
|
7
|
+
Options:
|
|
8
|
+
-h, --help Show help message and exit
|
|
9
|
+
-v, --version Version
|
|
10
|
+
-w, --watch Build and watch
|
|
11
|
+
-b, --builds BUILDS Build with specific components
|
|
12
|
+
|
|
13
|
+
Components:
|
|
14
|
+
|
|
15
|
+
${Object.entries(project.components).map(([key, component]) => {
|
|
16
|
+
return `${key}\t\t${component.description}\r\n`;
|
|
17
|
+
}).join('')}
|
|
18
|
+
Examples:
|
|
19
|
+
|
|
20
|
+
sdc-build-wp
|
|
21
|
+
sdc-build-wp --watch
|
|
22
|
+
sdc-build-wp --watch --builds=style,scripts
|
|
23
|
+
|
|
24
|
+
While watch is enabled, use the following keyboard commands to control the build process:
|
|
25
|
+
|
|
26
|
+
[r] Restart
|
|
27
|
+
[p] Pause/Resume
|
|
28
|
+
[q] Quit
|
|
29
|
+
`);
|
|
30
|
+
}
|
package/lib/project.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
import parseArgs from 'minimist';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
1
4
|
import { readFile } from 'fs/promises';
|
|
5
|
+
import { promises as fs } from 'fs';
|
|
6
|
+
import build from './build.js';
|
|
7
|
+
import * as utils from './utils.js';
|
|
8
|
+
import log from './logging.js';
|
|
9
|
+
import * as LibComponents from './components/index.js';
|
|
10
|
+
import help from './help.js';
|
|
2
11
|
|
|
3
12
|
let project = {
|
|
13
|
+
argv: null,
|
|
14
|
+
isRunning: false,
|
|
4
15
|
path: process.cwd(),
|
|
5
16
|
package: JSON.parse(await readFile(new URL(process.cwd() + '/package.json', import.meta.url))),
|
|
6
17
|
components: {},
|
|
@@ -54,3 +65,68 @@ project.chokidarOpts = {
|
|
|
54
65
|
};
|
|
55
66
|
|
|
56
67
|
export default project;
|
|
68
|
+
|
|
69
|
+
export async function init() {
|
|
70
|
+
project.argv = parseArgs(process.argv.slice(2));
|
|
71
|
+
project.components = Object.fromEntries(Object.entries(LibComponents).map(([name, Class]) => [name, new Class()]));
|
|
72
|
+
|
|
73
|
+
if (project.argv.help || project.argv.h) {
|
|
74
|
+
help();
|
|
75
|
+
process.exit(0);
|
|
76
|
+
} else if (project.argv.version || project.argv.v) {
|
|
77
|
+
console.log(JSON.parse(await fs.readFile(path.join(path.dirname(fileURLToPath(import.meta.url)), '../package.json'))).version);
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
project.builds = project.argv.builds ? (Array.isArray(project.argv.builds) ? project.argv.builds : project.argv.builds.split(',')) : Object.keys(project.components);
|
|
82
|
+
|
|
83
|
+
process.on('SIGINT', function () {
|
|
84
|
+
console.log(`\r`);
|
|
85
|
+
if (project.isRunning) {
|
|
86
|
+
utils.stopActiveComponents();
|
|
87
|
+
project.isRunning = false;
|
|
88
|
+
utils.clearScreen();
|
|
89
|
+
}
|
|
90
|
+
log('info', `Exited sdc-build-wp`);
|
|
91
|
+
if (process.stdin.isTTY) {
|
|
92
|
+
process.stdin.setRawMode(false);
|
|
93
|
+
process.stdin.pause();
|
|
94
|
+
}
|
|
95
|
+
process.exit(0);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function keypressListen() {
|
|
101
|
+
if (!process.stdin.isTTY) { return; }
|
|
102
|
+
|
|
103
|
+
process.stdin.setRawMode(true);
|
|
104
|
+
process.stdin.resume();
|
|
105
|
+
process.stdin.setEncoding('utf8');
|
|
106
|
+
|
|
107
|
+
process.stdin.on('data', (key) => {
|
|
108
|
+
switch (key) {
|
|
109
|
+
case '\u0003': // Ctrl+C
|
|
110
|
+
case 'q':
|
|
111
|
+
process.emit('SIGINT');
|
|
112
|
+
return;
|
|
113
|
+
case 'p':
|
|
114
|
+
project.isRunning = !project.isRunning;
|
|
115
|
+
utils.clearScreen();
|
|
116
|
+
if (project.isRunning) {
|
|
117
|
+
log('success', 'Resumed build process');
|
|
118
|
+
} else {
|
|
119
|
+
log('warn', 'Paused build process');
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
case 'r':
|
|
123
|
+
log('info', 'Restarted build process');
|
|
124
|
+
utils.stopActiveComponents();
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
utils.clearScreen();
|
|
127
|
+
build(true);
|
|
128
|
+
}, 100);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
package/lib/utils.js
CHANGED
|
@@ -3,6 +3,17 @@ import { readdir } from 'node:fs/promises';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import project from './project.js';
|
|
5
5
|
|
|
6
|
+
export function clearScreen() {
|
|
7
|
+
if (!process.stdout.isTTY) { return; }
|
|
8
|
+
process.stdout.write('\x1B[2J\x1B[0f');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function stopActiveComponents() {
|
|
12
|
+
if (project.components.server?.server) {
|
|
13
|
+
project.components.server.server.exit();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
export function camelToDash(camel) {
|
|
7
18
|
return camel.replace(/[A-Z]/g, m => '-' + m.toLowerCase());
|
|
8
19
|
}
|