wp-blank-scripts 4.0.0-alpha.1 → 4.0.0-alpha.3
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 -1
- package/cli/import.js +35 -5
- package/package.json +1 -1
- package/webpack.base.config.js +27 -3
- package/webpack.react.config.js +6 -1
package/README.md
CHANGED
package/cli/import.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const chalk = require('chalk');
|
|
1
5
|
const glob = require('glob');
|
|
2
6
|
|
|
3
7
|
const importSQL = require('../lib/importSQL');
|
|
@@ -10,10 +14,35 @@ const getMostRecentSqlFile = require('../utils/getMostRecentSqlFile');
|
|
|
10
14
|
// Constants
|
|
11
15
|
const { ENV_OPTIONS, SQL_FILE_NAME_ENV } = require('../constants');
|
|
12
16
|
|
|
17
|
+
function getRelativeTime(file) {
|
|
18
|
+
const diffMs = Date.now() - fs.statSync(file).mtime;
|
|
19
|
+
const diffMins = Math.floor(diffMs / 60000);
|
|
20
|
+
const diffHours = Math.floor(diffMins / 60);
|
|
21
|
+
const diffDays = Math.floor(diffHours / 24);
|
|
22
|
+
if (diffMins < 60) return `${diffMins}m ago`;
|
|
23
|
+
if (diffHours < 24) return `${diffHours}h ago`;
|
|
24
|
+
return `${diffDays}d ago`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function buildSqlChoices(files) {
|
|
28
|
+
const sorted = [...files].sort((a, b) => fs.statSync(b).mtime - fs.statSync(a).mtime);
|
|
29
|
+
const prodFiles = sorted.filter((f) => path.basename(f).includes(SQL_FILE_NAME_ENV.production));
|
|
30
|
+
const latestProd = prodFiles[0];
|
|
31
|
+
return sorted.map((file) => {
|
|
32
|
+
const name = path.basename(file);
|
|
33
|
+
const time = chalk.dim(`(${getRelativeTime(file)})`);
|
|
34
|
+
const isLatestProd = file === latestProd;
|
|
35
|
+
const label = isLatestProd
|
|
36
|
+
? `${chalk.green(name)} ${chalk.green('(latest)')} ${time}`
|
|
37
|
+
: `${name} ${time}`;
|
|
38
|
+
return { name: label, value: file, short: name };
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
13
42
|
function getEnvironmentFromFileName(file) {
|
|
14
43
|
let env;
|
|
15
44
|
|
|
16
|
-
Object.keys(SQL_FILE_NAME_ENV).forEach(key => {
|
|
45
|
+
Object.keys(SQL_FILE_NAME_ENV).forEach((key) => {
|
|
17
46
|
const namePrefix = SQL_FILE_NAME_ENV[key];
|
|
18
47
|
if (file.includes(namePrefix)) {
|
|
19
48
|
env = key;
|
|
@@ -27,13 +56,14 @@ module.exports = async () => {
|
|
|
27
56
|
const settings = getSettings();
|
|
28
57
|
const sqlDir = settings.directories.sql;
|
|
29
58
|
const sqlFiles = glob.sync(`${sqlDir}/**/*.sql`);
|
|
59
|
+
const sqlChoices = buildSqlChoices(sqlFiles);
|
|
30
60
|
|
|
31
61
|
try {
|
|
32
62
|
const options = await getCliOptions([
|
|
33
63
|
{
|
|
34
64
|
name: 'file',
|
|
35
65
|
message: 'Which file do you want to import?',
|
|
36
|
-
choices:
|
|
66
|
+
choices: sqlChoices,
|
|
37
67
|
type: 'list',
|
|
38
68
|
when: () => sqlFiles && sqlFiles.length,
|
|
39
69
|
},
|
|
@@ -42,14 +72,14 @@ module.exports = async () => {
|
|
|
42
72
|
message: 'Do you need to replace urls in the sql?',
|
|
43
73
|
type: 'confirm',
|
|
44
74
|
default: false,
|
|
45
|
-
when: answers => answers.file,
|
|
75
|
+
when: (answers) => answers.file,
|
|
46
76
|
},
|
|
47
77
|
{
|
|
48
78
|
name: 'environment',
|
|
49
79
|
message: 'Where environment are you importing from?',
|
|
50
80
|
choices: ENV_OPTIONS,
|
|
51
81
|
type: 'list',
|
|
52
|
-
when: answers => answers.replace,
|
|
82
|
+
when: (answers) => answers.replace,
|
|
53
83
|
},
|
|
54
84
|
{
|
|
55
85
|
name: 'currentEnvironment',
|
|
@@ -57,7 +87,7 @@ module.exports = async () => {
|
|
|
57
87
|
choices: ENV_OPTIONS,
|
|
58
88
|
default: 'local',
|
|
59
89
|
type: 'list',
|
|
60
|
-
when: answers => answers.replace,
|
|
90
|
+
when: (answers) => answers.replace,
|
|
61
91
|
},
|
|
62
92
|
]);
|
|
63
93
|
|
package/package.json
CHANGED
package/webpack.base.config.js
CHANGED
|
@@ -301,14 +301,38 @@ function makeBaseConfig(options) {
|
|
|
301
301
|
options: {
|
|
302
302
|
api: 'modern',
|
|
303
303
|
sourceMap: !isProd,
|
|
304
|
-
additionalData:
|
|
305
|
-
|
|
304
|
+
additionalData: (content, loaderContext) =>
|
|
305
|
+
loaderContext.resourcePath.endsWith('.css') ? content : sassVariables + content,
|
|
306
|
+
sassOptions: (loaderContext) => ({
|
|
307
|
+
syntax: loaderContext.resourcePath.endsWith('.css') ? 'scss' : undefined,
|
|
308
|
+
loadPaths: [process.cwd()],
|
|
309
|
+
// Handle @import 'node_modules/foo/bar' resolving to a .css file.
|
|
310
|
+
// Dart Sass won't find .css files when the extension is omitted, so
|
|
311
|
+
// we intercept those imports and load them manually.
|
|
312
|
+
importers: [
|
|
313
|
+
{
|
|
314
|
+
canonicalize(url) {
|
|
315
|
+
if (path.extname(url)) return null;
|
|
316
|
+
const cssPath = path.resolve(process.cwd(), url + '.css');
|
|
317
|
+
if (fs.existsSync(cssPath)) {
|
|
318
|
+
return new URL(`file://${cssPath}`);
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
},
|
|
322
|
+
load(canonicalUrl) {
|
|
323
|
+
return {
|
|
324
|
+
contents: fs.readFileSync(canonicalUrl.pathname, 'utf-8'),
|
|
325
|
+
syntax: 'css',
|
|
326
|
+
};
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
],
|
|
306
330
|
// Silence Dart Sass 2+ deprecation warnings from legacy project SCSS.
|
|
307
331
|
// These are expected in older projects and will need to be migrated
|
|
308
332
|
// project-by-project via: wp-scripts migrate-sass
|
|
309
333
|
// New projects using @use/@forward won't trigger these.
|
|
310
334
|
silenceDeprecations: ['import', 'color-functions', 'slash-div', 'global-builtin'],
|
|
311
|
-
},
|
|
335
|
+
}),
|
|
312
336
|
},
|
|
313
337
|
},
|
|
314
338
|
],
|
package/webpack.react.config.js
CHANGED
|
@@ -137,7 +137,12 @@ function makeReactWebpackConfig(options) {
|
|
|
137
137
|
options: {
|
|
138
138
|
sourceMap: !isProd,
|
|
139
139
|
api: 'modern',
|
|
140
|
-
additionalData: globalVariables
|
|
140
|
+
additionalData: globalVariables
|
|
141
|
+
? (content, loaderContext) =>
|
|
142
|
+
loaderContext.resourcePath.endsWith('.css')
|
|
143
|
+
? content
|
|
144
|
+
: globalVariables + content
|
|
145
|
+
: undefined,
|
|
141
146
|
},
|
|
142
147
|
},
|
|
143
148
|
],
|