sdc-build-wp 4.6.3 → 4.7.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 +2 -0
- package/index.js +49 -12
- package/lib/components/blocks.js +4 -2
- package/package.json +1 -1
- package/webpack.config.js +9 -0
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ project.components = Object.fromEntries(Object.entries(LibComponents).map(([name
|
|
|
12
12
|
const argv = parseArgs(process.argv.slice(2));
|
|
13
13
|
|
|
14
14
|
if (argv.help || argv.h) {
|
|
15
|
-
console.log(`
|
|
15
|
+
console.log(`
|
|
16
16
|
Usage: sdc-build-wp [options] [arguments]
|
|
17
17
|
|
|
18
18
|
Options:
|
|
@@ -33,16 +33,56 @@ sdc-build-wp --watch
|
|
|
33
33
|
sdc-build-wp --watch --builds=style,scripts
|
|
34
34
|
`);
|
|
35
35
|
|
|
36
|
-
process.exit(0);
|
|
36
|
+
process.exit(0);
|
|
37
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);
|
|
38
|
+
console.log(JSON.parse(await fs.readFile(path.join(path.dirname(fileURLToPath(import.meta.url)), 'package.json'))).version);
|
|
39
|
+
process.exit(0);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
project.builds = argv.builds ? (Array.isArray(argv.builds) ? argv.builds : argv.builds.split(',')) : Object.keys(project.components);
|
|
43
43
|
|
|
44
|
-
(async() => {
|
|
44
|
+
(async () => {
|
|
45
|
+
keypressListen();
|
|
46
|
+
await runBuild();
|
|
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();
|
|
54
|
+
}
|
|
55
|
+
stopActiveComponents()
|
|
56
|
+
log('info', `Exiting sdc-build-wp`);
|
|
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');
|
|
45
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() {
|
|
46
86
|
if (argv.watch && project.builds.includes('server')) {
|
|
47
87
|
project.builds.splice(project.builds.indexOf('server'), 1);
|
|
48
88
|
project.builds.unshift('server');
|
|
@@ -62,18 +102,15 @@ project.builds = argv.builds ? (Array.isArray(argv.builds) ? argv.builds : argv.
|
|
|
62
102
|
project.builds.splice(project.builds.indexOf('server'), 1);
|
|
63
103
|
project.builds.push('server');
|
|
64
104
|
log('info', `Started watching [${project.builds.join(', ')}]`);
|
|
105
|
+
log('info', `[r] to restart, [q] to quit`);
|
|
65
106
|
for (let build of project.builds) {
|
|
66
107
|
await project.components[build].watch();
|
|
67
108
|
}
|
|
68
109
|
}
|
|
110
|
+
}
|
|
69
111
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
process.on('SIGINT', function() {
|
|
73
|
-
console.log(`\r`);
|
|
112
|
+
function stopActiveComponents() {
|
|
74
113
|
if (project.components.server?.server) {
|
|
75
114
|
project.components.server.server.exit();
|
|
76
115
|
}
|
|
77
|
-
|
|
78
|
-
process.exit(0);
|
|
79
|
-
});
|
|
116
|
+
}
|
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
|
}
|
package/package.json
CHANGED