sdc-build-wp 5.3.0 → 5.3.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/lib/build.js +1 -1
- package/lib/components/blocks.js +4 -4
- package/lib/components/fonts.js +1 -1
- package/lib/components/html.js +1 -1
- package/lib/components/images.js +1 -1
- package/lib/components/php.js +2 -2
- package/lib/components/scripts.js +7 -35
- package/lib/components/style.js +8 -8
- package/lib/config-validator.js +2 -2
- package/lib/help.js +4 -3
- package/lib/logging.js +27 -4
- package/lib/project.js +10 -11
- package/lib/tui.js +2 -1
- package/lib/utils.js +5 -4
- package/package.json +1 -1
package/lib/build.js
CHANGED
|
@@ -39,7 +39,7 @@ export async function build(watch = false) {
|
|
|
39
39
|
|
|
40
40
|
promisesBuilds.push(
|
|
41
41
|
project.components[build].init().catch(error => {
|
|
42
|
-
|
|
42
|
+
log(null, error);
|
|
43
43
|
log('error', `Failed to initialize ${build} component`);
|
|
44
44
|
return { failed: true, component: build, error };
|
|
45
45
|
})
|
package/lib/components/blocks.js
CHANGED
|
@@ -156,7 +156,7 @@ export default class BlocksComponent extends BaseComponent {
|
|
|
156
156
|
|
|
157
157
|
await this.updateBuildCache(workingBlockJson, cacheOutputFile, dependencies);
|
|
158
158
|
} catch (error) {
|
|
159
|
-
|
|
159
|
+
this.log(null, error.stdout || error.stderr || error.message);
|
|
160
160
|
this.log('error', `Failed building ${entryLabel} block - See above error.`);
|
|
161
161
|
return false;
|
|
162
162
|
}
|
|
@@ -183,8 +183,8 @@ export default class BlocksComponent extends BaseComponent {
|
|
|
183
183
|
if (this.watcher) {
|
|
184
184
|
this.watcher.add([`${blockPath}/src`, `${blockPath}/src/**/*`]);
|
|
185
185
|
}
|
|
186
|
-
this.build(blockPath).catch(
|
|
187
|
-
|
|
186
|
+
this.build(blockPath).catch(error => {
|
|
187
|
+
this.log(null, error);
|
|
188
188
|
this.log('error', `Failed initial build for new block ${blockPath}`);
|
|
189
189
|
});
|
|
190
190
|
}
|
|
@@ -290,7 +290,7 @@ export default class BlocksComponent extends BaseComponent {
|
|
|
290
290
|
if (path.endsWith('.js')) {
|
|
291
291
|
if (!this.project.components.scripts.isBuilding) {
|
|
292
292
|
this.project.components.scripts.lint(path).catch(lintError => {
|
|
293
|
-
|
|
293
|
+
this.log(null, lintError);
|
|
294
294
|
this.log('warn', `Linting failed for ${path}`);
|
|
295
295
|
});
|
|
296
296
|
}
|
package/lib/components/fonts.js
CHANGED
|
@@ -27,7 +27,7 @@ export default class FontsComponent extends BaseComponent {
|
|
|
27
27
|
if (fontsDir.length == 0) { throw new Error('No files present'); }
|
|
28
28
|
await fs.copy(entry, `${this.project.path}${entryLabel}`);
|
|
29
29
|
entryLabel += ` (${fontsDir.filter(file => !file.startsWith('.')).length} files)`;
|
|
30
|
-
} catch(error) {
|
|
30
|
+
} catch (error) {
|
|
31
31
|
this.log('error', `${error} at ${entry.replace(this.project.path, '')}/. Skipping font copy`);
|
|
32
32
|
return false;
|
|
33
33
|
}
|
package/lib/components/html.js
CHANGED
|
@@ -78,7 +78,7 @@ export default class HTMLComponent extends BaseComponent {
|
|
|
78
78
|
entryLabel = `${formattedCount} html file${formattedCount > 1 ? 's' : ''}`;
|
|
79
79
|
}
|
|
80
80
|
} catch (error) {
|
|
81
|
-
|
|
81
|
+
this.log(null, error);
|
|
82
82
|
this.log('error', `Failed formatting ${entryLabel.replace(this.project.path, '')} - ${error.message}`);
|
|
83
83
|
return false;
|
|
84
84
|
}
|
package/lib/components/images.js
CHANGED
|
@@ -58,7 +58,7 @@ export default class ImagesComponent extends BaseComponent {
|
|
|
58
58
|
}
|
|
59
59
|
convertedImagesCount++;
|
|
60
60
|
} catch (error) {
|
|
61
|
-
|
|
61
|
+
this.log(null, error);
|
|
62
62
|
this.log('error', `Failed optimizing ${filePath.replace(this.project.path, '')} - See above error.`);
|
|
63
63
|
}
|
|
64
64
|
|
package/lib/components/php.js
CHANGED
|
@@ -29,7 +29,7 @@ export default class PHPComponent extends BaseComponent {
|
|
|
29
29
|
this.log('warn', 'PHP syntax checker not found. Skipping syntax check.');
|
|
30
30
|
return true;
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
this.log(null, error.stderr.replace(this.project.path, ''));
|
|
33
33
|
this.log('error', `Failed to validate ${entry.replace(this.project.path, '')} - See above error.`);
|
|
34
34
|
return false;
|
|
35
35
|
}
|
|
@@ -93,7 +93,7 @@ export default class PHPComponent extends BaseComponent {
|
|
|
93
93
|
)
|
|
94
94
|
)
|
|
95
95
|
) {
|
|
96
|
-
|
|
96
|
+
this.log(null, error.stderr?.length ? error.stderr : error.stdout);
|
|
97
97
|
this.log('error', `Failed linting ${entryLabel.replace(this.project.path, '')} - See above error.`);
|
|
98
98
|
return false;
|
|
99
99
|
}
|
|
@@ -2,7 +2,6 @@ import BaseComponent from './base.js';
|
|
|
2
2
|
import * as esbuild from 'esbuild';
|
|
3
3
|
import { ESLint } from 'eslint';
|
|
4
4
|
import * as eslintConfig from '../../eslint.config.js';
|
|
5
|
-
import tui from '../tui.js';
|
|
6
5
|
|
|
7
6
|
export default class ScriptsComponent extends BaseComponent {
|
|
8
7
|
|
|
@@ -36,11 +35,7 @@ export default class ScriptsComponent extends BaseComponent {
|
|
|
36
35
|
throw thisLint;
|
|
37
36
|
}
|
|
38
37
|
} catch (error) {
|
|
39
|
-
|
|
40
|
-
tui.log(String(error.stack || error));
|
|
41
|
-
} else {
|
|
42
|
-
console.error(error);
|
|
43
|
-
}
|
|
38
|
+
this.log(null, error);
|
|
44
39
|
this.log('error', `Failed linting ${entry.replace(`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.scripts}/`, '')} - See above error.`);
|
|
45
40
|
return false;
|
|
46
41
|
}
|
|
@@ -64,6 +59,7 @@ export default class ScriptsComponent extends BaseComponent {
|
|
|
64
59
|
globalName: 'sdcBuild',
|
|
65
60
|
treeShaking: true,
|
|
66
61
|
entryPoints: [entry],
|
|
62
|
+
logLevel: 'silent',
|
|
67
63
|
bundle: true,
|
|
68
64
|
minify: true,
|
|
69
65
|
outdir: `${this.project.paths.dist}/${this.project.paths.src.scripts}/`,
|
|
@@ -77,11 +73,7 @@ export default class ScriptsComponent extends BaseComponent {
|
|
|
77
73
|
|
|
78
74
|
await this.updateBuildCache(entry, outFile, dependencies);
|
|
79
75
|
} catch (error) {
|
|
80
|
-
|
|
81
|
-
tui.log(String(error.stack || error));
|
|
82
|
-
} else {
|
|
83
|
-
console.error(error);
|
|
84
|
-
}
|
|
76
|
+
this.log(null, String(error.message || error.stack || error));
|
|
85
77
|
this.log('error', `Failed building ${entryLabel} - See above error.`);
|
|
86
78
|
return false;
|
|
87
79
|
}
|
|
@@ -112,11 +104,7 @@ export default class ScriptsComponent extends BaseComponent {
|
|
|
112
104
|
await this.checkAndRebuildAffectedBlocks(path);
|
|
113
105
|
}
|
|
114
106
|
} catch (error) {
|
|
115
|
-
|
|
116
|
-
tui.log(String(error.stack || error));
|
|
117
|
-
} else {
|
|
118
|
-
console.error(error);
|
|
119
|
-
}
|
|
107
|
+
this.log(null, String(error.stack || error));
|
|
120
108
|
this.log('error', `Failed to process scripts`);
|
|
121
109
|
}
|
|
122
110
|
});
|
|
@@ -134,11 +122,7 @@ export default class ScriptsComponent extends BaseComponent {
|
|
|
134
122
|
affectedBlocks.add(blockPath);
|
|
135
123
|
}
|
|
136
124
|
} catch (error) {
|
|
137
|
-
|
|
138
|
-
tui.log(String(error.stack || error));
|
|
139
|
-
} else {
|
|
140
|
-
console.error(error);
|
|
141
|
-
}
|
|
125
|
+
this.log(null, String(error.stack || error));
|
|
142
126
|
}
|
|
143
127
|
}
|
|
144
128
|
|
|
@@ -168,23 +152,11 @@ export default class ScriptsComponent extends BaseComponent {
|
|
|
168
152
|
const formatterOutput = formatter.format(lintresults);
|
|
169
153
|
if (formatterOutput) {
|
|
170
154
|
const cleanedOutput = formatterOutput.replace(`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.scripts}/`, '');
|
|
171
|
-
|
|
172
|
-
cleanedOutput.split('\n').forEach(line => {
|
|
173
|
-
if (line.trim()) {
|
|
174
|
-
tui.log(line);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
} else {
|
|
178
|
-
console.log(cleanedOutput);
|
|
179
|
-
}
|
|
155
|
+
this.log(null, cleanedOutput)
|
|
180
156
|
}
|
|
181
157
|
return true;
|
|
182
158
|
} catch (error) {
|
|
183
|
-
|
|
184
|
-
tui.log(String(error.stack || error));
|
|
185
|
-
} else {
|
|
186
|
-
console.error(error);
|
|
187
|
-
}
|
|
159
|
+
this.log(null, error.stack || error);
|
|
188
160
|
return error;
|
|
189
161
|
}
|
|
190
162
|
}
|
package/lib/components/style.js
CHANGED
|
@@ -84,12 +84,12 @@ export default class StyleComponent extends BaseComponent {
|
|
|
84
84
|
}
|
|
85
85
|
try {
|
|
86
86
|
await fs.writeFile(this.project.paths.theme.scss, themeFileData);
|
|
87
|
-
} catch(error) {
|
|
88
|
-
|
|
87
|
+
} catch (error) {
|
|
88
|
+
this.log(null, error);
|
|
89
89
|
this.log('error', `Failed to write auto-generated _theme.scss - See above error.`);
|
|
90
90
|
}
|
|
91
|
-
} catch(error) {
|
|
92
|
-
|
|
91
|
+
} catch (error) {
|
|
92
|
+
this.log(null, error);
|
|
93
93
|
this.log('error', `Failed to read theme.json - See above error.`);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -110,7 +110,7 @@ export default class StyleComponent extends BaseComponent {
|
|
|
110
110
|
|
|
111
111
|
try {
|
|
112
112
|
await fs.access(`${this.project.path}/${this.project.paths.dist}/${this.project.paths.src.style}`);
|
|
113
|
-
} catch(error) {
|
|
113
|
+
} catch (error) {
|
|
114
114
|
await fs.mkdir(`${this.project.path}/${this.project.paths.dist}/${this.project.paths.src.style}`, { recursive: true });
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -123,7 +123,7 @@ export default class StyleComponent extends BaseComponent {
|
|
|
123
123
|
fix: true
|
|
124
124
|
});
|
|
125
125
|
if (stylelinted.errored) {
|
|
126
|
-
|
|
126
|
+
this.log(null, stylelinted.report);
|
|
127
127
|
throw Error('Linting error');
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -162,8 +162,8 @@ export default class StyleComponent extends BaseComponent {
|
|
|
162
162
|
thisClass.end({
|
|
163
163
|
itemLabel: entryLabel
|
|
164
164
|
});
|
|
165
|
-
} catch(error) {
|
|
166
|
-
|
|
165
|
+
} catch (error) {
|
|
166
|
+
this.log(null, error);
|
|
167
167
|
this.log('error', `Failed building ${entryLabel} - See above error.`);
|
|
168
168
|
return false;
|
|
169
169
|
}
|
package/lib/config-validator.js
CHANGED
package/lib/help.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import project from './project.js';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
+
import log from './logging.js';
|
|
3
4
|
|
|
4
5
|
export default function() {
|
|
5
|
-
|
|
6
|
+
log(null, `
|
|
6
7
|
${chalk.bold.blue('SDC Build WP')} - Custom WordPress build process
|
|
7
8
|
|
|
8
9
|
${chalk.yellow('Usage:')} sdc-build-wp [options] [arguments]
|
|
@@ -38,9 +39,9 @@ ${chalk.yellow('Examples:')}
|
|
|
38
39
|
|
|
39
40
|
${chalk.yellow('Watch Mode Controls:')}
|
|
40
41
|
${chalk.green('[r]')} Restart build process
|
|
41
|
-
|
|
42
|
+
${chalk.green('[c]')} Clear cache
|
|
42
43
|
${chalk.green('[p]')} Pause/Resume watching
|
|
43
|
-
|
|
44
|
+
${chalk.green('[n]')} New component
|
|
44
45
|
${chalk.green('[q]')} Quit and exit
|
|
45
46
|
|
|
46
47
|
${chalk.yellow('Configuration:')}
|
package/lib/logging.js
CHANGED
|
@@ -9,7 +9,8 @@ function getTime() {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function log(type, ...messages) {
|
|
12
|
-
let icon, time
|
|
12
|
+
let icon, time = null;
|
|
13
|
+
let prefix = '';
|
|
13
14
|
|
|
14
15
|
switch (type) {
|
|
15
16
|
case 'success':
|
|
@@ -33,14 +34,36 @@ function log(type, ...messages) {
|
|
|
33
34
|
prefix = chalk.gray('PHP: ');
|
|
34
35
|
break;
|
|
35
36
|
case 'info':
|
|
36
|
-
default:
|
|
37
37
|
icon = chalk.blue('ℹ');
|
|
38
38
|
time = chalk.bgBlue.gray(getTime());
|
|
39
39
|
break;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
let messagesString = messages.join(' ');
|
|
43
|
+
|
|
44
|
+
const logMessage = [icon, time, prefix, messagesString].filter(Boolean).join(' ');
|
|
45
|
+
if (tui.isInitialized) {
|
|
46
|
+
if (!type && messagesString.includes('\n')) {
|
|
47
|
+
messagesString.split('\n').forEach(line => {
|
|
48
|
+
if (line.trim()) {
|
|
49
|
+
tui.log(line);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
tui.log(String(logMessage));
|
|
55
|
+
} else {
|
|
56
|
+
switch (type) {
|
|
57
|
+
case 'error':
|
|
58
|
+
console.error(logMessage);
|
|
59
|
+
break;
|
|
60
|
+
case 'warn':
|
|
61
|
+
console.warn(logMessage);
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
console.log(logMessage);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
44
67
|
}
|
|
45
68
|
|
|
46
69
|
export default log;
|
package/lib/project.js
CHANGED
|
@@ -92,14 +92,14 @@ export async function init() {
|
|
|
92
92
|
const styleDir = `${project.path}/${project.paths.src.src}/${project.paths.src.style}`;
|
|
93
93
|
|
|
94
94
|
if (project.argv.version || project.argv.v) {
|
|
95
|
-
|
|
95
|
+
log(null, await utils.getThisPackageVersion());
|
|
96
96
|
process.exit(0);
|
|
97
97
|
} else if (project.argv['clear-cache']) {
|
|
98
98
|
try {
|
|
99
99
|
await project.components.cache.init();
|
|
100
100
|
await project.components.cache.clearCache();
|
|
101
101
|
} catch (error) {
|
|
102
|
-
|
|
102
|
+
log(null, error);
|
|
103
103
|
log('error', `Failed to clear cache`);
|
|
104
104
|
}
|
|
105
105
|
process.exit(0);
|
|
@@ -153,7 +153,6 @@ export async function init() {
|
|
|
153
153
|
});
|
|
154
154
|
|
|
155
155
|
process.on('SIGINT', async function() {
|
|
156
|
-
console.log(`\r`);
|
|
157
156
|
if (project.isRunning) {
|
|
158
157
|
await utils.stopActiveComponents();
|
|
159
158
|
project.isRunning = false;
|
|
@@ -167,7 +166,7 @@ export async function init() {
|
|
|
167
166
|
if (tui.getLogHistory) {
|
|
168
167
|
const logDump = tui.getLogHistory();
|
|
169
168
|
if (logDump && logDump.trim()) {
|
|
170
|
-
|
|
169
|
+
log(null, logDump);
|
|
171
170
|
}
|
|
172
171
|
}
|
|
173
172
|
log('info', `Exited sdc-build-wp`);
|
|
@@ -200,7 +199,7 @@ export function keypressListen() {
|
|
|
200
199
|
if (isPrompting) { return; }
|
|
201
200
|
switch (key) {
|
|
202
201
|
case '\r': // [Enter]/[Return]
|
|
203
|
-
|
|
202
|
+
log(null, '');
|
|
204
203
|
break;
|
|
205
204
|
case '\u0003': // [Ctrl]+C
|
|
206
205
|
case 'q':
|
|
@@ -290,7 +289,7 @@ async function handleCreateNew() {
|
|
|
290
289
|
project.components.blocks.addBlock(blockDir);
|
|
291
290
|
}
|
|
292
291
|
} catch (error) {
|
|
293
|
-
|
|
292
|
+
log(null, error);
|
|
294
293
|
log('error', `Failed to scaffold block`);
|
|
295
294
|
}
|
|
296
295
|
} else if (typeKey === 'p') {
|
|
@@ -321,7 +320,7 @@ async function handleCreateNew() {
|
|
|
321
320
|
project.components.php.globs.push(filePath);
|
|
322
321
|
}
|
|
323
322
|
} catch (error) {
|
|
324
|
-
|
|
323
|
+
log(null, error);
|
|
325
324
|
log('error', `Failed to create pattern`);
|
|
326
325
|
}
|
|
327
326
|
} else if (typeKey === 's') {
|
|
@@ -346,7 +345,7 @@ async function handleCreateNew() {
|
|
|
346
345
|
try {
|
|
347
346
|
templateObj = JSON.parse(templateRaw);
|
|
348
347
|
} catch (error) {
|
|
349
|
-
|
|
348
|
+
log(null, error);
|
|
350
349
|
throw new Error('Invalid style variation template JSON');
|
|
351
350
|
}
|
|
352
351
|
templateObj.title = name;
|
|
@@ -354,7 +353,7 @@ async function handleCreateNew() {
|
|
|
354
353
|
await fs.writeFile(filePath, JSON.stringify(templateObj, null, '\t'));
|
|
355
354
|
log('success', `Created style variation at styles/${slug}.json`);
|
|
356
355
|
} catch (error) {
|
|
357
|
-
|
|
356
|
+
log(null, error);
|
|
358
357
|
log('error', `Failed to create style variation`);
|
|
359
358
|
}
|
|
360
359
|
}
|
|
@@ -395,7 +394,7 @@ export async function loadConfig() {
|
|
|
395
394
|
project.paths.images = `${project.path}/${project.paths.src.src}/${project.paths.src.images}`;
|
|
396
395
|
project.entries = {};
|
|
397
396
|
} else {
|
|
398
|
-
|
|
397
|
+
log(null, error);
|
|
399
398
|
log('error', `Failed to load config: ${error.message}`);
|
|
400
399
|
process.exit(1);
|
|
401
400
|
}
|
|
@@ -414,7 +413,7 @@ export function setupConfigWatcher() {
|
|
|
414
413
|
await restartBuild();
|
|
415
414
|
});
|
|
416
415
|
configWatcher.on('error', (error) => {
|
|
417
|
-
|
|
416
|
+
log(null, error);
|
|
418
417
|
log('warn', `Config file watcher error`);
|
|
419
418
|
});
|
|
420
419
|
project.configWatcher = configWatcher;
|
package/lib/tui.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import blessed from 'blessed';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
+
import log from './logging.js';
|
|
3
4
|
|
|
4
5
|
class TUI {
|
|
5
6
|
constructor() {
|
|
@@ -195,7 +196,7 @@ class TUI {
|
|
|
195
196
|
log(message) {
|
|
196
197
|
this._logHistory.push(message);
|
|
197
198
|
if (!this.isInitialized) {
|
|
198
|
-
|
|
199
|
+
log(null, message);
|
|
199
200
|
return;
|
|
200
201
|
}
|
|
201
202
|
this.logBox.log(message);
|
package/lib/utils.js
CHANGED
|
@@ -21,7 +21,7 @@ export async function stopActiveComponents() {
|
|
|
21
21
|
try {
|
|
22
22
|
await project.configWatcher.close();
|
|
23
23
|
} catch (error) {
|
|
24
|
-
|
|
24
|
+
log(null, error);
|
|
25
25
|
log('error', 'Failed to stop config file watcher');
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -29,7 +29,7 @@ export async function stopActiveComponents() {
|
|
|
29
29
|
try {
|
|
30
30
|
project.components.server.server.exit();
|
|
31
31
|
} catch (error) {
|
|
32
|
-
|
|
32
|
+
this.log(null, error);
|
|
33
33
|
log('error', 'Failed to stop server');
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -41,7 +41,8 @@ export async function stopActiveComponents() {
|
|
|
41
41
|
try {
|
|
42
42
|
await component.watcher.close();
|
|
43
43
|
} catch (error) {
|
|
44
|
-
|
|
44
|
+
log(null, error);
|
|
45
|
+
log('error', `Failed to stop watcher for ${component.constructor.name}`);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -219,7 +220,7 @@ export async function ensureDir(dir) {
|
|
|
219
220
|
await fs.mkdir(dir, { recursive: true });
|
|
220
221
|
return true;
|
|
221
222
|
} catch (error) {
|
|
222
|
-
|
|
223
|
+
log(null, error);
|
|
223
224
|
log('error', `Failed to create directory ${dir}`);
|
|
224
225
|
return false;
|
|
225
226
|
}
|