sdc-build-wp 2.7.0 → 3.0.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 +5 -1
- package/index.js +16 -8
- package/lib/blocks.js +41 -38
- package/lib/bustCache.js +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -8,4 +8,8 @@ sdc-build-wp --watch # build and watch
|
|
|
8
8
|
|
|
9
9
|
## Develop
|
|
10
10
|
|
|
11
|
-
Develop locally with
|
|
11
|
+
Develop locally with the following command from within the test project directory:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
node ~/sites/sdc/sdc-build-wp/index.js --watch
|
|
15
|
+
```
|
package/index.js
CHANGED
|
@@ -9,26 +9,29 @@ import glob from 'glob';
|
|
|
9
9
|
import bustCache from './lib/bustCache.js';
|
|
10
10
|
import buildSass from './lib/style.js';
|
|
11
11
|
import buildJS from './lib/scripts.js';
|
|
12
|
-
import
|
|
12
|
+
import buildBlock from './lib/blocks.js';
|
|
13
13
|
import buildImages from './lib/images.js';
|
|
14
14
|
import buildFonts from './lib/fonts.js';
|
|
15
15
|
import buildBrowserSync from './lib/browsersync.js';
|
|
16
16
|
|
|
17
17
|
let chokidarOpts = {
|
|
18
|
-
ignoreInitial: true
|
|
18
|
+
ignoreInitial: true,
|
|
19
|
+
ignored: [
|
|
20
|
+
project.path + '/blocks/*/build/**/*'
|
|
21
|
+
]
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
let sassGlobPath = project.package?.sdc?.sassGlobPath || project.path + '{/_src/style,/blocks}/**/*.scss';
|
|
22
25
|
let sassGlob = glob.sync(sassGlobPath, {
|
|
23
26
|
ignore: [
|
|
24
|
-
project.path
|
|
27
|
+
project.path + '/_src/style/partials/_theme.scss'
|
|
25
28
|
]
|
|
26
29
|
});
|
|
27
30
|
let jsGlobPath = project.package?.sdc?.jsGlobPath || project.path + '/_src/scripts/**/*.js';
|
|
28
31
|
let jsGlob = glob.sync(jsGlobPath, {
|
|
29
32
|
ignore: []
|
|
30
33
|
});
|
|
31
|
-
let blockGlobPath = project.package?.sdc?.blockGlobPath || project.path + '/
|
|
34
|
+
let blockGlobPath = project.package?.sdc?.blockGlobPath || project.path + '/blocks/*';
|
|
32
35
|
let blockGlob = glob.sync(blockGlobPath);
|
|
33
36
|
|
|
34
37
|
function bustFunctionsCache() {
|
|
@@ -79,12 +82,17 @@ for (const [name, files] of Object.entries(entries)) {
|
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
function runBlocks() {
|
|
86
|
+
for (var block of blockGlob) {
|
|
87
|
+
buildBlock(block);
|
|
88
|
+
}
|
|
89
|
+
bustFunctionsCache();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
runBlocks();
|
|
84
93
|
if (argv.watch) {
|
|
85
94
|
chokidar.watch(blockGlob, chokidarOpts).on('all', (event, path) => {
|
|
86
|
-
|
|
87
|
-
bustFunctionsCache();
|
|
95
|
+
runBlocks();
|
|
88
96
|
});
|
|
89
97
|
}
|
|
90
98
|
|
package/lib/blocks.js
CHANGED
|
@@ -1,47 +1,50 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import project from '../lib/project.js';
|
|
3
3
|
import log from './logging.js';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
4
|
+
import { stat } from 'fs/promises';
|
|
5
|
+
import { spawn } from 'child_process';
|
|
6
|
+
import process from 'process';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
function cmd(...command) {
|
|
9
|
+
let p = spawn(command[0], command.slice(1), {
|
|
10
|
+
shell: true
|
|
11
|
+
});
|
|
12
|
+
return new Promise((resolveFunc) => {
|
|
13
|
+
// p.stdout.on("data", (x) => {
|
|
14
|
+
// process.stdout.write(x.toString());
|
|
15
|
+
// });
|
|
16
|
+
p.stderr.on('data', (x) => {
|
|
17
|
+
process.stderr.write(x.toString());
|
|
18
|
+
log('error', `Failed building blocks - See above error.`);
|
|
19
|
+
});
|
|
20
|
+
p.on('exit', (code) => {
|
|
21
|
+
resolveFunc(code);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const buildBlock = async (entry) => {
|
|
27
|
+
let workingBlockJson = null;
|
|
28
|
+
let potentialBlockJsonLocations = [
|
|
29
|
+
`${entry}/src/block.json`,
|
|
30
|
+
// `${entry}/block.json`
|
|
31
|
+
];
|
|
32
|
+
for (var location of potentialBlockJsonLocations) {
|
|
33
|
+
try {
|
|
34
|
+
await stat(location);
|
|
35
|
+
workingBlockJson = location
|
|
36
|
+
break;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
//
|
|
39
39
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
40
|
+
}
|
|
41
|
+
if (workingBlockJson === null) {
|
|
42
|
+
log('error', `Failed building ${entry} blocks - no block.json found.`);
|
|
42
43
|
return false;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
+
let timerStart = Date.now();
|
|
46
|
+
await cmd(`cd ${entry} && ${project.path}/node_modules/@wordpress/scripts/bin/wp-scripts.js`, 'build');
|
|
47
|
+
log('success', `Built ${entry.replace(project.path, '')} in ${Date.now() - timerStart}ms`);
|
|
45
48
|
};
|
|
46
49
|
|
|
47
|
-
export default
|
|
50
|
+
export default buildBlock;
|
package/lib/bustCache.js
CHANGED
|
@@ -3,6 +3,7 @@ import fs from 'fs';
|
|
|
3
3
|
const bustCache = (file) => {
|
|
4
4
|
fs.readFile(file, 'utf8', function (err, data) {
|
|
5
5
|
if (err) { return console.log(err); }
|
|
6
|
+
if (!data.includes('$cacheVersion')) { return; }
|
|
6
7
|
var result = data.replace(/(\$cacheVersion\ \=\ \')(.*)(\'\;)/g, "$1" + new Date().getTime() + "$3");
|
|
7
8
|
fs.writeFile(file, result, 'utf8', function (err) {
|
|
8
9
|
if (err) return console.log(err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdc-build-wp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Custom WordPress build process.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Robert Sefer",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"sdc-build-wp": "./index.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@wordpress/scripts": "^26.6.0",
|
|
22
23
|
"autoprefixer": "^10.4.13",
|
|
23
24
|
"browser-sync": "^2.27.11",
|
|
24
25
|
"chalk": "^5.2.0",
|