new-s-block 1.0.5 → 1.0.7

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.
Files changed (2) hide show
  1. package/bin/cli.js +39 -0
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -56,10 +56,47 @@ function prompt(rl, question) {
56
56
  });
57
57
  }
58
58
 
59
+
60
+
61
+ // ── Version check ─────────────────────────────────────────────────────────
62
+
63
+ function checkForUpdate() {
64
+ return new Promise(function (resolve) {
65
+ var https = require('https');
66
+ var pkg = require('../package.json');
67
+ var req = https.get('https://registry.npmjs.org/new-s-block/latest', { timeout: 3000 }, function (res) {
68
+ var data = '';
69
+ res.on('data', function (chunk) { data += chunk; });
70
+ res.on('end', function () {
71
+ try {
72
+ var latest = JSON.parse(data).version;
73
+ if (latest && latest !== pkg.version) {
74
+ var yellow = '\x1b[33m';
75
+ var reset = '\x1b[0m';
76
+ console.log(yellow + ' \u26A0 Update available: ' + pkg.version + ' \u2192 ' + latest + reset);
77
+ console.log(yellow + ' Run: npx new-s-block@latest' + reset + '\n');
78
+ }
79
+ } catch (e) { /* silently ignore */ }
80
+ resolve();
81
+ });
82
+ });
83
+ req.on('error', function () { resolve(); });
84
+ req.on('timeout', function () { req.destroy(); resolve(); });
85
+ });
86
+ }
87
+ // ── Version flag ─────────────────────────────────────────────────────────
88
+
89
+ if (process.argv.includes('--version') || process.argv.includes('-v')) {
90
+ var pkg = require('../package.json');
91
+ console.log(pkg.version);
92
+ process.exit(0);
93
+ }
94
+
59
95
  // ── Main ───────────────────────────────────────────────────────────────────
60
96
 
61
97
  async function main() {
62
98
  console.log('\n\uD83E\uDDF1 ACF Block Generator\n');
99
+ var updateCheck = checkForUpdate();
63
100
 
64
101
  const rl = readline.createInterface({
65
102
  input: process.stdin,
@@ -76,6 +113,8 @@ async function main() {
76
113
  }
77
114
  }
78
115
 
116
+ await updateCheck;
117
+
79
118
  // 2. Block title
80
119
  const defaultLabel = toTitleCase(blockName);
81
120
  const labelRaw = await prompt(rl, 'Block title [' + defaultLabel + ']: ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "new-s-block",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "CLI tool to scaffold ACF Gutenberg blocks",
5
5
  "bin": {
6
6
  "new-s-block": "./bin/cli.js"