@svgrid/ui 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/index.mjs +39 -19
  2. package/package.json +2 -2
package/index.mjs CHANGED
@@ -345,26 +345,30 @@ async function cmdAdd(registry, tokens, args) {
345
345
  return
346
346
  }
347
347
 
348
- // Ensure deps + install (on by default; --no-install just prints the command).
349
- const added = await ensureDeps(projectRoot, [...deps])
350
- const pm = detectPm(projectRoot)
351
- if (added.length) {
352
- if (args.install && projectRoot) {
353
- stdout.write(`\n${color('dim', `Installing with ${pm.id}...`)}\n`)
354
- // Single shell string (not bin + args[]) so Node doesn't warn DEP0190
355
- // under shell:true; the tokens here are fixed pm commands + npm package ids.
356
- const res = spawnSync(`${pm.add} ${added.join(' ')}`, { cwd: projectRoot, stdio: 'inherit', shell: true })
357
- if (res.status !== 0) {
358
- stdout.write(`${color('yellow', '!')} Install failed - run it yourself: ${color('cyan', `${pm.add} ${added.join(' ')}`)}\n`)
348
+ // Install the dependency - only meaningful inside a project (on by default;
349
+ // --no-install just prints the command). `add` writes into an EXISTING app;
350
+ // a no-project run is handled in the next-steps block below.
351
+ if (projectRoot) {
352
+ const pm = detectPm(projectRoot)
353
+ const added = await ensureDeps(projectRoot, [...deps])
354
+ if (added.length) {
355
+ if (args.install) {
356
+ stdout.write(`\n${color('dim', `Installing with ${pm.id}...`)}\n`)
357
+ // Single shell string (not bin + args[]) so Node doesn't warn DEP0190
358
+ // under shell:true; the tokens here are fixed pm commands + npm package ids.
359
+ const res = spawnSync(`${pm.add} ${added.join(' ')}`, { cwd: projectRoot, stdio: 'inherit', shell: true })
360
+ if (res.status !== 0) {
361
+ stdout.write(`${color('yellow', '!')} Install failed - run it yourself: ${color('cyan', `${pm.add} ${added.join(' ')}`)}\n`)
362
+ }
363
+ } else {
364
+ stdout.write(`\n${color('bold', 'Install the dependency')}\n ${color('cyan', `${pm.add} ${added.join(' ')}`)}\n`)
359
365
  }
360
- } else {
361
- stdout.write(`\n${color('bold', 'Install the dependency')}\n ${color('cyan', `${pm.add} ${added.join(' ')}`)}\n`)
366
+ } else if ([...deps].length) {
367
+ stdout.write(`\n${color('dim', `${[...deps].join(', ')} already in package.json.`)}\n`)
362
368
  }
363
- } else if ([...deps].length) {
364
- stdout.write(`\n${color('dim', `${[...deps].join(', ')} already in package.json.`)}\n`)
365
369
  }
366
370
 
367
- // Optional preview route(s).
371
+ // Optional preview route(s) - needs a SvelteKit project.
368
372
  if (args.preview) {
369
373
  if (isSvelteKit(projectRoot)) {
370
374
  const urls = await writePreviewRoutes(projectRoot, dest, items, args.force)
@@ -378,11 +382,27 @@ async function cmdAdd(registry, tokens, args) {
378
382
  }
379
383
  }
380
384
 
381
- // Usage hint.
385
+ // Next steps.
382
386
  const first = items[0]
387
+ const ids = items.map((it) => it.id).join(' ')
383
388
  stdout.write(`\n${color('green', '✔')} Added ${written.length} file(s). They're yours - edit away.\n`)
384
- if (first) {
385
- stdout.write(` ${color('dim', 'Use it:')} import { ${exportName(first.id)} } from '@svgrid/grid'\n`)
389
+ if (!projectRoot) {
390
+ // A lone component file with no app to run it - `add` targets an existing
391
+ // project. Point at the two real paths instead of leaving a stranded file.
392
+ stdout.write(
393
+ ` ${color('yellow', 'Heads up:')} no package.json here, so there's nothing to run this in yet.\n` +
394
+ ` ${color('dim', 'See it now:')} ${color('cyan', `npx @svgrid/ui try ${ids}`)} ${color('dim', '(no project needed)')}\n` +
395
+ ` ${color('dim', 'Start an app:')} ${color('cyan', 'npm create @svgrid@latest')} ${color('dim', '(then run add inside it)')}\n`,
396
+ )
397
+ } else {
398
+ stdout.write(` ${color('dim', 'Use it:')} import { ${exportName(first.id)} } from '@svgrid/grid'\n`)
399
+ // "See it" - skip when we already wrote preview routes just above.
400
+ if (!(args.preview && isSvelteKit(projectRoot))) {
401
+ stdout.write(` ${color('dim', 'See it:')} ${color('cyan', `npx @svgrid/ui try ${ids}`)} ${color('dim', '(opens in your browser)')}\n`)
402
+ if (isSvelteKit(projectRoot)) {
403
+ stdout.write(` ${color('dim', 'In app:')} re-run with ${color('cyan', '--preview')} to add a /preview/${first.id} route\n`)
404
+ }
405
+ }
386
406
  }
387
407
  stdout.write(`\n${color('dim', 'Docs:')} https://www.svgrid.com/docs/help/ui-components\n\n`)
388
408
  }
package/package.json CHANGED
@@ -4,8 +4,8 @@
4
4
  "type": "commercial",
5
5
  "url": "https://svgrid.com/pricing"
6
6
  },
7
- "version": "0.3.0",
8
- "description": "Add SvGrid UI components to your app in one command: npx @svgrid/ui add calendar",
7
+ "version": "0.3.2",
8
+ "description": "Add and preview SvGrid UI components in one command: npx @svgrid/ui try calendar",
9
9
  "type": "module",
10
10
  "license": "MIT",
11
11
  "author": "jQWidgets Ltd",