sdc-build-wp 2.0.2 → 2.5.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/index.js +13 -1
- package/lib/blocks.js +47 -0
- package/lib/style.js +18 -9
- package/package.json +13 -13
package/index.js
CHANGED
|
@@ -9,6 +9,7 @@ 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 buildBlocks from './lib/blocks.js';
|
|
12
13
|
import buildImages from './lib/images.js';
|
|
13
14
|
import buildFonts from './lib/fonts.js';
|
|
14
15
|
import buildBrowserSync from './lib/browsersync.js';
|
|
@@ -20,9 +21,11 @@ let chokidarOpts = {
|
|
|
20
21
|
let sassGlobPath = project.package?.sdc?.sassGlobPath || project.path + '/_src/style/**/*.scss';
|
|
21
22
|
let sassGlob = glob.sync(sassGlobPath, {
|
|
22
23
|
ignore: [
|
|
23
|
-
project.path + '/_src/style/partials/
|
|
24
|
+
project.path + '/_src/style/partials/_theme.scss'
|
|
24
25
|
]
|
|
25
26
|
});
|
|
27
|
+
let blockGlobPath = project.package?.sdc?.blockGlobPath || project.path + '/_src/blocks/**/*.{js,jsx}';
|
|
28
|
+
let blockGlob = glob.sync(blockGlobPath);
|
|
26
29
|
|
|
27
30
|
function bustFunctionsCache() {
|
|
28
31
|
bustCache(project.path + '/functions.php');
|
|
@@ -68,6 +71,15 @@ for (const [name, files] of Object.entries(entries)) {
|
|
|
68
71
|
});
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
buildBlocks(blockGlob);
|
|
75
|
+
bustFunctionsCache();
|
|
76
|
+
if (argv.watch) {
|
|
77
|
+
chokidar.watch(blockGlob, chokidarOpts).on('all', (event, path) => {
|
|
78
|
+
buildBlocks(blockGlob);
|
|
79
|
+
bustFunctionsCache();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
71
83
|
filesSass.forEach((file) => {
|
|
72
84
|
buildSass(file, sassGlob);
|
|
73
85
|
bustFunctionsCache();
|
package/lib/blocks.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import project from '../lib/project.js';
|
|
3
|
+
import log from './logging.js';
|
|
4
|
+
import esbuild from 'esbuild';
|
|
5
|
+
import { ESLint } from 'eslint';
|
|
6
|
+
import { readFile } from 'fs/promises';
|
|
7
|
+
|
|
8
|
+
const buildBlocks = async (entries) => {
|
|
9
|
+
let timerStart = Date.now();
|
|
10
|
+
try {
|
|
11
|
+
const eslint = new ESLint({
|
|
12
|
+
baseConfig: JSON.parse(await readFile(new URL('../.eslintrc', import.meta.url))),
|
|
13
|
+
fix: true
|
|
14
|
+
});
|
|
15
|
+
const lintresults = await eslint.lintFiles(entries);
|
|
16
|
+
await ESLint.outputFixes(lintresults);
|
|
17
|
+
const formatter = await eslint.loadFormatter('stylish');
|
|
18
|
+
const formatterOutput = formatter.format(lintresults);
|
|
19
|
+
if (formatterOutput) { console.log(formatterOutput.replace(project.path + '/_src/blocks/', '')); }
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.log(error);
|
|
22
|
+
log('error', `Failed linting ${entries.length} blocks - See above error.`);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const result = await esbuild.build({
|
|
27
|
+
platform: 'node',
|
|
28
|
+
entryPoints: entries,
|
|
29
|
+
bundle: true,
|
|
30
|
+
loader: { '.js' : 'jsx' },
|
|
31
|
+
minify: true,
|
|
32
|
+
outdir: 'dist/blocks/',
|
|
33
|
+
entryNames: '[dir]/[name].min',
|
|
34
|
+
plugins: [],
|
|
35
|
+
sourcemap: true
|
|
36
|
+
});
|
|
37
|
+
if (result.warnings.length > 0) {
|
|
38
|
+
log('warn', result.warnings);
|
|
39
|
+
}
|
|
40
|
+
} catch (error) {
|
|
41
|
+
log('error', `Failed building ${entries.length} blocks - See above error.`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
log('success', `Built ${entries.length} blocks in ${Date.now() - timerStart}ms`);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default buildBlocks;
|
package/lib/style.js
CHANGED
|
@@ -13,18 +13,27 @@ import { promises } from 'fs';
|
|
|
13
13
|
const buildColors = async () => {
|
|
14
14
|
try {
|
|
15
15
|
let theme = JSON.parse(await promises.readFile(project.path + '/theme.json'));
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
colorFileData += `$${color['slug']}: ${color['color']};\n`;
|
|
16
|
+
let themeFileData = `// This file is automatically generated. Do not edit.\n`;
|
|
17
|
+
if (theme.settings?.typography?.fontFamilies) {
|
|
18
|
+
for (var fontFamily of theme.settings.typography.fontFamilies) {
|
|
19
|
+
themeFileData += `$${fontFamily['slug']}: ${fontFamily['fontFamily']};\n`;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
}
|
|
22
|
+
if (theme.settings?.color?.palette) {
|
|
23
|
+
for (var color of theme.settings.color.palette) {
|
|
24
|
+
themeFileData += `$${color['slug']}: ${color['color']};\n`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (theme.settings?.color?.gradients) {
|
|
28
|
+
for (var color of theme.settings.color.gradients) {
|
|
29
|
+
themeFileData += `$gradient-${color['slug']}: ${color['gradient']};\n`;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
32
|
+
try {
|
|
33
|
+
await promises.writeFile(project.path + '/_src/style/partials/_theme.scss', themeFileData);
|
|
34
|
+
} catch {
|
|
35
|
+
log('error', `Failed to write auto-generated _theme.scss - See above error.`);
|
|
36
|
+
}
|
|
28
37
|
} catch {
|
|
29
38
|
log('error', `Failed to read theme.json - See above error.`);
|
|
30
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdc-build-wp",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Custom WordPress build process.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Robert Sefer",
|
|
@@ -19,23 +19,23 @@
|
|
|
19
19
|
"sdc-build-wp": "./index.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"autoprefixer": "^10.4.
|
|
23
|
-
"browser-sync": "^2.27.
|
|
24
|
-
"chalk": "^5.0.
|
|
25
|
-
"chokidar": "^3.5.
|
|
26
|
-
"esbuild": "^0.14.
|
|
27
|
-
"eslint": "^8.
|
|
28
|
-
"fs-extra": "^10.
|
|
29
|
-
"glob": "^
|
|
22
|
+
"autoprefixer": "^10.4.7",
|
|
23
|
+
"browser-sync": "^2.27.10",
|
|
24
|
+
"chalk": "^5.0.1",
|
|
25
|
+
"chokidar": "^3.5.3",
|
|
26
|
+
"esbuild": "^0.14.46",
|
|
27
|
+
"eslint": "^8.18.0",
|
|
28
|
+
"fs-extra": "^10.1.0",
|
|
29
|
+
"glob": "^8.0.3",
|
|
30
30
|
"imagemin": "^8.0.1",
|
|
31
31
|
"imagemin-jpegtran": "^7.0.0",
|
|
32
32
|
"imagemin-pngquant": "^9.0.2",
|
|
33
33
|
"imagemin-svgo": "^10.0.1",
|
|
34
|
-
"minimist": "^1.2.
|
|
34
|
+
"minimist": "^1.2.6",
|
|
35
35
|
"postcss": "^8.4.5",
|
|
36
|
-
"postcss-scss": "^4.0.
|
|
36
|
+
"postcss-scss": "^4.0.4",
|
|
37
37
|
"postcss-sort-media-queries": "^4.2.1",
|
|
38
|
-
"sass": "^1.
|
|
39
|
-
"stylelint": "^14.
|
|
38
|
+
"sass": "^1.52.3",
|
|
39
|
+
"stylelint": "^14.9.1"
|
|
40
40
|
}
|
|
41
41
|
}
|