sdc-build-wp 4.6.2 → 4.7.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/README.md CHANGED
@@ -15,3 +15,5 @@ Develop locally with the following command from within the test project director
15
15
  ```
16
16
  node ~/sites/sdc/sdc-build-wp/index.js --watch
17
17
  ```
18
+
19
+ While watch is running, pressing `r` restarts the process. Pressing `q` quits the process.
package/eslint.config.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import { defineConfig } from 'eslint/config';
2
+ import stylistic from '@stylistic/eslint-plugin';
2
3
 
3
4
  export default defineConfig([
4
5
  {
6
+ plugins: {
7
+ '@stylistic': stylistic
8
+ },
5
9
  languageOptions: {
6
10
  parserOptions: {
7
11
  ecmaVersion: 'latest',
@@ -19,7 +23,8 @@ export default defineConfig([
19
23
  {
20
24
  max: 1
21
25
  }
22
- ]
26
+ ],
27
+ '@stylistic/quotes': [1, 'single']
23
28
  }
24
29
  }
25
30
  ]);
package/index.js CHANGED
@@ -12,7 +12,7 @@ project.components = Object.fromEntries(Object.entries(LibComponents).map(([name
12
12
  const argv = parseArgs(process.argv.slice(2));
13
13
 
14
14
  if (argv.help || argv.h) {
15
- console.log(`
15
+ console.log(`
16
16
  Usage: sdc-build-wp [options] [arguments]
17
17
 
18
18
  Options:
@@ -33,16 +33,56 @@ sdc-build-wp --watch
33
33
  sdc-build-wp --watch --builds=style,scripts
34
34
  `);
35
35
 
36
- process.exit(0);
36
+ process.exit(0);
37
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);
39
- process.exit(0);
38
+ console.log(JSON.parse(await fs.readFile(path.join(path.dirname(fileURLToPath(import.meta.url)), 'package.json'))).version);
39
+ process.exit(0);
40
40
  }
41
41
 
42
42
  project.builds = argv.builds ? (Array.isArray(argv.builds) ? argv.builds : argv.builds.split(',')) : Object.keys(project.components);
43
43
 
44
- (async() => {
44
+ (async () => {
45
+ keypressListen();
46
+ await runBuild();
47
+ })();
48
+
49
+ process.on('SIGINT', function () {
50
+ console.log(`\r`);
51
+ if (process.stdin.isTTY) {
52
+ process.stdin.setRawMode(false);
53
+ process.stdin.pause();
54
+ }
55
+ stopActiveComponents()
56
+ log('info', `Exiting sdc-build-wp`);
57
+ process.exit(0);
58
+ });
59
+
60
+ function keypressListen() {
61
+ if (!process.stdin.isTTY) { return; }
62
+
63
+ process.stdin.setRawMode(true);
64
+ process.stdin.resume();
65
+ process.stdin.setEncoding('utf8');
45
66
 
67
+ process.stdin.on('data', (key) => {
68
+ switch (key) {
69
+ case '\u0003': // Ctrl+C
70
+ case 'q':
71
+ process.emit('SIGINT');
72
+ return;
73
+ case 'r':
74
+ log('info', 'Restart requested...');
75
+ stopActiveComponents()
76
+ setTimeout(() => {
77
+ process.stdout.write('\x1B[2J\x1B[0f'); // Clear screen
78
+ runBuild();
79
+ }, 100);
80
+ break;
81
+ }
82
+ });
83
+ }
84
+
85
+ async function runBuild() {
46
86
  if (argv.watch && project.builds.includes('server')) {
47
87
  project.builds.splice(project.builds.indexOf('server'), 1);
48
88
  project.builds.unshift('server');
@@ -62,18 +102,15 @@ project.builds = argv.builds ? (Array.isArray(argv.builds) ? argv.builds : argv.
62
102
  project.builds.splice(project.builds.indexOf('server'), 1);
63
103
  project.builds.push('server');
64
104
  log('info', `Started watching [${project.builds.join(', ')}]`);
105
+ log('info', `[r] to restart, [q] to quit`);
65
106
  for (let build of project.builds) {
66
107
  await project.components[build].watch();
67
108
  }
68
109
  }
110
+ }
69
111
 
70
- })();
71
-
72
- process.on('SIGINT', function() {
73
- console.log(`\r`);
112
+ function stopActiveComponents() {
74
113
  if (project.components.server?.server) {
75
114
  project.components.server.server.exit();
76
115
  }
77
- log('info', `Exiting sdc-build-wp`);
78
- process.exit(0);
79
- });
116
+ }
@@ -1,3 +1,4 @@
1
+ import { fileURLToPath } from 'url';
1
2
  import BaseComponent from './base.js';
2
3
  import { stat } from 'fs/promises';
3
4
  import { exec } from 'child_process';
@@ -55,12 +56,13 @@ export default class BlocksComponent extends BaseComponent {
55
56
  `build`,
56
57
  `--source-path=.${entry.replace(this.project.path, '')}/src`,
57
58
  `--output-path=.${entry.replace(this.project.path, '')}/build`,
58
- `--webpack-copy-php`
59
+ `--webpack-copy-php`,
60
+ `--config=${this.path.resolve(this.path.dirname(fileURLToPath(import.meta.url)), '../../webpack.config.js')}`,
59
61
  ];
60
62
  let execPromise = promisify(exec);
61
63
  const { stdout, stderr } = await execPromise(cmds.join(' '));
62
64
  } catch (error) {
63
- console.log(error.stdout);
65
+ console.log(error.stdout || error);
64
66
  this.log('error', `Failed building ${entryLabel} block - See above error.`);
65
67
  return false;
66
68
  }
@@ -87,6 +89,9 @@ export default class BlocksComponent extends BaseComponent {
87
89
  ...this.project.chokidarOpts
88
90
  }).on('all', (event, path) => {
89
91
  if (!['unlink', 'unlinkDir'].includes(event)) {
92
+ if (path.endsWith('.js')) {
93
+ this.project.components.scripts.lint(path);
94
+ }
90
95
  this.process(block);
91
96
  }
92
97
  });
@@ -28,16 +28,10 @@ export default class ScriptsComponent extends BaseComponent {
28
28
  this.start();
29
29
 
30
30
  try {
31
- const eslint = new ESLint({
32
- fix: true,
33
- overrideConfigFile: true,
34
- overrideConfig: eslintConfig.default[0]
35
- });
36
- const lintresults = await eslint.lintFiles(options.entriesToLint || [entry]);
37
- await ESLint.outputFixes(lintresults);
38
- const formatter = await eslint.loadFormatter('stylish');
39
- const formatterOutput = formatter.format(lintresults);
40
- if (formatterOutput) { console.log(formatterOutput.replace(`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.scripts}/`, '')); }
31
+ let thisLint = await this.lint(entry, options);
32
+ if (thisLint instanceof Error) {
33
+ throw thisLint;
34
+ }
41
35
  } catch (error) {
42
36
  console.log(error);
43
37
  this.log('error', `Failed linting ${entry.replace(`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.scripts}/`, '')} - See above error.`);
@@ -82,4 +76,22 @@ export default class ScriptsComponent extends BaseComponent {
82
76
  });
83
77
  }
84
78
 
79
+ async lint(entry, options) {
80
+ try {
81
+ const eslint = new ESLint({
82
+ fix: true,
83
+ overrideConfigFile: true,
84
+ overrideConfig: eslintConfig.default[0]
85
+ });
86
+ const lintresults = await eslint.lintFiles(options?.entriesToLint || [entry]);
87
+ await ESLint.outputFixes(lintresults);
88
+ const formatter = await eslint.loadFormatter('stylish');
89
+ const formatterOutput = formatter.format(lintresults);
90
+ if (formatterOutput) { console.log(formatterOutput.replace(`${this.project.path}/${this.project.paths.src.src}/${this.project.paths.src.scripts}/`, '')); }
91
+ return true;
92
+ } catch (error) {
93
+ return error;
94
+ }
95
+ }
96
+
85
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-build-wp",
3
- "version": "4.6.2",
3
+ "version": "4.7.0",
4
4
  "description": "Custom WordPress build process.",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -22,6 +22,7 @@
22
22
  "sdc-build-wp": "./index.js"
23
23
  },
24
24
  "dependencies": {
25
+ "@stylistic/eslint-plugin": "^5.2.2",
25
26
  "@stylistic/stylelint-plugin": "^4.0.0",
26
27
  "@typescript-eslint/eslint-plugin": "^8.38.0",
27
28
  "@typescript-eslint/parser": "^8.38.0",
@@ -0,0 +1,9 @@
1
+ import defaultConfig from '@wordpress/scripts/config/webpack.config.js';
2
+
3
+ export default {
4
+ ...defaultConfig,
5
+ mode: 'production',
6
+ cache: {
7
+ type: 'memory'
8
+ }
9
+ };