sdc-build-wp 1.3.1 → 2.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/.stylelintrc CHANGED
@@ -1,15 +1,23 @@
1
1
  {
2
- "rules": {
3
- "indentation": "tab",
4
- "max-empty-lines": 1,
5
- "rule-empty-line-before": [
6
- "always",
7
- {
8
- "ignore": [
9
- "after-comment"
10
- ]
11
- }
12
- ],
13
- "color-no-invalid-hex": true
14
- }
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
+ }
15
23
  }
package/index.js CHANGED
@@ -17,6 +17,13 @@ let chokidarOpts = {
17
17
  ignoreInitial: true
18
18
  };
19
19
 
20
+ let sassGlobPath = project.package?.sdc?.sassGlobPath || project.path + '/_src/style/**/*.scss';
21
+ let sassGlob = glob.sync(sassGlobPath, {
22
+ ignore: [
23
+ project.path + '/_src/style/partials/_colors.scss'
24
+ ]
25
+ });
26
+
20
27
  function bustFunctionsCache() {
21
28
  bustCache(project.path + '/functions.php');
22
29
  }
@@ -62,17 +69,26 @@ for (const [name, files] of Object.entries(entries)) {
62
69
  }
63
70
 
64
71
  filesSass.forEach((file) => {
65
- buildSass(file);
72
+ buildSass(file, sassGlob);
66
73
  bustFunctionsCache();
67
74
  });
68
75
  if (argv.watch) {
69
- chokidar.watch(project.path + '/_src/style/**/*', chokidarOpts).on('all', (event, path) => {
76
+ chokidar.watch(sassGlob, chokidarOpts).on('all', (event, path) => {
70
77
  filesSass.forEach((file) => {
71
- buildSass(file);
78
+ buildSass(file, sassGlob);
72
79
  bustFunctionsCache();
73
80
  });
74
81
  });
75
82
  }
83
+ if (argv.watch) {
84
+ chokidar.watch(project.path + '/theme.json', chokidarOpts).on('all', (event, path) => {
85
+ filesSass.forEach((file) => {
86
+ buildSass(file, sassGlob);
87
+ bustFunctionsCache();
88
+ });
89
+ });
90
+ }
91
+
76
92
  frontrunImages()
77
93
  if (argv.watch) {
78
94
  chokidar.watch(project.path + '/_src/images/**/*', chokidarOpts).on('all', (event, path) => {
package/lib/logging.js CHANGED
@@ -11,7 +11,7 @@ function log(type, ...messages) {
11
11
  case 'success':
12
12
  console.log.call(
13
13
  console,
14
- chalk.green(''),
14
+ chalk.green(''),
15
15
  chalk.gray(getTime()),
16
16
  ...messages
17
17
  );
@@ -19,7 +19,7 @@ function log(type, ...messages) {
19
19
  case 'error':
20
20
  console.log.call(
21
21
  console,
22
- chalk.red('×'),
22
+ chalk.red(''),
23
23
  chalk.bgRed.gray(getTime()),
24
24
  ...messages
25
25
  );
@@ -27,7 +27,7 @@ function log(type, ...messages) {
27
27
  case 'warn':
28
28
  console.log.call(
29
29
  console,
30
- chalk.yellow('!'),
30
+ chalk.yellow(''),
31
31
  chalk.bgYellow.gray(getTime()),
32
32
  ...messages
33
33
  );
package/lib/scripts.js CHANGED
@@ -5,14 +5,12 @@ import esbuild from 'esbuild';
5
5
  import { ESLint } from 'eslint';
6
6
  import { readFile } from 'fs/promises';
7
7
 
8
- const eslintConfig = JSON.parse(await readFile(new URL('../.eslintrc', import.meta.url)))
9
-
10
8
  const buildJS = async (entry) => {
11
9
  let entryLabel = `/dist/scripts/${path.parse(entry).base.replace('.js', '.min.js')}`;
12
10
  let timerStart = Date.now();
13
11
  try {
14
12
  const eslint = new ESLint({
15
- baseConfig: eslintConfig,
13
+ baseConfig: JSON.parse(await readFile(new URL('../.eslintrc', import.meta.url))),
16
14
  fix: true
17
15
  });
18
16
  const lintresults = await eslint.lintFiles([entry]);
package/lib/style.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { fileURLToPath } from 'url';
3
4
  import project from '../lib/project.js';
4
5
  import log from './logging.js';
5
6
  import sass from 'sass';
@@ -7,19 +8,37 @@ import postcss from 'postcss';
7
8
  import autoprefixer from 'autoprefixer';
8
9
  import sortMQ from 'postcss-sort-media-queries';
9
10
  import stylelint from 'stylelint';
10
- import { fileURLToPath } from 'url';
11
- import { dirname } from 'path';
12
- const __filename = fileURLToPath(import.meta.url);
13
- const __dirname = dirname(__filename);
11
+ import { promises } from 'fs';
12
+
13
+ const buildColors = async () => {
14
+ try {
15
+ let theme = JSON.parse(await promises.readFile(project.path + '/theme.json'));
16
+ if (theme.settings?.color?.palette?.length > 0) {
17
+ let palette = theme.settings.color.palette;
18
+ let colorFileData = `// This file is automatically generated. Do not edit.\n`;
19
+ for (var color of palette) {
20
+ colorFileData += `$${color['slug']}: ${color['color']};\n`;
21
+ }
22
+ try {
23
+ await promises.writeFile(project.path + '/_src/style/partials/_colors.scss', colorFileData);
24
+ } catch {
25
+ log('error', `Failed to read write colors.scss - See above error.`);
26
+ }
27
+ }
28
+ } catch {
29
+ log('error', `Failed to read theme.json - See above error.`);
30
+ }
31
+ };
14
32
 
15
- const buildSass = (entry) => {
33
+ const buildSass = async (entry, entriesToLint) => {
34
+ await buildColors();
16
35
  let timerStart = Date.now();
17
36
  let outFile = project.path + '/dist/style/' + path.parse(entry).name + '.min.css';
18
37
  let entryLabel = outFile.replace(project.path, '');
19
38
  stylelint.lint({
20
- configFile: path.resolve(__dirname, '../.stylelintrc'),
39
+ configFile: path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../.stylelintrc'),
21
40
  formatter: 'string',
22
- files: [entry],
41
+ files: entriesToLint || [entry],
23
42
  customSyntax: 'postcss-scss',
24
43
  fix: true
25
44
  }).then((data) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-build-wp",
3
- "version": "1.3.1",
3
+ "version": "2.0.0",
4
4
  "description": "Custom WordPress build process.",
5
5
  "author": {
6
6
  "name": "Robert Sefer",
@@ -21,21 +21,21 @@
21
21
  "dependencies": {
22
22
  "autoprefixer": "^10.4.0",
23
23
  "browser-sync": "^2.27.7",
24
- "chalk": "^4.1.2",
24
+ "chalk": "^5.0.0",
25
25
  "chokidar": "^3.5.2",
26
- "esbuild": "^0.13.11",
27
- "eslint": "^8.1.0",
26
+ "esbuild": "^0.14.8",
27
+ "eslint": "^8.5.0",
28
28
  "fs-extra": "^10.0.0",
29
29
  "glob": "^7.2.0",
30
- "imagemin": "^7.0.1",
30
+ "imagemin": "^8.0.1",
31
31
  "imagemin-jpegtran": "^7.0.0",
32
32
  "imagemin-pngquant": "^9.0.2",
33
- "imagemin-svgo": "^9.0.0",
33
+ "imagemin-svgo": "^10.0.1",
34
34
  "minimist": "^1.2.5",
35
- "postcss": "^8.3.11",
35
+ "postcss": "^8.4.5",
36
36
  "postcss-scss": "^4.0.2",
37
- "postcss-sort-media-queries": "^4.1.0",
38
- "sass": "^1.43.4",
39
- "stylelint": "^14.0.1"
37
+ "postcss-sort-media-queries": "^4.2.1",
38
+ "sass": "^1.45.1",
39
+ "stylelint": "^14.2.0"
40
40
  }
41
41
  }