wp-blank-scripts 3.0.0-beta.7 → 3.0.0-beta.9

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.
@@ -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,
@@ -9,7 +9,7 @@ module.exports = {
9
9
  {
10
10
  files: '*.php',
11
11
  options: {
12
- phpVersion: '7.2',
12
+ phpVersion: '7.4',
13
13
  tabWidth: 4,
14
14
  braceStyle: '1tbs',
15
15
  },
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,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.0.0-beta.7",
3
+ "version": "3.0.0-beta.9",
4
4
  "description": "Personal Wordpress Scripts",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -31,6 +31,7 @@
31
31
  "author": "ViVO Digital",
32
32
  "license": "ISC",
33
33
  "dependencies": {
34
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
34
35
  "@prettier/plugin-php": "^0.19.6",
35
36
  "@swc/cli": "^0.1.62",
36
37
  "@swc/core": "^1.3.67",
@@ -59,13 +60,13 @@
59
60
  "mini-css-extract-plugin": "^2.7.6",
60
61
  "mysql": "^2.18.1",
61
62
  "node-fetch": "2",
62
- "normalize.css": "^8.0.1",
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-refresh": "^0.14.0",
69
70
  "replace-in-file": "^7.0.1",
70
71
  "rimraf": "^5.0.1",
71
72
  "rsync": "^0.6.1",
@@ -172,13 +172,15 @@ function makeBaseConfig(options) {
172
172
  rules: [
173
173
  {
174
174
  test: /\.[jt]sx?$/,
175
- exclude: /node_modules\/(?!(dom7|swiper)\/)/,
175
+ exclude: /node_modules/,
176
176
  use: {
177
- loader: 'esbuild-loader',
177
+ loader: 'swc-loader',
178
178
  options: {
179
- loader: 'jsx',
180
- jsxFactory: 'wp.element.createElement',
181
- target: 'es2015',
179
+ jsc: {
180
+ parser: {
181
+ jsx: true,
182
+ },
183
+ },
182
184
  },
183
185
  },
184
186
  ...loaderOverrides.js,
@@ -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,22 +17,24 @@ 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: {
@@ -56,6 +59,12 @@ function makeReactWebpackConfig(options) {
56
59
  parser: {
57
60
  jsx: true,
58
61
  },
62
+ transform: {
63
+ react: {
64
+ development: !isProd,
65
+ refresh: !isProd,
66
+ },
67
+ },
59
68
  },
60
69
  },
61
70
  },
@@ -198,10 +207,9 @@ function makeReactWebpackConfig(options) {
198
207
  version: false,
199
208
  },
200
209
  };
201
-
202
210
  if (!isProd) {
203
- config.entry.main = ['webpack-hot-middleware/client', config.entry.main];
204
211
  config.plugins.push(new webpack.HotModuleReplacementPlugin());
212
+ config.plugins.push(new ReactRefreshWebpackPlugin());
205
213
  }
206
214
 
207
215
  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
- };