sdc-build-wp 2.7.1 → 3.0.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/README.md +5 -1
- package/index.js +16 -8
- package/lib/blocks.js +41 -38
- package/lib/style.js +35 -31
- package/package.json +3 -2
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/style.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import project from '../lib/project.js';
|
|
5
5
|
import log from './logging.js';
|
|
6
|
-
import sass from 'sass';
|
|
6
|
+
import * as sass from 'sass';
|
|
7
7
|
import postcss from 'postcss';
|
|
8
8
|
import autoprefixer from 'autoprefixer';
|
|
9
9
|
import sortMQ from 'postcss-sort-media-queries';
|
|
@@ -59,39 +59,43 @@ const buildSass = async (entry, name, entriesToLint) => {
|
|
|
59
59
|
log('error', `Failed linting ${entry.replace(project.path + '/_src/style/', '')} - See above error.`);
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
if (!fs.existsSync(project.path + '/dist/style')) {
|
|
76
|
-
fs.mkdirSync(project.path + '/dist/style');
|
|
77
|
-
}
|
|
78
|
-
postcss([
|
|
79
|
-
autoprefixer(),
|
|
80
|
-
sortMQ()
|
|
81
|
-
]).process(result.css, { from: undefined }).then(resultPost => {
|
|
82
|
-
fs.writeFile(outFile, resultPost.css, function(err) {
|
|
83
|
-
if (err) {
|
|
84
|
-
console.log(err);
|
|
85
|
-
log('error', `Failed saving ${entryLabel} - See above error.`);
|
|
86
|
-
return false;
|
|
87
|
-
} else {
|
|
88
|
-
log('success', `Built ${entryLabel} in ${Date.now() - timerStart}ms`);
|
|
62
|
+
try {
|
|
63
|
+
const result = sass.compile(entry, {
|
|
64
|
+
style: 'compressed'
|
|
65
|
+
});
|
|
66
|
+
fs.writeFile(outFile, result.css, function(err) {
|
|
67
|
+
if (err) {
|
|
68
|
+
console.log(err);
|
|
69
|
+
log('error', `Failed building ${entryLabel} - See above error.`);
|
|
70
|
+
return false;
|
|
71
|
+
} else {
|
|
72
|
+
if (!fs.existsSync(project.path + '/dist')) {
|
|
73
|
+
fs.mkdirSync(project.path + '/dist');
|
|
89
74
|
}
|
|
90
|
-
|
|
75
|
+
if (!fs.existsSync(project.path + '/dist/style')) {
|
|
76
|
+
fs.mkdirSync(project.path + '/dist/style');
|
|
77
|
+
}
|
|
78
|
+
postcss([
|
|
79
|
+
autoprefixer(),
|
|
80
|
+
sortMQ()
|
|
81
|
+
]).process(result.css, { from: undefined }).then(resultPost => {
|
|
82
|
+
fs.writeFile(outFile, resultPost.css, function(err) {
|
|
83
|
+
if (err) {
|
|
84
|
+
console.log(err);
|
|
85
|
+
log('error', `Failed saving ${entryLabel} - See above error.`);
|
|
86
|
+
return false;
|
|
87
|
+
} else {
|
|
88
|
+
log('success', `Built ${entryLabel} in ${Date.now() - timerStart}ms`);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
91
93
|
});
|
|
92
|
-
}
|
|
94
|
+
} catch {
|
|
95
|
+
log('error', `Failed building ${entryLabel} - See above error.`);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
93
98
|
});
|
|
94
|
-
|
|
95
99
|
};
|
|
96
100
|
|
|
97
101
|
export default buildSass;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdc-build-wp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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",
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"postcss": "^8.4.20",
|
|
36
37
|
"postcss-scss": "^4.0.6",
|
|
37
38
|
"postcss-sort-media-queries": "^4.3.0",
|
|
38
|
-
"sass": "^1.
|
|
39
|
+
"sass": "^1.63.4",
|
|
39
40
|
"stylelint": "^14.16.0"
|
|
40
41
|
}
|
|
41
42
|
}
|