wp-blank-scripts 3.1.0-beta.2 → 3.1.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
@@ -2,7 +2,26 @@
2
2
 
3
3
  CLI and build tool for Wordpress projects.
4
4
 
5
- ### Project Structure
5
+ ## Upgrade to v3
6
+
7
+ Surprisingly there are no breaking changes.
8
+
9
+ **v3 Warnings**
10
+
11
+ #### Sass division outside of calc() deprecated
12
+
13
+ Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.
14
+ Recommendation: math.div(-$grid-gutter, 2) or calc(-1 * $grid-gutter / 2). More info and automated migrator: https://sass-lang.com/d/slash-div
15
+
16
+ Fix:
17
+
18
+ ```
19
+ npm install -g sass-migrator
20
+ sass-migrator division **/*.scss
21
+
22
+ ```
23
+
24
+ ## Project Structure
6
25
 
7
26
  ```
8
27
  /
@@ -368,3 +387,6 @@ exports.checkProjectDependencies = () => {
368
387
  }
369
388
  };
370
389
  ```
390
+
391
+ ## Node Version
392
+ Currently supports `18.8.0` for all projects running `wp-blank-scripts@3.0.0`
@@ -1,7 +1,7 @@
1
1
  const chalk = require('chalk');
2
2
  const inquirer = require('inquirer');
3
3
 
4
- const addSettings = require('../lib/addSettings');
4
+ const addDeployConfig = require('../lib/addDeployConfig');
5
5
 
6
6
  const logger = require('../logger');
7
7
  const getCliOptions = require('../utils/getCliOptions');
@@ -64,23 +64,23 @@ module.exports = async () => {
64
64
  {
65
65
  name: 'urlProduction',
66
66
  message: 'What is the production URL?',
67
- when: answers => answers.environment === 'production',
67
+ when: (answers) => answers.environment === 'production',
68
68
  },
69
69
  {
70
70
  name: 'hostProduction',
71
71
  message: 'What is the production server host?',
72
- when: answers => answers.environment === 'production',
72
+ when: (answers) => answers.environment === 'production',
73
73
  },
74
74
  {
75
75
  name: 'userProduction',
76
76
  message: 'What is the production server user?',
77
- when: answers => answers.environment === 'production',
77
+ when: (answers) => answers.environment === 'production',
78
78
  },
79
79
  {
80
80
  name: 'destinationProduction',
81
81
  message: 'What is the production path?',
82
- when: answers => answers.environment === 'production',
83
- default: answers => {
82
+ when: (answers) => answers.environment === 'production',
83
+ default: (answers) => {
84
84
  const user = answers.userProduction;
85
85
  return `/home/${user}/public_html`;
86
86
  },
@@ -88,40 +88,40 @@ module.exports = async () => {
88
88
  {
89
89
  name: 'dbNameProduction',
90
90
  message: 'Production database name?',
91
- when: answers => answers.environment === 'production',
91
+ when: (answers) => answers.environment === 'production',
92
92
  },
93
93
  {
94
94
  name: 'dbUserNameProduction',
95
95
  message: 'Production database username?',
96
- when: answers => answers.environment === 'production',
96
+ when: (answers) => answers.environment === 'production',
97
97
  },
98
98
  {
99
99
  name: 'dbPasswordProduction',
100
100
  message: 'Production database password?',
101
- when: answers => answers.environment === 'production',
101
+ when: (answers) => answers.environment === 'production',
102
102
  },
103
103
  {
104
104
  name: 'urlStaging',
105
105
  message: 'What is the staging URL?',
106
- when: answers => answers.environment === 'staging',
106
+ when: (answers) => answers.environment === 'staging',
107
107
  },
108
108
  {
109
109
  name: 'hostStaging',
110
110
  message: 'What is the staging server host?',
111
- when: answers => answers.environment === 'staging',
111
+ when: (answers) => answers.environment === 'staging',
112
112
  default: 'staging.vivo.digital',
113
113
  },
114
114
  {
115
115
  name: 'userStaging',
116
116
  message: 'What is the staging server user?',
117
- when: answers => answers.environment === 'staging',
117
+ when: (answers) => answers.environment === 'staging',
118
118
  default: 'stagingvivo',
119
119
  },
120
120
  {
121
121
  name: 'destinationStaging',
122
122
  message: 'What is the staging path?',
123
- when: answers => answers.environment === 'staging',
124
- default: answers => {
123
+ when: (answers) => answers.environment === 'staging',
124
+ default: (answers) => {
125
125
  const user = answers.userStaging;
126
126
  let url = answers.urlStaging;
127
127
  url = url && url.replace('https://', '');
@@ -132,17 +132,17 @@ module.exports = async () => {
132
132
  {
133
133
  name: 'dbNameStaging',
134
134
  message: 'Staging database name?',
135
- when: answers => answers.environment === 'staging',
135
+ when: (answers) => answers.environment === 'staging',
136
136
  },
137
137
  {
138
138
  name: 'dbUserNameStaging',
139
139
  message: 'Staging database username?',
140
- when: answers => answers.environment === 'staging',
140
+ when: (answers) => answers.environment === 'staging',
141
141
  },
142
142
  {
143
143
  name: 'dbPasswordStaging',
144
144
  message: 'Staging database password?',
145
- when: answers => answers.environment === 'staging',
145
+ when: (answers) => answers.environment === 'staging',
146
146
  },
147
147
  ]);
148
148
 
@@ -150,7 +150,7 @@ module.exports = async () => {
150
150
  const confirmed = options.didPrompt ? await confirmOptions(options) : true;
151
151
 
152
152
  if (confirmed) {
153
- await addSettings(options);
153
+ await addDeployConfig(options);
154
154
  logger.success(`${options.environment} Settings updated!`);
155
155
  }
156
156
  } catch (err) {
@@ -26,6 +26,7 @@ module.exports = {
26
26
  'react/forbid-prop-types': 0,
27
27
  'react/require-default-props': 0,
28
28
  'react/sort-comp': 0,
29
+ 'react/function-component-definition': 0,
29
30
  'prefer-destructuring': 0,
30
31
  'no-nested-ternary': 0,
31
32
  'no-continue': 0,
@@ -8,7 +8,7 @@ module.exports = {
8
8
  {
9
9
  files: '*.php',
10
10
  options: {
11
- phpVersion: '7.2',
11
+ phpVersion: '7.4',
12
12
  tabWidth: 4,
13
13
  braceStyle: '1tbs',
14
14
  },
package/index.js CHANGED
@@ -10,11 +10,9 @@ const deploy = require('./cli/deploy');
10
10
  const importSQL = require('./cli/import');
11
11
  const exportSQL = require('./cli/export');
12
12
  const pullSQL = require('./cli/pull');
13
- const upgrade = require('./cli/upgrade');
14
- const settings = require('./cli/settings'); //@TODO rename... addDeployConfig
13
+ const addDeployConfig = require('./cli/config');
15
14
 
16
15
  const exitWithError = require('./utils/exitWithError');
17
- const logger = require('./logger');
18
16
 
19
17
  const _ = () => {};
20
18
 
@@ -23,7 +21,7 @@ yargs
23
21
  .command(
24
22
  'build',
25
23
  'Build',
26
- yargs =>
24
+ (yargs) =>
27
25
  yargs.option('environment', {
28
26
  describe: 'The environment to build for.',
29
27
  }),
@@ -34,7 +32,7 @@ yargs
34
32
  .command(
35
33
  'setup',
36
34
  'Setup Project',
37
- yargs =>
35
+ (yargs) =>
38
36
  yargs
39
37
  .option('projectLocation', {
40
38
  describe: 'Where is the project located?',
@@ -59,7 +57,7 @@ yargs
59
57
  .command(
60
58
  'deploy',
61
59
  'Deploy',
62
- yargs =>
60
+ (yargs) =>
63
61
  yargs
64
62
  .option('environment', {
65
63
  describe: 'The environment to deploy to.',
@@ -81,7 +79,7 @@ yargs
81
79
  .command(
82
80
  'import',
83
81
  'Import SQL',
84
- yargs =>
82
+ (yargs) =>
85
83
  yargs
86
84
  .option('file', {
87
85
  describe: 'The path to the file to import.',
@@ -103,7 +101,7 @@ yargs
103
101
  .command(
104
102
  'export',
105
103
  'Export SQL',
106
- yargs =>
104
+ (yargs) =>
107
105
  yargs.option('environment', {
108
106
  describe: 'The environment you are exporting for.',
109
107
  }),
@@ -112,7 +110,7 @@ yargs
112
110
  .command(
113
111
  'pull',
114
112
  'Pull SQL',
115
- yargs =>
113
+ (yargs) =>
116
114
  yargs.option('environment', {
117
115
  describe: 'The environment you are pulling from.',
118
116
  }),
@@ -121,31 +119,30 @@ yargs
121
119
  .command(
122
120
  'hooks',
123
121
  'Run a git hook',
124
- yargs =>
122
+ (yargs) =>
125
123
  yargs.option('type', {
126
124
  describe: 'The git hook to run.',
127
125
  }),
128
126
  hooks
129
127
  )
130
- .command('upgrade', 'Upgrade to v0.4', _, upgrade)
131
128
  .command(
132
- 'settings',
133
- 'Add Deployment Settings',
134
- yargs =>
129
+ 'config',
130
+ 'Add deployment config',
131
+ (yargs) =>
135
132
  yargs.option('environment', {
136
- describe: 'What environment are you adding settings for?',
133
+ describe: 'What environment are you adding deployment config for?',
137
134
  }),
138
- settings
135
+ addDeployConfig
139
136
  )
140
137
  .help()
141
138
  .alias('h', 'help')
142
139
  .demandCommand()
143
140
  .strict().argv;
144
141
 
145
- process.on('uncaughtException', err => {
142
+ process.on('uncaughtException', (err) => {
146
143
  exitWithError(err.message);
147
144
  });
148
145
 
149
- process.on('unhandledRejection', err => {
146
+ process.on('unhandledRejection', (err) => {
150
147
  exitWithError(err instanceof Error ? err.stack || err.message : 'Something went wrong');
151
148
  });
@@ -1,12 +1,11 @@
1
1
  const fs = require('fs');
2
2
  const glob = require('glob');
3
- const slugify = require('slugify');
4
3
  const replace = require('replace-in-file');
5
4
 
6
5
  const logger = require('../logger');
7
6
  const getProjectPath = require('../utils/getProjectPath');
8
7
 
9
- const getReplacements = options => {
8
+ const getReplacements = (options) => {
10
9
  if (options.environment === 'production') {
11
10
  return [
12
11
  ['{{url_production}}', options.urlProduction],
@@ -32,7 +31,7 @@ const getReplacements = options => {
32
31
  return;
33
32
  };
34
33
 
35
- module.exports = async options => {
34
+ module.exports = async (options) => {
36
35
  const projectPath = getProjectPath();
37
36
  const filesToReplace = [
38
37
  ...glob.sync('config/*', { cwd: projectPath, dot: true }),
@@ -44,7 +43,7 @@ module.exports = async options => {
44
43
  let files = filesToReplace;
45
44
  if (getProjectPath() !== process.cwd()) {
46
45
  // Check if the script is being run from outside of the project and then fix the paths
47
- files = files.map(file => getProjectPath(file));
46
+ files = files.map((file) => getProjectPath(file));
48
47
  }
49
48
 
50
49
  // Remove any files that don't exist
@@ -1,5 +1,4 @@
1
1
  const chalk = require('chalk');
2
- const opn = require('opn');
3
2
  const rimraf = require('rimraf');
4
3
  const webpack = require('webpack');
5
4
  const { merge } = require('webpack-merge');
@@ -119,7 +118,7 @@ module.exports = async (envConfig = {}, buildOptions, failOnError = false) => {
119
118
  browserSync({
120
119
  host: 'localhost',
121
120
  https: process.env.HTTPS,
122
- open: false,
121
+ open: true,
123
122
  port: process.env.PORT || 3000,
124
123
  proxy: {
125
124
  target: url,
@@ -133,7 +132,6 @@ module.exports = async (envConfig = {}, buildOptions, failOnError = false) => {
133
132
  });
134
133
 
135
134
  devMiddleware.waitUntilValid(() => {
136
- opn(url.replace('8888', process.env.PORT));
137
135
  logger.success('Build finished successfully!');
138
136
  });
139
137
 
@@ -160,12 +158,13 @@ module.exports = async (envConfig = {}, buildOptions, failOnError = false) => {
160
158
  const info = stats.toJson();
161
159
 
162
160
  if (stats.hasWarnings()) {
161
+ console.log(info.warnings);
163
162
  info.warnings.forEach((warning) => logger.warn(warning));
164
163
  }
165
164
 
166
165
  if (stats.hasErrors()) {
167
166
  info.errors.forEach((error) => {
168
- logger.error(chalk.red(error));
167
+ console.log(error);
169
168
  });
170
169
 
171
170
  logger.error('Build finished with errors');
package/logger.js CHANGED
@@ -30,4 +30,4 @@ module.exports = {
30
30
  if (!this.enabled) return;
31
31
  log('info', chalk.blue('ℹ'), ...args);
32
32
  },
33
- }
33
+ };
@@ -1,35 +1,12 @@
1
1
  const fs = require('fs');
2
2
  const chalk = require('chalk');
3
+ const rimraf = require('rimraf');
3
4
 
4
5
  const logger = require('../logger');
5
6
  const getProjectPath = require('../utils/getProjectPath');
6
7
  const execAsync = require('../utils/execAsync');
7
8
 
8
- const BABEL = ['@babel/polyfill', '@babel/runtime', 'babel-polyfill', 'babel-runtime'];
9
-
10
9
  async function checkProjectDependencies() {
11
- const projectPackage = getProjectPath('package.json');
12
- const pck = JSON.parse(fs.readFileSync(projectPackage, 'utf8'));
13
- const { dependencies, devDependencies } = pck;
14
-
15
- // Babel polyfill/runtime check
16
- if (BABEL.some((name) => dependencies[name])) {
17
- logger.warn(
18
- `${chalk.bold('babel polyfill or runtimeyfi')} is no longer required with >=0.4.0.
19
- Please remove it from your project devDependencies: ${chalk.yellow(
20
- `yarn remove ${BABEL.join(' ')}`
21
- )}`
22
- );
23
- }
24
-
25
- // mamp-cli
26
- if (devDependencies['mamp-cli']) {
27
- logger.warn(
28
- `${chalk.bold('mamp-cli')} is no longer required with >=2.0.0.
29
- Please remove it from your project devDependencies: ${chalk.yellow('yarn remove mamp-cli')}`
30
- );
31
- }
32
-
33
10
  const vendorDir = getProjectPath('vendor');
34
11
  const hasInstalledComposer = fs.existsSync(vendorDir);
35
12
  if (!hasInstalledComposer) {
@@ -54,7 +31,7 @@ async function checkProjectDependencies() {
54
31
  // Delete old config if it exists
55
32
  if (fs.existsSync(oldHuskyConfig)) {
56
33
  try {
57
- fs.unlinkSync(oldHuskyConfig);
34
+ rimraf.sync(oldHuskyConfig);
58
35
  logger.info('Old Husky config deleted');
59
36
  } catch (err) {
60
37
  console.warn('Error while deleting old Husky config:', err);
@@ -63,10 +40,12 @@ async function checkProjectDependencies() {
63
40
 
64
41
  if (!fs.existsSync(huskyDirectory)) {
65
42
  // Husky now requires a "one-time" explicit git hook activation
66
- await execAsync('yarn husky install');
43
+ const husky = `node_modules/.bin/husky`;
44
+
45
+ await execAsync(`${husky} install`);
67
46
  logger.info('Upgrading Husky git hooks config');
68
- execAsync(`npx husky add .husky/pre-commit 'lint-staged'`);
69
- execAsync(`npx husky add .husky/post-merge 'wp-scripts hooks --type="post-merge"'`);
47
+ await execAsync(`${husky} add .husky/pre-commit 'npx lint-staged'`);
48
+ await execAsync(`${husky} add .husky/post-merge 'wp-scripts hooks --type="post-merge"'`);
70
49
  logger.success('Husky upgrade successful!');
71
50
  }
72
51
  }
@@ -1,20 +1,12 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
- const logger = require('../logger');
5
-
6
4
  let overrides;
7
5
  const overridesPath = path.resolve(process.cwd(), './tasks/overrides.js');
8
6
  if (fs.existsSync(overridesPath)) {
9
7
  overrides = require(overridesPath);
10
8
  }
11
9
 
12
- if (overrides.copyFxClasses) {
13
- logger.warn(
14
- `You are using the old "copyFxClasses" override, please upgrade your code to use the new "copyFx" API.`
15
- );
16
- }
17
-
18
10
  const checkProjectDependencies = require('./checkProjectDependencies');
19
11
  const copyFx = require('./copyFx');
20
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wp-blank-scripts",
3
- "version": "3.1.0-beta.2",
3
+ "version": "3.1.0",
4
4
  "description": "Personal Wordpress Scripts",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
11
11
  },
12
12
  "engines": {
13
- "node": ">=9"
13
+ "node": ">=10"
14
14
  },
15
15
  "files": [
16
16
  "cli",
@@ -31,8 +31,10 @@
31
31
  "author": "ViVO Digital",
32
32
  "license": "ISC",
33
33
  "dependencies": {
34
- "@hot-loader/react-dom": "^17.0.2",
34
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
35
35
  "@prettier/plugin-php": "^0.19.6",
36
+ "@swc/cli": "^0.1.62",
37
+ "@swc/core": "^1.3.67",
36
38
  "browser-sync": "^2.29.3",
37
39
  "chalk": "4.1.2",
38
40
  "copy-webpack-plugin": "^11.0.0",
@@ -58,15 +60,13 @@
58
60
  "mini-css-extract-plugin": "^2.7.6",
59
61
  "mysql": "^2.18.1",
60
62
  "node-fetch": "2",
61
- "normalize.css": "^8.0.1",
62
- "opn": "^6.0.0",
63
63
  "ora": "^5.4.1",
64
64
  "postcss": "^8.4.24",
65
65
  "postcss-loader": "^7.3.3",
66
66
  "postcss-preset-env": "^8.5.0",
67
67
  "prettier": "^2.8.8",
68
68
  "raw-loader": "^4.0.2",
69
- "react-hot-loader": "^4.13.1",
69
+ "react-refresh": "^0.14.0",
70
70
  "replace-in-file": "^7.0.1",
71
71
  "rimraf": "^5.0.1",
72
72
  "rsync": "^0.6.1",
@@ -77,9 +77,9 @@
77
77
  "slugify": "^1.6.6",
78
78
  "ssh2": "0.8.9",
79
79
  "style-loader": "^3.3.3",
80
+ "swc-loader": "^0.2.3",
80
81
  "tempy": "^0.2.1",
81
82
  "terser-webpack-plugin": "^5.3.9",
82
- "time-fix-plugin": "^2.0.7",
83
83
  "webpack": "^5.87.0",
84
84
  "webpack-dev-middleware": "^6.1.1",
85
85
  "webpack-hot-middleware": "^2.25.3",
@@ -5,7 +5,6 @@ const CopyPlugin = require('copy-webpack-plugin');
5
5
  const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
6
6
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7
7
  const TerserPlugin = require('terser-webpack-plugin');
8
- const TimeFixPlugin = require('time-fix-plugin');
9
8
  const cssnano = require('cssnano');
10
9
  const glob = require('glob');
11
10
  const postcssPresetEnv = require('postcss-preset-env');
@@ -35,6 +34,7 @@ function makeBaseConfig(options) {
35
34
  const themePath = path.join(buildPath, themeDir);
36
35
 
37
36
  const fxFiles = getFxFiles(copyFx());
37
+ const fontsDir = path.join(sourceDir, 'assets', 'fonts');
38
38
 
39
39
  const sourceFiles = [
40
40
  {
@@ -51,11 +51,15 @@ function makeBaseConfig(options) {
51
51
  to: path.join(themePath, 'assets', 'img'),
52
52
  globOptions: { ignore: ['.DS_Store'] },
53
53
  },
54
- {
55
- from: path.join(sourceDir, 'assets', 'fonts'),
56
- to: path.join(themePath, 'assets', 'fonts'),
57
- globOptions: { ignore: ['.DS_Store'] },
58
- },
54
+ ...(fs.existsSync(fontsDir)
55
+ ? [
56
+ {
57
+ from: fontsDir,
58
+ to: path.join(themePath, 'assets', 'fonts'),
59
+ globOptions: { ignore: ['.DS_Store'] },
60
+ },
61
+ ]
62
+ : []),
59
63
  {
60
64
  from: path.join(sourceDir, 'templates'),
61
65
  to: themePath,
@@ -108,6 +112,15 @@ function makeBaseConfig(options) {
108
112
  { from: 'wp-content', to: 'wp-content' },
109
113
  ];
110
114
 
115
+ // @TODO: temporary for development of blocks package
116
+ const includeBlocks = process.env.MASTER_BLOCKS;
117
+ const masterBlocks = [
118
+ {
119
+ from: path.join(__dirname, '../../vivo/vivo-master-blocks/dist'),
120
+ to: path.join(themePath, 'inc', 'vivo-master-blocks'),
121
+ },
122
+ ];
123
+
111
124
  let customFiles = [];
112
125
  if (typeof copyFiles === 'function') {
113
126
  customFiles = copyFiles({
@@ -119,7 +132,13 @@ function makeBaseConfig(options) {
119
132
  });
120
133
  }
121
134
 
122
- const filesToCopy = [...sourceFiles, ...envFiles, ...wordpressFiles, ...customFiles];
135
+ const filesToCopy = [
136
+ ...sourceFiles,
137
+ ...envFiles,
138
+ ...wordpressFiles,
139
+ ...customFiles,
140
+ ...(includeBlocks ? masterBlocks : []),
141
+ ];
123
142
 
124
143
  // Admin entries
125
144
  const adminScripts = glob.sync(path.join(sourcePath, 'assets', 'admin', 'js', '*.js'));
@@ -168,14 +187,15 @@ function makeBaseConfig(options) {
168
187
  rules: [
169
188
  {
170
189
  test: /\.[jt]sx?$/,
171
- exclude: /node_modules\/(?!(dom7|swiper)\/)/,
190
+ exclude: /node_modules/,
172
191
  use: {
173
- loader: 'esbuild-loader',
192
+ loader: 'swc-loader',
174
193
  options: {
175
- loader: 'jsx',
176
- // TODO: Remove in react build
177
- jsxFactory: 'wp.element.createElement',
178
- target: 'es2015',
194
+ jsc: {
195
+ parser: {
196
+ jsx: true,
197
+ },
198
+ },
179
199
  },
180
200
  },
181
201
  ...loaderOverrides.js,
@@ -241,8 +261,6 @@ function makeBaseConfig(options) {
241
261
  ],
242
262
  },
243
263
  plugins: [
244
- // TODO: See if we can remove
245
- // new TimeFixPlugin(),
246
264
  new CopyPlugin({ patterns: filesToCopy }),
247
265
  new RemoveEmptyScriptsPlugin({ silent: true }),
248
266
  ],
@@ -264,6 +282,7 @@ function makeBaseConfig(options) {
264
282
  minimizer: [
265
283
  new TerserPlugin({
266
284
  parallel: true,
285
+ include: [sourcePath],
267
286
  terserOptions: {
268
287
  sourceMap: true,
269
288
  keep_classnames: true,
@@ -6,6 +6,7 @@ const webpack = require('webpack');
6
6
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7
7
  const HtmlWebpackPlugin = require('html-webpack-plugin');
8
8
  const postcssPresetEnv = require('postcss-preset-env');
9
+ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
9
10
  const cssnano = require('cssnano');
10
11
 
11
12
  const getSettings = require('./utils/projectSettings');
@@ -16,26 +17,28 @@ function makeReactWebpackConfig(options) {
16
17
  const isProd = mode === 'production';
17
18
  const sourceDir = 'app';
18
19
  const sourcePath = path.join(process.cwd(), sourceDir);
19
- const entryPath = path.join(sourcePath, 'index.js');
20
+ const entryPath = [path.join(sourcePath, 'index.js')];
20
21
  const globalVariablesPath = path.join(sourcePath, 'variables.scss');
21
22
 
22
23
  const settings = getSettings();
23
24
  const themeDir = path.join('wp-content', 'themes', settings.project);
24
25
 
25
- if (!fs.existsSync(entryPath)) {
26
- const relativeEntryPath = path.relative(process.cwd(), entryPath);
26
+ if (!fs.existsSync(entryPath[0])) {
27
+ const relativeEntryPath = path.relative(process.cwd(), entryPath[0]);
27
28
  exitWithError(`This project is a React project, but the entry file is missing.
28
29
  Please create ${chalk.yellow(relativeEntryPath)} to continue.`);
29
30
  }
30
31
 
32
+ if (!isProd) {
33
+ entryPath.unshift('webpack-hot-middleware/client');
34
+ }
35
+
31
36
  const config = {
32
37
  entry: {
33
- // Make sure global is first
34
- style: ['normalize.css'],
35
38
  main: entryPath,
36
39
  },
37
40
  output: {
38
- filename: chunkData => {
41
+ filename: (chunkData) => {
39
42
  if (chunkData.chunk.name === 'adminScripts') {
40
43
  return path.join(themeDir, 'assets', 'js', 'admin.js');
41
44
  }
@@ -46,16 +49,37 @@ function makeReactWebpackConfig(options) {
46
49
  },
47
50
  module: {
48
51
  rules: [
52
+ {
53
+ test: /.*\.(glb|gltf|bin)$/i,
54
+ type: 'asset/resource'
55
+ },
56
+ {
57
+ test: /\.[jt]sx?$/,
58
+ exclude: /node_modules/,
59
+ use: {
60
+ loader: 'swc-loader',
61
+ options: {
62
+ sourceMap: true,
63
+ jsc: {
64
+ parser: {
65
+ jsx: true,
66
+ },
67
+ transform: {
68
+ react: {
69
+ development: !isProd,
70
+ refresh: !isProd,
71
+ },
72
+ },
73
+ },
74
+ },
75
+ },
76
+ },
49
77
  {
50
78
  test: /\.css$/,
51
79
  include: [sourcePath],
52
80
  use: [
53
81
  {
54
- loader: MiniCssExtractPlugin.loader,
55
- options: {
56
- hmr: !isProd,
57
- reloadAll: true,
58
- },
82
+ loader: !isProd ? 'style-loader' : MiniCssExtractPlugin.loader,
59
83
  },
60
84
  {
61
85
  loader: 'css-loader',
@@ -64,14 +88,15 @@ function makeReactWebpackConfig(options) {
64
88
  {
65
89
  loader: 'postcss-loader',
66
90
  options: {
67
- ident: 'postcss',
68
- plugins() {
69
- if (isProd) {
70
- return [postcssPresetEnv(), cssnano()];
71
- }
72
- return [postcssPresetEnv({ browsers: 'last 2 versions' })];
91
+ postcssOptions: {
92
+ plugins() {
93
+ if (isProd) {
94
+ return [postcssPresetEnv(), cssnano()];
95
+ }
96
+ return [postcssPresetEnv({ browsers: 'last 2 versions' })];
97
+ },
98
+ sourceMap: !isProd,
73
99
  },
74
- sourceMap: true,
75
100
  },
76
101
  },
77
102
  ],
@@ -79,13 +104,9 @@ function makeReactWebpackConfig(options) {
79
104
  {
80
105
  test: /\.scss$/,
81
106
  include: [sourcePath],
82
- loader: [
107
+ use: [
83
108
  {
84
- loader: MiniCssExtractPlugin.loader,
85
- options: {
86
- hmr: !isProd,
87
- reloadAll: true,
88
- },
109
+ loader: !isProd ? 'style-loader' : MiniCssExtractPlugin.loader,
89
110
  },
90
111
  {
91
112
  loader: 'css-loader',
@@ -97,14 +118,15 @@ function makeReactWebpackConfig(options) {
97
118
  {
98
119
  loader: 'postcss-loader',
99
120
  options: {
100
- ident: 'postcss',
101
- plugins() {
102
- if (isProd) {
103
- return [postcssPresetEnv(), cssnano()];
104
- }
105
- return [postcssPresetEnv({ browsers: 'last 2 versions' })];
121
+ postcssOptions: {
122
+ plugins() {
123
+ if (isProd) {
124
+ return [postcssPresetEnv(), cssnano()];
125
+ }
126
+ return [postcssPresetEnv({ browsers: 'last 2 versions' })];
127
+ },
128
+ sourceMap: !isProd,
106
129
  },
107
- sourceMap: true,
108
130
  },
109
131
  },
110
132
  {
@@ -121,19 +143,6 @@ function makeReactWebpackConfig(options) {
121
143
  },
122
144
  ],
123
145
  },
124
- {
125
- test: /\.(eot|ttf|woff|woff2)$/,
126
- include: [sourcePath],
127
- use: [
128
- {
129
- loader: 'file-loader',
130
- options: {
131
- name: '[contenthash].[ext]',
132
- outputPath: path.join(themeDir, 'assets', 'fonts'),
133
- },
134
- },
135
- ],
136
- },
137
146
  {
138
147
  test: /.*\.(gif|png|svg|jpe?g)$/i,
139
148
  include: [sourcePath],
@@ -164,20 +173,13 @@ function makeReactWebpackConfig(options) {
164
173
  excludeChunks: ['adminScripts', 'admin.style'],
165
174
  }),
166
175
  new MiniCssExtractPlugin({
167
- moduleFilename({ name }) {
176
+ filename({ name }) {
168
177
  if (name === 'admin.style') {
169
178
  return path.join(themeDir, 'assets', 'css', 'admin.style.css');
170
179
  }
171
180
 
172
181
  return path.join(themeDir, 'assets', 'css', isProd ? '[contenthash].css' : '[name].css');
173
182
  },
174
- fallback: 'style-loader',
175
- use: [
176
- {
177
- loader: 'css-loader',
178
- options: { minimize: isProd, url: false, sourceMap: !isProd },
179
- },
180
- ],
181
183
  }),
182
184
  ],
183
185
  optimization: {
@@ -210,15 +212,9 @@ function makeReactWebpackConfig(options) {
210
212
  version: false,
211
213
  },
212
214
  };
213
-
214
215
  if (!isProd) {
215
- config.entry.main = [
216
- 'webpack-hot-middleware/client',
217
- 'react-hot-loader/patch',
218
- config.entry.main,
219
- ];
220
216
  config.plugins.push(new webpack.HotModuleReplacementPlugin());
221
- config.resolve.alias['react-dom'] = '@hot-loader/react-dom';
217
+ config.plugins.push(new ReactRefreshWebpackPlugin({ overlay: false }));
222
218
  }
223
219
 
224
220
  return config;
@@ -13,7 +13,6 @@ const getSettings = require('./utils/projectSettings');
13
13
 
14
14
  function makeWpWebpackConfig() {
15
15
  const mode = process.env.NODE_ENV || 'development';
16
- const isProd = mode === 'production';
17
16
 
18
17
  const settings = getSettings();
19
18
 
@@ -25,12 +24,12 @@ function makeWpWebpackConfig() {
25
24
 
26
25
  // Source entries
27
26
  const mainScripts = {};
28
- glob.sync(path.join(sourcePath, 'assets', 'js', '*.js')).forEach(filePath => {
27
+ glob.sync(path.join(sourcePath, 'assets', 'js', '*.js')).forEach((filePath) => {
29
28
  const name = path.basename(filePath, '.js');
30
29
  mainScripts[name] = [filePath];
31
30
  });
32
31
 
33
- glob.sync(path.join(sourcePath, 'assets', 'js', 'gutenberg', '*.js')).forEach(filePath => {
32
+ glob.sync(path.join(sourcePath, 'assets', 'js', 'gutenberg', '*.js')).forEach((filePath) => {
34
33
  const name = path.basename(filePath, '.js');
35
34
  mainScripts[`gutenberg/${name}`] = [filePath];
36
35
  });
@@ -52,7 +51,7 @@ function makeWpWebpackConfig() {
52
51
  return {
53
52
  entry: {
54
53
  ...mainScripts,
55
- style: ['normalize.css', ...fxFiles.sass, ...mainStyles],
54
+ style: [...fxFiles.sass, ...mainStyles],
56
55
  },
57
56
  plugins: [
58
57
  new MiniCssExtractPlugin({
package/cli/upgrade.js DELETED
@@ -1,150 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const rimraf = require('rimraf');
4
- const replace = require('replace-in-file');
5
- const ora = require('ora');
6
-
7
- const execAsync = require('../utils/execAsync');
8
- const logger = require('../logger');
9
-
10
- const unusedPackages = [
11
- 'pace-progress',
12
- '@babel/polyfill',
13
- '@babel/runtime',
14
- 'babel-polyfill',
15
- 'babel-runtime',
16
- ];
17
-
18
- const filesToChange = [
19
- [path.join('config', 'htaccess.txt'), path.join('config', '.htaccess')],
20
- [
21
- path.join('config', 'htaccess-staging.txt'),
22
- path.join('config', '.htaccess-staging'),
23
- ],
24
- [
25
- path.join('config', 'htaccess-production.txt'),
26
- path.join('config', '.htaccess-production'),
27
- ],
28
- ];
29
-
30
- module.exports = async () => {
31
- logger.log('Upgrading your project to the latest wp-blank-scripts');
32
-
33
- // Rename files
34
- filesToChange.forEach(([to, from]) => {
35
- if (fs.existsSync(to)) {
36
- fs.renameSync(to, from);
37
- logger.log(`Renamed ${to} to ${from}`);
38
- }
39
- });
40
-
41
- const pckFile = fs.readFileSync('package.json');
42
- const pck = JSON.parse(pckFile);
43
-
44
- // Remove browserify-shim from package.json
45
- delete pck['browserify-shim'];
46
- delete pck['browserify'];
47
- logger.log('Removed browserify & browserify-shim config');
48
-
49
- // Add new pull command
50
- pck.scripts.pull = 'wp-scripts pull';
51
-
52
- // Add new vivo config
53
- pck.vivo = {
54
- 'dev-command': 'start',
55
- designs: [],
56
- };
57
-
58
- logger.log('Added new fields to project package');
59
-
60
- fs.writeFileSync('package.json', JSON.stringify(pck, null, 2));
61
-
62
- // Remove pace-progress occurences from style.scss, preloader.scss, main.js
63
- const scriptFilePP = path.join('src', 'assets', 'js', 'main.js');
64
- const styleFilePP = path.join(
65
- 'src',
66
- 'assets',
67
- 'css',
68
- 'partials',
69
- 'preloader.scss'
70
- );
71
- const mainStyleFile = path.join('src', 'assets', 'css', 'style.scss');
72
-
73
- // Remove from main.js
74
- const importLinesPreloader = [
75
- '// Pace',
76
- 'import pace from \'pace-progress\';',
77
- 'pace.start();',
78
- ];
79
- replace.sync({
80
- files: scriptFilePP,
81
- from: importLinesPreloader,
82
- to: '',
83
- });
84
-
85
- // Delete preloader.scss
86
- rimraf.sync(styleFilePP);
87
- logger.log('Removed pace-progress from project');
88
-
89
- // Remove import from style.scss
90
- const importPreloaderStyles = '@import \'partials/preloader\';';
91
- replace.sync({
92
- files: mainStyleFile,
93
- from: importPreloaderStyles,
94
- to: '',
95
- });
96
-
97
- // Rename admin.css
98
- const enqueueFile = path.join('src', 'inc', 'fx-enqueue.php');
99
- replace.sync({
100
- files: enqueueFile,
101
- from: 'admin.css',
102
- to: 'admin.style.css',
103
- });
104
- logger.log('Renamed admin styles in enqueue');
105
-
106
- // Remove normalize.css
107
- const normalizeFile = path.join(
108
- 'src',
109
- 'assets',
110
- 'css',
111
- 'vendor',
112
- 'normalize.scss'
113
- );
114
- rimraf.sync(normalizeFile);
115
- const styleFile = path.join('src', 'assets', 'css', 'style.scss');
116
- const importLine = '@import \'vendor/normalize\';';
117
- replace.sync({
118
- files: styleFile,
119
- from: importLine,
120
- to: '',
121
- });
122
- logger.log('Removed normalize.css from project');
123
-
124
- // Remove deployment.log
125
- rimraf.sync('deployment.log');
126
- logger.log('Removed deployment.log from project');
127
-
128
- const packagesToRemove = unusedPackages.filter(p =>
129
- Boolean(pck.dependencies[p] || pck.devDependencies[p])
130
- );
131
-
132
- if (packagesToRemove.length > 0) {
133
- // Remove unused packages
134
- logger.log('Removing unused packages...');
135
-
136
- const spinner = ora();
137
- spinner.prefixText = logger.prefix;
138
- spinner.start();
139
- await execAsync(`yarn remove ${packagesToRemove.join(' ')}`);
140
-
141
- spinner.stop();
142
- logger.log(
143
- `Removed ${packagesToRemove.length} package${
144
- packagesToRemove.length === 1 ? '' : 's'
145
- }`
146
- );
147
- }
148
-
149
- logger.success('Upgraded to wp-blank-scripts v0.4, you\'re good to go!');
150
- };