wp-blank-scripts 3.0.0-beta.0 → 3.0.0-beta.4
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 +1 -9
- package/config/lint-staged.config.js +1 -1
- package/lib/buildProject.js +16 -4
- package/logger.js +1 -1
- package/overridable/checkProjectDependencies.js +28 -25
- package/package.json +2 -3
- package/utils/checkNodeVersion.js +3 -1
- package/webpack.base.config.js +16 -13
- package/webpack.react.config.js +33 -47
- package/config/.huskyrc.js +0 -6
package/README.md
CHANGED
|
@@ -290,21 +290,13 @@ exports.copyFiles = (paths) => {
|
|
|
290
290
|
},
|
|
291
291
|
{
|
|
292
292
|
// Copy files inside a directory the the theme
|
|
293
|
-
from: path.join(sourceDir, 'new-directory'
|
|
293
|
+
from: path.join(sourceDir, 'new-directory'),
|
|
294
294
|
to: themePath,
|
|
295
|
-
transformPath(targetPath) {
|
|
296
|
-
// Need to fix the path
|
|
297
|
-
return targetPath.replace(path.join(sourceDir, 'new-directory'), '');
|
|
298
|
-
},
|
|
299
295
|
},
|
|
300
296
|
{
|
|
301
297
|
// Copy file from a directory to the root directory
|
|
302
298
|
from: path.join(sourceDir, 'directory-file-was-in', 'file.txt'),
|
|
303
299
|
to: '',
|
|
304
|
-
transformPath(targetPath) {
|
|
305
|
-
// Need to fix the path again, otherwise it will stay in the directory
|
|
306
|
-
return targetPath.replace('directory-file-was-in', '');
|
|
307
|
-
},
|
|
308
300
|
},
|
|
309
301
|
{
|
|
310
302
|
// Copy all files from vendor (except vivo-digital & johnpbloch) to the theme/inc/vendor
|
package/lib/buildProject.js
CHANGED
|
@@ -88,12 +88,22 @@ module.exports = async (envConfig = {}, buildOptions, failOnError = false) => {
|
|
|
88
88
|
const settings = getSettings();
|
|
89
89
|
const url = settings.url[options.environment];
|
|
90
90
|
|
|
91
|
-
const compiler = webpack(config, (err
|
|
92
|
-
if (err
|
|
91
|
+
const compiler = webpack(config, (err) => {
|
|
92
|
+
if (err) {
|
|
93
93
|
logger.error(err.stack || err);
|
|
94
|
+
|
|
95
|
+
if (err.details) {
|
|
96
|
+
logger.error(err.details);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (failOnError) {
|
|
100
|
+
exitWithError();
|
|
101
|
+
}
|
|
102
|
+
|
|
94
103
|
return;
|
|
95
104
|
}
|
|
96
105
|
});
|
|
106
|
+
|
|
97
107
|
const devMiddleware = webpackDevMiddleware(compiler, {
|
|
98
108
|
publicPath: config.output.publicPath,
|
|
99
109
|
stats: {
|
|
@@ -103,6 +113,7 @@ module.exports = async (envConfig = {}, buildOptions, failOnError = false) => {
|
|
|
103
113
|
},
|
|
104
114
|
writeToDisk: true,
|
|
105
115
|
});
|
|
116
|
+
|
|
106
117
|
const hotMiddleware = webpackHotMiddleware(compiler);
|
|
107
118
|
|
|
108
119
|
browserSync({
|
|
@@ -149,11 +160,12 @@ module.exports = async (envConfig = {}, buildOptions, failOnError = false) => {
|
|
|
149
160
|
const info = stats.toJson();
|
|
150
161
|
|
|
151
162
|
if (stats.hasWarnings()) {
|
|
152
|
-
info.warnings.forEach(warning => logger.warn(warning));
|
|
163
|
+
info.warnings.forEach((warning) => logger.warn(warning));
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
if (stats.hasErrors()) {
|
|
156
|
-
info.errors.forEach(error => {
|
|
167
|
+
info.errors.forEach((error) => {
|
|
168
|
+
console.log(error);
|
|
157
169
|
logger.error(chalk.red(error));
|
|
158
170
|
});
|
|
159
171
|
|
package/logger.js
CHANGED
|
@@ -1,34 +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');
|
|
7
|
+
const execAsync = require('../utils/execAsync');
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function checkProjectDependencies() {
|
|
10
|
-
const projectPackage = getProjectPath('package.json');
|
|
11
|
-
const pck = JSON.parse(fs.readFileSync(projectPackage, 'utf8'));
|
|
12
|
-
const { dependencies, devDependencies } = pck;
|
|
13
|
-
|
|
14
|
-
// Babel polyfill/runtime check
|
|
15
|
-
if (BABEL.some(name => dependencies[name])) {
|
|
16
|
-
logger.warn(
|
|
17
|
-
`${chalk.bold('babel polyfill or runtimeyfi')} is no longer required with >=0.4.0.
|
|
18
|
-
Please remove it from your project devDependencies: ${chalk.yellow(
|
|
19
|
-
`yarn remove ${BABEL.join(' ')}`
|
|
20
|
-
)}`
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// mamp-cli
|
|
25
|
-
if (devDependencies['mamp-cli']) {
|
|
26
|
-
logger.warn(
|
|
27
|
-
`${chalk.bold('mamp-cli')} is no longer required with >=2.0.0.
|
|
28
|
-
Please remove it from your project devDependencies: ${chalk.yellow('yarn remove mamp-cli')}`
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
9
|
+
async function checkProjectDependencies() {
|
|
32
10
|
const vendorDir = getProjectPath('vendor');
|
|
33
11
|
const hasInstalledComposer = fs.existsSync(vendorDir);
|
|
34
12
|
if (!hasInstalledComposer) {
|
|
@@ -45,6 +23,31 @@ function checkProjectDependencies() {
|
|
|
45
23
|
// Warn if fx-classes < v2 is being used
|
|
46
24
|
logger.warn('You are using an old version of fx-classes, please upgrade to at least v2.');
|
|
47
25
|
}
|
|
26
|
+
|
|
27
|
+
// Husky pre-commit hooks activation and migration from v4 to v8
|
|
28
|
+
const huskyDirectory = getProjectPath('.husky');
|
|
29
|
+
const oldHuskyConfig = getProjectPath('.huskyrc.js');
|
|
30
|
+
|
|
31
|
+
// Delete old config if it exists
|
|
32
|
+
if (fs.existsSync(oldHuskyConfig)) {
|
|
33
|
+
try {
|
|
34
|
+
rimraf.sync(oldHuskyConfig);
|
|
35
|
+
logger.info('Old Husky config deleted');
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.warn('Error while deleting old Husky config:', err);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!fs.existsSync(huskyDirectory)) {
|
|
42
|
+
// Husky now requires a "one-time" explicit git hook activation
|
|
43
|
+
const husky = `node_modules/.bin/husky`;
|
|
44
|
+
|
|
45
|
+
await execAsync(`${husky} install`);
|
|
46
|
+
logger.info('Upgrading Husky git hooks config');
|
|
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"'`);
|
|
49
|
+
logger.success('Husky upgrade successful!');
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
module.exports = checkProjectDependencies;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wp-blank-scripts",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
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": ">=
|
|
13
|
+
"node": ">=10"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"cli",
|
|
@@ -79,7 +79,6 @@
|
|
|
79
79
|
"style-loader": "^3.3.3",
|
|
80
80
|
"tempy": "^0.2.1",
|
|
81
81
|
"terser-webpack-plugin": "^5.3.9",
|
|
82
|
-
"time-fix-plugin": "^2.0.7",
|
|
83
82
|
"webpack": "^5.87.0",
|
|
84
83
|
"webpack-dev-middleware": "^6.1.1",
|
|
85
84
|
"webpack-hot-middleware": "^2.25.3",
|
|
@@ -34,7 +34,9 @@ async function checkNodeVerion() {
|
|
|
34
34
|
const currentVersion = await getCurrentNodeVersion();
|
|
35
35
|
|
|
36
36
|
if (projectVersion && !isValidNodeVersion(projectVersion, currentVersion)) {
|
|
37
|
-
logger.warn(
|
|
37
|
+
logger.warn(
|
|
38
|
+
`Your node version (v${currentVersion}) is not valid. This project requires node ${projectVersion}.`
|
|
39
|
+
);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
|
package/webpack.base.config.js
CHANGED
|
@@ -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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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,
|
|
@@ -173,7 +177,6 @@ function makeBaseConfig(options) {
|
|
|
173
177
|
loader: 'esbuild-loader',
|
|
174
178
|
options: {
|
|
175
179
|
loader: 'jsx',
|
|
176
|
-
// TODO: Remove in react build
|
|
177
180
|
jsxFactory: 'wp.element.createElement',
|
|
178
181
|
target: 'es2015',
|
|
179
182
|
},
|
|
@@ -197,11 +200,11 @@ function makeBaseConfig(options) {
|
|
|
197
200
|
loader: 'postcss-loader',
|
|
198
201
|
options: {
|
|
199
202
|
postcssOptions: {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
postcssPresetEnv(
|
|
203
|
-
|
|
204
|
-
]
|
|
203
|
+
plugins() {
|
|
204
|
+
if (isProd) {
|
|
205
|
+
return [postcssPresetEnv(), cssnano()];
|
|
206
|
+
}
|
|
207
|
+
return [postcssPresetEnv({ browsers: 'last 2 versions' })];
|
|
205
208
|
},
|
|
206
209
|
},
|
|
207
210
|
sourceMap: !isProd,
|
|
@@ -211,7 +214,7 @@ function makeBaseConfig(options) {
|
|
|
211
214
|
loader: 'sass-loader',
|
|
212
215
|
options: {
|
|
213
216
|
sourceMap: !isProd,
|
|
214
|
-
|
|
217
|
+
additionalData: sassVariables,
|
|
215
218
|
},
|
|
216
219
|
},
|
|
217
220
|
],
|
package/webpack.react.config.js
CHANGED
|
@@ -35,7 +35,7 @@ function makeReactWebpackConfig(options) {
|
|
|
35
35
|
main: entryPath,
|
|
36
36
|
},
|
|
37
37
|
output: {
|
|
38
|
-
filename: chunkData => {
|
|
38
|
+
filename: (chunkData) => {
|
|
39
39
|
if (chunkData.chunk.name === 'adminScripts') {
|
|
40
40
|
return path.join(themeDir, 'assets', 'js', 'admin.js');
|
|
41
41
|
}
|
|
@@ -46,16 +46,24 @@ function makeReactWebpackConfig(options) {
|
|
|
46
46
|
},
|
|
47
47
|
module: {
|
|
48
48
|
rules: [
|
|
49
|
+
{
|
|
50
|
+
test: /\.[jt]sx?$/,
|
|
51
|
+
exclude: /node_modules\/(?!(dom7|swiper)\/)/,
|
|
52
|
+
use: {
|
|
53
|
+
loader: 'esbuild-loader',
|
|
54
|
+
options: {
|
|
55
|
+
loader: 'jsx',
|
|
56
|
+
jsxFactory: 'React.createElement',
|
|
57
|
+
target: 'es2015',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
49
61
|
{
|
|
50
62
|
test: /\.css$/,
|
|
51
63
|
include: [sourcePath],
|
|
52
64
|
use: [
|
|
53
65
|
{
|
|
54
|
-
loader: MiniCssExtractPlugin.loader,
|
|
55
|
-
options: {
|
|
56
|
-
hmr: !isProd,
|
|
57
|
-
reloadAll: true,
|
|
58
|
-
},
|
|
66
|
+
loader: !isProd ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
59
67
|
},
|
|
60
68
|
{
|
|
61
69
|
loader: 'css-loader',
|
|
@@ -64,14 +72,15 @@ function makeReactWebpackConfig(options) {
|
|
|
64
72
|
{
|
|
65
73
|
loader: 'postcss-loader',
|
|
66
74
|
options: {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
postcssOptions: {
|
|
76
|
+
plugins() {
|
|
77
|
+
if (isProd) {
|
|
78
|
+
return [postcssPresetEnv(), cssnano()];
|
|
79
|
+
}
|
|
80
|
+
return [postcssPresetEnv({ browsers: 'last 2 versions' })];
|
|
81
|
+
},
|
|
82
|
+
sourceMap: !isProd,
|
|
73
83
|
},
|
|
74
|
-
sourceMap: true,
|
|
75
84
|
},
|
|
76
85
|
},
|
|
77
86
|
],
|
|
@@ -79,13 +88,9 @@ function makeReactWebpackConfig(options) {
|
|
|
79
88
|
{
|
|
80
89
|
test: /\.scss$/,
|
|
81
90
|
include: [sourcePath],
|
|
82
|
-
|
|
91
|
+
use: [
|
|
83
92
|
{
|
|
84
|
-
loader: MiniCssExtractPlugin.loader,
|
|
85
|
-
options: {
|
|
86
|
-
hmr: !isProd,
|
|
87
|
-
reloadAll: true,
|
|
88
|
-
},
|
|
93
|
+
loader: !isProd ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
89
94
|
},
|
|
90
95
|
{
|
|
91
96
|
loader: 'css-loader',
|
|
@@ -97,14 +102,15 @@ function makeReactWebpackConfig(options) {
|
|
|
97
102
|
{
|
|
98
103
|
loader: 'postcss-loader',
|
|
99
104
|
options: {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
postcssOptions: {
|
|
106
|
+
plugins() {
|
|
107
|
+
if (isProd) {
|
|
108
|
+
return [postcssPresetEnv(), cssnano()];
|
|
109
|
+
}
|
|
110
|
+
return [postcssPresetEnv({ browsers: 'last 2 versions' })];
|
|
111
|
+
},
|
|
112
|
+
sourceMap: !isProd,
|
|
106
113
|
},
|
|
107
|
-
sourceMap: true,
|
|
108
114
|
},
|
|
109
115
|
},
|
|
110
116
|
{
|
|
@@ -121,19 +127,6 @@ function makeReactWebpackConfig(options) {
|
|
|
121
127
|
},
|
|
122
128
|
],
|
|
123
129
|
},
|
|
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
130
|
{
|
|
138
131
|
test: /.*\.(gif|png|svg|jpe?g)$/i,
|
|
139
132
|
include: [sourcePath],
|
|
@@ -164,20 +157,13 @@ function makeReactWebpackConfig(options) {
|
|
|
164
157
|
excludeChunks: ['adminScripts', 'admin.style'],
|
|
165
158
|
}),
|
|
166
159
|
new MiniCssExtractPlugin({
|
|
167
|
-
|
|
160
|
+
filename({ name }) {
|
|
168
161
|
if (name === 'admin.style') {
|
|
169
162
|
return path.join(themeDir, 'assets', 'css', 'admin.style.css');
|
|
170
163
|
}
|
|
171
164
|
|
|
172
165
|
return path.join(themeDir, 'assets', 'css', isProd ? '[contenthash].css' : '[name].css');
|
|
173
166
|
},
|
|
174
|
-
fallback: 'style-loader',
|
|
175
|
-
use: [
|
|
176
|
-
{
|
|
177
|
-
loader: 'css-loader',
|
|
178
|
-
options: { minimize: isProd, url: false, sourceMap: !isProd },
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
167
|
}),
|
|
182
168
|
],
|
|
183
169
|
optimization: {
|