sdc-build-wp 4.6.3 → 4.7.1
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 +8 -0
- package/index.js +67 -16
- package/lib/components/blocks.js +5 -2
- 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/project.js +1 -0
- package/lib/utils.js +11 -0
- package/package.json +1 -1
- package/webpack.config.js +9 -0
package/README.md
CHANGED
|
@@ -15,3 +15,11 @@ Develop locally with the following command from within the test project director
|
|
|
15
15
|
```
|
|
16
16
|
node ~/sites/sdc/sdc-build-wp/index.js --watch
|
|
17
17
|
```
|
|
18
|
+
|
|
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
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'url';
|
|
|
5
5
|
import { promises as fs } from 'fs';
|
|
6
6
|
import project from './lib/project.js';
|
|
7
7
|
import log from './lib/logging.js';
|
|
8
|
+
import * as utils from './lib/utils.js';
|
|
8
9
|
import * as LibComponents from './lib/components/index.js';
|
|
9
10
|
|
|
10
11
|
project.components = Object.fromEntries(Object.entries(LibComponents).map(([name, Class]) => [name, new Class()]));
|
|
@@ -12,7 +13,7 @@ project.components = Object.fromEntries(Object.entries(LibComponents).map(([name
|
|
|
12
13
|
const argv = parseArgs(process.argv.slice(2));
|
|
13
14
|
|
|
14
15
|
if (argv.help || argv.h) {
|
|
15
|
-
console.log(`
|
|
16
|
+
console.log(`
|
|
16
17
|
Usage: sdc-build-wp [options] [arguments]
|
|
17
18
|
|
|
18
19
|
Options:
|
|
@@ -31,18 +32,76 @@ Examples:
|
|
|
31
32
|
sdc-build-wp
|
|
32
33
|
sdc-build-wp --watch
|
|
33
34
|
sdc-build-wp --watch --builds=style,scripts
|
|
35
|
+
|
|
36
|
+
While watch is enabled, use the following keyboard commands to control the build process:
|
|
37
|
+
|
|
38
|
+
[r] Restart
|
|
39
|
+
[p] Pause/Resume
|
|
40
|
+
[q] Quit
|
|
34
41
|
`);
|
|
35
42
|
|
|
36
|
-
process.exit(0);
|
|
43
|
+
process.exit(0);
|
|
37
44
|
} 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);
|
|
45
|
+
console.log(JSON.parse(await fs.readFile(path.join(path.dirname(fileURLToPath(import.meta.url)), 'package.json'))).version);
|
|
46
|
+
process.exit(0);
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
project.builds = argv.builds ? (Array.isArray(argv.builds) ? argv.builds : argv.builds.split(',')) : Object.keys(project.components);
|
|
43
50
|
|
|
44
|
-
(async() => {
|
|
51
|
+
(async () => {
|
|
52
|
+
keypressListen();
|
|
53
|
+
await runBuild();
|
|
54
|
+
})();
|
|
55
|
+
|
|
56
|
+
process.on('SIGINT', function () {
|
|
57
|
+
console.log(`\r`);
|
|
58
|
+
utils.stopActiveComponents();
|
|
59
|
+
project.isRunning = false;
|
|
60
|
+
utils.clearScreen();
|
|
61
|
+
log('info', `Exited sdc-build-wp`);
|
|
62
|
+
if (process.stdin.isTTY) {
|
|
63
|
+
process.stdin.setRawMode(false);
|
|
64
|
+
process.stdin.pause();
|
|
65
|
+
}
|
|
66
|
+
process.exit(0);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function keypressListen() {
|
|
70
|
+
if (!process.stdin.isTTY) { return; }
|
|
71
|
+
|
|
72
|
+
process.stdin.setRawMode(true);
|
|
73
|
+
process.stdin.resume();
|
|
74
|
+
process.stdin.setEncoding('utf8');
|
|
45
75
|
|
|
76
|
+
process.stdin.on('data', (key) => {
|
|
77
|
+
switch (key) {
|
|
78
|
+
case '\u0003': // Ctrl+C
|
|
79
|
+
case 'q':
|
|
80
|
+
process.emit('SIGINT');
|
|
81
|
+
return;
|
|
82
|
+
case 'p':
|
|
83
|
+
project.isRunning = !project.isRunning;
|
|
84
|
+
utils.clearScreen();
|
|
85
|
+
if (project.isRunning) {
|
|
86
|
+
log('success', 'Resumed build process');
|
|
87
|
+
} else {
|
|
88
|
+
log('warn', 'Paused build process');
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
case 'r':
|
|
92
|
+
log('info', 'Restarted build process');
|
|
93
|
+
utils.stopActiveComponents();
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
utils.clearScreen();
|
|
96
|
+
runBuild();
|
|
97
|
+
}, 100);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function runBuild() {
|
|
104
|
+
project.isRunning = true;
|
|
46
105
|
if (argv.watch && project.builds.includes('server')) {
|
|
47
106
|
project.builds.splice(project.builds.indexOf('server'), 1);
|
|
48
107
|
project.builds.unshift('server');
|
|
@@ -56,24 +115,16 @@ project.builds = argv.builds ? (Array.isArray(argv.builds) ? argv.builds : argv.
|
|
|
56
115
|
promisesBuilds.push(project.components[build].init());
|
|
57
116
|
}
|
|
58
117
|
await Promise.all(promisesBuilds);
|
|
118
|
+
utils.clearScreen();
|
|
59
119
|
log('info', `Finished initial build in ${Math.round((performance.now() - initialBuildTimerStart) / 1000)} seconds`);
|
|
60
120
|
|
|
61
121
|
if (argv.watch && project.builds.includes('server')) {
|
|
62
122
|
project.builds.splice(project.builds.indexOf('server'), 1);
|
|
63
123
|
project.builds.push('server');
|
|
64
124
|
log('info', `Started watching [${project.builds.join(', ')}]`);
|
|
125
|
+
log('info', `[r] to restart, [p] to pause/resume, [q] to quit`);
|
|
65
126
|
for (let build of project.builds) {
|
|
66
127
|
await project.components[build].watch();
|
|
67
128
|
}
|
|
68
129
|
}
|
|
69
|
-
|
|
70
|
-
})();
|
|
71
|
-
|
|
72
|
-
process.on('SIGINT', function() {
|
|
73
|
-
console.log(`\r`);
|
|
74
|
-
if (project.components.server?.server) {
|
|
75
|
-
project.components.server.server.exit();
|
|
76
|
-
}
|
|
77
|
-
log('info', `Exiting sdc-build-wp`);
|
|
78
|
-
process.exit(0);
|
|
79
|
-
});
|
|
130
|
+
}
|
package/lib/components/blocks.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
1
2
|
import BaseComponent from './base.js';
|
|
2
3
|
import { stat } from 'fs/promises';
|
|
3
4
|
import { exec } from 'child_process';
|
|
@@ -55,12 +56,13 @@ export default class BlocksComponent extends BaseComponent {
|
|
|
55
56
|
`build`,
|
|
56
57
|
`--source-path=.${entry.replace(this.project.path, '')}/src`,
|
|
57
58
|
`--output-path=.${entry.replace(this.project.path, '')}/build`,
|
|
58
|
-
`--webpack-copy-php
|
|
59
|
+
`--webpack-copy-php`,
|
|
60
|
+
`--config=${this.path.resolve(this.path.dirname(fileURLToPath(import.meta.url)), '../../webpack.config.js')}`,
|
|
59
61
|
];
|
|
60
62
|
let execPromise = promisify(exec);
|
|
61
63
|
const { stdout, stderr } = await execPromise(cmds.join(' '));
|
|
62
64
|
} catch (error) {
|
|
63
|
-
console.log(error.stdout);
|
|
65
|
+
console.log(error.stdout || error);
|
|
64
66
|
this.log('error', `Failed building ${entryLabel} block - See above error.`);
|
|
65
67
|
return false;
|
|
66
68
|
}
|
|
@@ -86,6 +88,7 @@ export default class BlocksComponent extends BaseComponent {
|
|
|
86
88
|
this.chokidar.watch(`${block}/src`, {
|
|
87
89
|
...this.project.chokidarOpts
|
|
88
90
|
}).on('all', (event, path) => {
|
|
91
|
+
if (!this.project.isRunning) { return; }
|
|
89
92
|
if (!['unlink', 'unlinkDir'].includes(event)) {
|
|
90
93
|
if (path.endsWith('.js')) {
|
|
91
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/project.js
CHANGED
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
|
}
|
package/package.json
CHANGED