@wix/web50-cli 0.1.0 → 0.1.1

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 (122) hide show
  1. package/dist/cjs/auth/deviceFlow.js +99 -13
  2. package/dist/cjs/auth/deviceFlow.js.map +1 -1
  3. package/dist/cjs/auth/index.js +65 -12
  4. package/dist/cjs/auth/index.js.map +1 -1
  5. package/dist/cjs/auth/secretStore.js.map +1 -1
  6. package/dist/cjs/cli.js +29 -1
  7. package/dist/cjs/cli.js.map +1 -1
  8. package/dist/cjs/commands/bundle.js +95 -0
  9. package/dist/cjs/commands/bundle.js.map +1 -0
  10. package/dist/cjs/commands/conversation.js +50 -0
  11. package/dist/cjs/commands/conversation.js.map +1 -0
  12. package/dist/cjs/commands/conversationWizard.js +526 -0
  13. package/dist/cjs/commands/conversationWizard.js.map +1 -0
  14. package/dist/cjs/commands/deploy.js +192 -0
  15. package/dist/cjs/commands/deploy.js.map +1 -0
  16. package/dist/cjs/commands/embed.js +118 -0
  17. package/dist/cjs/commands/embed.js.map +1 -0
  18. package/dist/cjs/commands/getClientId.js +60 -0
  19. package/dist/cjs/commands/getClientId.js.map +1 -0
  20. package/dist/cjs/commands/init.js +31 -26
  21. package/dist/cjs/commands/init.js.map +1 -1
  22. package/dist/cjs/commands/instructions.js +360 -0
  23. package/dist/cjs/commands/instructions.js.map +1 -0
  24. package/dist/cjs/commands/login.js +59 -4
  25. package/dist/cjs/commands/login.js.map +1 -1
  26. package/dist/cjs/commands/logout.js +16 -0
  27. package/dist/cjs/commands/logout.js.map +1 -0
  28. package/dist/cjs/commands/serve.js +122 -0
  29. package/dist/cjs/commands/serve.js.map +1 -0
  30. package/dist/cjs/commands/storybook.js +102 -0
  31. package/dist/cjs/commands/storybook.js.map +1 -0
  32. package/dist/cjs/commands/validate.js +266 -18
  33. package/dist/cjs/commands/validate.js.map +1 -1
  34. package/dist/cjs/commands/whoami.js +48 -0
  35. package/dist/cjs/commands/whoami.js.map +1 -0
  36. package/dist/cjs/utils/print.js +12 -0
  37. package/dist/cjs/utils/print.js.map +1 -1
  38. package/dist/cjs/utils/project.js +11 -0
  39. package/dist/cjs/utils/project.js.map +1 -1
  40. package/dist/cjs/utils/wixApi.js +55 -0
  41. package/dist/cjs/utils/wixApi.js.map +1 -0
  42. package/dist/esm/auth/deviceFlow.js +106 -13
  43. package/dist/esm/auth/deviceFlow.js.map +1 -1
  44. package/dist/esm/auth/index.js +71 -13
  45. package/dist/esm/auth/index.js.map +1 -1
  46. package/dist/esm/auth/secretStore.js.map +1 -1
  47. package/dist/esm/cli.js +29 -1
  48. package/dist/esm/cli.js.map +1 -1
  49. package/dist/esm/commands/bundle.js +92 -0
  50. package/dist/esm/commands/bundle.js.map +1 -0
  51. package/dist/esm/commands/conversation.js +44 -0
  52. package/dist/esm/commands/conversation.js.map +1 -0
  53. package/dist/esm/commands/conversationWizard.js +527 -0
  54. package/dist/esm/commands/conversationWizard.js.map +1 -0
  55. package/dist/esm/commands/deploy.js +194 -0
  56. package/dist/esm/commands/deploy.js.map +1 -0
  57. package/dist/esm/commands/embed.js +112 -0
  58. package/dist/esm/commands/embed.js.map +1 -0
  59. package/dist/esm/commands/getClientId.js +56 -0
  60. package/dist/esm/commands/getClientId.js.map +1 -0
  61. package/dist/esm/commands/init.js +32 -27
  62. package/dist/esm/commands/init.js.map +1 -1
  63. package/dist/esm/commands/instructions.js +360 -0
  64. package/dist/esm/commands/instructions.js.map +1 -0
  65. package/dist/esm/commands/login.js +62 -6
  66. package/dist/esm/commands/login.js.map +1 -1
  67. package/dist/esm/commands/logout.js +12 -0
  68. package/dist/esm/commands/logout.js.map +1 -0
  69. package/dist/esm/commands/serve.js +117 -0
  70. package/dist/esm/commands/serve.js.map +1 -0
  71. package/dist/esm/commands/storybook.js +97 -0
  72. package/dist/esm/commands/storybook.js.map +1 -0
  73. package/dist/esm/commands/validate.js +269 -19
  74. package/dist/esm/commands/validate.js.map +1 -1
  75. package/dist/esm/commands/whoami.js +44 -0
  76. package/dist/esm/commands/whoami.js.map +1 -0
  77. package/dist/esm/utils/print.js +10 -0
  78. package/dist/esm/utils/print.js.map +1 -1
  79. package/dist/esm/utils/project.js +8 -0
  80. package/dist/esm/utils/project.js.map +1 -1
  81. package/dist/esm/utils/wixApi.js +51 -0
  82. package/dist/esm/utils/wixApi.js.map +1 -0
  83. package/dist/types/auth/deviceFlow.d.ts +3 -1
  84. package/dist/types/auth/deviceFlow.d.ts.map +1 -1
  85. package/dist/types/auth/index.d.ts +5 -1
  86. package/dist/types/auth/index.d.ts.map +1 -1
  87. package/dist/types/auth/secretStore.d.ts +2 -0
  88. package/dist/types/auth/secretStore.d.ts.map +1 -1
  89. package/dist/types/commands/bundle.d.ts +10 -0
  90. package/dist/types/commands/bundle.d.ts.map +1 -0
  91. package/dist/types/commands/conversation.d.ts +3 -0
  92. package/dist/types/commands/conversation.d.ts.map +1 -0
  93. package/dist/types/commands/conversationWizard.d.ts +3 -0
  94. package/dist/types/commands/conversationWizard.d.ts.map +1 -0
  95. package/dist/types/commands/deploy.d.ts +3 -0
  96. package/dist/types/commands/deploy.d.ts.map +1 -0
  97. package/dist/types/commands/embed.d.ts +3 -0
  98. package/dist/types/commands/embed.d.ts.map +1 -0
  99. package/dist/types/commands/getClientId.d.ts +3 -0
  100. package/dist/types/commands/getClientId.d.ts.map +1 -0
  101. package/dist/types/commands/init.d.ts.map +1 -1
  102. package/dist/types/commands/instructions.d.ts +3 -0
  103. package/dist/types/commands/instructions.d.ts.map +1 -0
  104. package/dist/types/commands/login.d.ts.map +1 -1
  105. package/dist/types/commands/logout.d.ts +3 -0
  106. package/dist/types/commands/logout.d.ts.map +1 -0
  107. package/dist/types/commands/serve.d.ts +3 -0
  108. package/dist/types/commands/serve.d.ts.map +1 -0
  109. package/dist/types/commands/storybook.d.ts +3 -0
  110. package/dist/types/commands/storybook.d.ts.map +1 -0
  111. package/dist/types/commands/validate.d.ts +5 -0
  112. package/dist/types/commands/validate.d.ts.map +1 -1
  113. package/dist/types/commands/whoami.d.ts +3 -0
  114. package/dist/types/commands/whoami.d.ts.map +1 -0
  115. package/dist/types/utils/print.d.ts +3 -0
  116. package/dist/types/utils/print.d.ts.map +1 -1
  117. package/dist/types/utils/project.d.ts +10 -0
  118. package/dist/types/utils/project.d.ts.map +1 -1
  119. package/dist/types/utils/wixApi.d.ts +9 -0
  120. package/dist/types/utils/wixApi.d.ts.map +1 -0
  121. package/package.json +5 -5
  122. package/defaults/package.json +0 -42
@@ -0,0 +1,194 @@
1
+ import { Command } from 'commander';
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+ import { findProjectRoot } from '../utils/project';
5
+ import { wixRequest } from '../utils/wixApi';
6
+ import { success, error, warn, spinner, step } from '../utils/print';
7
+ import { execSync } from 'child_process';
8
+ import { runValidation } from './validate';
9
+ function getProjectRoot() {
10
+ const root = findProjectRoot(process.cwd());
11
+ if (!root) {
12
+ error('Not inside a web5 project. Run this command from your project directory.');
13
+ process.exit(1);
14
+ }
15
+ return root;
16
+ }
17
+
18
+ // ── Sub-deployers ─────────────────────────────────────────────────────────────
19
+
20
+ async function deployAiInstructions(root, opts) {
21
+ if (opts === void 0) {
22
+ opts = {};
23
+ }
24
+ const yamlPath = path.join(root, 'src', 'configuration', 'ai', 'prompt-instructions.yaml');
25
+ if (!fs.existsSync(yamlPath)) {
26
+ error(`AI instructions file not found: ${yamlPath}`);
27
+ process.exit(1);
28
+ }
29
+ const content = fs.readFileSync(yamlPath, 'utf8');
30
+ const sp = spinner('Deploying AI instructions...');
31
+ try {
32
+ const data = await wixRequest({
33
+ path: '/web5/instruction/cli',
34
+ method: 'POST',
35
+ body: {
36
+ instruction: content
37
+ }
38
+ });
39
+ sp.stop();
40
+ success(`AI instructions deployed (version ${data.instruction.version})`);
41
+ if (opts.activate) {
42
+ const version = data.instruction.version;
43
+ const sp2 = spinner(`Activating version ${version}...`);
44
+ try {
45
+ await wixRequest({
46
+ path: `/web5/instructions/cli/activate/${version}`,
47
+ method: 'POST'
48
+ });
49
+ sp2.stop();
50
+ success(`Activated version ${version}`);
51
+ } catch (err_) {
52
+ sp2.stop();
53
+ error(err_.message);
54
+ process.exit(1);
55
+ }
56
+ }
57
+ } catch (err_) {
58
+ sp.stop();
59
+ error(err_.message);
60
+ process.exit(1);
61
+ }
62
+ }
63
+ async function deployComponents() {
64
+ warn('Components deploy: to be developed');
65
+ }
66
+
67
+ // ── Rollback ──────────────────────────────────────────────────────────────────
68
+
69
+ async function rollbackInstructions() {
70
+ const sp = spinner('Fetching instructions for rollback...');
71
+ try {
72
+ const data = await wixRequest({
73
+ path: '/web5/instructions/cli/query',
74
+ method: 'POST',
75
+ body: {
76
+ query: {}
77
+ }
78
+ });
79
+ sp.stop();
80
+ const instructions = data.instructions ?? [];
81
+ const active = instructions.find(i => i.active);
82
+ if (!active) {
83
+ error('No active instruction found — nothing to roll back from.');
84
+ process.exit(1);
85
+ }
86
+ const previous = instructions.filter(i => !i.active && i.version < active.version).sort((a, b) => b.version - a.version)[0];
87
+ if (!previous) {
88
+ error(`No previous version found before v${active.version}.`);
89
+ process.exit(1);
90
+ }
91
+ const sp2 = spinner(`Rolling back to version ${previous.version}...`);
92
+ await wixRequest({
93
+ path: `/web5/instructions/cli/activate/${previous.version}`,
94
+ method: 'POST'
95
+ });
96
+ sp2.stop();
97
+ success(`Rolled back to version ${previous.version} (was v${active.version})`);
98
+ } catch (err_) {
99
+ sp.stop();
100
+ error(err_.message);
101
+ process.exit(1);
102
+ }
103
+ }
104
+
105
+ // ── Stepped runner ────────────────────────────────────────────────────────────
106
+
107
+ async function runWithSteps(root, targets, opts) {
108
+ if (opts === void 0) {
109
+ opts = {};
110
+ }
111
+ const needsBundle = targets.includes('components');
112
+
113
+ // Calculate total steps
114
+ let totalSteps = 0;
115
+ if (!opts.skipValidate) totalSteps++;
116
+ if (needsBundle && !opts.skipBundle) totalSteps++;
117
+ totalSteps++; // deploy
118
+
119
+ let currentStep = 0;
120
+ if (!opts.skipValidate) {
121
+ step(++currentStep, totalSteps, 'Verification');
122
+ const valid = runValidation(root);
123
+ if (!valid) {
124
+ error('Verification failed. Fix errors before deploying.');
125
+ process.exit(1);
126
+ }
127
+ }
128
+ if (needsBundle && !opts.skipBundle) {
129
+ step(++currentStep, totalSteps, 'Bundle');
130
+ try {
131
+ execSync('npm run bundle', {
132
+ cwd: root,
133
+ stdio: 'inherit'
134
+ });
135
+ } catch {
136
+ error('Bundle failed. Fix errors before deploying.');
137
+ process.exit(1);
138
+ }
139
+ }
140
+ step(++currentStep, totalSteps, 'Deploy');
141
+ for (const target of targets) {
142
+ if (target === 'components') await deployComponents();
143
+ if (target === 'instructions') await deployAiInstructions(root, {
144
+ activate: opts.activate
145
+ });
146
+ }
147
+ console.log('');
148
+ }
149
+
150
+ // ── Subcommands ───────────────────────────────────────────────────────────────
151
+
152
+ const instructionsCmd = new Command('instructions').description('Deploy AI instructions from src/configuration/ai/prompt-instructions.yaml').option('--skip-validate', 'Skip the pre-deploy validation step').option('--activate', 'Automatically activate the deployed version').action(async opts => {
153
+ const root = getProjectRoot();
154
+ await runWithSteps(root, ['instructions'], {
155
+ skipValidate: opts.skipValidate,
156
+ activate: opts.activate
157
+ });
158
+ });
159
+ const componentsCmd = new Command('components').description('Deploy components').option('--skip-validate', 'Skip the pre-deploy validation step').option('--skip-bundle', 'Skip the bundle step (reuse existing build artifact)').action(async opts => {
160
+ const root = getProjectRoot();
161
+ await runWithSteps(root, ['components'], {
162
+ skipValidate: opts.skipValidate,
163
+ skipBundle: opts.skipBundle
164
+ });
165
+ });
166
+
167
+ // ── Root deploy command ───────────────────────────────────────────────────────
168
+
169
+ export const deployCommand = new Command('deploy').description('Deploy project resources to the Web5 platform').option('--target <target>', 'What to deploy: instructions, components, or all').option('--skip-validate', 'Skip the pre-deploy validation step').option('--skip-bundle', 'Skip the bundle step (reuse existing build artifact)').option('--rollback', 'Re-activate the previous instruction version').action(async opts => {
170
+ const root = getProjectRoot();
171
+ if (opts.rollback) {
172
+ await rollbackInstructions();
173
+ return;
174
+ }
175
+ let targets;
176
+ if (!opts.target || opts.target === 'all') {
177
+ targets = ['components', 'instructions'];
178
+ } else if (opts.target === 'instructions' || opts.target === 'components') {
179
+ targets = [opts.target];
180
+ } else {
181
+ error(`Unknown target: '${opts.target}'. Valid values: instructions, components, all`);
182
+ process.exit(1);
183
+ }
184
+ await runWithSteps(root, targets, {
185
+ skipValidate: opts.skipValidate,
186
+ skipBundle: opts.skipBundle
187
+ });
188
+ }).addCommand(instructionsCmd).addCommand(componentsCmd);
189
+ deployCommand.on('command:*', _ref => {
190
+ let [cmd] = _ref;
191
+ error(`Unknown deploy target: '${cmd}'. Valid targets: components, instructions`);
192
+ process.exit(1);
193
+ });
194
+ //# sourceMappingURL=deploy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Command","fs","path","findProjectRoot","wixRequest","success","error","warn","spinner","step","execSync","runValidation","getProjectRoot","root","process","cwd","exit","deployAiInstructions","opts","yamlPath","join","existsSync","content","readFileSync","sp","data","method","body","instruction","stop","version","activate","sp2","err_","message","deployComponents","rollbackInstructions","query","instructions","active","find","i","previous","filter","sort","a","b","runWithSteps","targets","needsBundle","includes","totalSteps","skipValidate","skipBundle","currentStep","valid","stdio","target","console","log","instructionsCmd","description","option","action","componentsCmd","deployCommand","rollback","addCommand","on","_ref","cmd"],"sources":["../../../src/commands/deploy.ts"],"sourcesContent":["import { Command } from 'commander';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { findProjectRoot } from '../utils/project';\nimport { wixRequest } from '../utils/wixApi';\nimport { success, error, warn, spinner, step } from '../utils/print';\nimport { execSync } from 'child_process';\nimport { runValidation } from './validate';\n\nfunction getProjectRoot(): string {\n const root = findProjectRoot(process.cwd());\n if (!root) {\n error(\n 'Not inside a web5 project. Run this command from your project directory.',\n );\n process.exit(1);\n }\n return root;\n}\n\n// ── Sub-deployers ─────────────────────────────────────────────────────────────\n\ninterface Instruction {\n id: string;\n version: number;\n content: string;\n active?: boolean;\n}\n\nasync function deployAiInstructions(\n root: string,\n opts: { activate?: boolean } = {},\n): Promise<void> {\n const yamlPath = path.join(\n root,\n 'src',\n 'configuration',\n 'ai',\n 'prompt-instructions.yaml',\n );\n\n if (!fs.existsSync(yamlPath)) {\n error(`AI instructions file not found: ${yamlPath}`);\n process.exit(1);\n }\n\n const content = fs.readFileSync(yamlPath, 'utf8');\n const sp = spinner('Deploying AI instructions...');\n\n try {\n const data = await wixRequest<{ instruction: Instruction }>({\n path: '/web5/instruction/cli',\n method: 'POST',\n body: { instruction: content },\n });\n sp.stop();\n success(`AI instructions deployed (version ${data.instruction.version})`);\n\n if (opts.activate) {\n const version = data.instruction.version;\n const sp2 = spinner(`Activating version ${version}...`);\n try {\n await wixRequest({\n path: `/web5/instructions/cli/activate/${version}`,\n method: 'POST',\n });\n sp2.stop();\n success(`Activated version ${version}`);\n } catch (err_) {\n sp2.stop();\n error((err_ as Error).message);\n process.exit(1);\n }\n }\n } catch (err_) {\n sp.stop();\n error((err_ as Error).message);\n process.exit(1);\n }\n}\n\nasync function deployComponents(): Promise<void> {\n warn('Components deploy: to be developed');\n}\n\n// ── Rollback ──────────────────────────────────────────────────────────────────\n\nasync function rollbackInstructions(): Promise<void> {\n const sp = spinner('Fetching instructions for rollback...');\n try {\n const data = await wixRequest<{ instructions: Instruction[] }>({\n path: '/web5/instructions/cli/query',\n method: 'POST',\n body: { query: {} },\n });\n sp.stop();\n\n const instructions = data.instructions ?? [];\n const active = instructions.find((i) => i.active);\n if (!active) {\n error('No active instruction found — nothing to roll back from.');\n process.exit(1);\n }\n\n const previous = instructions\n .filter((i) => !i.active && i.version < active.version)\n .sort((a, b) => b.version - a.version)[0];\n\n if (!previous) {\n error(`No previous version found before v${active.version}.`);\n process.exit(1);\n }\n\n const sp2 = spinner(`Rolling back to version ${previous.version}...`);\n await wixRequest({\n path: `/web5/instructions/cli/activate/${previous.version}`,\n method: 'POST',\n });\n sp2.stop();\n success(`Rolled back to version ${previous.version} (was v${active.version})`);\n } catch (err_) {\n sp.stop();\n error((err_ as Error).message);\n process.exit(1);\n }\n}\n\n// ── Stepped runner ────────────────────────────────────────────────────────────\n\nasync function runWithSteps(\n root: string,\n targets: ('components' | 'instructions')[],\n opts: { skipValidate?: boolean; skipBundle?: boolean; activate?: boolean } = {},\n): Promise<void> {\n const needsBundle = targets.includes('components');\n\n // Calculate total steps\n let totalSteps = 0;\n if (!opts.skipValidate) totalSteps++;\n if (needsBundle && !opts.skipBundle) totalSteps++;\n totalSteps++; // deploy\n\n let currentStep = 0;\n\n if (!opts.skipValidate) {\n step(++currentStep, totalSteps, 'Verification');\n const valid = runValidation(root);\n if (!valid) {\n error('Verification failed. Fix errors before deploying.');\n process.exit(1);\n }\n }\n\n if (needsBundle && !opts.skipBundle) {\n step(++currentStep, totalSteps, 'Bundle');\n try {\n execSync('npm run bundle', { cwd: root, stdio: 'inherit' });\n } catch {\n error('Bundle failed. Fix errors before deploying.');\n process.exit(1);\n }\n }\n\n step(++currentStep, totalSteps, 'Deploy');\n for (const target of targets) {\n if (target === 'components') await deployComponents();\n if (target === 'instructions') await deployAiInstructions(root, { activate: opts.activate });\n }\n\n console.log('');\n}\n\n// ── Subcommands ───────────────────────────────────────────────────────────────\n\nconst instructionsCmd = new Command('instructions')\n .description(\n 'Deploy AI instructions from src/configuration/ai/prompt-instructions.yaml',\n )\n .option('--skip-validate', 'Skip the pre-deploy validation step')\n .option('--activate', 'Automatically activate the deployed version')\n .action(async (opts: { skipValidate?: boolean; activate?: boolean }) => {\n const root = getProjectRoot();\n await runWithSteps(root, ['instructions'], {\n skipValidate: opts.skipValidate,\n activate: opts.activate,\n });\n });\n\nconst componentsCmd = new Command('components')\n .description('Deploy components')\n .option('--skip-validate', 'Skip the pre-deploy validation step')\n .option('--skip-bundle', 'Skip the bundle step (reuse existing build artifact)')\n .action(async (opts: { skipValidate?: boolean; skipBundle?: boolean }) => {\n const root = getProjectRoot();\n await runWithSteps(root, ['components'], {\n skipValidate: opts.skipValidate,\n skipBundle: opts.skipBundle,\n });\n });\n\n// ── Root deploy command ───────────────────────────────────────────────────────\n\nexport const deployCommand = new Command('deploy')\n .description('Deploy project resources to the Web5 platform')\n .option('--target <target>', 'What to deploy: instructions, components, or all')\n .option('--skip-validate', 'Skip the pre-deploy validation step')\n .option('--skip-bundle', 'Skip the bundle step (reuse existing build artifact)')\n .option('--rollback', 'Re-activate the previous instruction version')\n .action(async (opts: {\n target?: string;\n skipValidate?: boolean;\n skipBundle?: boolean;\n rollback?: boolean;\n }) => {\n const root = getProjectRoot();\n\n if (opts.rollback) {\n await rollbackInstructions();\n return;\n }\n\n type DeployTarget = 'components' | 'instructions';\n let targets: DeployTarget[];\n\n if (!opts.target || opts.target === 'all') {\n targets = ['components', 'instructions'];\n } else if (opts.target === 'instructions' || opts.target === 'components') {\n targets = [opts.target as DeployTarget];\n } else {\n error(`Unknown target: '${opts.target}'. Valid values: instructions, components, all`);\n process.exit(1);\n }\n\n await runWithSteps(root, targets, {\n skipValidate: opts.skipValidate,\n skipBundle: opts.skipBundle,\n });\n })\n .addCommand(instructionsCmd)\n .addCommand(componentsCmd);\n\ndeployCommand.on('command:*', ([cmd]: string[]) => {\n error(\n `Unknown deploy target: '${cmd}'. Valid targets: components, instructions`,\n );\n process.exit(1);\n});\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,WAAW;AACnC,OAAO,KAAKC,EAAE,MAAM,IAAI;AACxB,OAAO,KAAKC,IAAI,MAAM,MAAM;AAC5B,SAASC,eAAe,QAAQ,kBAAkB;AAClD,SAASC,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,OAAO,EAAEC,KAAK,EAAEC,IAAI,EAAEC,OAAO,EAAEC,IAAI,QAAQ,gBAAgB;AACpE,SAASC,QAAQ,QAAQ,eAAe;AACxC,SAASC,aAAa,QAAQ,YAAY;AAE1C,SAASC,cAAcA,CAAA,EAAW;EAChC,MAAMC,IAAI,GAAGV,eAAe,CAACW,OAAO,CAACC,GAA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,IAAI,CAACuC,MAAM,KAAK,KAAK,EAAE;IACzCT,OAAO,GAAG,CAAC,YAAY,EAAE,cAAc,CAAC;EAC1C,CAAC,MAAM,IAAI9B,IAAI,CAACuC,MAAM,KAAK,cAAc,IAAIvC,IAAI,CAACuC,MAAM,KAAK,YAAY,EAAE;IACzET,OAAO,GAAG,CAAC9B,IAAI,CAACuC,MAAM,CAAiB;EACzC,CAAC,MAAM;IACLnD,KAAK,CAAC,oBAAoBY,IAAI,CAACuC,MAAM,gDAAgD,CAAC;IACtF3C,OAAO,CAACE,IAAI,CAAC,CAAC,CAAC;EACjB;EAEA,MAAM+B,YAAY,CAAClC,IAAI,EAAEmC,OAAO,EAAE;IAChCI,YAAY,EAAElC,IAAI,CAACkC,YAAY;IAC/BC,UAAU,EAAEnC,IAAI,CAACmC;EACnB,CAAC,CAAC;AACJ,CAAC,CAAC,CACDc,UAAU,CAACP,eAAe,CAAC,CAC3BO,UAAU,CAACH,aAAa,CAAC;AAE5BC,aAAa,CAACG,EAAE,CAAC,WAAW,EAAEC,IAAA,IAAqB;EAAA,IAApB,CAACC,GAAG,CAAW,GAAAD,IAAA;EAC5C/D,KAAK,CACH,2BAA2BgE,GAAG,4CAChC,CAAC;EACDxD,OAAO,CAACE,IAAI,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,112 @@
1
+ import { Command } from 'commander';
2
+ import * as readline from 'readline';
3
+ import { execSync } from 'child_process';
4
+ import inquirer from 'inquirer';
5
+ import { wixRequest } from '../utils/wixApi';
6
+ import { isJsonMode } from '../utils/print';
7
+ import { findProjectRoot, readConfig, writeConfig } from '../utils/project';
8
+ function copyToClipboard(text) {
9
+ const cmd = process.platform === 'win32' ? `echo ${text} | clip` : process.platform === 'darwin' ? 'pbcopy' : 'xclip -selection clipboard';
10
+ execSync(process.platform === 'win32' ? `echo ${text} | clip` : cmd, process.platform === 'win32' ? undefined : {
11
+ input: text
12
+ });
13
+ }
14
+ async function promptCopyToClipboard(text) {
15
+ const rl = readline.createInterface({
16
+ input: process.stdin,
17
+ output: process.stdout
18
+ });
19
+ return new Promise(resolve => {
20
+ rl.question('\nPress Enter to copy to clipboard...', () => {
21
+ rl.close();
22
+ copyToClipboard(text);
23
+ console.log('Copied to clipboard.');
24
+ resolve();
25
+ });
26
+ });
27
+ }
28
+ async function promptForType() {
29
+ const {
30
+ type
31
+ } = await inquirer.prompt([{
32
+ type: 'list',
33
+ name: 'type',
34
+ message: 'Select embed type:',
35
+ choices: [{
36
+ name: 'Script tag',
37
+ value: 'script'
38
+ }, {
39
+ name: 'React component',
40
+ value: 'react'
41
+ }]
42
+ }]);
43
+ return type;
44
+ }
45
+ async function getOrCreateClientId() {
46
+ var _createData$oAuthApp;
47
+ console.log('Searching for client ID...');
48
+ const queryData = await wixRequest({
49
+ path: '/oauth-app/v1/oauth-apps/query',
50
+ method: 'POST',
51
+ body: {}
52
+ });
53
+ const apps = queryData.oAuthApps ?? [];
54
+ const existing = apps.find(app => app.name === 'web5');
55
+ if (existing) {
56
+ console.log(`Found client ID: ${existing.id}`);
57
+ return existing.id;
58
+ }
59
+ console.log('Client ID not found, creating...');
60
+ const createData = await wixRequest({
61
+ path: '/oauth-app/v1/oauth-apps',
62
+ method: 'POST',
63
+ body: {
64
+ oAuthApp: {
65
+ name: 'web5',
66
+ application_type: 'WEB_APP'
67
+ }
68
+ }
69
+ });
70
+ const id = (_createData$oAuthApp = createData.oAuthApp) == null ? void 0 : _createData$oAuthApp.id;
71
+ if (!id) {
72
+ throw new Error('Failed to create OAuth app — no ID returned');
73
+ }
74
+ console.log(`Client ID created: ${id}`);
75
+ return id;
76
+ }
77
+ export const embedCommand = new Command('embed').description('Generate embed code for a Web5 component').option('--type <type>', 'Embed type: script or react').option('--client-id <id>', 'Use this client ID instead of fetching from the API').option('--no-clipboard', 'Print to stdout only — skip the clipboard prompt').action(async opts => {
78
+ try {
79
+ const type = opts.type ?? (await promptForType());
80
+ if (type === 'react') {
81
+ console.log('no react for now');
82
+ return;
83
+ }
84
+ const root = findProjectRoot(process.cwd());
85
+ const config = root ? readConfig(root) : null;
86
+ const clientId = opts.clientId ?? ((config == null ? void 0 : config.clientId) || undefined) ?? (await getOrCreateClientId());
87
+ if (root && config && config.clientId !== clientId) {
88
+ writeConfig(root, {
89
+ ...config,
90
+ clientId
91
+ });
92
+ }
93
+ const embedScript = `<script src="https://www.wix.com/embed/v1/component.js" data-client-id="${clientId}"></script>`;
94
+ if (isJsonMode()) {
95
+ console.log(JSON.stringify({
96
+ type,
97
+ clientId,
98
+ embedCode: embedScript
99
+ }));
100
+ return;
101
+ }
102
+ console.log('\nEmbed script:\n');
103
+ console.log(embedScript);
104
+ if (opts.clipboard !== false && process.stdout.isTTY) {
105
+ await promptCopyToClipboard(embedScript);
106
+ }
107
+ } catch (err) {
108
+ console.error('Error:', err.message);
109
+ process.exit(1);
110
+ }
111
+ });
112
+ //# sourceMappingURL=embed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Command","readline","execSync","inquirer","wixRequest","isJsonMode","findProjectRoot","readConfig","writeConfig","copyToClipboard","text","cmd","process","platform","undefined","input","promptCopyToClipboard","rl","createInterface","stdin","output","stdout","Promise","resolve","question","close","console","log","promptForType","type","prompt","name","message","choices","value","getOrCreateClientId","_createData$oAuthApp","queryData","path","method","body","apps","oAuthApps","existing","find","app","id","createData","oAuthApp","application_type","Error","embedCommand","description","option","action","opts","root","cwd","config","clientId","embedScript","JSON","stringify","embedCode","clipboard","isTTY","err","error","exit"],"sources":["../../../src/commands/embed.ts"],"sourcesContent":["import { Command } from 'commander';\nimport * as readline from 'readline';\nimport { execSync } from 'child_process';\nimport inquirer from 'inquirer';\nimport { wixRequest } from '../utils/wixApi';\nimport { isJsonMode } from '../utils/print';\nimport { findProjectRoot, readConfig, writeConfig } from '../utils/project';\n\nfunction copyToClipboard(text: string): void {\n const cmd =\n process.platform === 'win32'\n ? `echo ${text} | clip`\n : process.platform === 'darwin'\n ? 'pbcopy'\n : 'xclip -selection clipboard';\n\n execSync(\n process.platform === 'win32' ? `echo ${text} | clip` : cmd,\n process.platform === 'win32' ? undefined : { input: text },\n );\n}\n\nasync function promptCopyToClipboard(text: string): Promise<void> {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n return new Promise((resolve) => {\n rl.question('\\nPress Enter to copy to clipboard...', () => {\n rl.close();\n copyToClipboard(text);\n console.log('Copied to clipboard.');\n resolve();\n });\n });\n}\n\ntype EmbedType = 'script' | 'react';\n\ninterface OAuthApp {\n id: string;\n name: string;\n}\n\ninterface QueryResponse {\n oAuthApps?: OAuthApp[];\n}\n\ninterface CreateResponse {\n oAuthApp?: OAuthApp;\n}\n\nasync function promptForType(): Promise<EmbedType> {\n const { type } = await inquirer.prompt<{ type: EmbedType }>([\n {\n type: 'list',\n name: 'type',\n message: 'Select embed type:',\n choices: [\n { name: 'Script tag', value: 'script' },\n { name: 'React component', value: 'react' },\n ],\n },\n ]);\n return type;\n}\n\nasync function getOrCreateClientId(): Promise<string> {\n console.log('Searching for client ID...');\n\n const queryData = await wixRequest<QueryResponse>({\n path: '/oauth-app/v1/oauth-apps/query',\n method: 'POST',\n body: {},\n });\n\n const apps = queryData.oAuthApps ?? [];\n const existing = apps.find((app) => app.name === 'web5');\n\n if (existing) {\n console.log(`Found client ID: ${existing.id}`);\n return existing.id;\n }\n\n console.log('Client ID not found, creating...');\n\n const createData = await wixRequest<CreateResponse>({\n path: '/oauth-app/v1/oauth-apps',\n method: 'POST',\n body: { oAuthApp: { name: 'web5', application_type: 'WEB_APP' } },\n });\n\n const id = createData.oAuthApp?.id;\n if (!id) {\n throw new Error('Failed to create OAuth app — no ID returned');\n }\n\n console.log(`Client ID created: ${id}`);\n return id;\n}\n\nexport const embedCommand = new Command('embed')\n .description('Generate embed code for a Web5 component')\n .option('--type <type>', 'Embed type: script or react')\n .option('--client-id <id>', 'Use this client ID instead of fetching from the API')\n .option('--no-clipboard', 'Print to stdout only — skip the clipboard prompt')\n .action(async (opts: { type?: string; clientId?: string; clipboard: boolean }) => {\n try {\n const type: EmbedType = opts.type as EmbedType ?? (await promptForType());\n\n if (type === 'react') {\n console.log('no react for now');\n return;\n }\n\n const root = findProjectRoot(process.cwd());\n const config = root ? readConfig(root) : null;\n\n const clientId =\n opts.clientId ??\n (config?.clientId || undefined) ??\n (await getOrCreateClientId());\n\n if (root && config && config.clientId !== clientId) {\n writeConfig(root, { ...config, clientId });\n }\n\n const embedScript = `<script src=\"https://www.wix.com/embed/v1/component.js\" data-client-id=\"${clientId}\"></script>`;\n\n if (isJsonMode()) {\n console.log(JSON.stringify({ type, clientId, embedCode: embedScript }));\n return;\n }\n\n console.log('\\nEmbed script:\\n');\n console.log(embedScript);\n\n if (opts.clipboard !== false && process.stdout.isTTY) {\n await promptCopyToClipboard(embedScript);\n }\n } catch (err) {\n console.error('Error:', (err as Error).message);\n process.exit(1);\n }\n });\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,WAAW;AACnC,OAAO,KAAKC,QAAQ,MAAM,UAAU;AACpC,SAASC,QAAQ,QAAQ,eAAe;AACxC,OAAOC,QAAQ,MAAM,UAAU;AAC/B,SAASC,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,SAASC,eAAe,EAAEC,UAAU,EAAEC,WAAW,QAAQ,kBAAkB;AAE3E,SAASC,eAAeA,CAACC,IAAY,EAAQ;EAC3C,MAAMC,GAAG,GACPC,OAAO,CAACC,QAAQ,KAAK,OAAO,GACxB,QAAQH,IAAI,SAAS,GACrBE,OAAO,CAACC,QAAQ,KAAK,QAAQ,GAC7B,QAAQ,GACR,4BAA4B;EAElCX,QAAQ,CACNU,OAAO,CAACC,QAAQ,KAAK,OAAO,GAAG,QAAQH,IAAI,SAAS,GAAGC,GAAG,EAC1DC,OAAO,CAACC,QAAQ,KAAK,OAAO,GAAGC,SAAS,GAAG;IAAEC,KAAK,EAAEL;EAAK,CAC3D,CAAC;AACH;AAE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AC,CAAC;IAC3C,MAAMC,MAAM,GAAGF,IAAI,GAAGjD,UAAU,CAACiD,IAAI,CAAC,GAAG,IAAI;IAE7C,MAAMG,QAAQ,GACZJ,IAAI,CAACI,QAAQ,KACZ,CAAAD,MAAM,oBAANA,MAAM,CAAEC,QAAQ,KAAI7C,SAAS,CAAC,KAC9B,MAAMqB,mBAAmB,CAAC,CAAC,CAAC;IAE/B,IAAIqB,IAAI,IAAIE,MAAM,IAAIA,MAAM,CAACC,QAAQ,KAAKA,QAAQ,EAAE;MAClDnD,WAAW,CAACgD,IAAI,EAAE;QAAE,GAAGE,MAAM;QAAEC;MAAS,CAAC,CAAC;IAC5C;IAEA,MAAMC,WAAW,GAAG,2EAA2ED,QAAQ,aAAa;IAEpH,IAAItD,UAAU,CAAC,CAAC,EAAE;MAChBqB,OAAO,CAACC,GAAG,CAACkC,IAAI,CAACC,SAAS,CAAC;QAAEjC,IAAI;QAAE8B,QAAQ;QAAEI,SAAS,EAAEH;MAAY,CAAC,CAAC,CAAC;MACvE;IACF;IAEAlC,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC;IAChCD,OAAO,CAACC,GAAG,CAACiC,WAAW,CAAC;IAExB,IAAIL,IAAI,CAACS,SAAS,KAAK,KAAK,IAAIpD,OAAO,CAACS,MAAM,CAAC4C,KAAK,EAAE;MACpD,MAAMjD,qBAAqB,CAAC4C,WAAW,CAAC;IAC1C;EACF,CAAC,CAAC,OAAOM,GAAG,EAAE;IACZxC,OAAO,CAACyC,KAAK,CAAC,QAAQ,EAAGD,GAAG,CAAWlC,OAAO,CAAC;IAC/CpB,OAAO,CAACwD,IAAI,CAAC,CAAC,CAAC;EACjB;AACF,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,56 @@
1
+ import { Command } from 'commander';
2
+ import { wixRequest } from '../utils/wixApi';
3
+ import { success, isJsonMode } from '../utils/print';
4
+ export const getClientIdCommand = new Command('get-client-id').description('Get the client ID of the web5 OAuth app').option('--name <app-name>', 'Filter by OAuth app name', 'web5').option('--create-if-missing', 'Create the OAuth app if it does not exist').action(async opts => {
5
+ try {
6
+ const data = await wixRequest({
7
+ path: '/oauth-app/v1/oauth-apps/query',
8
+ method: 'POST',
9
+ body: {}
10
+ });
11
+ const apps = data.oAuthApps ?? [];
12
+ const filtered = apps.filter(a => a.name === opts.name);
13
+ const existing = filtered[0];
14
+ if (!existing && opts.createIfMissing) {
15
+ const createData = await wixRequest({
16
+ path: '/oauth-app/v1/oauth-apps',
17
+ method: 'POST',
18
+ body: {
19
+ oAuthApp: {
20
+ name: opts.name,
21
+ application_type: 'WEB_APP'
22
+ }
23
+ }
24
+ });
25
+ const created = createData.oAuthApp;
26
+ if (!created) {
27
+ console.error('Error: Failed to create OAuth app — no ID returned');
28
+ process.exit(1);
29
+ }
30
+ if (isJsonMode()) {
31
+ console.log(JSON.stringify({
32
+ id: created.id,
33
+ name: created.name,
34
+ created: true
35
+ }));
36
+ } else {
37
+ success(`Created OAuth app '${created.name}': ${created.id}`);
38
+ }
39
+ return;
40
+ }
41
+ if (isJsonMode()) {
42
+ console.log(JSON.stringify(filtered));
43
+ } else if (existing) {
44
+ success(`${existing.name}: ${existing.id}`);
45
+ } else {
46
+ console.log(`No OAuth app named '${opts.name}' found.`);
47
+ if (!opts.createIfMissing) {
48
+ console.log('Tip: use --create-if-missing to create it automatically.');
49
+ }
50
+ }
51
+ } catch (err) {
52
+ console.error('Error:', err.message);
53
+ process.exit(1);
54
+ }
55
+ });
56
+ //# sourceMappingURL=getClientId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Command","wixRequest","success","isJsonMode","getClientIdCommand","description","option","action","opts","data","path","method","body","apps","oAuthApps","filtered","filter","a","name","existing","createIfMissing","createData","oAuthApp","application_type","created","console","error","process","exit","log","JSON","stringify","id","err","message"],"sources":["../../../src/commands/getClientId.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { wixRequest } from '../utils/wixApi';\nimport { success, isJsonMode } from '../utils/print';\n\ninterface OAuthApp {\n id: string;\n name: string;\n}\n\ninterface QueryResponse {\n oAuthApps?: OAuthApp[];\n}\n\ninterface CreateResponse {\n oAuthApp?: OAuthApp;\n}\n\nexport const getClientIdCommand = new Command('get-client-id')\n .description('Get the client ID of the web5 OAuth app')\n .option('--name <app-name>', 'Filter by OAuth app name', 'web5')\n .option('--create-if-missing', 'Create the OAuth app if it does not exist')\n .action(async (opts: { name: string; createIfMissing?: boolean }) => {\n try {\n const data = await wixRequest<QueryResponse>({\n path: '/oauth-app/v1/oauth-apps/query',\n method: 'POST',\n body: {},\n });\n\n const apps = data.oAuthApps ?? [];\n const filtered = apps.filter((a) => a.name === opts.name);\n const existing = filtered[0];\n\n if (!existing && opts.createIfMissing) {\n const createData = await wixRequest<CreateResponse>({\n path: '/oauth-app/v1/oauth-apps',\n method: 'POST',\n body: { oAuthApp: { name: opts.name, application_type: 'WEB_APP' } },\n });\n const created = createData.oAuthApp;\n if (!created) {\n console.error('Error: Failed to create OAuth app — no ID returned');\n process.exit(1);\n }\n if (isJsonMode()) {\n console.log(JSON.stringify({ id: created.id, name: created.name, created: true }));\n } else {\n success(`Created OAuth app '${created.name}': ${created.id}`);\n }\n return;\n }\n\n if (isJsonMode()) {\n console.log(JSON.stringify(filtered));\n } else if (existing) {\n success(`${existing.name}: ${existing.id}`);\n } else {\n console.log(`No OAuth app named '${opts.name}' found.`);\n if (!opts.createIfMissing) {\n console.log('Tip: use --create-if-missing to create it automatically.');\n }\n }\n } catch (err) {\n console.error('Error:', (err as Error).message);\n process.exit(1);\n }\n });\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,WAAW;AACnC,SAASC,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,OAAO,EAAEC,UAAU,QAAQ,gBAAgB;AAepD,OAAO,MAAMC,kBAAkB,GAAG,IAAIJ,OAAO,CAAC,eAAe,CAAC,CAC3DK,WAAW,CAAC,yCAAyC,CAAC,CACtDC,MAAM,CAAC,mBAAmB,EAAE,0BAA0B,EAAE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CAACQ,EAAE,EAAE,CAAC;MAC/D;MACA;IACF;IAEA,IAAI7B,UAAU,CAAC,CAAC,EAAE;MAChBsB,OAAO,CAACI,GAAG,CAACC,IAAI,CAACC,SAAS,CAAChB,QAAQ,CAAC,CAAC;IACvC,CAAC,MAAM,IAAII,QAAQ,EAAE;MACnBjB,OAAO,CAAC,GAAGiB,QAAQ,CAACD,IAAI,KAAKC,QAAQ,CAACa,EAAE,EAAE,CAAC;IAC7C,CAAC,MAAM;MACLP,OAAO,CAACI,GAAG,CAAC,uBAAuBrB,IAAI,CAACU,IAAI,UAAU,CAAC;MACvD,IAAI,CAACV,IAAI,CAACY,eAAe,EAAE;QACzBK,OAAO,CAACI,GAAG,CAAC,0DAA0D,CAAC;MACzE;IACF;EACF,CAAC,CAAC,OAAOI,GAAG,EAAE;IACZR,OAAO,CAACC,KAAK,CAAC,QAAQ,EAAGO,GAAG,CAAWC,OAAO,CAAC;IAC/CP,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC;EACjB;AACF,CAAC,CAAC","ignoreList":[]}
@@ -2,10 +2,23 @@ import { Command } from 'commander';
2
2
  import inquirer from 'inquirer';
3
3
  import * as path from 'path';
4
4
  import * as fs from 'fs';
5
- import { readFile } from 'fs/promises';
5
+ import { readFile, cp } from 'fs/promises';
6
+ import chalk from 'chalk';
6
7
  import { success, error, info, warn } from '../utils/print';
7
8
  import { atomicWrite, ensureDir } from '../utils/fs';
8
9
  const DEFAULTS_DIR = path.join(__dirname, '../../../defaults');
10
+ function printBanner() {
11
+ const logo = ['██╗ ██╗ ███████╗ ██████╗ ███████╗', '██║ ██║ ██╔════╝ ██╔══██╗ ██╔════╝', '██║ █╗ ██║ █████╗ ██████╔╝ ███████╗', '██║███╗██║ ██╔══╝ ██╔══██╗ ╚════██║', '╚███╔███╔╝ ███████╗ ██████╔╝ ███████║', ' ╚══╝╚══╝ ╚══════╝ ╚═════╝ ╚══════╝'];
12
+ console.log('');
13
+ for (const line of logo) {
14
+ console.log(chalk.cyan(line));
15
+ }
16
+ console.log('');
17
+ console.log(chalk.dim(' Build AI-powered client components for the Wix platform.'));
18
+ console.log(chalk.dim(' Define sections, actions, and AI instructions —'));
19
+ console.log(chalk.dim(' the platform interprets user intent and delivers personalized experiences.'));
20
+ console.log('');
21
+ }
9
22
  async function copyDefault(srcRelative, destAbsolute, substitutions) {
10
23
  if (substitutions === void 0) {
11
24
  substitutions = {};
@@ -17,6 +30,13 @@ async function copyDefault(srcRelative, destAbsolute, substitutions) {
17
30
  }
18
31
  await atomicWrite(destAbsolute, content);
19
32
  }
33
+ async function copyDefaultTree(srcRelative, destAbsolute, filter) {
34
+ const srcPath = path.join(DEFAULTS_DIR, srcRelative);
35
+ await cp(srcPath, destAbsolute, {
36
+ recursive: true,
37
+ filter
38
+ });
39
+ }
20
40
  function findExistingConfig(startDir) {
21
41
  let current = startDir;
22
42
  let parent = path.dirname(current);
@@ -55,6 +75,7 @@ async function resolveString(flag, isTTY, question, opts) {
55
75
  }
56
76
  export const initCommand = new Command('init').description('Scaffold a new Web5 client component library').option('--mode <mode>', 'scaffold mode: defaults or scratch', 'defaults').option('--name <name>', 'npm package name (e.g. @wix/my-components)').option('--display-name <displayName>', 'human-readable display name').option('--dir <dir>', 'output directory (default: derived from package name)').action(async opts => {
57
77
  try {
78
+ printBanner();
58
79
  const existing = findExistingConfig(process.cwd());
59
80
  if (existing) {
60
81
  warn(`web5.config.json already exists at ${existing}`);
@@ -73,27 +94,10 @@ export const initCommand = new Command('init').description('Scaffold a new Web5
73
94
  exitMsg: '--name is required in non-interactive mode'
74
95
  });
75
96
 
76
- // ── Collect: display name ─────────────────────────────────────────────
77
- const defaultDisplay = name.split('/').pop().replace(/-/g, ' ');
78
- const displayName = await resolveString(opts.displayName, isTTY, [{
79
- type: 'input',
80
- name: 'value',
81
- message: 'Display name:',
82
- default: defaultDisplay
83
- }], {
84
- defaultValue: defaultDisplay
85
- });
86
-
87
- // ── Collect: output directory ─────────────────────────────────────────
88
- const defaultDir = name.split('/').pop();
89
- const dir = await resolveString(opts.dir, isTTY, [{
90
- type: 'input',
91
- name: 'value',
92
- message: 'Output directory:',
93
- default: defaultDir
94
- }], {
95
- defaultValue: defaultDir
96
- });
97
+ // ── Derive: display name and output directory from package name ───────
98
+ const stem = name.split('/').pop();
99
+ const displayName = opts.displayName ?? stem.replace(/-/g, ' ');
100
+ const dir = opts.dir ?? stem;
97
101
  const outDir = path.resolve(process.cwd(), dir);
98
102
  if (fs.existsSync(outDir) && fs.readdirSync(outDir).length > 0) {
99
103
  warn(`Directory ${outDir} already exists and is not empty`);
@@ -107,16 +111,17 @@ export const initCommand = new Command('init').description('Scaffold a new Web5
107
111
 
108
112
  // ── Root config files ─────────────────────────────────────────────────
109
113
  await copyDefault('web5.config.json', path.join(outDir, 'web5.config.json'), subs);
110
- await copyDefault('package.json', path.join(outDir, 'package.json'), subs);
114
+ await copyDefault('package.template.json', path.join(outDir, 'package.json'), subs);
111
115
  await copyDefault('tsconfig.json', path.join(outDir, 'tsconfig.json'));
112
116
 
113
117
  // ── src/ ──────────────────────────────────────────────────────────────
114
118
  await copyDefault('src/index.ts', path.join(outDir, 'src', 'index.ts'), subs);
115
119
  await copyDefault('src/createRegistry.ts', path.join(outDir, 'src', 'createRegistry.ts'));
116
- await copyDefault('src/components/types.ts', path.join(outDir, 'src', 'components', 'types.ts'));
117
-
120
+ await copyDefaultTree('src/components', path.join(outDir, 'src', 'components'));
121
+ await copyDefaultTree('.storybook', path.join(outDir, '.storybook'));
122
+ await copyDefault('src/vite.cdn.config.ts', path.join(outDir, 'src', 'vite.cdn.config.ts'));
118
123
  // ── src/configuration/ ────────────────────────────────────────────────
119
- await copyDefault('src/configuration/client.config.ts', path.join(outDir, 'src', 'configuration', 'client.config.ts'));
124
+ await copyDefault('src/client.config.ts', path.join(outDir, 'src', 'client.config.ts'));
120
125
  await copyDefault('src/configuration/ai/prompt-instructions.yaml', path.join(outDir, 'src', 'configuration', 'ai', 'prompt-instructions.yaml'));
121
126
  await copyDefault('src/configuration/cms/cms-mapping.yaml', path.join(outDir, 'src', 'configuration', 'cms', 'cms-mapping.yaml'));
122
127
  await copyDefault('src/configuration/cms/cms-schema.yaml', path.join(outDir, 'src', 'configuration', 'cms', 'cms-schema.yaml'));
@@ -152,7 +157,7 @@ export const initCommand = new Command('init').description('Scaffold a new Web5
152
157
  console.log('');
153
158
  info('Next steps:');
154
159
  info(` cd ${dir}`);
155
- info(' yarn install');
160
+ info(' npm install');
156
161
  } catch (err_) {
157
162
  error(err_ instanceof Error ? err_.message : String(err_));
158
163
  process.exit(1);