sdc-build-wp 4.3.1 → 4.3.3

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 CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import parseArgs from 'minimist';
3
3
  const argv = parseArgs(process.argv.slice(2));
4
+ import path from 'path';
5
+ import { fileURLToPath } from 'url';
4
6
  import { promises as fs } from 'fs';
5
7
  import { Tail } from 'tail';
6
8
  import project from './lib/project.js';
@@ -14,9 +16,10 @@ console.log(`
14
16
  Usage: sdc-build-wp [options] [arguments]
15
17
 
16
18
  Options:
17
- -h, --help Show help message and exit
18
- -w, --watch Build and watch
19
- -b, --build BUILDS Build with specific components
19
+ -h, --help Show help message and exit
20
+ -v, --version Version
21
+ -w, --watch Build and watch
22
+ -b, --build BUILDS Build with specific components
20
23
 
21
24
  Components:
22
25
 
@@ -30,6 +33,9 @@ sdc-build-wp --watch
30
33
  sdc-build-wp --watch --builds=style,scripts
31
34
  `);
32
35
 
36
+ process.exit(0);
37
+ } else if (argv.version || argv.v) {
38
+ console.log(JSON.parse(await fs.readFile(path.join(path.dirname(fileURLToPath(import.meta.url)), 'package.json'))).version);
33
39
  process.exit(0);
34
40
  }
35
41
 
@@ -44,7 +50,7 @@ project.builds = argv.builds ? argv.builds.split(',') : Object.keys(project.comp
44
50
  }
45
51
  log('info', `Finished initial build in ${Math.round((Date.now() - initialBuildTimerStart) / 1000)} seconds`);
46
52
 
47
- if (argv.watch || argv.w) {
53
+ if (argv.watch) {
48
54
  for (let build of project.builds) {
49
55
  await project.components[build].watch();
50
56
  }
@@ -1,6 +1,5 @@
1
1
  import BaseComponent from './base.js';
2
- import fs from 'fs';
3
- import { promises } from 'fs';
2
+ import { promises as fs } from 'fs';
4
3
  import { fileURLToPath } from 'url';
5
4
  import * as sass from 'sass';
6
5
  import postcss from 'postcss';
@@ -26,7 +25,7 @@ export default class StyleComponent extends BaseComponent {
26
25
 
27
26
  async buildTheme() {
28
27
  try {
29
- let theme = JSON.parse(await promises.readFile(this.project.path + '/theme.json'));
28
+ let theme = JSON.parse(await fs.readFile(this.project.path + '/theme.json'));
30
29
  let themeFileData = `// This file is automatically generated from theme.json. Do not edit.\n`;
31
30
  if (theme.settings?.custom) {
32
31
  for (var customAttribute in theme.settings.custom) {
@@ -75,7 +74,7 @@ export default class StyleComponent extends BaseComponent {
75
74
  }
76
75
  }
77
76
  try {
78
- await promises.writeFile(this.project.path + '/_src/style/partials/_theme.scss', themeFileData);
77
+ await fs.writeFile(this.project.path + '/_src/style/partials/_theme.scss', themeFileData);
79
78
  } catch(error) {
80
79
  console.error(error);
81
80
  this.log('error', `Failed to write auto-generated _theme.scss - See above error.`);
@@ -100,57 +99,38 @@ export default class StyleComponent extends BaseComponent {
100
99
  this.start();
101
100
 
102
101
  try {
103
- await promises.access(`${this.project.path}/dist/style`);
102
+ await fs.access(`${this.project.path}/dist/style`);
104
103
  } catch(error) {
105
- await promises.mkdir(`${this.project.path}/dist/style`, { recursive: true });
104
+ await fs.mkdir(`${this.project.path}/dist/style`, { recursive: true });
106
105
  }
107
-
108
- stylelint.lint({
109
- configFile: this.path.resolve(this.path.dirname(fileURLToPath(import.meta.url)), '../../.stylelintrc.json'),
110
- formatter: 'string',
111
- files: options.entriesToLint || [entry],
112
- customSyntax: 'postcss-scss',
113
- fix: true
114
- }).then((data) => {
115
- if (data.errored) {
116
- console.error(data.report);
117
- this.log('error', `Failed linting ${entry.replace(this.project.path + '/_src/style/', '')} - See above linting error.`);
118
- return false;
119
- }
120
- try {
121
- const result = sass.compile(entry, {
122
- style: 'compressed'
123
- });
124
- fs.writeFile(outFile, result.css, function(err) {
125
- if (err) {
126
- console.error(err);
127
- this.log('error', `Failed compiling ${entryLabel} - See above file writing error.`);
128
- return false;
129
- } else {
130
- postcss([
131
- autoprefixer(),
132
- sortMQ()
133
- ]).process(result.css, { from: undefined }).then(resultPost => {
134
- fs.writeFile(outFile, resultPost.css, function(err) {
135
- if (err) {
136
- console.log(err);
137
- this.log('error', `Failed saving ${entryLabel} - See above postcss error.`);
138
- return false;
139
- } else {
140
- thisClass.end({
141
- itemLabel: entryLabel
142
- });
143
- }
144
- });
145
- });
146
- }
147
- });
148
- } catch(error) {
149
- console.error(error);
150
- log('error', `Failed building ${entryLabel} - See above sass error.`);
151
- return false;
106
+ try {
107
+ const stylelinted = await stylelint.lint({
108
+ configFile: this.path.resolve(this.path.dirname(fileURLToPath(import.meta.url)), '../../.stylelintrc.json'),
109
+ formatter: 'string',
110
+ files: options.entriesToLint || [entry],
111
+ customSyntax: 'postcss-scss',
112
+ fix: true
113
+ });
114
+ if (stylelinted.errored) {
115
+ console.error(stylelinted.report);
116
+ throw Error('Linting error');
152
117
  }
153
- });
118
+ const compileResult = await sass.compileAsync(entry, {
119
+ style: 'compressed'
120
+ });
121
+ const postcssResult = await postcss([
122
+ autoprefixer(),
123
+ sortMQ()
124
+ ]).process(compileResult.css, { from: undefined });
125
+ await fs.writeFile(outFile, postcssResult.css);
126
+ thisClass.end({
127
+ itemLabel: entryLabel
128
+ });
129
+ } catch(error) {
130
+ console.error(error);
131
+ this.log('error', `Failed building ${entryLabel} - See above error.`);
132
+ return false;
133
+ }
154
134
  }
155
135
 
156
136
  async process(entry, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-build-wp",
3
- "version": "4.3.1",
3
+ "version": "4.3.3",
4
4
  "description": "Custom WordPress build process.",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@stylistic/stylelint-plugin": "^3.1.2",
26
- "@wordpress/scripts": "^30.11.0",
26
+ "@wordpress/scripts": "^30.12.0",
27
27
  "autoprefixer": "^10.4.20",
28
28
  "browser-sync": "^3.0.3",
29
29
  "chalk": "^5.4.1",
@@ -39,8 +39,8 @@
39
39
  "postcss": "^8.5.3",
40
40
  "postcss-scss": "^4.0.9",
41
41
  "postcss-sort-media-queries": "^5.2.0",
42
- "sass": "^1.85.0",
43
- "stylelint": "^16.14.1",
42
+ "sass": "^1.85.1",
43
+ "stylelint": "^16.15.0",
44
44
  "tail": "^2.2.6"
45
45
  }
46
46
  }