sdc-build-wp 4.3.4 → 4.3.5
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/index.js +4 -4
- package/lib/components/blocks.js +17 -33
- package/lib/components/fonts.js +15 -2
- package/lib/components/images.js +1 -1
- package/lib/components/php.js +2 -3
- package/lib/components/scripts.js +6 -5
- package/lib/components/server.js +4 -4
- package/lib/components/style.js +6 -6
- package/lib/project.js +14 -2
- package/package.json +1 -1
package/index.js
CHANGED
@@ -17,9 +17,9 @@ Usage: sdc-build-wp [options] [arguments]
|
|
17
17
|
|
18
18
|
Options:
|
19
19
|
-h, --help Show help message and exit
|
20
|
-
|
20
|
+
-v, --version Version
|
21
21
|
-w, --watch Build and watch
|
22
|
-
-b, --
|
22
|
+
-b, --builds BUILDS Build with specific components
|
23
23
|
|
24
24
|
Components:
|
25
25
|
|
@@ -39,12 +39,12 @@ console.log(JSON.parse(await fs.readFile(path.join(path.dirname(fileURLToPath(im
|
|
39
39
|
process.exit(0);
|
40
40
|
}
|
41
41
|
|
42
|
-
project.builds = argv.builds ? argv.builds.split(',') : Object.keys(project.components);
|
42
|
+
project.builds = argv.builds ? (Array.isArray(argv.builds) ? argv.builds : argv.builds.split(',')) : Object.keys(project.components);
|
43
43
|
|
44
44
|
(async() => {
|
45
45
|
|
46
46
|
let initialBuildTimerStart = Date.now();
|
47
|
-
log('info', `
|
47
|
+
log('info', `Started initial build [${project.builds.join(', ')}]`);
|
48
48
|
for (let build of project.builds) {
|
49
49
|
await project.components[build].init();
|
50
50
|
}
|
package/lib/components/blocks.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import BaseComponent from './base.js';
|
2
2
|
import { stat } from 'fs/promises';
|
3
|
-
import {
|
4
|
-
import
|
3
|
+
import { exec } from 'child_process';
|
4
|
+
import { promisify } from 'util';
|
5
5
|
|
6
6
|
export default class BlocksComponent extends BaseComponent {
|
7
7
|
|
@@ -49,14 +49,21 @@ export default class BlocksComponent extends BaseComponent {
|
|
49
49
|
this.log('error', `Failed building ${entry} blocks - no block.json found.`);
|
50
50
|
return false;
|
51
51
|
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
try {
|
53
|
+
const cmds = [
|
54
|
+
`${this.project.path}/node_modules/@wordpress/scripts/bin/wp-scripts.js`,
|
55
|
+
`build`,
|
56
|
+
`--source-path=.${entry.replace(this.project.path, '')}/src`,
|
57
|
+
`--output-path=.${entry.replace(this.project.path, '')}/build`,
|
58
|
+
`--webpack-copy-php`
|
59
|
+
];
|
60
|
+
let execPromise = promisify(exec);
|
61
|
+
const { stdout, stderr } = await execPromise(cmds.join(' '));
|
62
|
+
} catch (error) {
|
63
|
+
console.log(error.stdout);
|
64
|
+
this.log('error', `Failed building ${entryLabel} block - See above error.`);
|
65
|
+
return false;
|
66
|
+
}
|
60
67
|
|
61
68
|
this.end({
|
62
69
|
itemLabel: entryLabel,
|
@@ -85,26 +92,3 @@ export default class BlocksComponent extends BaseComponent {
|
|
85
92
|
}
|
86
93
|
|
87
94
|
}
|
88
|
-
|
89
|
-
function cmd(commands) {
|
90
|
-
let p = spawn(commands[0], commands.slice(1), {
|
91
|
-
shell: true
|
92
|
-
});
|
93
|
-
return new Promise((resolveFunc) => {
|
94
|
-
p.stdout.on('data', (x) => {
|
95
|
-
if (x.toString().includes('Error:')) {
|
96
|
-
process.stdout.write(x.toString());
|
97
|
-
log('error', `Failed building ${entryLabel} block - See above error.`);
|
98
|
-
}
|
99
|
-
});
|
100
|
-
p.stderr.on('data', (x) => {
|
101
|
-
if (x.toString().includes('Error:')) {
|
102
|
-
process.stderr.write(x.toString());
|
103
|
-
log('error', `Failed building ${entryLabel} block - See above error.`);
|
104
|
-
}
|
105
|
-
});
|
106
|
-
p.on('exit', (code) => {
|
107
|
-
resolveFunc(code);
|
108
|
-
});
|
109
|
-
});
|
110
|
-
}
|
package/lib/components/fonts.js
CHANGED
@@ -10,11 +10,15 @@ export default class FontsComponent extends BaseComponent {
|
|
10
10
|
}
|
11
11
|
|
12
12
|
async init() {
|
13
|
+
this.globs = await Array.fromAsync(
|
14
|
+
this.glob(this.project.package?.sdc?.fontsPath ||
|
15
|
+
`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.fonts}`)
|
16
|
+
);
|
13
17
|
await this.process();
|
14
18
|
}
|
15
19
|
|
16
20
|
async build(entry) {
|
17
|
-
let entryLabel =
|
21
|
+
let entryLabel = `/${this.project.paths.dist}/${this.project.paths.src.fonts}`;
|
18
22
|
|
19
23
|
this.start();
|
20
24
|
|
@@ -22,6 +26,7 @@ export default class FontsComponent extends BaseComponent {
|
|
22
26
|
const fontsDir = await readdir(entry);
|
23
27
|
if (fontsDir.length == 0) { throw new Error('No files present'); }
|
24
28
|
await fs.copy(entry, `${this.project.path}${entryLabel}`);
|
29
|
+
entryLabel += ` (${fontsDir.filter(file => !file.startsWith('.')).length} files)`;
|
25
30
|
} catch(error) {
|
26
31
|
this.log('info', `${error} at ${entry.replace(this.project.path, '')}/. Skipping font copy`);
|
27
32
|
return false;
|
@@ -33,7 +38,15 @@ export default class FontsComponent extends BaseComponent {
|
|
33
38
|
}
|
34
39
|
|
35
40
|
async process() {
|
36
|
-
await this.build(`${this.project.path}
|
41
|
+
await this.build(`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.fonts}`);
|
42
|
+
}
|
43
|
+
|
44
|
+
watch() {
|
45
|
+
this.chokidar.watch(this.globs, {
|
46
|
+
...this.project.chokidarOpts
|
47
|
+
}).on('all', (event, path) => {
|
48
|
+
this.process();
|
49
|
+
});
|
37
50
|
}
|
38
51
|
|
39
52
|
}
|
package/lib/components/images.js
CHANGED
@@ -25,7 +25,7 @@ export default class ImagesComponent extends BaseComponent {
|
|
25
25
|
|
26
26
|
async build(entry, options) {
|
27
27
|
let timerStart = Date.now();
|
28
|
-
let dest = entry.replace(
|
28
|
+
let dest = entry.replace(`${this.project.paths.src.src}/${this.project.paths.src.images}`, `${this.project.paths.dist}/${this.project.paths.src.images}`);
|
29
29
|
const files = await imagemin([entry + '/*'], {
|
30
30
|
destination: dest,
|
31
31
|
plugins: [
|
package/lib/components/php.js
CHANGED
@@ -8,7 +8,6 @@ export default class PHPComponent extends BaseComponent {
|
|
8
8
|
constructor() {
|
9
9
|
super();
|
10
10
|
this.description = `Lint (and fix) php files`;
|
11
|
-
this.execPromise = promisify(exec);
|
12
11
|
}
|
13
12
|
|
14
13
|
async init() {
|
@@ -56,8 +55,8 @@ export default class PHPComponent extends BaseComponent {
|
|
56
55
|
phpFiles,
|
57
56
|
additionalFlags
|
58
57
|
];
|
59
|
-
|
60
|
-
const { stdout, stderr } = await
|
58
|
+
let execPromise = promisify(exec);
|
59
|
+
const { stdout, stderr } = await execPromise(cmds.join(' '), {
|
61
60
|
cwd: this.path.resolve(this.path.dirname(fileURLToPath(import.meta.url)), '../../')
|
62
61
|
}); // returns an error if any violations are found, so we can't rely on the try/catch as usual
|
63
62
|
} catch (error) {
|
@@ -14,7 +14,7 @@ export default class ScriptsComponent extends BaseComponent {
|
|
14
14
|
this.files = this.utils.addEntriesByFiletypes(['.js']);
|
15
15
|
this.globs = await Array.fromAsync(
|
16
16
|
this.glob(this.project.package?.sdc?.jsGlobPath ||
|
17
|
-
`${this.project.path}
|
17
|
+
`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.scripts}/**/*.js`)
|
18
18
|
);
|
19
19
|
await this.process();
|
20
20
|
}
|
@@ -23,7 +23,7 @@ export default class ScriptsComponent extends BaseComponent {
|
|
23
23
|
options = Object.assign({}, {
|
24
24
|
entriesToLint: null
|
25
25
|
}, options);
|
26
|
-
let entryLabel =
|
26
|
+
let entryLabel = `/${this.project.paths.dist}/${this.project.paths.src.scripts}/${this.utils.entryBasename(entry).replace('.js', '.min.js')}`;
|
27
27
|
|
28
28
|
this.start();
|
29
29
|
|
@@ -37,10 +37,10 @@ export default class ScriptsComponent extends BaseComponent {
|
|
37
37
|
await ESLint.outputFixes(lintresults);
|
38
38
|
const formatter = await eslint.loadFormatter('stylish');
|
39
39
|
const formatterOutput = formatter.format(lintresults);
|
40
|
-
if (formatterOutput) { console.log(formatterOutput.replace(this.project.path
|
40
|
+
if (formatterOutput) { console.log(formatterOutput.replace(`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.scripts}/`, '')); }
|
41
41
|
} catch (error) {
|
42
42
|
console.log(error);
|
43
|
-
this.log('error', `Failed linting ${entry.replace(this.project.path
|
43
|
+
this.log('error', `Failed linting ${entry.replace(`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.scripts}/`, '')} - See above error.`);
|
44
44
|
return false;
|
45
45
|
}
|
46
46
|
|
@@ -51,7 +51,7 @@ export default class ScriptsComponent extends BaseComponent {
|
|
51
51
|
bundle: true,
|
52
52
|
loader: { '.js': 'jsx' },
|
53
53
|
minify: true,
|
54
|
-
outdir:
|
54
|
+
outdir: `${this.project.paths.dist}/${this.project.paths.src.scripts}/`,
|
55
55
|
entryNames: '[dir]/[name].min',
|
56
56
|
plugins: [],
|
57
57
|
sourcemap: true
|
@@ -60,6 +60,7 @@ export default class ScriptsComponent extends BaseComponent {
|
|
60
60
|
log('warn', result.warnings);
|
61
61
|
}
|
62
62
|
} catch (error) {
|
63
|
+
console.error(error);
|
63
64
|
this.log('error', `Failed building ${entryLabel} - See above error.`);
|
64
65
|
return false;
|
65
66
|
}
|
package/lib/components/server.js
CHANGED
@@ -15,12 +15,12 @@ export default class ServerComponent extends BaseComponent {
|
|
15
15
|
|
16
16
|
start() {
|
17
17
|
let watchedFiles = [
|
18
|
-
this.project.path
|
19
|
-
this.project.path
|
20
|
-
this.project.path
|
18
|
+
`${this.project.path}/${this.project.paths.dist}/**/*`,
|
19
|
+
`${this.project.path}/**/*.html`,
|
20
|
+
`${this.project.path}/**/*.json`,
|
21
21
|
];
|
22
22
|
if (!this.project.shouldPHPLint) {
|
23
|
-
watchedFiles.push(this.project.path
|
23
|
+
watchedFiles.push(`${this.project.path}/**/*.php`);
|
24
24
|
}
|
25
25
|
let bsOptions = {
|
26
26
|
logPrefix: '',
|
package/lib/components/style.js
CHANGED
@@ -18,14 +18,14 @@ export default class StyleComponent extends BaseComponent {
|
|
18
18
|
this.files = this.utils.addEntriesByFiletypes(['.scss']);
|
19
19
|
this.globs = await Array.fromAsync(
|
20
20
|
this.glob(this.project.package?.sdc?.sassGlobPath ||
|
21
|
-
`${this.project.path}{
|
21
|
+
`${this.project.path}{/${this.project.paths.src.src}/${this.project.paths.src.style},/blocks}/**/*.scss`)
|
22
22
|
);
|
23
23
|
await this.process();
|
24
24
|
}
|
25
25
|
|
26
26
|
async buildTheme() {
|
27
27
|
try {
|
28
|
-
let theme = JSON.parse(await fs.readFile(this.project.
|
28
|
+
let theme = JSON.parse(await fs.readFile(this.project.paths.theme.json));
|
29
29
|
let themeFileData = `// This file is automatically generated from theme.json. Do not edit.\n`;
|
30
30
|
if (theme.settings?.custom) {
|
31
31
|
for (var customAttribute in theme.settings.custom) {
|
@@ -74,7 +74,7 @@ export default class StyleComponent extends BaseComponent {
|
|
74
74
|
}
|
75
75
|
}
|
76
76
|
try {
|
77
|
-
await fs.writeFile(this.project.
|
77
|
+
await fs.writeFile(this.project.paths.theme.scss, themeFileData);
|
78
78
|
} catch(error) {
|
79
79
|
console.error(error);
|
80
80
|
this.log('error', `Failed to write auto-generated _theme.scss - See above error.`);
|
@@ -91,7 +91,7 @@ export default class StyleComponent extends BaseComponent {
|
|
91
91
|
entriesToLint: []
|
92
92
|
}, options);
|
93
93
|
let thisClass = this;
|
94
|
-
let outFile = this.project.path
|
94
|
+
let outFile = `${this.project.path}/${this.project.paths.dist}/${options.name}.min.css`;
|
95
95
|
if (options.name.startsWith('blocks/')) {
|
96
96
|
outFile = this.project.path + '/' + options.name + '.min.css';
|
97
97
|
}
|
@@ -99,9 +99,9 @@ export default class StyleComponent extends BaseComponent {
|
|
99
99
|
this.start();
|
100
100
|
|
101
101
|
try {
|
102
|
-
await fs.access(`${this.project.path}
|
102
|
+
await fs.access(`${this.project.path}/${this.project.paths.dist}/${this.project.paths.src.style}`);
|
103
103
|
} catch(error) {
|
104
|
-
await fs.mkdir(`${this.project.path}
|
104
|
+
await fs.mkdir(`${this.project.path}/${this.project.paths.dist}/${this.project.paths.src.style}`, { recursive: true });
|
105
105
|
}
|
106
106
|
try {
|
107
107
|
const stylelinted = await stylelint.lint({
|
package/lib/project.js
CHANGED
@@ -16,15 +16,27 @@ let project = {
|
|
16
16
|
project.shouldPHPLint = typeof project.package.sdc?.php === 'undefined' || typeof project.package.sdc?.php.enabled === 'undefined' || project.package.sdc?.php.enabled == true;
|
17
17
|
|
18
18
|
project.paths = {
|
19
|
+
src: {
|
20
|
+
src: '_src',
|
21
|
+
fonts: 'fonts',
|
22
|
+
images: 'images',
|
23
|
+
scripts: 'scripts',
|
24
|
+
style: 'style'
|
25
|
+
},
|
26
|
+
dist: 'dist'
|
27
|
+
};
|
28
|
+
|
29
|
+
project.paths = {
|
30
|
+
...project.paths,
|
19
31
|
theme: {
|
20
32
|
json: `${project.path}/theme.json`,
|
21
|
-
scss: `${project.path}
|
33
|
+
scss: `${project.path}/${project.paths.src.src}/${project.paths.src.style}/partials/_theme.scss`
|
22
34
|
},
|
23
35
|
nodeModules: `${project.path}/node_modules`,
|
24
36
|
composer: {
|
25
37
|
vendor: `${project.path}/vendor`
|
26
38
|
},
|
27
|
-
images: project.package?.sdc?.imagesPath || `${project.path}
|
39
|
+
images: project.package?.sdc?.imagesPath || `${project.path}/${project.paths.src.src}/${project.paths.src.images}`,
|
28
40
|
errorLog: process.env.ERROR_LOG_PATH || project.package.sdc?.error_log_path || '../../../../../logs/php/error.log'
|
29
41
|
};
|
30
42
|
|