@magmonium/cli 0.8.0 → 0.8.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.
@@ -17,11 +17,34 @@ function bumpPatchVersion(version) {
17
17
  return `${major}.${minor}.${patch}`;
18
18
  }
19
19
 
20
+ /**
21
+ * Which app a `mag_assets` source belongs to, and where its bundle goes.
22
+ *
23
+ * Monorepo: `apps/m-comics/mag_assets` → `m-comics`, into `dist/apps/m-comics-wc`.
24
+ *
25
+ * Standalone (an app scaffolded by the m-one-ui editor): `mag_assets` sits at
26
+ * the root, so the folder above it names nothing — `path.basename('.')` is `.`.
27
+ * The app is its one manifest in `remote/`, whose file name is the slug the
28
+ * scaffold's `cd.yml` zips from `dist/<slug>-wc` (ADR 0087).
29
+ */
30
+ function resolveApp(source, remoteFiles) {
31
+ const appDir = path.dirname(source);
32
+ if (path.resolve(appDir) !== process.cwd()) {
33
+ const appName = path.basename(appDir);
34
+ return { appName, distDestDir: path.join('dist', 'apps', `${appName}-wc`) };
35
+ }
36
+
37
+ const manifests = remoteFiles.filter((f) => f.endsWith('.yml'));
38
+ if (manifests.length !== 1) return { appName: null, distDestDir: null };
39
+ const appName = path.basename(manifests[0], '.yml');
40
+ return { appName, distDestDir: path.join('dist', `${appName}-wc`) };
41
+ }
42
+
20
43
  function assetsWcCommand(program) {
21
44
  program
22
45
  .command('assets-wc')
23
46
  .description(
24
- "Compile all assets then copy each WC app's public/assets to dist/apps/{appName}-wc/"
47
+ "Compile all assets then copy each WC app's public/assets to dist/apps/{appName}-wc/ (standalone: dist/{appName}-wc/)"
25
48
  )
26
49
  .option('-c, --config <path>', 'Config file path', './mag-cli.config.js')
27
50
  .option('-a, --app <name>', 'Target app name (e.g., m-comics)')
@@ -115,14 +138,13 @@ function assetsWcCommand(program) {
115
138
  const remoteDir = path.join(source, 'remote');
116
139
  if (!fs.existsSync(remoteDir)) continue;
117
140
 
118
- // Derive appName: apps/m-comics/mag_assets → m-comics
119
- const appDir = path.dirname(source);
120
- const appName = path.basename(appDir);
141
+ const remoteFiles = fs.readdirSync(remoteDir);
142
+ const { appName, distDestDir } = resolveApp(source, remoteFiles);
143
+ if (!appName) continue;
121
144
 
122
145
  if (options.app && options.app !== appName) continue;
123
146
 
124
147
  const expectedYml = `${appName}.yml`;
125
- const remoteFiles = fs.readdirSync(remoteDir);
126
148
  if (!remoteFiles.includes(expectedYml)) continue;
127
149
 
128
150
  try {
@@ -171,9 +193,6 @@ function assetsWcCommand(program) {
171
193
  );
172
194
  }
173
195
 
174
- // Destination: dist/apps/m-comics-wc (for CI/CD bundle)
175
- const distDestDir = path.join('dist', 'apps', `${appName}-wc`);
176
-
177
196
  console.log(`\n ${appName}`);
178
197
  console.log(` source : ${output}`);
179
198
  console.log(` dist : ${distDestDir}`);
@@ -195,7 +214,12 @@ function assetsWcCommand(program) {
195
214
  // ── WC JS bundle ─────────────────────────────────────────────────
196
215
  const remoteDistDir = path.join(distDestDir, 'remote');
197
216
  console.log(` 🔧 Building WC JS bundle...`);
198
- await new WebComponentBuilder(remoteDir, remoteDistDir).compile();
217
+ const built = await new WebComponentBuilder(
218
+ remoteDir,
219
+ remoteDistDir
220
+ ).compile();
221
+ if (built.length === 0)
222
+ throw new Error(`no WC bundle built from ${remoteDir}`);
199
223
  console.log(` ✅ WC bundle → ${remoteDistDir}`);
200
224
 
201
225
  // ── PWA build (if pwa: key present in YAML) ─────────────────────
@@ -220,7 +244,16 @@ function assetsWcCommand(program) {
220
244
 
221
245
  console.log('\n──────────────────────────────────────');
222
246
  if (results.length === 0) {
223
- console.log(' ℹ️ No WC-enabled apps found.');
247
+ // Without `--app`, nothing built is a failure, not a no-op: the CD step
248
+ // after this zips a dist folder that was never written, and fails there
249
+ // instead. `--app m-ui` builds nothing by design — m-ui has no manifest
250
+ // and runs this only for the filtered compile.
251
+ if (options.app) {
252
+ console.log(' ℹ️ No WC-enabled apps found.');
253
+ } else {
254
+ console.error(' ❌ No WC-enabled apps found.');
255
+ process.exit(1);
256
+ }
224
257
  } else {
225
258
  for (const r of results) {
226
259
  if (r.status === 'ok') console.log(` ✅ ${r.appName}`);