sdc-build-wp 1.2.1 → 1.3.4
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.js → .eslintrc} +2 -2
- package/.stylelintrc +23 -0
- package/index.js +18 -14
- package/lib/browsersync.js +4 -3
- package/lib/bustCache.js +3 -5
- package/lib/fonts.js +14 -6
- package/lib/images.js +7 -7
- package/lib/logging.js +5 -6
- package/lib/project.js +4 -2
- package/lib/scripts.js +8 -8
- package/lib/style.js +16 -13
- package/package.json +11 -10
- package/stylelint.config.js +0 -15
package/.stylelintrc
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"rules": {
|
|
3
|
+
"indentation": "tab",
|
|
4
|
+
"max-empty-lines": 1,
|
|
5
|
+
"rule-empty-line-before": [
|
|
6
|
+
"always",
|
|
7
|
+
{
|
|
8
|
+
"ignore": [ "after-comment" ]
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
"block-opening-brace-space-before": "always-multi-line",
|
|
12
|
+
"block-opening-brace-newline-after": "always-multi-line",
|
|
13
|
+
"no-empty-first-line": true,
|
|
14
|
+
"selector-max-empty-lines": 0,
|
|
15
|
+
"color-function-notation": "modern",
|
|
16
|
+
"color-hex-length": "long",
|
|
17
|
+
"color-no-invalid-hex": true,
|
|
18
|
+
"color-named": "never",
|
|
19
|
+
"shorthand-property-no-redundant-values": true,
|
|
20
|
+
"number-leading-zero": "always",
|
|
21
|
+
"no-eol-whitespace": true
|
|
22
|
+
}
|
|
23
|
+
}
|
package/index.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
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';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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';
|
|
14
15
|
|
|
15
16
|
let chokidarOpts = {
|
|
16
17
|
ignoreInitial: true
|
|
17
18
|
};
|
|
18
19
|
|
|
20
|
+
let sassGlobPath = project.package?.sdc?.sassGlobPath || project.path + '/_src/style/**/*.scss';
|
|
21
|
+
let sassGlob = glob.sync(sassGlobPath);
|
|
22
|
+
|
|
19
23
|
function bustFunctionsCache() {
|
|
20
24
|
bustCache(project.path + '/functions.php');
|
|
21
25
|
}
|
|
@@ -61,13 +65,13 @@ for (const [name, files] of Object.entries(entries)) {
|
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
filesSass.forEach((file) => {
|
|
64
|
-
buildSass(file);
|
|
68
|
+
buildSass(file, sassGlob);
|
|
65
69
|
bustFunctionsCache();
|
|
66
70
|
});
|
|
67
71
|
if (argv.watch) {
|
|
68
|
-
chokidar.watch(
|
|
72
|
+
chokidar.watch(sassGlob, chokidarOpts).on('all', (event, path) => {
|
|
69
73
|
filesSass.forEach((file) => {
|
|
70
|
-
buildSass(file);
|
|
74
|
+
buildSass(file, sassGlob);
|
|
71
75
|
bustFunctionsCache();
|
|
72
76
|
});
|
|
73
77
|
});
|
package/lib/browsersync.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import project from '../lib/project.js';
|
|
2
|
+
import { create as bsCreate } from 'browser-sync';
|
|
3
|
+
const browserSync = bsCreate();
|
|
3
4
|
|
|
4
5
|
const buildBrowserSync = () => {
|
|
5
6
|
browserSync.init({
|
|
@@ -25,4 +26,4 @@ const buildBrowserSync = () => {
|
|
|
25
26
|
});
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
export default buildBrowserSync;
|
package/lib/bustCache.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
2
|
|
|
3
3
|
const bustCache = (file) => {
|
|
4
4
|
fs.readFile(file, 'utf8', function (err, data) {
|
|
5
|
-
if (err) {
|
|
6
|
-
return console.log(err);
|
|
7
|
-
}
|
|
5
|
+
if (err) { return console.log(err); }
|
|
8
6
|
var result = data.replace(/(\$cacheVersion\ \=\ \')(.*)(\'\;)/g, "$1" + new Date().getTime() + "$3");
|
|
9
7
|
fs.writeFile(file, result, 'utf8', function (err) {
|
|
10
8
|
if (err) return console.log(err);
|
|
@@ -12,4 +10,4 @@ const bustCache = (file) => {
|
|
|
12
10
|
});
|
|
13
11
|
};
|
|
14
12
|
|
|
15
|
-
|
|
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,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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';
|
|
7
7
|
|
|
8
8
|
const buildImages = async (images) => {
|
|
9
9
|
let timerStart = Date.now();
|
|
@@ -18,4 +18,4 @@ const buildImages = async (images) => {
|
|
|
18
18
|
log('success', `Built /dist/images/${images.replace(project.path + '/_src/images/', '')} in ${Date.now() - timerStart}ms`);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
export default buildImages;
|
package/lib/logging.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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
6
|
return new Date().toLocaleTimeString('en-US');
|
|
@@ -12,7 +11,7 @@ function log(type, ...messages) {
|
|
|
12
11
|
case 'success':
|
|
13
12
|
console.log.call(
|
|
14
13
|
console,
|
|
15
|
-
chalk.green('
|
|
14
|
+
chalk.green('✔'),
|
|
16
15
|
chalk.gray(getTime()),
|
|
17
16
|
...messages
|
|
18
17
|
);
|
|
@@ -20,7 +19,7 @@ function log(type, ...messages) {
|
|
|
20
19
|
case 'error':
|
|
21
20
|
console.log.call(
|
|
22
21
|
console,
|
|
23
|
-
chalk.red('
|
|
22
|
+
chalk.red('✖'),
|
|
24
23
|
chalk.bgRed.gray(getTime()),
|
|
25
24
|
...messages
|
|
26
25
|
);
|
|
@@ -28,7 +27,7 @@ function log(type, ...messages) {
|
|
|
28
27
|
case 'warn':
|
|
29
28
|
console.log.call(
|
|
30
29
|
console,
|
|
31
|
-
chalk.yellow('
|
|
30
|
+
chalk.yellow('⚠'),
|
|
32
31
|
chalk.bgYellow.gray(getTime()),
|
|
33
32
|
...messages
|
|
34
33
|
);
|
|
@@ -45,4 +44,4 @@ function log(type, ...messages) {
|
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
export default log;
|
package/lib/project.js
CHANGED
package/lib/scripts.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
7
|
|
|
8
8
|
const buildJS = async (entry) => {
|
|
9
9
|
let entryLabel = `/dist/scripts/${path.parse(entry).base.replace('.js', '.min.js')}`;
|
|
10
10
|
let timerStart = Date.now();
|
|
11
11
|
try {
|
|
12
12
|
const eslint = new ESLint({
|
|
13
|
-
baseConfig:
|
|
13
|
+
baseConfig: JSON.parse(await readFile(new URL('../.eslintrc', import.meta.url))),
|
|
14
14
|
fix: true
|
|
15
15
|
});
|
|
16
16
|
const lintresults = await eslint.lintFiles([entry]);
|
|
@@ -45,4 +45,4 @@ const buildJS = async (entry) => {
|
|
|
45
45
|
log('success', `Built ${entryLabel} in ${Date.now() - timerStart}ms`);
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
export default buildJS;
|
package/lib/style.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
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
|
-
const buildSass = (entry) => {
|
|
12
|
+
const buildSass = (entry, entriesToLint) => {
|
|
12
13
|
let timerStart = Date.now();
|
|
13
14
|
let outFile = project.path + '/dist/style/' + path.parse(entry).name + '.min.css';
|
|
14
15
|
let entryLabel = outFile.replace(project.path, '');
|
|
15
16
|
stylelint.lint({
|
|
16
|
-
configFile: path.resolve(
|
|
17
|
+
configFile: path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../.stylelintrc'),
|
|
17
18
|
formatter: 'string',
|
|
18
|
-
files: [entry],
|
|
19
|
+
files: entriesToLint || [entry],
|
|
19
20
|
customSyntax: 'postcss-scss',
|
|
20
21
|
fix: true
|
|
21
22
|
}).then((data) => {
|
|
@@ -47,6 +48,8 @@ const buildSass = (entry) => {
|
|
|
47
48
|
fs.writeFile(outFile, resultPost.css, function(err) {
|
|
48
49
|
if (err) {
|
|
49
50
|
console.log(err);
|
|
51
|
+
log('error', `Failed saving ${entryLabel} - See above error.`);
|
|
52
|
+
return false;
|
|
50
53
|
} else {
|
|
51
54
|
log('success', `Built ${entryLabel} in ${Date.now() - timerStart}ms`);
|
|
52
55
|
}
|
|
@@ -57,4 +60,4 @@ const buildSass = (entry) => {
|
|
|
57
60
|
|
|
58
61
|
};
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
export default buildSass;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdc-build-wp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "Custom WordPress build process.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Robert Sefer",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "git://github.com/SeferDesign/sdc-build-wp.git"
|
|
13
13
|
},
|
|
14
|
+
"type": "module",
|
|
14
15
|
"scripts": {
|
|
15
16
|
"test": "echo \"Skipping tests.\""
|
|
16
17
|
},
|
|
@@ -20,21 +21,21 @@
|
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"autoprefixer": "^10.4.0",
|
|
22
23
|
"browser-sync": "^2.27.7",
|
|
23
|
-
"chalk": "^
|
|
24
|
+
"chalk": "^5.0.0",
|
|
24
25
|
"chokidar": "^3.5.2",
|
|
25
|
-
"esbuild": "^0.
|
|
26
|
-
"eslint": "^8.
|
|
26
|
+
"esbuild": "^0.14.8",
|
|
27
|
+
"eslint": "^8.5.0",
|
|
27
28
|
"fs-extra": "^10.0.0",
|
|
28
29
|
"glob": "^7.2.0",
|
|
29
|
-
"imagemin": "^
|
|
30
|
+
"imagemin": "^8.0.1",
|
|
30
31
|
"imagemin-jpegtran": "^7.0.0",
|
|
31
32
|
"imagemin-pngquant": "^9.0.2",
|
|
32
|
-
"imagemin-svgo": "^
|
|
33
|
+
"imagemin-svgo": "^10.0.1",
|
|
33
34
|
"minimist": "^1.2.5",
|
|
34
|
-
"postcss": "^8.
|
|
35
|
+
"postcss": "^8.4.5",
|
|
35
36
|
"postcss-scss": "^4.0.2",
|
|
36
|
-
"postcss-sort-media-queries": "^4.1
|
|
37
|
-
"sass": "^1.
|
|
38
|
-
"stylelint": "^14.0
|
|
37
|
+
"postcss-sort-media-queries": "^4.2.1",
|
|
38
|
+
"sass": "^1.45.1",
|
|
39
|
+
"stylelint": "^14.2.0"
|
|
39
40
|
}
|
|
40
41
|
}
|
package/stylelint.config.js
DELETED