sdc-build-wp 5.3.0 → 5.3.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 +1 -1
- package/lib/components/blocks.js +4 -4
- package/lib/components/cache.js +6 -5
- package/lib/components/errors.js +6 -0
- 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/server.js +1 -1
- package/lib/components/style.js +8 -8
- package/lib/config-validator.js +2 -2
- package/lib/help.js +5 -4
- package/lib/logging.js +27 -4
- package/lib/project.js +20 -15
- package/lib/tui.js +5 -4
- 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/cache.js
CHANGED
|
@@ -8,7 +8,7 @@ export default class CacheComponent extends BaseComponent {
|
|
|
8
8
|
constructor() {
|
|
9
9
|
super();
|
|
10
10
|
this.description = 'Build caching';
|
|
11
|
-
this.cacheDir =
|
|
11
|
+
this.cacheDir = this.project.cacheDir;
|
|
12
12
|
this.manifestPath = `${this.cacheDir}/manifest.json`;
|
|
13
13
|
this.manifest = {};
|
|
14
14
|
this.hashCache = new Map();
|
|
@@ -47,6 +47,7 @@ export default class CacheComponent extends BaseComponent {
|
|
|
47
47
|
|
|
48
48
|
async ensureGitignore() {
|
|
49
49
|
const gitignorePath = path.join(this.project.path, '.gitignore');
|
|
50
|
+
const cacheIgnoreEntry = `${path.basename(this.project.sdcDir)}/${path.basename(this.cacheDir)}/`;
|
|
50
51
|
|
|
51
52
|
try {
|
|
52
53
|
let gitignoreContent = '';
|
|
@@ -60,16 +61,16 @@ export default class CacheComponent extends BaseComponent {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
const lines = gitignoreContent.split('\n');
|
|
63
|
-
let hasSDCBuild = lines.some(line => line.trim() ===
|
|
64
|
+
let hasSDCBuild = lines.some(line => line.trim() === cacheIgnoreEntry);
|
|
64
65
|
let needsUpdate = false;
|
|
65
66
|
|
|
66
67
|
if (!hasSDCBuild) {
|
|
67
68
|
if (gitignoreContent && !gitignoreContent.endsWith('\n')) {
|
|
68
69
|
gitignoreContent += '\n';
|
|
69
70
|
}
|
|
70
|
-
gitignoreContent +=
|
|
71
|
+
gitignoreContent += `${cacheIgnoreEntry}\n`;
|
|
71
72
|
needsUpdate = true;
|
|
72
|
-
this.log('info',
|
|
73
|
+
this.log('info', `Added ${cacheIgnoreEntry} to .gitignore`);
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
if (needsUpdate || !gitignoreExists) {
|
|
@@ -277,7 +278,7 @@ export default class CacheComponent extends BaseComponent {
|
|
|
277
278
|
async watch() {
|
|
278
279
|
this.watcher = this.chokidar.watch([
|
|
279
280
|
`${this.project.path}/**/*`,
|
|
280
|
-
`!${this.project.
|
|
281
|
+
`!${this.project.sdcDir}/**/*`,
|
|
281
282
|
`!${this.project.paths.nodeModules}/**/*`,
|
|
282
283
|
`!${this.project.paths.composer.vendor}/**/*`,
|
|
283
284
|
`!${this.project.path}/.git/**/*`
|
package/lib/components/errors.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import BaseComponent from './base.js';
|
|
2
|
+
import path from 'path';
|
|
2
3
|
import fs from 'fs-extra';
|
|
3
4
|
import { Tail } from 'tail';
|
|
4
5
|
|
|
@@ -23,6 +24,11 @@ export default class ErrorsComponent extends BaseComponent {
|
|
|
23
24
|
|
|
24
25
|
async watch() {
|
|
25
26
|
let component = this;
|
|
27
|
+
try {
|
|
28
|
+
await fs.access(this.project.paths.errorLog);
|
|
29
|
+
} catch {
|
|
30
|
+
await fs.ensureFile(path.resolve(this.project.paths.errorLog));
|
|
31
|
+
}
|
|
26
32
|
try {
|
|
27
33
|
await fs.access(this.project.paths.errorLog);
|
|
28
34
|
new Tail(this.project.paths.errorLog).on('line', function(data) {
|
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/server.js
CHANGED
|
@@ -16,7 +16,7 @@ export default class ServerComponent extends BaseComponent {
|
|
|
16
16
|
this.server = create('SDC WP Build Server');
|
|
17
17
|
this.watchedFiles = [];
|
|
18
18
|
this.ignoredFiles = [
|
|
19
|
-
|
|
19
|
+
`${this.project.cacheDir}/**`,
|
|
20
20
|
`node_modules/**`,
|
|
21
21
|
`vendor/**/*`,
|
|
22
22
|
`**/*.map`
|
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,13 +39,13 @@ ${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:')}
|
|
47
|
-
Place your configuration in ${chalk.cyan(
|
|
48
|
+
Place your configuration in ${chalk.cyan(`${project.sdcDirName}/${project.configFileName}`)}
|
|
48
49
|
See documentation for available options.
|
|
49
50
|
`);
|
|
50
51
|
}
|
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
|
@@ -29,7 +29,12 @@ let project = {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
project.sdcDirName = '.sdc-build-wp';
|
|
33
|
+
project.cacheDirName = 'cache';
|
|
34
|
+
project.configFileName = 'config.json';
|
|
35
|
+
project.sdcDir = path.join(project.path, project.sdcDirName);
|
|
36
|
+
project.cacheDir = path.join(project.sdcDir, project.cacheDirName);
|
|
37
|
+
const configPath = path.join(project.sdcDir, project.configFileName);
|
|
33
38
|
|
|
34
39
|
project.paths = {
|
|
35
40
|
src: {
|
|
@@ -66,7 +71,7 @@ project.chokidarOpts = {
|
|
|
66
71
|
`${project.paths.composer.vendor}/**/*`,
|
|
67
72
|
project.paths.theme.scss,
|
|
68
73
|
`${project.path}/blocks/*/build/*.php`,
|
|
69
|
-
`${project.
|
|
74
|
+
`${project.cacheDir}/**/*`,
|
|
70
75
|
]
|
|
71
76
|
};
|
|
72
77
|
|
|
@@ -92,14 +97,14 @@ export async function init() {
|
|
|
92
97
|
const styleDir = `${project.path}/${project.paths.src.src}/${project.paths.src.style}`;
|
|
93
98
|
|
|
94
99
|
if (project.argv.version || project.argv.v) {
|
|
95
|
-
|
|
100
|
+
log(null, await utils.getThisPackageVersion());
|
|
96
101
|
process.exit(0);
|
|
97
102
|
} else if (project.argv['clear-cache']) {
|
|
98
103
|
try {
|
|
99
104
|
await project.components.cache.init();
|
|
100
105
|
await project.components.cache.clearCache();
|
|
101
106
|
} catch (error) {
|
|
102
|
-
|
|
107
|
+
log(null, error);
|
|
103
108
|
log('error', `Failed to clear cache`);
|
|
104
109
|
}
|
|
105
110
|
process.exit(0);
|
|
@@ -153,7 +158,6 @@ export async function init() {
|
|
|
153
158
|
});
|
|
154
159
|
|
|
155
160
|
process.on('SIGINT', async function() {
|
|
156
|
-
console.log(`\r`);
|
|
157
161
|
if (project.isRunning) {
|
|
158
162
|
await utils.stopActiveComponents();
|
|
159
163
|
project.isRunning = false;
|
|
@@ -167,7 +171,7 @@ export async function init() {
|
|
|
167
171
|
if (tui.getLogHistory) {
|
|
168
172
|
const logDump = tui.getLogHistory();
|
|
169
173
|
if (logDump && logDump.trim()) {
|
|
170
|
-
|
|
174
|
+
log(null, logDump);
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
log('info', `Exited sdc-build-wp`);
|
|
@@ -200,7 +204,7 @@ export function keypressListen() {
|
|
|
200
204
|
if (isPrompting) { return; }
|
|
201
205
|
switch (key) {
|
|
202
206
|
case '\r': // [Enter]/[Return]
|
|
203
|
-
|
|
207
|
+
log(null, '');
|
|
204
208
|
break;
|
|
205
209
|
case '\u0003': // [Ctrl]+C
|
|
206
210
|
case 'q':
|
|
@@ -290,7 +294,7 @@ async function handleCreateNew() {
|
|
|
290
294
|
project.components.blocks.addBlock(blockDir);
|
|
291
295
|
}
|
|
292
296
|
} catch (error) {
|
|
293
|
-
|
|
297
|
+
log(null, error);
|
|
294
298
|
log('error', `Failed to scaffold block`);
|
|
295
299
|
}
|
|
296
300
|
} else if (typeKey === 'p') {
|
|
@@ -321,7 +325,7 @@ async function handleCreateNew() {
|
|
|
321
325
|
project.components.php.globs.push(filePath);
|
|
322
326
|
}
|
|
323
327
|
} catch (error) {
|
|
324
|
-
|
|
328
|
+
log(null, error);
|
|
325
329
|
log('error', `Failed to create pattern`);
|
|
326
330
|
}
|
|
327
331
|
} else if (typeKey === 's') {
|
|
@@ -346,7 +350,7 @@ async function handleCreateNew() {
|
|
|
346
350
|
try {
|
|
347
351
|
templateObj = JSON.parse(templateRaw);
|
|
348
352
|
} catch (error) {
|
|
349
|
-
|
|
353
|
+
log(null, error);
|
|
350
354
|
throw new Error('Invalid style variation template JSON');
|
|
351
355
|
}
|
|
352
356
|
templateObj.title = name;
|
|
@@ -354,7 +358,7 @@ async function handleCreateNew() {
|
|
|
354
358
|
await fs.writeFile(filePath, JSON.stringify(templateObj, null, '\t'));
|
|
355
359
|
log('success', `Created style variation at styles/${slug}.json`);
|
|
356
360
|
} catch (error) {
|
|
357
|
-
|
|
361
|
+
log(null, error);
|
|
358
362
|
log('error', `Failed to create style variation`);
|
|
359
363
|
}
|
|
360
364
|
}
|
|
@@ -363,13 +367,14 @@ async function handleCreateNew() {
|
|
|
363
367
|
export async function convertPackageToConfig() {
|
|
364
368
|
if (!project.package.sdc) { return; }
|
|
365
369
|
try {
|
|
370
|
+
await fs.mkdir(project.sdcDir, { recursive: true });
|
|
366
371
|
await fs.writeFile(configPath, JSON.stringify(project.package.sdc, null, '\t'));
|
|
367
|
-
log('success',
|
|
372
|
+
log('success', `Converted package.json sdc to ${path.basename(project.sdcDir)}/${project.configFileName}`);
|
|
368
373
|
delete project.package.sdc;
|
|
369
374
|
await fs.writeFile(path.join(project.path, 'package.json'), JSON.stringify(project.package, null, '\t'));
|
|
370
375
|
log('success', 'Updated package.json to remove sdc');
|
|
371
376
|
} catch (error) {
|
|
372
|
-
log('error', `Failed to convert package.json sdc to .
|
|
377
|
+
log('error', `Failed to convert package.json sdc to ${path.basename(project.sdcDir)}/${project.configFileName}: ${error.message}`);
|
|
373
378
|
process.exit(1);
|
|
374
379
|
}
|
|
375
380
|
}
|
|
@@ -395,7 +400,7 @@ export async function loadConfig() {
|
|
|
395
400
|
project.paths.images = `${project.path}/${project.paths.src.src}/${project.paths.src.images}`;
|
|
396
401
|
project.entries = {};
|
|
397
402
|
} else {
|
|
398
|
-
|
|
403
|
+
log(null, error);
|
|
399
404
|
log('error', `Failed to load config: ${error.message}`);
|
|
400
405
|
process.exit(1);
|
|
401
406
|
}
|
|
@@ -414,7 +419,7 @@ export function setupConfigWatcher() {
|
|
|
414
419
|
await restartBuild();
|
|
415
420
|
});
|
|
416
421
|
configWatcher.on('error', (error) => {
|
|
417
|
-
|
|
422
|
+
log(null, error);
|
|
418
423
|
log('warn', `Config file watcher error`);
|
|
419
424
|
});
|
|
420
425
|
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() {
|
|
@@ -20,6 +21,9 @@ class TUI {
|
|
|
20
21
|
|
|
21
22
|
init() {
|
|
22
23
|
if (this.isInitialized) {
|
|
24
|
+
// If already initialized, redraw the header to reflect current state
|
|
25
|
+
this.updateHeader();
|
|
26
|
+
this.render();
|
|
23
27
|
return;
|
|
24
28
|
}
|
|
25
29
|
|
|
@@ -130,9 +134,6 @@ class TUI {
|
|
|
130
134
|
const lines = [];
|
|
131
135
|
|
|
132
136
|
let titleLine = ' ' + chalk.bold.blue('SDC Build WP');
|
|
133
|
-
if (this.watchMode) {
|
|
134
|
-
titleLine += chalk.gray(' (watch mode)');
|
|
135
|
-
}
|
|
136
137
|
if (this.isPaused) {
|
|
137
138
|
titleLine += chalk.bold.yellow(' [PAUSED]');
|
|
138
139
|
}
|
|
@@ -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
|
}
|