wp-blank-scripts 4.0.0-alpha.1 → 4.0.0-alpha.2

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
@@ -4,7 +4,7 @@ CLI and build tool for WordPress projects at ViVO Digital.
4
4
 
5
5
  ## Requirements
6
6
 
7
- - Node `>=22`
7
+ - Node `>=18`
8
8
  - MAMP (optional — skipped automatically if not installed)
9
9
 
10
10
  ## Project Structure
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: sqlFiles,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wp-blank-scripts",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "Personal Wordpress Scripts",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -301,8 +301,31 @@ function makeBaseConfig(options) {
301
301
  options: {
302
302
  api: 'modern',
303
303
  sourceMap: !isProd,
304
- additionalData: sassVariables,
304
+ additionalData: (content, loaderContext) =>
305
+ loaderContext.resourcePath.endsWith('.css') ? content : sassVariables + content,
305
306
  sassOptions: {
307
+ loadPaths: [process.cwd()],
308
+ // Handle @import 'node_modules/foo/bar' resolving to a .css file.
309
+ // Dart Sass won't find .css files when the extension is omitted, so
310
+ // we intercept those imports and load them manually.
311
+ importers: [
312
+ {
313
+ canonicalize(url) {
314
+ if (path.extname(url)) return null;
315
+ const cssPath = path.resolve(process.cwd(), url + '.css');
316
+ if (fs.existsSync(cssPath)) {
317
+ return new URL(`file://${cssPath}`);
318
+ }
319
+ return null;
320
+ },
321
+ load(canonicalUrl) {
322
+ return {
323
+ contents: fs.readFileSync(canonicalUrl.pathname, 'utf-8'),
324
+ syntax: 'css',
325
+ };
326
+ },
327
+ },
328
+ ],
306
329
  // Silence Dart Sass 2+ deprecation warnings from legacy project SCSS.
307
330
  // These are expected in older projects and will need to be migrated
308
331
  // project-by-project via: wp-scripts migrate-sass
@@ -137,7 +137,12 @@ function makeReactWebpackConfig(options) {
137
137
  options: {
138
138
  sourceMap: !isProd,
139
139
  api: 'modern',
140
- additionalData: globalVariables || undefined,
140
+ additionalData: globalVariables
141
+ ? (content, loaderContext) =>
142
+ loaderContext.resourcePath.endsWith('.css')
143
+ ? content
144
+ : globalVariables + content
145
+ : undefined,
141
146
  },
142
147
  },
143
148
  ],