({ args })
| 248 | }, |
| 249 | }, |
| 250 | async run({ args }) { |
| 251 | const projectDir = resolve(args.dir ?? process.cwd()); |
| 252 | const json = args.json === true; |
| 253 | const skipClipboard = args["no-clipboard"] === true; |
| 254 | const hasConfigBefore = existsSync(projectConfigPath(projectDir)); |
| 255 | |
| 256 | // Try single item first. If it fails, check if the name matches a tag. |
| 257 | try { |
| 258 | const result = await runAdd({ name: args.name, projectDir, skipClipboard }); |
| 259 | const wroteConfig = !hasConfigBefore && existsSync(projectConfigPath(projectDir)); |
| 260 | |
| 261 | if (json) { |
| 262 | console.log(JSON.stringify(result)); |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | if (wroteConfig) { |
| 267 | console.log(c.dim(`Wrote default ${projectConfigPath(projectDir)}`)); |
| 268 | } |
| 269 | for (const warning of result.warnings) { |
| 270 | console.warn(c.warn(`Warning: ${warning}`)); |
| 271 | } |
| 272 | console.log(""); |
| 273 | console.log(`${c.success("✓")} Added ${c.accent(result.name)} (${result.type})`); |
| 274 | for (const file of result.written) { |
| 275 | console.log(` ${c.dim(relative(projectDir, file))}`); |
| 276 | } |
| 277 | if (result.snippet) { |
| 278 | console.log(""); |
| 279 | console.log(c.dim("Include snippet:")); |
| 280 | console.log(` ${result.snippet}`); |
| 281 | console.log(""); |
| 282 | console.log( |
| 283 | result.clipboardCopied |
| 284 | ? c.dim("Copied to clipboard — paste into your host composition.") |
| 285 | : c.dim("Paste the snippet above into your host composition."), |
| 286 | ); |
| 287 | } |
| 288 | } catch (singleErr) { |
| 289 | // Not a single item — try as a tag for bulk install |
| 290 | if (!(singleErr instanceof AddError) || singleErr.code !== "unknown-item") { |
| 291 | const msg = singleErr instanceof Error ? singleErr.message : String(singleErr); |
| 292 | if (json) console.log(JSON.stringify({ ok: false, error: msg })); |
| 293 | else console.error(c.error(msg)); |
| 294 | process.exit(1); |
| 295 | } |
| 296 | |
| 297 | let config = loadProjectConfig(projectDir); |
| 298 | if ( |
| 299 | !existsSync(projectConfigPath(projectDir)) && |
| 300 | existsSync(resolve(projectDir, "index.html")) |
| 301 | ) { |
| 302 | writeProjectConfig(projectDir, DEFAULT_PROJECT_CONFIG); |
| 303 | config = DEFAULT_PROJECT_CONFIG; |
| 304 | } |
| 305 | |
| 306 | let items: Awaited<ReturnType<typeof resolveItemsByTag>>; |
| 307 | try { |
nothing calls this directly
no test coverage detected