@svgrid/ui 0.3.1 → 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.
- package/index.mjs +31 -19
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -345,26 +345,30 @@ async function cmdAdd(registry, tokens, args) {
|
|
|
345
345
|
return
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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('
|
|
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,14 +382,22 @@ async function cmdAdd(registry, tokens, args) {
|
|
|
378
382
|
}
|
|
379
383
|
}
|
|
380
384
|
|
|
381
|
-
// Next steps
|
|
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 (
|
|
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 {
|
|
385
398
|
stdout.write(` ${color('dim', 'Use it:')} import { ${exportName(first.id)} } from '@svgrid/grid'\n`)
|
|
386
399
|
// "See it" - skip when we already wrote preview routes just above.
|
|
387
400
|
if (!(args.preview && isSvelteKit(projectRoot))) {
|
|
388
|
-
const ids = items.map((it) => it.id).join(' ')
|
|
389
401
|
stdout.write(` ${color('dim', 'See it:')} ${color('cyan', `npx @svgrid/ui try ${ids}`)} ${color('dim', '(opens in your browser)')}\n`)
|
|
390
402
|
if (isSvelteKit(projectRoot)) {
|
|
391
403
|
stdout.write(` ${color('dim', 'In app:')} re-run with ${color('cyan', '--preview')} to add a /preview/${first.id} route\n`)
|
package/package.json
CHANGED