sdc-build-wp 1.0.10 → 1.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/.eslintrc +19 -0
- package/.stylelintrc +15 -0
- package/index.js +21 -22
- package/lib/browsersync.js +18 -10
- package/lib/bustCache.js +3 -8
- package/lib/fonts.js +14 -6
- package/lib/images.js +9 -10
- package/lib/logging.js +7 -15
- package/lib/project.js +6 -0
- package/lib/scripts.js +23 -7
- package/lib/style.js +53 -36
- package/package.json +21 -17
package/.eslintrc
ADDED
package/.stylelintrc
ADDED
package/index.js
CHANGED
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const glob = require('glob');
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import project from './lib/project.js';
|
|
4
|
+
import parseArgs from 'minimist';
|
|
5
|
+
const argv = parseArgs(process.argv.slice(2));
|
|
6
|
+
import chokidar from 'chokidar';
|
|
7
|
+
import glob from 'glob';
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
import bustCache from './lib/bustCache.js';
|
|
10
|
+
import buildSass from './lib/style.js';
|
|
11
|
+
import buildJS from './lib/scripts.js';
|
|
12
|
+
import buildImages from './lib/images.js';
|
|
13
|
+
import buildFonts from './lib/fonts.js';
|
|
14
|
+
import buildBrowserSync from './lib/browsersync.js';
|
|
16
15
|
|
|
17
16
|
let chokidarOpts = {
|
|
18
17
|
ignoreInitial: true
|
|
19
18
|
};
|
|
20
19
|
|
|
21
20
|
function bustFunctionsCache() {
|
|
22
|
-
bustCache(
|
|
21
|
+
bustCache(project.path + '/functions.php');
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
function frontrunImages() {
|
|
26
|
-
[
|
|
25
|
+
[project.path + '/_src/images/', project.path + '/_src/images/**/*/'].forEach((block) => {
|
|
27
26
|
glob(block, {}, function(err, directory) {
|
|
28
27
|
directory.forEach((dir) => {
|
|
29
28
|
buildImages(dir);
|
|
30
|
-
})
|
|
29
|
+
});
|
|
31
30
|
});
|
|
32
31
|
});
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
let entries = {};
|
|
36
|
-
for (const [name, files] of Object.entries(
|
|
35
|
+
for (const [name, files] of Object.entries(project.package.sdc.entries)) {
|
|
37
36
|
entries[name] = [];
|
|
38
37
|
files.forEach(function(file) {
|
|
39
|
-
entries[name].push(
|
|
38
|
+
entries[name].push(project.path + file);
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -44,7 +43,7 @@ let filesSass = [];
|
|
|
44
43
|
|
|
45
44
|
for (const [name, files] of Object.entries(entries)) {
|
|
46
45
|
files.forEach(function(file) {
|
|
47
|
-
switch (
|
|
46
|
+
switch (path.parse(file).ext) {
|
|
48
47
|
case '.scss':
|
|
49
48
|
filesSass.push(file);
|
|
50
49
|
break;
|
|
@@ -67,7 +66,7 @@ filesSass.forEach((file) => {
|
|
|
67
66
|
bustFunctionsCache();
|
|
68
67
|
});
|
|
69
68
|
if (argv.watch) {
|
|
70
|
-
chokidar.watch(
|
|
69
|
+
chokidar.watch(project.path + '/_src/style/**/*', chokidarOpts).on('all', (event, path) => {
|
|
71
70
|
filesSass.forEach((file) => {
|
|
72
71
|
buildSass(file);
|
|
73
72
|
bustFunctionsCache();
|
|
@@ -76,12 +75,12 @@ if (argv.watch) {
|
|
|
76
75
|
}
|
|
77
76
|
frontrunImages()
|
|
78
77
|
if (argv.watch) {
|
|
79
|
-
chokidar.watch(
|
|
78
|
+
chokidar.watch(project.path + '/_src/images/**/*', chokidarOpts).on('all', (event, path) => {
|
|
80
79
|
frontrunImages();
|
|
81
80
|
});
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
buildFonts(
|
|
83
|
+
buildFonts(project.path + '/_src/fonts');
|
|
85
84
|
|
|
86
85
|
if (argv.watch) {
|
|
87
86
|
buildBrowserSync();
|
package/lib/browsersync.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const browserSync =
|
|
1
|
+
import project from '../lib/project.js';
|
|
2
|
+
import { create as bsCreate } from 'browser-sync';
|
|
3
|
+
const browserSync = bsCreate();
|
|
4
4
|
|
|
5
5
|
const buildBrowserSync = () => {
|
|
6
6
|
browserSync.init({
|
|
7
|
-
port:
|
|
8
|
-
proxy:
|
|
7
|
+
port: project.package.sdc?.port || 3000,
|
|
8
|
+
proxy: project.package.sdc?.browsersync?.localProxyURL,
|
|
9
9
|
files: [
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
project.path + '/dist/**/*',
|
|
11
|
+
project.path + '/**/*.php'
|
|
12
12
|
],
|
|
13
|
-
open:
|
|
13
|
+
open: project.package.sdc?.open || false,
|
|
14
14
|
https: (process.env.SSL_KEY_PATH && process.env.SSL_CRT_PATH ? {
|
|
15
15
|
key: process.env.SSL_KEY_PATH,
|
|
16
16
|
cert: process.env.SSL_CRT_PATH
|
|
17
|
-
} : false)
|
|
17
|
+
} : false),
|
|
18
|
+
ui: false,
|
|
19
|
+
notify: {
|
|
20
|
+
styles: {
|
|
21
|
+
top: 'auto',
|
|
22
|
+
bottom: '0',
|
|
23
|
+
borderRadius: '5px 0px 0px'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
18
26
|
});
|
|
19
27
|
};
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
export default buildBrowserSync;
|
package/lib/bustCache.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const pathConfig = require('path');
|
|
3
|
-
const parentPath = process.cwd();
|
|
4
|
-
const ourPackage = require(process.cwd() + '/package.json');
|
|
1
|
+
import fs from 'fs';
|
|
5
2
|
|
|
6
3
|
const bustCache = (file) => {
|
|
7
4
|
fs.readFile(file, 'utf8', function (err, data) {
|
|
8
|
-
if (err) {
|
|
9
|
-
return console.log(err);
|
|
10
|
-
}
|
|
5
|
+
if (err) { return console.log(err); }
|
|
11
6
|
var result = data.replace(/(\$cacheVersion\ \=\ \')(.*)(\'\;)/g, "$1" + new Date().getTime() + "$3");
|
|
12
7
|
fs.writeFile(file, result, 'utf8', function (err) {
|
|
13
8
|
if (err) return console.log(err);
|
|
@@ -15,4 +10,4 @@ const bustCache = (file) => {
|
|
|
15
10
|
});
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
export default bustCache;
|
package/lib/fonts.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import project from '../lib/project.js';
|
|
2
|
+
import log from './logging.js';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import { readdir } from 'fs/promises';
|
|
4
5
|
|
|
5
6
|
const buildFonts = async (fonts) => {
|
|
6
7
|
let timerStart = Date.now();
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
try {
|
|
9
|
+
const fontsDir = await readdir(fonts);
|
|
10
|
+
if (fontsDir.length == 0) { throw new Error('No files in directory'); }
|
|
11
|
+
await fs.copy(fonts, project.path + '/dist/fonts');
|
|
12
|
+
log('success', `Built /dist/fonts in ${Date.now() - timerStart}ms`);
|
|
13
|
+
} catch {
|
|
14
|
+
log('info', `No files present at ${fonts.replace(project.path, '')}/. Skipping font copy`);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
9
17
|
};
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
export default buildFonts;
|
package/lib/images.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const imageminSvgo = require('imagemin-svgo');
|
|
1
|
+
import project from '../lib/project.js';
|
|
2
|
+
import log from './logging.js';
|
|
3
|
+
import imagemin from 'imagemin';
|
|
4
|
+
import imageminJpegtran from 'imagemin-jpegtran';
|
|
5
|
+
import imageminPngquant from 'imagemin-pngquant';
|
|
6
|
+
import imageminSvgo from 'imagemin-svgo';
|
|
8
7
|
|
|
9
8
|
const buildImages = async (images) => {
|
|
10
9
|
let timerStart = Date.now();
|
|
11
10
|
const files = await imagemin([images + '*'], {
|
|
12
|
-
destination:
|
|
11
|
+
destination: project.path + '/dist/images/' + (images.replace(project.path + '/_src/images/', '')),
|
|
13
12
|
plugins: [
|
|
14
13
|
imageminJpegtran(),
|
|
15
14
|
imageminPngquant(),
|
|
16
15
|
imageminSvgo()
|
|
17
16
|
]
|
|
18
17
|
});
|
|
19
|
-
log('success', `Built /dist/images/${images.replace(
|
|
18
|
+
log('success', `Built /dist/images/${images.replace(project.path + '/_src/images/', '')} in ${Date.now() - timerStart}ms`);
|
|
20
19
|
};
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
export default buildImages;
|
package/lib/logging.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// based heavily on Nick Salloum's 'node-pretty-log'
|
|
2
2
|
// https://github.com/callmenick/node-pretty-log
|
|
3
|
-
|
|
4
|
-
const chalk = require('chalk');
|
|
3
|
+
import chalk from 'chalk';
|
|
5
4
|
|
|
6
5
|
function getTime() {
|
|
7
|
-
|
|
8
|
-
return now.toLocaleTimeString('en-US');
|
|
6
|
+
return new Date().toLocaleTimeString('en-US');
|
|
9
7
|
}
|
|
10
8
|
|
|
11
9
|
function log(type, ...messages) {
|
|
@@ -13,7 +11,7 @@ function log(type, ...messages) {
|
|
|
13
11
|
case 'success':
|
|
14
12
|
console.log.call(
|
|
15
13
|
console,
|
|
16
|
-
chalk.green('
|
|
14
|
+
chalk.green('✔'),
|
|
17
15
|
chalk.gray(getTime()),
|
|
18
16
|
...messages
|
|
19
17
|
);
|
|
@@ -21,7 +19,7 @@ function log(type, ...messages) {
|
|
|
21
19
|
case 'error':
|
|
22
20
|
console.log.call(
|
|
23
21
|
console,
|
|
24
|
-
chalk.red('
|
|
22
|
+
chalk.red('✖'),
|
|
25
23
|
chalk.bgRed.gray(getTime()),
|
|
26
24
|
...messages
|
|
27
25
|
);
|
|
@@ -29,12 +27,13 @@ function log(type, ...messages) {
|
|
|
29
27
|
case 'warn':
|
|
30
28
|
console.log.call(
|
|
31
29
|
console,
|
|
32
|
-
chalk.yellow('
|
|
30
|
+
chalk.yellow('⚠'),
|
|
33
31
|
chalk.bgYellow.gray(getTime()),
|
|
34
32
|
...messages
|
|
35
33
|
);
|
|
36
34
|
break;
|
|
37
35
|
case 'info':
|
|
36
|
+
default:
|
|
38
37
|
console.log.call(
|
|
39
38
|
console,
|
|
40
39
|
chalk.blue('ℹ'),
|
|
@@ -42,14 +41,7 @@ function log(type, ...messages) {
|
|
|
42
41
|
...messages
|
|
43
42
|
);
|
|
44
43
|
break;
|
|
45
|
-
default:
|
|
46
|
-
console.log.call(
|
|
47
|
-
console,
|
|
48
|
-
chalk.blue('ℹ'),
|
|
49
|
-
chalk.gray(getTime()),
|
|
50
|
-
...messages
|
|
51
|
-
);
|
|
52
44
|
}
|
|
53
45
|
}
|
|
54
46
|
|
|
55
|
-
|
|
47
|
+
export default log;
|
package/lib/project.js
ADDED
package/lib/scripts.js
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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';
|
|
6
7
|
|
|
7
8
|
const buildJS = async (entry) => {
|
|
8
|
-
let entryLabel = `/dist/scripts/${
|
|
9
|
+
let entryLabel = `/dist/scripts/${path.parse(entry).base.replace('.js', '.min.js')}`;
|
|
9
10
|
let timerStart = Date.now();
|
|
11
|
+
try {
|
|
12
|
+
const eslint = new ESLint({
|
|
13
|
+
baseConfig: JSON.parse(await readFile(new URL('../.eslintrc', import.meta.url))),
|
|
14
|
+
fix: true
|
|
15
|
+
});
|
|
16
|
+
const lintresults = await eslint.lintFiles([entry]);
|
|
17
|
+
await ESLint.outputFixes(lintresults);
|
|
18
|
+
const formatter = await eslint.loadFormatter('stylish');
|
|
19
|
+
const formatterOutput = formatter.format(lintresults);
|
|
20
|
+
if (formatterOutput) { console.log(formatterOutput.replace(project.path + '/_src/scripts/', '')); }
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.log(error);
|
|
23
|
+
log('error', `Failed linting ${entry.replace(project.path + '/_src/scripts/', '')} - See above error.`);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
10
26
|
try {
|
|
11
27
|
const result = await esbuild.build({
|
|
12
28
|
platform: 'node',
|
|
@@ -29,4 +45,4 @@ const buildJS = async (entry) => {
|
|
|
29
45
|
log('success', `Built ${entryLabel} in ${Date.now() - timerStart}ms`);
|
|
30
46
|
};
|
|
31
47
|
|
|
32
|
-
|
|
48
|
+
export default buildJS;
|
package/lib/style.js
CHANGED
|
@@ -1,46 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import project from '../lib/project.js';
|
|
5
|
+
import log from './logging.js';
|
|
6
|
+
import sass from 'sass';
|
|
7
|
+
import postcss from 'postcss';
|
|
8
|
+
import autoprefixer from 'autoprefixer';
|
|
9
|
+
import sortMQ from 'postcss-sort-media-queries';
|
|
10
|
+
import stylelint from 'stylelint';
|
|
10
11
|
|
|
11
12
|
const buildSass = (entry) => {
|
|
12
13
|
let timerStart = Date.now();
|
|
13
|
-
let outFile =
|
|
14
|
-
let entryLabel = outFile.replace(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
let outFile = project.path + '/dist/style/' + path.parse(entry).name + '.min.css';
|
|
15
|
+
let entryLabel = outFile.replace(project.path, '');
|
|
16
|
+
stylelint.lint({
|
|
17
|
+
configFile: path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../.stylelintrc'),
|
|
18
|
+
formatter: 'string',
|
|
19
|
+
files: [entry],
|
|
20
|
+
customSyntax: 'postcss-scss',
|
|
21
|
+
fix: true
|
|
22
|
+
}).then((data) => {
|
|
23
|
+
if (data.errored) {
|
|
24
|
+
console.log(data.output);
|
|
25
|
+
log('error', `Failed linting ${entry.replace(project.path + '/_src/style/', '')} - See above error.`);
|
|
23
26
|
return false;
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
fs.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
sass.render({
|
|
29
|
+
file: entry,
|
|
30
|
+
outFile: outFile,
|
|
31
|
+
outputStyle: 'compressed'
|
|
32
|
+
}, function(error, result) {
|
|
33
|
+
if (error) {
|
|
34
|
+
console.log(error.formatted);
|
|
35
|
+
log('error', `Failed building ${entryLabel} - See above error.`);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (!fs.existsSync(project.path + '/dist')) {
|
|
39
|
+
fs.mkdirSync(project.path + '/dist');
|
|
40
|
+
}
|
|
41
|
+
if (!fs.existsSync(project.path + '/dist/style')) {
|
|
42
|
+
fs.mkdirSync(project.path + '/dist/style');
|
|
43
|
+
}
|
|
44
|
+
postcss([
|
|
45
|
+
autoprefixer(),
|
|
46
|
+
sortMQ()
|
|
47
|
+
]).process(result.css, { from: undefined }).then(resultPost => {
|
|
48
|
+
fs.writeFile(outFile, resultPost.css, function(err) {
|
|
49
|
+
if (err) {
|
|
50
|
+
console.log(err);
|
|
51
|
+
log('error', `Failed saving ${entryLabel} - See above error.`);
|
|
52
|
+
return false;
|
|
53
|
+
} else {
|
|
54
|
+
log('success', `Built ${entryLabel} in ${Date.now() - timerStart}ms`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
41
57
|
});
|
|
42
58
|
});
|
|
43
59
|
});
|
|
60
|
+
|
|
44
61
|
};
|
|
45
62
|
|
|
46
|
-
|
|
63
|
+
export default buildSass;
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdc-build-wp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Custom WordPress build process.",
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Robert Sefer",
|
|
7
|
+
"email": "rob@seferdesign.com",
|
|
8
|
+
"url": "https://seferdesign.com"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git://github.com/SeferDesign/sdc-build-wp.git"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "echo \"Skipping tests.\""
|
|
17
|
+
},
|
|
17
18
|
"bin": {
|
|
18
19
|
"sdc-build-wp": "./index.js"
|
|
19
20
|
},
|
|
@@ -22,16 +23,19 @@
|
|
|
22
23
|
"browser-sync": "^2.27.7",
|
|
23
24
|
"chalk": "^4.1.2",
|
|
24
25
|
"chokidar": "^3.5.2",
|
|
25
|
-
"esbuild": "^0.13.
|
|
26
|
+
"esbuild": "^0.13.14",
|
|
27
|
+
"eslint": "^8.2.0",
|
|
26
28
|
"fs-extra": "^10.0.0",
|
|
27
29
|
"glob": "^7.2.0",
|
|
28
|
-
"imagemin": "^
|
|
30
|
+
"imagemin": "^8.0.1",
|
|
29
31
|
"imagemin-jpegtran": "^7.0.0",
|
|
30
32
|
"imagemin-pngquant": "^9.0.2",
|
|
31
|
-
"imagemin-svgo": "^
|
|
33
|
+
"imagemin-svgo": "^10.0.0",
|
|
32
34
|
"minimist": "^1.2.5",
|
|
33
35
|
"postcss": "^8.3.11",
|
|
36
|
+
"postcss-scss": "^4.0.2",
|
|
34
37
|
"postcss-sort-media-queries": "^4.1.0",
|
|
35
|
-
"sass": "^1.43.4"
|
|
38
|
+
"sass": "^1.43.4",
|
|
39
|
+
"stylelint": "^14.1.0"
|
|
36
40
|
}
|
|
37
41
|
}
|