@magmonium/cli 0.10.7 → 0.10.10

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.
@@ -105,10 +105,12 @@ function emitFrom(root, tests) {
105
105
  }
106
106
  const source = read.source;
107
107
  if (source.codegen && isNewer(source.codegen, pkg.version)) {
108
- throw new Error(
108
+ const error = new Error(
109
109
  `the design was written by @magmonium/cli ${source.codegen}, newer than this ${pkg.version}.\n` +
110
110
  ` Pin the version it needs: npm install --save-dev --save-exact @magmonium/cli@${source.codegen}`
111
111
  );
112
+ error.needs = source.codegen;
113
+ throw error;
112
114
  }
113
115
 
114
116
  const ws = {
@@ -240,6 +242,8 @@ async function watchGenerated({
240
242
  `🔁 gen-code: ${reason} → ${result.written.length} written, ${result.removed.length} removed`
241
243
  );
242
244
  } catch (error) {
245
+ // Too old a CLI at start: the caller upgrades and runs the watch again.
246
+ if (error.needs && reason === 'start') throw error;
243
247
  // A design file mid-save or hand-broken: the code on disk stays as the
244
248
  // last good emit until the next save reads cleanly.
245
249
  log(`⚠️ gen-code: ${error.message}`);
@@ -309,6 +313,38 @@ async function watchGenerated({
309
313
  return { close };
310
314
  }
311
315
 
316
+ /** Set on the re-run so a still-too-old install cannot loop. */
317
+ const UPGRADED_ENV = 'MAG_CLI_UPGRADED';
318
+
319
+ /**
320
+ * The design needs a newer CLI than the app has installed: pin that exact
321
+ * version in the app, then run the same `gen-code` again from the new install.
322
+ * Exits with the re-run's code, so `prestart` goes on to `ng serve` after it.
323
+ */
324
+ function upgradeAndRerun(root, needs) {
325
+ const { spawnSync } = require('child_process');
326
+ const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
327
+ console.log(
328
+ `⬆️ gen-code: the design needs @magmonium/cli ${needs} (installed ${pkg.version}) — installing it`
329
+ );
330
+ const install = spawnSync(
331
+ npm,
332
+ ['install', '--save-dev', '--save-exact', `@magmonium/cli@${needs}`],
333
+ { cwd: root, stdio: 'inherit', shell: process.platform === 'win32' }
334
+ );
335
+ if (install.status !== 0) {
336
+ console.error(`❌ gen-code: npm install @magmonium/cli@${needs} failed`);
337
+ process.exit(install.status || 1);
338
+ }
339
+ const bin = path.join(root, 'node_modules', '@magmonium', 'cli', 'bin', 'cli.js');
340
+ const rerun = spawnSync(process.execPath, [bin, ...process.argv.slice(2)], {
341
+ cwd: process.cwd(),
342
+ stdio: 'inherit',
343
+ env: { ...process.env, [UPGRADED_ENV]: needs },
344
+ });
345
+ process.exit(rerun.status ?? 1);
346
+ }
347
+
312
348
  function genCodeCommand(program) {
313
349
  program
314
350
  .command('gen-code')
@@ -321,14 +357,25 @@ function genCodeCommand(program) {
321
357
  'Keep regenerating on every .magmonium/ change, and put back hand edits to generated files'
322
358
  )
323
359
  .option('--run <command>', 'With --watch: run this command beside the watch (e.g. "ng serve")')
360
+ .option(
361
+ '--no-install',
362
+ 'Fail instead of installing the newer @magmonium/cli the design needs'
363
+ )
324
364
  .action(async (options) => {
325
365
  const root = options.root || process.cwd();
366
+ const fail = (error) => {
367
+ if (error.needs && options.install && !process.env[UPGRADED_ENV]) {
368
+ upgradeAndRerun(root, error.needs);
369
+ return;
370
+ }
371
+ console.error(`❌ gen-code: ${error.message}`);
372
+ process.exit(1);
373
+ };
326
374
  if (options.watch) {
327
375
  try {
328
376
  await watchGenerated({ root, run: options.run });
329
377
  } catch (error) {
330
- console.error(`❌ gen-code: ${error.message}`);
331
- process.exit(1);
378
+ fail(error);
332
379
  }
333
380
  return;
334
381
  }
@@ -338,8 +385,7 @@ function genCodeCommand(program) {
338
385
  `✅ gen-code: ${written} file(s) generated from ${DESIGN_ROOT}/`
339
386
  );
340
387
  } catch (error) {
341
- console.error(`❌ gen-code: ${error.message}`);
342
- process.exit(1);
388
+ fail(error);
343
389
  }
344
390
  });
345
391
  }
package/codegen/index.js CHANGED
@@ -29003,7 +29003,7 @@ __export(package_exports, {
29003
29003
  version: () => version
29004
29004
  });
29005
29005
  var name = "@magmonium/one";
29006
- var version = "0.4.131";
29006
+ var version = "0.4.135";
29007
29007
  var description = "Magmonium One \u2014 Angular design-system primitives for mm Apps";
29008
29008
  var author = "magmonium";
29009
29009
  var license = "MIT";
@@ -29071,7 +29071,7 @@ __export(package_exports2, {
29071
29071
  version: () => version2
29072
29072
  });
29073
29073
  var name2 = "@magmonium/cli";
29074
- var version2 = "0.10.7";
29074
+ var version2 = "0.10.10";
29075
29075
  var description2 = "A powerful and extensible asset compilation tool that can be shared across multiple projects";
29076
29076
  var bin = {
29077
29077
  "mag-cli": "bin/cli.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magmonium/cli",
3
- "version": "0.10.7",
3
+ "version": "0.10.10",
4
4
  "description": "A powerful and extensible asset compilation tool that can be shared across multiple projects",
5
5
  "bin": {
6
6
  "mag-cli": "bin/cli.js"