create-semaphor-app 0.1.3 → 0.1.4

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/README.md CHANGED
@@ -32,10 +32,52 @@ Options:
32
32
  --install-claude-plugin Install the Claude Code plugin without prompting.
33
33
  --template <source> Starter source. Defaults to the public starter repo.
34
34
  --template-ref <ref> Git branch/tag for the default starter repo. Defaults to main.
35
+ --shadcn-preset <preset> Apply a shadcn preset before adding Semaphor components.
36
+ --shadcn-base <base> Pass base or radix to shadcn init when using a preset.
37
+ --components <list> Add Semaphor registry components. Use none, query, metrics,
38
+ filters, card, table, matrix, recommended, all, or a comma-separated list.
35
39
  --yes Use noninteractive defaults; skip optional plugin installs unless explicit.
36
40
  --help Show help.
37
41
  ```
38
42
 
43
+ ## shadcn Presets And Semaphor Components
44
+
45
+ The starter ships with a working shadcn setup. For teams that bring their own
46
+ style, pass a shadcn preset during creation:
47
+
48
+ ```bash
49
+ npx create-semaphor-app@latest my-app --shadcn-preset <preset-id>
50
+ ```
51
+
52
+ Semaphor UI helpers can be added from the public shadcn registry at scaffold
53
+ time:
54
+
55
+ ```bash
56
+ npx create-semaphor-app@latest my-app --components table
57
+ npx create-semaphor-app@latest my-app --components query-state,view-card,metric-kpis,filter-controls,server-data-table,matrix-table
58
+ ```
59
+
60
+ Component presets:
61
+
62
+ | Value | Installs |
63
+ | --- | --- |
64
+ | `none` | No Semaphor registry components. This is the default. |
65
+ | `query` | `query-state` |
66
+ | `metrics` | `query-state-boundary`, `metric-kpis` |
67
+ | `filters` | `filter-controls` |
68
+ | `card` | `view-card` |
69
+ | `table` | `query-state`, `server-data-table` |
70
+ | `matrix` | `query-state`, `matrix-table` |
71
+ | `recommended` | `query-state`, `query-state-boundary`, `view-card`, `metric-kpis`, `filter-controls`, `server-data-table` |
72
+ | `all` | `query-state`, `query-state-boundary`, `view-card`, `metric-kpis`, `filter-controls`, `server-data-table`, `matrix-table` |
73
+
74
+ Registry components install as source into the generated app. They are optional
75
+ UI accelerators and do not replace `react-semaphor/data-app-sdk`.
76
+
77
+ `--shadcn-preset` and `--components` run the shadcn CLI, so they cannot be
78
+ combined with `--no-install`. To skip installs, scaffold the app first and run
79
+ the shadcn commands manually later.
80
+
39
81
  ## Local Validation
40
82
 
41
83
  ```bash
@@ -13,6 +13,47 @@ const DEFAULT_TEMPLATE_REF = 'main';
13
13
  const DEFAULT_APP_NAME = 'semaphor-data-app';
14
14
  const MARKETPLACE = 'semaphor-analytics/agent-plugin';
15
15
  const PLUGIN_ID = 'semaphor@semaphor-analytics';
16
+ const SEMAPHOR_COMPONENT_REGISTRY = 'semaphor-analytics/semaphor-data-app-components';
17
+ const SEMAPHOR_COMPONENT_PRESETS = Object.freeze({
18
+ none: [],
19
+ query: ['query-state'],
20
+ table: ['query-state', 'server-data-table'],
21
+ metrics: ['query-state-boundary', 'metric-kpis'],
22
+ filters: ['filter-controls'],
23
+ card: ['view-card'],
24
+ matrix: ['query-state', 'matrix-table'],
25
+ recommended: [
26
+ 'query-state',
27
+ 'query-state-boundary',
28
+ 'view-card',
29
+ 'metric-kpis',
30
+ 'filter-controls',
31
+ 'server-data-table',
32
+ ],
33
+ all: [
34
+ 'query-state',
35
+ 'query-state-boundary',
36
+ 'view-card',
37
+ 'metric-kpis',
38
+ 'filter-controls',
39
+ 'server-data-table',
40
+ 'matrix-table',
41
+ ],
42
+ });
43
+ const SEMAPHOR_COMPONENT_ALIASES = Object.freeze({
44
+ 'query-state': 'query-state',
45
+ 'query-state-boundary': 'query-state-boundary',
46
+ 'view-card': 'view-card',
47
+ card: 'view-card',
48
+ 'server-data-table': 'server-data-table',
49
+ table: 'server-data-table',
50
+ 'metric-kpis': 'metric-kpis',
51
+ kpis: 'metric-kpis',
52
+ 'filter-controls': 'filter-controls',
53
+ filters: 'filter-controls',
54
+ 'matrix-table': 'matrix-table',
55
+ matrix: 'matrix-table',
56
+ });
16
57
  const canPrompt = Boolean(process.stdin.isTTY && process.stdout.isTTY);
17
58
 
18
59
  const cwd = process.cwd();
@@ -31,6 +72,10 @@ Options:
31
72
  --install-claude-plugin Install the Claude Code plugin without prompting.
32
73
  --template <source> Starter source. Can be a local directory or git URL.
33
74
  --template-ref <ref> Git branch/tag for the default starter repo.
75
+ --shadcn-preset <preset> Apply a shadcn preset before adding Semaphor components.
76
+ --shadcn-base <base> Pass base or radix to shadcn init when using a preset.
77
+ --components <list> Add Semaphor registry components. Use none, query, metrics,
78
+ filters, card, table, matrix, recommended, all, or a comma-separated list.
34
79
  --yes, -y Use noninteractive defaults; skip optional plugin installs unless explicit.
35
80
  --help, -h Show this help.
36
81
  `;
@@ -46,6 +91,9 @@ function parseArgs(argv) {
46
91
  installClaudePlugin: false,
47
92
  template: DEFAULT_TEMPLATE_REPO,
48
93
  templateRef: DEFAULT_TEMPLATE_REF,
94
+ shadcnPreset: null,
95
+ shadcnBase: null,
96
+ components: 'none',
49
97
  yes: false,
50
98
  help: false,
51
99
  };
@@ -74,6 +122,18 @@ function parseArgs(argv) {
74
122
  parsed.templateRef = readRequiredValue(argv, ++i, arg);
75
123
  } else if (arg.startsWith('--template-ref=')) {
76
124
  parsed.templateRef = arg.slice('--template-ref='.length);
125
+ } else if (arg === '--shadcn-preset') {
126
+ parsed.shadcnPreset = readRequiredValue(argv, ++i, arg);
127
+ } else if (arg.startsWith('--shadcn-preset=')) {
128
+ parsed.shadcnPreset = arg.slice('--shadcn-preset='.length);
129
+ } else if (arg === '--shadcn-base') {
130
+ parsed.shadcnBase = readRequiredValue(argv, ++i, arg);
131
+ } else if (arg.startsWith('--shadcn-base=')) {
132
+ parsed.shadcnBase = arg.slice('--shadcn-base='.length);
133
+ } else if (arg === '--components') {
134
+ parsed.components = readRequiredValue(argv, ++i, arg);
135
+ } else if (arg.startsWith('--components=')) {
136
+ parsed.components = arg.slice('--components='.length);
77
137
  } else if (arg === '--yes' || arg === '-y') {
78
138
  parsed.yes = true;
79
139
  } else if (arg.startsWith('-')) {
@@ -225,6 +285,23 @@ function resolvePackageManager(requested) {
225
285
  return 'npm';
226
286
  }
227
287
 
288
+ function hasOwn(object, key) {
289
+ return Object.prototype.hasOwnProperty.call(object, key);
290
+ }
291
+
292
+ function resolveShadcnRunner(packageManager) {
293
+ if (packageManager === 'pnpm') {
294
+ return { command: 'pnpm', args: ['dlx', 'shadcn@latest'] };
295
+ }
296
+ if (packageManager === 'yarn') {
297
+ return { command: 'yarn', args: ['dlx', 'shadcn@latest'] };
298
+ }
299
+ if (packageManager === 'bun') {
300
+ return { command: 'bunx', args: ['--bun', 'shadcn@latest'] };
301
+ }
302
+ return { command: 'npx', args: ['shadcn@latest'] };
303
+ }
304
+
228
305
  function installArgs(packageManager) {
229
306
  if (packageManager === 'yarn') return [];
230
307
  return ['install'];
@@ -315,6 +392,107 @@ function loadTemplate(template, templateRef) {
315
392
  return { tempRoot, templateDir };
316
393
  }
317
394
 
395
+ function normalizeSemaphorComponents(value) {
396
+ const raw = String(value || 'none')
397
+ .split(',')
398
+ .map((entry) => entry.trim().toLowerCase())
399
+ .filter(Boolean);
400
+ if (raw.length === 0) return [];
401
+
402
+ const components = [];
403
+ for (const entry of raw) {
404
+ if (hasOwn(SEMAPHOR_COMPONENT_PRESETS, entry)) {
405
+ components.push(...SEMAPHOR_COMPONENT_PRESETS[entry]);
406
+ continue;
407
+ }
408
+ if (!hasOwn(SEMAPHOR_COMPONENT_ALIASES, entry)) {
409
+ throw new Error(
410
+ `Unsupported Semaphor component "${entry}". Use none, query, metrics, filters, card, table, matrix, recommended, all, or one of ${Object.keys(SEMAPHOR_COMPONENT_ALIASES).join(', ')}.`,
411
+ );
412
+ }
413
+ components.push(SEMAPHOR_COMPONENT_ALIASES[entry]);
414
+ }
415
+
416
+ return Array.from(new Set(components));
417
+ }
418
+
419
+ function normalizeShadcnBase(value) {
420
+ if (!value) return null;
421
+ const normalized = String(value).trim().toLowerCase();
422
+ if (!['base', 'radix'].includes(normalized)) {
423
+ throw new Error('--shadcn-base must be base or radix.');
424
+ }
425
+ return normalized;
426
+ }
427
+
428
+ function validateScaffoldOptions(args) {
429
+ const components = normalizeSemaphorComponents(args.components);
430
+ normalizeShadcnBase(args.shadcnBase);
431
+
432
+ if (args.shadcnBase && !args.shadcnPreset) {
433
+ throw new Error('--shadcn-base requires --shadcn-preset.');
434
+ }
435
+
436
+ if (args.shadcnPreset !== null && String(args.shadcnPreset).trim() === '') {
437
+ throw new Error('--shadcn-preset requires a non-empty preset id.');
438
+ }
439
+
440
+ if (!args.install && (args.shadcnPreset || components.length > 0)) {
441
+ throw new Error(
442
+ '--no-install cannot be combined with --shadcn-preset or --components. Run create-semaphor-app with installs enabled, or add shadcn components manually after scaffolding.',
443
+ );
444
+ }
445
+ }
446
+
447
+ function runShadcn(packageManager, targetDir, args) {
448
+ const runner = resolveShadcnRunner(packageManager);
449
+ ensureCommand(runner.command, runner.command);
450
+ runRequired(runner.command, [...runner.args, ...args], {
451
+ cwd: targetDir,
452
+ stdio: 'inherit',
453
+ });
454
+ }
455
+
456
+ function customizeShadcn(args, packageManager, targetDir) {
457
+ const components = normalizeSemaphorComponents(args.components);
458
+ const shadcnBase = normalizeShadcnBase(args.shadcnBase);
459
+
460
+ if (!args.shadcnPreset && components.length === 0) {
461
+ return { presetApplied: false, components };
462
+ }
463
+
464
+ if (args.shadcnPreset) {
465
+ const initArgs = [
466
+ 'init',
467
+ '--preset',
468
+ args.shadcnPreset,
469
+ '--template',
470
+ 'vite',
471
+ '--force',
472
+ '--reinstall',
473
+ ];
474
+ if (shadcnBase) {
475
+ initArgs.push('--base', shadcnBase);
476
+ }
477
+ console.log(`\nApplying shadcn preset ${args.shadcnPreset}...`);
478
+ runShadcn(packageManager, targetDir, initArgs);
479
+ console.log('✓ Applied shadcn preset');
480
+ }
481
+
482
+ if (components.length > 0) {
483
+ console.log('\nAdding Semaphor registry components...');
484
+ for (const component of components) {
485
+ runShadcn(packageManager, targetDir, [
486
+ 'add',
487
+ `${SEMAPHOR_COMPONENT_REGISTRY}/${component}`,
488
+ ]);
489
+ console.log(`✓ Added ${component}`);
490
+ }
491
+ }
492
+
493
+ return { presetApplied: Boolean(args.shadcnPreset), components };
494
+ }
495
+
318
496
  function detectAgents() {
319
497
  return {
320
498
  codex: commandExists('codex'),
@@ -411,12 +589,22 @@ async function maybeInstallPlugins(args, rl) {
411
589
  return { detected, results, skipped: false };
412
590
  }
413
591
 
414
- function printNextSteps({ targetDir, packageManager, pluginSummary }) {
592
+ function printNextSteps({ targetDir, packageManager, pluginSummary, shadcnSummary }) {
415
593
  const relativeTarget = path.relative(cwd, targetDir) || '.';
416
594
  console.log('\nNext:');
417
595
  console.log(` cd ${relativeTarget}`);
418
596
  console.log(` ${packageManager} run dev`);
419
597
 
598
+ if (shadcnSummary?.presetApplied || shadcnSummary?.components?.length > 0) {
599
+ console.log('\nConfigured shadcn:');
600
+ if (shadcnSummary.presetApplied) {
601
+ console.log(' - Applied custom preset');
602
+ }
603
+ for (const component of shadcnSummary.components ?? []) {
604
+ console.log(` - Added Semaphor ${component}`);
605
+ }
606
+ }
607
+
420
608
  if (pluginSummary?.skipped) {
421
609
  printPluginInstructions();
422
610
  printBuildPrompt();
@@ -487,6 +675,14 @@ async function main() {
487
675
  console.log(usage());
488
676
  return;
489
677
  }
678
+ try {
679
+ validateScaffoldOptions(args);
680
+ } catch (error) {
681
+ console.error(error instanceof Error ? error.message : String(error));
682
+ console.error('');
683
+ console.error(usage());
684
+ process.exit(1);
685
+ }
490
686
 
491
687
  const rl = readline.createInterface({
492
688
  input: process.stdin,
@@ -520,11 +716,13 @@ async function main() {
520
716
  console.log('Skipping dependency installation.');
521
717
  }
522
718
 
719
+ const shadcnSummary = customizeShadcn(args, packageManager, target.targetDir);
523
720
  const pluginSummary = await maybeInstallPlugins(args, rl);
524
721
  printNextSteps({
525
722
  targetDir: target.targetDir,
526
723
  packageManager,
527
724
  pluginSummary,
725
+ shadcnSummary,
528
726
  });
529
727
  } catch (error) {
530
728
  console.error('\nUnable to create Semaphor app.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-semaphor-app",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Create a Semaphor Data App starter project.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -168,6 +168,100 @@ async function main() {
168
168
  console.log('✓ fake Codex plugin install path');
169
169
  }
170
170
 
171
+ {
172
+ const root = createTempRoot('shadcn-');
173
+ const binDir = path.join(root, 'bin');
174
+ fs.mkdirSync(binDir, { recursive: true });
175
+ const shadcnLog = path.join(root, 'shadcn.log');
176
+ const npmLog = path.join(root, 'npm.log');
177
+ createFakeCommand(binDir, 'npx', shadcnLog);
178
+ createFakeCommand(binDir, 'npm', npmLog);
179
+
180
+ const result = runCli([
181
+ 'styled-app',
182
+ '--template',
183
+ defaultLocalStarterPath,
184
+ '--skip-plugin',
185
+ '--yes',
186
+ '--package-manager',
187
+ 'npm',
188
+ '--shadcn-preset',
189
+ 'test-preset',
190
+ '--shadcn-base',
191
+ 'base',
192
+ '--components',
193
+ 'recommended,matrix-table',
194
+ ], {
195
+ cwd: root,
196
+ env: {
197
+ ...process.env,
198
+ PATH: `${binDir}${path.delimiter}${process.env.PATH || ''}`,
199
+ },
200
+ });
201
+ assertSuccess(result, 'shadcn preset and component install');
202
+ assertScaffold(root, 'styled-app');
203
+ const npmInstallLog = fs.readFileSync(npmLog, 'utf8');
204
+ assert(npmInstallLog.includes('npm install'), 'expected npm install command');
205
+ const log = fs.readFileSync(shadcnLog, 'utf8');
206
+ assert(
207
+ log.includes('npx shadcn@latest init --preset test-preset --template vite --force --reinstall --base base'),
208
+ 'expected shadcn preset init command',
209
+ );
210
+ assert(
211
+ log.includes('npx shadcn@latest add semaphor-analytics/semaphor-data-app-components/query-state'),
212
+ 'expected query-state registry add command',
213
+ );
214
+ assert(
215
+ log.includes('npx shadcn@latest add semaphor-analytics/semaphor-data-app-components/query-state-boundary'),
216
+ 'expected query-state-boundary registry add command',
217
+ );
218
+ assert(
219
+ log.includes('npx shadcn@latest add semaphor-analytics/semaphor-data-app-components/view-card'),
220
+ 'expected view-card registry add command',
221
+ );
222
+ assert(
223
+ log.includes('npx shadcn@latest add semaphor-analytics/semaphor-data-app-components/metric-kpis'),
224
+ 'expected metric-kpis registry add command',
225
+ );
226
+ assert(
227
+ log.includes('npx shadcn@latest add semaphor-analytics/semaphor-data-app-components/filter-controls'),
228
+ 'expected filter-controls registry add command',
229
+ );
230
+ assert(
231
+ log.includes('npx shadcn@latest add semaphor-analytics/semaphor-data-app-components/server-data-table'),
232
+ 'expected server-data-table registry add command',
233
+ );
234
+ assert(
235
+ log.includes('npx shadcn@latest add semaphor-analytics/semaphor-data-app-components/matrix-table'),
236
+ 'expected matrix-table registry add command',
237
+ );
238
+ console.log('✓ shadcn preset and registry component path');
239
+ }
240
+
241
+ {
242
+ const root = createTempRoot('no-install-shadcn-');
243
+ const result = runCli([
244
+ 'invalid-shadcn-app',
245
+ '--template',
246
+ defaultLocalStarterPath,
247
+ '--no-install',
248
+ '--skip-plugin',
249
+ '--yes',
250
+ '--components',
251
+ 'table',
252
+ ], { cwd: root });
253
+ assert(result.status !== 0, 'expected shadcn options with --no-install to fail');
254
+ assert(
255
+ result.stderr.includes('--no-install cannot be combined'),
256
+ 'expected actionable --no-install error',
257
+ );
258
+ assert(
259
+ !fs.existsSync(path.join(root, 'invalid-shadcn-app')),
260
+ 'invalid shadcn options should fail before scaffolding',
261
+ );
262
+ console.log('✓ rejects shadcn customization with --no-install');
263
+ }
264
+
171
265
  console.log('✓ cleaned up temp projects');
172
266
  } finally {
173
267
  for (const root of tempRoots.reverse()) {