wp-blank-scripts 3.1.11 → 4.0.0-dev

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wp-blank-scripts",
3
- "version": "3.1.11",
3
+ "version": "4.0.0-dev",
4
4
  "description": "Personal Wordpress Scripts",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -50,6 +50,7 @@
50
50
  "eslint-plugin-jsx-a11y": "^6.7.1",
51
51
  "eslint-plugin-prettier": "^4.2.1",
52
52
  "eslint-plugin-react": "^7.32.2",
53
+ "file-loader": "^6.2.0",
53
54
  "get-port": "5.1.1",
54
55
  "glob": "^10.2.7",
55
56
  "html-webpack-plugin": "^5.5.3",
@@ -67,7 +68,7 @@
67
68
  "raw-loader": "^4.0.2",
68
69
  "react-refresh": "^0.14.0",
69
70
  "replace-in-file": "^7.0.1",
70
- "rimraf": "^5.0.5",
71
+ "rimraf": "^5.0.1",
71
72
  "rsync": "^0.6.1",
72
73
  "sass": "^1.63.4",
73
74
  "sass-loader": "^13.3.2",
@@ -91,4 +92,4 @@
91
92
  "eslint-plugin-jsx-a11y": "^6.1.2",
92
93
  "eslint-plugin-node": "^11.1.0"
93
94
  }
94
- }
95
+ }
@@ -67,6 +67,33 @@ function makeBaseConfig(options) {
67
67
  ignore: ['.DS_Store'],
68
68
  },
69
69
  },
70
+ // Blocks
71
+ // @TODO, copy the blocks into their own folders
72
+ {
73
+ from: path.join(sourceDir, 'blocks', '**', 'block.json'), // Include only block.json
74
+ to({ absoluteFilename }) {
75
+ // Extract the directory structure after 'blocks'
76
+ const relativePath = path.relative(
77
+ path.join(sourceDir, 'blocks'),
78
+ path.dirname(absoluteFilename)
79
+ );
80
+ // Join the themePath with the relative path to get the desired structure
81
+ return path.join(themePath, 'blocks', relativePath, 'block.json');
82
+ },
83
+ },
84
+ {
85
+ from: path.join(sourceDir, 'blocks', '**', 'render.php'), // Include only render.php
86
+ to({ absoluteFilename }) {
87
+ // Extract the directory structure after 'blocks'
88
+ const relativePath = path.relative(
89
+ path.join(sourceDir, 'blocks'),
90
+ path.dirname(absoluteFilename)
91
+ );
92
+ // Join the themePath with the relative path to get the desired structure
93
+ return path.join(themePath, 'blocks', relativePath, 'render.php');
94
+ },
95
+ },
96
+ // /End blocks
70
97
  {
71
98
  from: path.join(sourceDir, 'inc'),
72
99
  to: path.join(themePath, 'inc'),
@@ -116,7 +143,7 @@ function makeBaseConfig(options) {
116
143
  const includeBlocks = process.env.MASTER_BLOCKS;
117
144
  const masterBlocks = [
118
145
  {
119
- from: path.join(process.cwd(), '../../vivo/vivo-master-blocks/dist'),
146
+ from: path.join(process.cwd(), 'vendor/vivo-digital/vivo-master-blocks/dist'),
120
147
  to: path.join(themePath, 'inc', 'vivo-master-blocks'),
121
148
  },
122
149
  ];
@@ -141,10 +168,31 @@ function makeBaseConfig(options) {
141
168
  ];
142
169
 
143
170
  // Admin entries
144
- const adminScripts = glob.sync(path.join(sourcePath, 'assets', 'admin', 'js', '*.js'));
145
- const adminStyles = glob.sync(path.join(sourcePath, 'assets', 'admin', 'css', '*.scss'));
171
+ const adminScripts = glob.sync(path.join(sourcePath, 'assets', 'admin', '*.js'));
172
+
173
+ const adminStyles = glob.sync(path.join(sourcePath, 'assets', 'admin', '*.scss'));
174
+ const mainStyleVariables = path.join(sourcePath, 'assets', 'css', 'utils', 'variables.scss'); //* Not sure if this is needed.
175
+
176
+ const blockJsonFiles = [];
177
+
178
+ glob.sync(path.join(sourcePath, 'blocks', '***', '*.json')).forEach((filePath) => {
179
+ blockJsonFiles.push(filePath);
180
+ });
146
181
 
147
- const mainStyleVariables = path.join(sourcePath, 'assets', 'css', 'utils', 'variables.scss');
182
+ const blockJsonScripts = [];
183
+ const blockJsonStyles = [];
184
+
185
+ blockJsonFiles.forEach((file) => {
186
+ const content = JSON.parse(fs.readFileSync(file, 'utf-8'));
187
+ if (content.editorScript) {
188
+ const editorScript = `${path.dirname(file)}/${content.editorScript}`;
189
+ blockJsonScripts.push(editorScript);
190
+ }
191
+ if (content.editorStyle) {
192
+ const editorStyle = `${path.dirname(file)}/${content.editorStyle}`;
193
+ blockJsonStyles.push(editorStyle);
194
+ }
195
+ });
148
196
 
149
197
  let sassVariables = `$env: ${process.env.NODE_ENV};`;
150
198
 
@@ -169,8 +217,8 @@ function makeBaseConfig(options) {
169
217
  mode,
170
218
  target: 'web',
171
219
  entry: {
172
- adminScripts: [...fxFiles.admin.js, ...adminScripts],
173
- 'admin.style': [...fxFiles.admin.sass, ...adminStyles],
220
+ adminScripts: [...fxFiles.admin.js, ...blockJsonScripts, ...adminScripts],
221
+ 'admin.style': [...fxFiles.admin.sass, ...blockJsonStyles, ...adminStyles],
174
222
  },
175
223
  output: {
176
224
  path: buildPath,
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const fs = require('fs');
2
3
 
3
4
  const glob = require('glob');
4
5
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
@@ -6,52 +7,49 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6
7
  const logger = require('./logger');
7
8
 
8
9
  // Overridable build config utils
9
- const { copyFx } = require('./overridable');
10
-
11
- const getFxFiles = require('./utils/getFxFiles');
12
10
  const getSettings = require('./utils/projectSettings');
13
11
 
14
12
  function makeWpWebpackConfig() {
15
- const mode = process.env.NODE_ENV || 'development';
16
-
17
13
  const settings = getSettings();
18
14
 
19
15
  const sourceDir = 'src';
20
16
  const sourcePath = path.join(process.cwd(), sourceDir);
21
17
  const themeDir = path.join('wp-content', 'themes', settings.project);
22
18
 
23
- const fxFiles = getFxFiles(copyFx());
19
+ const blockJsonFiles = [];
24
20
 
25
- // Source entries
26
- const mainScripts = {};
27
- glob.sync(path.join(sourcePath, 'assets', 'js', '*.js')).forEach((filePath) => {
28
- const name = path.basename(filePath, '.js');
29
- mainScripts[name] = [filePath];
21
+ glob.sync(path.join(sourcePath, 'blocks', '***', '*.json')).forEach((filePath) => {
22
+ blockJsonFiles.push(filePath);
30
23
  });
31
24
 
32
- glob.sync(path.join(sourcePath, 'assets', 'js', 'gutenberg', '*.js')).forEach((filePath) => {
33
- const name = path.basename(filePath, '.js');
34
- mainScripts[`gutenberg/${name}`] = [filePath];
25
+ const blockJsonScripts = [];
26
+ const blockJsonStyles = [];
27
+
28
+ blockJsonFiles.forEach((file) => {
29
+ const content = JSON.parse(fs.readFileSync(file, 'utf-8'));
30
+ if (content.viewScript) {
31
+ const viewScript = `${path.dirname(file)}/${content.viewScript}`;
32
+ blockJsonScripts.push(viewScript);
33
+ }
34
+ if (content.style) {
35
+ const style = `${path.dirname(file)}/${content.style}`;
36
+ blockJsonStyles.push(style);
37
+ }
35
38
  });
36
39
 
37
- if (!mainScripts.main) {
38
- mainScripts.main = [];
39
- }
40
+ const entryScript = glob.sync(path.join(sourcePath, 'index.js'));
40
41
 
41
- const commonChunkFilePath = mainScripts.main[0];
42
- if (!commonChunkFilePath) {
43
- // We have to have a main.js file to put all common code in, so warn if it's not there
44
- logger.warn('No file was found for the common chunk, make sure you have a main.js file');
42
+ if (!entryScript) {
43
+ // We have to have a index.js file to put all common code in, so warn if it's not there
44
+ logger.warn('No file was found for the common chunk, make sure you have a index.js file');
45
45
  }
46
46
 
47
- mainScripts.main.push(...fxFiles.js);
48
-
49
- const mainStyles = glob.sync(path.join(sourcePath, 'assets', 'css', '*.scss'));
47
+ const mainStyles = glob.sync(path.join(sourcePath, 'style.scss'));
50
48
 
51
49
  return {
52
50
  entry: {
53
- ...mainScripts,
54
- style: [...fxFiles.sass, ...mainStyles],
51
+ main: [...blockJsonScripts, ...entryScript],
52
+ style: [...blockJsonStyles, ...mainStyles],
55
53
  },
56
54
  plugins: [
57
55
  new MiniCssExtractPlugin({