sdc-build-wp 3.0.8 → 3.2.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.
@@ -0,0 +1,26 @@
1
+ {
2
+ "plugins": [
3
+ "@stylistic/stylelint-plugin"
4
+ ],
5
+ "rules": {
6
+ "@stylistic/indentation": "tab",
7
+ "@stylistic/max-empty-lines": 1,
8
+ "rule-empty-line-before": [
9
+ "always",
10
+ {
11
+ "ignore": [ "after-comment" ]
12
+ }
13
+ ],
14
+ "@stylistic/block-opening-brace-space-before": "always-multi-line",
15
+ "@stylistic/block-opening-brace-newline-after": "always-multi-line",
16
+ "@stylistic/no-empty-first-line": true,
17
+ "@stylistic/selector-max-empty-lines": 0,
18
+ "color-function-notation": "modern",
19
+ "color-hex-length": "long",
20
+ "color-no-invalid-hex": true,
21
+ "color-named": "never",
22
+ "shorthand-property-no-redundant-values": true,
23
+ "@stylistic/number-leading-zero": "always",
24
+ "@stylistic/no-eol-whitespace": true
25
+ }
26
+ }
package/index.js CHANGED
@@ -4,10 +4,10 @@ import project from './lib/project.js';
4
4
  import parseArgs from 'minimist';
5
5
  const argv = parseArgs(process.argv.slice(2));
6
6
  import chokidar from 'chokidar';
7
- import glob from 'glob';
7
+ import { glob } from 'glob';
8
8
 
9
9
  import bustCache from './lib/bustCache.js';
10
- import buildSass from './lib/style.js';
10
+ import { buildSass, buildSassTheme } from './lib/style.js';
11
11
  import buildJS from './lib/scripts.js';
12
12
  import buildBlock from './lib/blocks.js';
13
13
  import buildImages from './lib/images.js';
@@ -97,6 +97,7 @@ if (argv.watch) {
97
97
  }
98
98
 
99
99
  function runSass() {
100
+ buildSassTheme();
100
101
  for (var block of filesSass) {
101
102
  buildSass(block.file, block.name, sassGlob);
102
103
  bustFunctionsCache();
@@ -13,6 +13,7 @@ const buildBrowserSync = () => {
13
13
  project.path + '/**/*.html',
14
14
  project.path + '/**/*.json',
15
15
  ],
16
+ watchEvents: project.package.sdc?.browsersync?.watchEvents || ['add', 'change', 'unlink', 'addDir', 'unlinkDir'],
16
17
  open: project.package.sdc?.open || false,
17
18
  https: (process.env.SSL_KEY_PATH && process.env.SSL_CRT_PATH ? {
18
19
  key: process.env.SSL_KEY_PATH,
package/lib/scripts.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from 'path';
2
2
  import project from '../lib/project.js';
3
3
  import log from './logging.js';
4
- import esbuild from 'esbuild';
4
+ import * as esbuild from 'esbuild';
5
5
  import { ESLint } from 'eslint';
6
6
  import { readFile } from 'fs/promises';
7
7
 
package/lib/style.js CHANGED
@@ -10,10 +10,42 @@ import sortMQ from 'postcss-sort-media-queries';
10
10
  import stylelint from 'stylelint';
11
11
  import { promises } from 'fs';
12
12
 
13
- const buildColors = async () => {
13
+ function camelToDash(camel) {
14
+ return camel.replace(/[A-Z]/g, m => '-' + m.toLowerCase());
15
+ }
16
+
17
+ const buildSassTheme = async () => {
14
18
  try {
15
19
  let theme = JSON.parse(await promises.readFile(project.path + '/theme.json'));
16
- let themeFileData = `// This file is automatically generated. Do not edit.\n`;
20
+ let themeFileData = `// This file is automatically generated from theme.json. Do not edit.\n`;
21
+ if (theme.settings?.custom) {
22
+ for (var customAttribute in theme.settings.custom) {
23
+ if (customAttribute == 'dirDist') {
24
+ themeFileData += `$themeDirDist: "${theme.settings.custom[customAttribute]}"; // --wp--custom--${camelToDash(customAttribute)}\n`;
25
+ } else if (['breakpoints-rem', 'breakpoint-mobile'].includes(customAttribute)) {
26
+ // handled later in file - see 'fontSizeBase'
27
+ } else {
28
+ themeFileData += `$${customAttribute}: "${theme.settings.custom[customAttribute]}"; // --wp--custom--${camelToDash(customAttribute)}\n`;
29
+ //
30
+ }
31
+ }
32
+ }
33
+ if (theme.styles?.typography) {
34
+ if (theme.styles.typography.fontSize) {
35
+ let fontSizeBase = theme.styles.typography.fontSize;
36
+ themeFileData += `$font-size-base: ${theme.styles.typography.fontSize}; // --wp--preset--font-size\n`;
37
+ if (theme.settings.custom && theme.settings.custom['breakpoints-rem']) {
38
+ for (var breakpoint in theme.settings.custom['breakpoints-rem']) {
39
+ themeFileData += `$screen-${breakpoint}: ${theme.settings.custom['breakpoints-rem'][breakpoint]}rem;\n`;
40
+ themeFileData += `$screen-${breakpoint}-px: ${theme.settings.custom['breakpoints-rem'][breakpoint] * fontSizeBase.replace('px', '')}px;\n`;
41
+ }
42
+ if (theme.settings.custom['breakpoint-mobile']) {
43
+ themeFileData += `$mobile-breakpoint: $screen-${theme.settings.custom['breakpoint-mobile']};\n`;
44
+ themeFileData += `$mobile-breakpoint-px: $screen-${theme.settings.custom['breakpoint-mobile']}-px;\n`;
45
+ }
46
+ }
47
+ }
48
+ }
17
49
  if (theme.settings?.typography?.fontFamilies) {
18
50
  for (var fontFamily of theme.settings.typography.fontFamilies) {
19
51
  themeFileData += `$${fontFamily['slug']}: ${fontFamily['fontFamily']}; // --wp--preset--font-family--${fontFamily['slug']}\n`;
@@ -31,16 +63,17 @@ const buildColors = async () => {
31
63
  }
32
64
  try {
33
65
  await promises.writeFile(project.path + '/_src/style/partials/_theme.scss', themeFileData);
34
- } catch {
66
+ } catch(error) {
67
+ console.error(error);
35
68
  log('error', `Failed to write auto-generated _theme.scss - See above error.`);
36
69
  }
37
- } catch {
70
+ } catch(error) {
71
+ console.error(error);
38
72
  log('error', `Failed to read theme.json - See above error.`);
39
73
  }
40
74
  };
41
75
 
42
76
  const buildSass = async (entry, name, entriesToLint) => {
43
- await buildColors();
44
77
  let timerStart = Date.now();
45
78
  let outFile = project.path + '/dist/' + name + '.min.css';
46
79
  if (name.startsWith('blocks/')) {
@@ -48,7 +81,7 @@ const buildSass = async (entry, name, entriesToLint) => {
48
81
  }
49
82
  let entryLabel = outFile.replace(project.path, '');
50
83
  stylelint.lint({
51
- configFile: path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../.stylelintrc'),
84
+ configFile: path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../.stylelintrc.json'),
52
85
  formatter: 'string',
53
86
  files: entriesToLint || [entry],
54
87
  customSyntax: 'postcss-scss',
@@ -99,4 +132,4 @@ const buildSass = async (entry, name, entriesToLint) => {
99
132
  });
100
133
  };
101
134
 
102
- export default buildSass;
135
+ export { buildSass, buildSassTheme };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-build-wp",
3
- "version": "3.0.8",
3
+ "version": "3.2.0",
4
4
  "description": "Custom WordPress build process.",
5
5
  "author": {
6
6
  "name": "Robert Sefer",
@@ -19,24 +19,25 @@
19
19
  "sdc-build-wp": "./index.js"
20
20
  },
21
21
  "dependencies": {
22
- "@wordpress/scripts": "^26.6.0",
23
- "autoprefixer": "^10.4.13",
24
- "browser-sync": "^2.27.11",
25
- "chalk": "^5.2.0",
26
- "chokidar": "^3.5.3",
27
- "esbuild": "^0.16.10",
28
- "eslint": "^8.30.0",
29
- "fs-extra": "^11.1.0",
30
- "glob": "^8.0.3",
22
+ "@stylistic/stylelint-plugin": "^2.1.1",
23
+ "@wordpress/scripts": "^27.5.0",
24
+ "autoprefixer": "^10.4.19",
25
+ "browser-sync": "^3.0.2",
26
+ "chalk": "^5.3.0",
27
+ "chokidar": "^3.6.0",
28
+ "esbuild": "^0.20.2",
29
+ "eslint": "^8.57.0",
30
+ "fs-extra": "^11.2.0",
31
+ "glob": "^10.3.12",
31
32
  "imagemin": "^8.0.1",
32
33
  "imagemin-jpegtran": "^7.0.0",
33
34
  "imagemin-pngquant": "^9.0.2",
34
35
  "imagemin-svgo": "^10.0.1",
35
- "minimist": "^1.2.7",
36
- "postcss": "^8.4.20",
37
- "postcss-scss": "^4.0.6",
38
- "postcss-sort-media-queries": "^4.3.0",
39
- "sass": "^1.63.4",
40
- "stylelint": "^14.16.0"
36
+ "minimist": "^1.2.8",
37
+ "postcss": "^8.4.38",
38
+ "postcss-scss": "^4.0.9",
39
+ "postcss-sort-media-queries": "^5.2.0",
40
+ "sass": "^1.72.0",
41
+ "stylelint": "^16.3.1"
41
42
  }
42
43
  }
package/.stylelintrc DELETED
@@ -1,23 +0,0 @@
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
- }