sdc-build-wp 3.2.4 → 3.4.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/index.js CHANGED
@@ -4,8 +4,11 @@ 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, globSync } from 'glob';
8
+ import { existsSync } from 'node:fs';
9
+ import { Tail } from 'tail';
8
10
 
11
+ import log from './lib/logging.js';
9
12
  import bustCache from './lib/bustCache.js';
10
13
  import { buildSass, buildSassTheme } from './lib/style.js';
11
14
  import buildJS from './lib/scripts.js';
@@ -22,32 +25,56 @@ let chokidarOpts = {
22
25
  };
23
26
 
24
27
  let sassGlobPath = project.package?.sdc?.sassGlobPath || project.path + '{/_src/style,/blocks}/**/*.scss';
25
- let sassGlob = glob.sync(sassGlobPath, {
28
+ let sassGlob = globSync(sassGlobPath, {
26
29
  ignore: [
27
30
  project.path + '/_src/style/partials/_theme.scss'
28
31
  ]
29
32
  });
30
33
  let jsGlobPath = project.package?.sdc?.jsGlobPath || project.path + '/_src/scripts/**/*.js';
31
- let jsGlob = glob.sync(jsGlobPath, {
34
+ let jsGlob = globSync(jsGlobPath, {
32
35
  ignore: []
33
36
  });
34
37
  let blockGlobPath = project.package?.sdc?.blockGlobPath || project.path + '/blocks/*';
35
- let blockGlob = glob.sync(blockGlobPath);
38
+ let blockGlob = globSync(blockGlobPath);
36
39
 
37
40
  function bustFunctionsCache() {
38
41
  bustCache(project.path + '/functions.php');
39
42
  }
40
43
 
41
44
  function frontrunImages() {
42
- [project.path + '/_src/images/', project.path + '/_src/images/**/*/'].forEach((block) => {
43
- glob(block, {}, function(err, directory) {
44
- directory.forEach((dir) => {
45
- buildImages(dir);
46
- });
45
+ [
46
+ project.path + '/_src/images/',
47
+ project.path + '/_src/images/**/*/'
48
+ ].forEach((block) => {
49
+ const imageDirectories = globSync(block);
50
+ imageDirectories.forEach((dir) => {
51
+ buildImages(dir);
47
52
  });
48
53
  });
49
54
  }
50
55
 
56
+ function runBlocks() {
57
+ for (var block of blockGlob) {
58
+ buildBlock(block);
59
+ }
60
+ bustFunctionsCache();
61
+ }
62
+
63
+ function runSass() {
64
+ buildSassTheme();
65
+ for (var block of filesSass) {
66
+ buildSass(block.file, block.name, sassGlob);
67
+ bustFunctionsCache();
68
+ }
69
+ }
70
+
71
+ function runJS() {
72
+ for (var block of filesJS) {
73
+ buildJS(block.file, block.name, jsGlob);
74
+ bustFunctionsCache();
75
+ }
76
+ }
77
+
51
78
  let entries = {};
52
79
  for (const [name, files] of Object.entries(project.package.sdc.entries)) {
53
80
  entries[name] = [];
@@ -55,7 +82,7 @@ for (const [name, files] of Object.entries(project.package.sdc.entries)) {
55
82
  entries[name].push(project.path + file);
56
83
  });
57
84
  }
58
- let sassBlocksGlob = glob.sync(project.path + '/blocks/*/*.scss');
85
+ let sassBlocksGlob = globSync(project.path + '/blocks/*/*.scss');
59
86
  for (var filename of sassBlocksGlob) {
60
87
  entries[`blocks/${path.basename(path.dirname(filename))}/style`] = [ filename ];
61
88
  }
@@ -82,64 +109,36 @@ for (const [name, files] of Object.entries(entries)) {
82
109
  });
83
110
  }
84
111
 
85
- function runBlocks() {
86
- for (var block of blockGlob) {
87
- buildBlock(block);
88
- }
89
- bustFunctionsCache();
90
- }
91
-
92
112
  runBlocks();
113
+ runSass();
114
+ runJS();
115
+ frontrunImages()
116
+ buildFonts(project.path + '/_src/fonts');
117
+
93
118
  if (argv.watch) {
119
+ buildBrowserSync();
94
120
  chokidar.watch(blockGlob, chokidarOpts).on('all', (event, path) => {
95
121
  runBlocks();
96
122
  });
97
- }
98
-
99
- function runSass() {
100
- buildSassTheme();
101
- for (var block of filesSass) {
102
- buildSass(block.file, block.name, sassGlob);
103
- bustFunctionsCache();
104
- }
105
- }
106
-
107
- runSass();
108
- if (argv.watch) {
109
123
  chokidar.watch(sassGlob, chokidarOpts).on('all', (event, path) => {
110
124
  runSass();
111
125
  });
112
- }
113
-
114
- function runJS() {
115
- for (var block of filesJS) {
116
- buildJS(block.file, block.name, jsGlob);
117
- bustFunctionsCache();
118
- }
119
- }
120
-
121
- runJS();
122
- if (argv.watch) {
123
- chokidar.watch(jsGlob, chokidarOpts).on('all', (event, path) => {
124
- runJS();
125
- });
126
- }
127
-
128
- if (argv.watch) {
129
126
  chokidar.watch(project.path + '/theme.json', chokidarOpts).on('all', (event, path) => {
130
127
  runSass();
131
128
  });
132
- }
133
-
134
- frontrunImages()
135
- if (argv.watch) {
129
+ chokidar.watch(jsGlob, chokidarOpts).on('all', (event, path) => {
130
+ runJS();
131
+ });
136
132
  chokidar.watch(project.path + '/_src/images/**/*', chokidarOpts).on('all', (event, path) => {
137
133
  frontrunImages();
138
134
  });
139
- }
140
-
141
- buildFonts(project.path + '/_src/fonts');
142
-
143
- if (argv.watch) {
144
- buildBrowserSync();
135
+ let errorLogPath = process.env.ERROR_LOG_PATH || project.package.sdc?.error_log_path || '../../../../../logs/php/error.log';
136
+ if (existsSync(errorLogPath)) {
137
+ let errorLogTail = new Tail(errorLogPath);
138
+ errorLogTail.on('line', function(data) {
139
+ log('php', data);
140
+ });
141
+ } else {
142
+ log('info', `Cannot find error log @ ${errorLogPath}. Skipping watching php error logs`);
143
+ }
145
144
  }
@@ -27,6 +27,14 @@ const buildBrowserSync = () => {
27
27
  bottom: '0',
28
28
  borderRadius: '5px 0px 0px'
29
29
  }
30
+ },
31
+ snippetOptions: {
32
+ rule: {
33
+ match: /<\/body>/i,
34
+ fn: function (snippet, match) {
35
+ return snippet + match;
36
+ }
37
+ }
30
38
  }
31
39
  });
32
40
  };
package/lib/images.js CHANGED
@@ -7,15 +7,16 @@ import imageminSvgo from 'imagemin-svgo';
7
7
 
8
8
  const buildImages = async (images) => {
9
9
  let timerStart = Date.now();
10
- const files = await imagemin([images + '*'], {
11
- destination: project.path + '/dist/images/' + (images.replace(project.path + '/_src/images/', '')),
10
+ let dest = images.replace('_src/images', 'dist/images');
11
+ const files = await imagemin([images + '/*'], {
12
+ destination: dest,
12
13
  plugins: [
13
14
  imageminJpegtran(),
14
15
  imageminPngquant(),
15
16
  imageminSvgo()
16
17
  ]
17
18
  });
18
- log('success', `Built /dist/images/${images.replace(project.path + '/_src/images/', '')} in ${Date.now() - timerStart}ms`);
19
+ log('success', `Built ${dest.replace(project.path, '')} (${files.length} image${files.length == 1 ? '' : 's'}) in ${Date.now() - timerStart}ms`);
19
20
  };
20
21
 
21
22
  export default buildImages;
package/lib/logging.js CHANGED
@@ -32,6 +32,13 @@ function log(type, ...messages) {
32
32
  ...messages
33
33
  );
34
34
  break;
35
+ case 'php':
36
+ console.log.call(
37
+ console,
38
+ chalk.blue('ℹ'),
39
+ ...messages
40
+ );
41
+ break;
35
42
  case 'info':
36
43
  default:
37
44
  console.log.call(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-build-wp",
3
- "version": "3.2.4",
3
+ "version": "3.4.0",
4
4
  "description": "Custom WordPress build process.",
5
5
  "engines": {
6
6
  "node": "^20"
@@ -41,6 +41,7 @@
41
41
  "postcss-scss": "^4.0.9",
42
42
  "postcss-sort-media-queries": "^5.2.0",
43
43
  "sass": "^1.75.0",
44
- "stylelint": "^16.4.0"
44
+ "stylelint": "^16.4.0",
45
+ "tail": "^2.2.6"
45
46
  }
46
47
  }