sdc-build-wp 5.6.0 → 5.6.2
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/lib/build.js +4 -3
- package/lib/components/blocks.js +10 -34
- package/lib/tui.js +99 -32
- package/package.json +5 -1
- package/webpack.config.js +1 -8
package/lib/build.js
CHANGED
|
@@ -4,17 +4,16 @@ import log from './logging.js';
|
|
|
4
4
|
import { styleText } from 'node:util';
|
|
5
5
|
import tui from './tui.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
export async function build(watch = false) {
|
|
9
8
|
|
|
10
9
|
if (watch) {
|
|
11
10
|
tui.init();
|
|
12
11
|
tui.setComponents(project.builds, true);
|
|
13
|
-
const commands =
|
|
12
|
+
const commands = `${styleText('gray', 'Commands:')} ${styleText(['underline', 'green'], 'r')}estart, ${styleText(['underline', 'green'], 'c')}lear cache, ${styleText(['underline', 'green'], 'p')}ause/resume, ${styleText(['underline', 'green'], 'n')}ew component, ${styleText(['underline', 'green'], 'q')}uit`;
|
|
14
13
|
tui.setCommands(commands);
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
log('info',
|
|
16
|
+
log('info', 'Started sdc-build-wp');
|
|
18
17
|
|
|
19
18
|
if (project.builds.includes('cache')) {
|
|
20
19
|
try {
|
|
@@ -61,6 +60,7 @@ export async function build(watch = false) {
|
|
|
61
60
|
project.builds.splice(project.builds.indexOf('server'), 1);
|
|
62
61
|
project.builds.push('server');
|
|
63
62
|
|
|
63
|
+
tui.finishInitialLoading();
|
|
64
64
|
log('info', `Finished initial build in ${Math.round((performance.now() - initialBuildTimerStart) / 1000)} seconds`);
|
|
65
65
|
log('info', `Started watching [${project.builds.join(', ')}]`);
|
|
66
66
|
|
|
@@ -77,6 +77,7 @@ export async function build(watch = false) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
} else {
|
|
80
|
+
tui.finishInitialLoading();
|
|
80
81
|
log('info', `Finished initial build in ${Math.round((performance.now() - initialBuildTimerStart) / 1000)} seconds`);
|
|
81
82
|
process.emit('SIGINT');
|
|
82
83
|
}
|
package/lib/components/blocks.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
1
2
|
import BaseComponent from './base.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { stat, readFile } from 'fs/promises';
|
|
4
|
+
import { exec } from 'child_process';
|
|
4
5
|
import { promisify } from 'util';
|
|
5
6
|
import { createHash } from 'crypto';
|
|
6
7
|
|
|
@@ -9,31 +10,6 @@ export default class BlocksComponent extends BaseComponent {
|
|
|
9
10
|
constructor() {
|
|
10
11
|
super();
|
|
11
12
|
this.description = `Process the theme's WordPress blocks`;
|
|
12
|
-
this._didLogWpScriptsFallback = false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async getWpScriptsRunner() {
|
|
16
|
-
const localWpScripts = `${this.project.path}/node_modules/@wordpress/scripts/bin/wp-scripts.js`;
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
await access(localWpScripts);
|
|
20
|
-
return {
|
|
21
|
-
command: process.execPath,
|
|
22
|
-
baseArgs: [localWpScripts]
|
|
23
|
-
};
|
|
24
|
-
} catch {
|
|
25
|
-
if (!this._didLogWpScriptsFallback) {
|
|
26
|
-
this.log('info', 'Using temporary @wordpress/scripts via npx for block builds');
|
|
27
|
-
this._didLogWpScriptsFallback = true;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const npxCommand = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
command: npxCommand,
|
|
34
|
-
baseArgs: ['--yes', '--package', '@wordpress/scripts@31', 'wp-scripts']
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
13
|
}
|
|
38
14
|
|
|
39
15
|
async init() {
|
|
@@ -156,17 +132,17 @@ export default class BlocksComponent extends BaseComponent {
|
|
|
156
132
|
this.clearHashCache([workingBlockJson, ...dependencies]);
|
|
157
133
|
|
|
158
134
|
try {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
'build',
|
|
135
|
+
const cmds = [
|
|
136
|
+
`${this.project.path}/node_modules/@wordpress/scripts/bin/wp-scripts.js`,
|
|
137
|
+
`build`,
|
|
163
138
|
`--source-path=.${entry.replace(this.project.path, '')}/src`,
|
|
164
139
|
`--output-path=.${entry.replace(this.project.path, '')}/build`,
|
|
165
|
-
|
|
140
|
+
`--webpack-copy-php`,
|
|
141
|
+
`--config=${this.path.resolve(this.path.dirname(fileURLToPath(import.meta.url)), '../../webpack.config.js')}`,
|
|
166
142
|
];
|
|
167
|
-
const
|
|
143
|
+
const execPromise = promisify(exec);
|
|
168
144
|
const timeoutMS = 40000;
|
|
169
|
-
const buildPromise =
|
|
145
|
+
const buildPromise = execPromise(cmds.join(' '), {
|
|
170
146
|
maxBuffer: 1024 * 1024 * 10,
|
|
171
147
|
cwd: this.project.path
|
|
172
148
|
});
|
package/lib/tui.js
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Box, Text, render as renderInk, useInput, useStdout } from 'ink';
|
|
3
|
+
import Spinner from 'ink-spinner';
|
|
4
|
+
import { TitledBox, titleStyles } from '@mishieck/ink-titled-box';
|
|
3
5
|
import { styleText } from 'node:util';
|
|
4
6
|
import log from './logging.js';
|
|
5
7
|
|
|
6
8
|
const sgrMouseRegex = /\x1b\[<(\d+);(\d+);(\d+)([mM])/g;
|
|
9
|
+
const ansiSgrRegex = /\x1b\[[0-9;]*m/g;
|
|
10
|
+
const headerColumnGap = 2;
|
|
11
|
+
|
|
12
|
+
function getVisibleTextLength(text) {
|
|
13
|
+
return (text || '').replace(ansiSgrRegex, '').length;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getWrappedLineCount(text, width) {
|
|
17
|
+
return Math.max(1, Math.ceil(getVisibleTextLength(text) / Math.max(1, width)));
|
|
18
|
+
}
|
|
7
19
|
|
|
8
20
|
function TUIRoot({ tui }) {
|
|
9
21
|
const { stdout } = useStdout();
|
|
10
22
|
const terminalRows = stdout?.rows || 24;
|
|
11
|
-
const
|
|
23
|
+
const terminalColumns = stdout?.columns || 80;
|
|
24
|
+
const header = tui.getHeaderLayout(terminalColumns);
|
|
12
25
|
const promptLines = tui.getPromptRenderLines();
|
|
13
|
-
const
|
|
26
|
+
const isInitialLoading = tui.isInitialLoading();
|
|
27
|
+
const loadingLineCount = isInitialLoading ? 1 : 0;
|
|
28
|
+
const availableLogRows = Math.max(3, terminalRows - header.lineCount - promptLines.length - loadingLineCount - 4);
|
|
14
29
|
const visibleLogs = tui.getVisibleLogLines(availableLogRows);
|
|
15
30
|
|
|
16
31
|
useInput((input, key) => {
|
|
@@ -51,23 +66,45 @@ function TUIRoot({ tui }) {
|
|
|
51
66
|
Box,
|
|
52
67
|
{ flexDirection: 'column' },
|
|
53
68
|
React.createElement(
|
|
54
|
-
|
|
69
|
+
TitledBox,
|
|
55
70
|
{
|
|
56
71
|
borderStyle: 'round',
|
|
72
|
+
titles: ['SDC Build WP'],
|
|
57
73
|
borderColor: 'blue',
|
|
58
74
|
paddingX: 1,
|
|
59
75
|
flexDirection: 'column'
|
|
60
76
|
},
|
|
61
|
-
|
|
77
|
+
header.titleLine || header.urlLine
|
|
78
|
+
? React.createElement(
|
|
79
|
+
Box,
|
|
80
|
+
{
|
|
81
|
+
flexDirection: 'row',
|
|
82
|
+
flexWrap: 'wrap',
|
|
83
|
+
columnGap: headerColumnGap
|
|
84
|
+
},
|
|
85
|
+
header.titleLine ? React.createElement(Text, { key: 'header-title' }, header.titleLine) : null,
|
|
86
|
+
header.urlLine ? React.createElement(Text, { key: 'header-url' }, header.urlLine) : null
|
|
87
|
+
)
|
|
88
|
+
: null,
|
|
89
|
+
header.detailLines.map((line, index) => React.createElement(Text, { key: `header-${index}` }, line)),
|
|
90
|
+
isInitialLoading
|
|
91
|
+
? React.createElement(
|
|
92
|
+
Text,
|
|
93
|
+
{ color: 'cyan' },
|
|
94
|
+
React.createElement(Spinner, { type: 'dots' }),
|
|
95
|
+
' Initial loading...'
|
|
96
|
+
)
|
|
97
|
+
: null
|
|
62
98
|
),
|
|
63
99
|
React.createElement(
|
|
64
100
|
Box,
|
|
65
101
|
{
|
|
66
102
|
borderStyle: 'single',
|
|
67
103
|
borderColor: 'blue',
|
|
104
|
+
borderTop: false,
|
|
68
105
|
paddingX: 1,
|
|
69
106
|
flexDirection: 'column',
|
|
70
|
-
height: availableLogRows +
|
|
107
|
+
height: availableLogRows + 1
|
|
71
108
|
},
|
|
72
109
|
visibleLogs.map((line, index) => React.createElement(Text, { key: `log-${index}` }, line))
|
|
73
110
|
),
|
|
@@ -104,14 +141,17 @@ class TUI {
|
|
|
104
141
|
this._logScrollOffset = 0;
|
|
105
142
|
this._activePrompt = null;
|
|
106
143
|
this._mouseDataHandler = null;
|
|
144
|
+
this._isInitialLoading = false;
|
|
107
145
|
}
|
|
108
146
|
|
|
109
147
|
init() {
|
|
110
148
|
if (this.isInitialized) {
|
|
149
|
+
this._isInitialLoading = true;
|
|
111
150
|
this.render();
|
|
112
151
|
return;
|
|
113
152
|
}
|
|
114
153
|
|
|
154
|
+
this._isInitialLoading = true;
|
|
115
155
|
this.isInitialized = true;
|
|
116
156
|
this.app = renderInk(React.createElement(TUIRoot, { tui: this }), {
|
|
117
157
|
exitOnCtrlC: false,
|
|
@@ -126,6 +166,19 @@ class TUI {
|
|
|
126
166
|
this.render();
|
|
127
167
|
}
|
|
128
168
|
|
|
169
|
+
isInitialLoading() {
|
|
170
|
+
return this._isInitialLoading;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
finishInitialLoading() {
|
|
174
|
+
if (!this._isInitialLoading) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
this._isInitialLoading = false;
|
|
179
|
+
this.render();
|
|
180
|
+
}
|
|
181
|
+
|
|
129
182
|
isMouseEscapeSequence(input) {
|
|
130
183
|
if (!input || typeof input !== 'string') {
|
|
131
184
|
return false;
|
|
@@ -189,50 +242,63 @@ class TUI {
|
|
|
189
242
|
process.stdout.write('\x1b[?1000l\x1b[?1002l\x1b[?1006l');
|
|
190
243
|
}
|
|
191
244
|
|
|
192
|
-
|
|
193
|
-
const
|
|
245
|
+
getHeaderLayout(terminalColumns = 80) {
|
|
246
|
+
const detailLines = [];
|
|
247
|
+
const innerWidth = Math.max(1, terminalColumns - 4);
|
|
248
|
+
const statusMessages = [];
|
|
194
249
|
|
|
195
|
-
let titleLine = '
|
|
196
|
-
if (this.isPaused) {
|
|
197
|
-
titleLine += styleText(['bold', 'yellow'], ' [PAUSED]');
|
|
198
|
-
}
|
|
199
|
-
if (!this.isMouseEnabled) {
|
|
200
|
-
titleLine += styleText(['bold', 'yellow'], ' [TEXT SELECT - Press Enter to Exit]');
|
|
201
|
-
}
|
|
250
|
+
let titleLine = '';
|
|
202
251
|
if (this.components.length > 0) {
|
|
203
|
-
titleLine
|
|
252
|
+
titleLine = styleText('gray', 'Components: ') + styleText('cyan', this.components.join(', '));
|
|
204
253
|
}
|
|
205
|
-
lines.push(titleLine);
|
|
206
254
|
|
|
255
|
+
let urlLine = '';
|
|
207
256
|
if (this.urls.local || this.urls.external) {
|
|
208
|
-
let urlLine = ' ';
|
|
209
257
|
if (this.urls.local) {
|
|
210
|
-
urlLine
|
|
258
|
+
urlLine = `${styleText('gray', 'Local:')} ${styleText('green', this.urls.local)}`;
|
|
211
259
|
}
|
|
212
260
|
if (this.urls.external) {
|
|
213
|
-
if (urlLine
|
|
261
|
+
if (urlLine) {
|
|
214
262
|
urlLine += ' ';
|
|
215
263
|
}
|
|
216
|
-
urlLine +=
|
|
264
|
+
urlLine += `${styleText('gray', 'External:')} ${styleText('green', this.urls.external)}`;
|
|
217
265
|
}
|
|
218
|
-
lines.push(urlLine);
|
|
219
|
-
} else {
|
|
220
|
-
lines.push(' ');
|
|
221
266
|
}
|
|
222
267
|
|
|
223
268
|
if (this.commands) {
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
269
|
+
detailLines.push(this.commands);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (this.isPaused) {
|
|
273
|
+
statusMessages.push(styleText(['bold', 'yellow'], 'PAUSED'));
|
|
227
274
|
}
|
|
228
275
|
|
|
229
276
|
if (!this.isMouseEnabled) {
|
|
230
|
-
|
|
231
|
-
} else {
|
|
232
|
-
lines.push(' ');
|
|
277
|
+
statusMessages.push(styleText(['bold', 'yellow'], 'TEXT SELECT') + styleText('yellow', ' - Press [ENTER] to enable scroll.'));
|
|
233
278
|
}
|
|
234
279
|
|
|
235
|
-
|
|
280
|
+
if (statusMessages.length > 0) {
|
|
281
|
+
detailLines.push(statusMessages.join(styleText('gray', ' | ')));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const hasTitleOrUrl = Boolean(titleLine || urlLine);
|
|
285
|
+
const titleWidth = getVisibleTextLength(titleLine);
|
|
286
|
+
const urlWidth = getVisibleTextLength(urlLine);
|
|
287
|
+
const topLineCount = hasTitleOrUrl
|
|
288
|
+
? (titleLine && urlLine
|
|
289
|
+
? (titleWidth + headerColumnGap + urlWidth <= innerWidth
|
|
290
|
+
? 1
|
|
291
|
+
: getWrappedLineCount(titleLine, innerWidth) + getWrappedLineCount(urlLine, innerWidth))
|
|
292
|
+
: getWrappedLineCount(titleLine || urlLine, innerWidth))
|
|
293
|
+
: 0;
|
|
294
|
+
const detailLineCount = detailLines.reduce((count, line) => count + getWrappedLineCount(line, innerWidth), 0);
|
|
295
|
+
|
|
296
|
+
return {
|
|
297
|
+
titleLine,
|
|
298
|
+
urlLine,
|
|
299
|
+
detailLines,
|
|
300
|
+
lineCount: topLineCount + detailLineCount
|
|
301
|
+
};
|
|
236
302
|
}
|
|
237
303
|
|
|
238
304
|
setURLs(local, external) {
|
|
@@ -325,7 +391,7 @@ class TUI {
|
|
|
325
391
|
return [
|
|
326
392
|
this._activePrompt.prompt,
|
|
327
393
|
`${styleText('gray', '>')} ${this._activePrompt.value}${cursor}`,
|
|
328
|
-
styleText('gray', 'Type your value, Enter to submit, Esc
|
|
394
|
+
styleText('gray', 'Type your value, Enter to submit, Esc to cancel.')
|
|
329
395
|
];
|
|
330
396
|
}
|
|
331
397
|
|
|
@@ -375,7 +441,7 @@ class TUI {
|
|
|
375
441
|
resolve(value);
|
|
376
442
|
return;
|
|
377
443
|
}
|
|
378
|
-
if (key.escape
|
|
444
|
+
if (key.escape) {
|
|
379
445
|
const resolve = this._activePrompt.resolve;
|
|
380
446
|
this._activePrompt = null;
|
|
381
447
|
this.render();
|
|
@@ -489,6 +555,7 @@ class TUI {
|
|
|
489
555
|
this.isMouseEnabled = true;
|
|
490
556
|
this._activePrompt = null;
|
|
491
557
|
this._logScrollOffset = 0;
|
|
558
|
+
this._isInitialLoading = false;
|
|
492
559
|
|
|
493
560
|
if (process.stdout.isTTY) {
|
|
494
561
|
process.stdout.write('\x1b[?25h');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdc-build-wp",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.2",
|
|
4
4
|
"description": "Custom WordPress build process.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -22,16 +22,20 @@
|
|
|
22
22
|
"sdc-build-wp": "./index.js"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@mishieck/ink-titled-box": "^0.4.2",
|
|
25
26
|
"@stylistic/eslint-plugin": "^5.6.1",
|
|
26
27
|
"@stylistic/stylelint-plugin": "^4.0.0",
|
|
27
28
|
"@typescript-eslint/eslint-plugin": "^8.48.1",
|
|
28
29
|
"@typescript-eslint/parser": "^8.48.1",
|
|
30
|
+
"@wordpress/scripts": "^31.4.0",
|
|
31
|
+
"ajv": "^8.18.0",
|
|
29
32
|
"autoprefixer": "^10.4.24",
|
|
30
33
|
"browser-sync": "^3.0.4",
|
|
31
34
|
"chokidar": "^5.0.0",
|
|
32
35
|
"esbuild": "^0.27.3",
|
|
33
36
|
"eslint": "^9.39.1",
|
|
34
37
|
"ink": "^6.8.0",
|
|
38
|
+
"ink-spinner": "^5.0.0",
|
|
35
39
|
"postcss": "^8.5.6",
|
|
36
40
|
"postcss-scss": "^4.0.9",
|
|
37
41
|
"postcss-sort-media-queries": "^5.2.0",
|
package/webpack.config.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
try {
|
|
4
|
-
const wpConfig = await import('@wordpress/scripts/config/webpack.config.js');
|
|
5
|
-
defaultConfig = wpConfig.default || {};
|
|
6
|
-
} catch {
|
|
7
|
-
defaultConfig = {};
|
|
8
|
-
}
|
|
1
|
+
import defaultConfig from '@wordpress/scripts/config/webpack.config.js';
|
|
9
2
|
|
|
10
3
|
export default {
|
|
11
4
|
...defaultConfig,
|