swallowkit 1.0.0-beta.2 → 1.0.0-beta.21

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 (191) hide show
  1. package/LICENSE +21 -21
  2. package/README.ja.md +312 -215
  3. package/README.md +369 -216
  4. package/dist/__tests__/fixtures.d.ts +22 -0
  5. package/dist/__tests__/fixtures.d.ts.map +1 -0
  6. package/dist/__tests__/fixtures.js +146 -0
  7. package/dist/__tests__/fixtures.js.map +1 -0
  8. package/dist/cli/commands/add-auth.d.ts +10 -0
  9. package/dist/cli/commands/add-auth.d.ts.map +1 -0
  10. package/dist/cli/commands/add-auth.js +444 -0
  11. package/dist/cli/commands/add-auth.js.map +1 -0
  12. package/dist/cli/commands/add-connector.d.ts +20 -0
  13. package/dist/cli/commands/add-connector.d.ts.map +1 -0
  14. package/dist/cli/commands/add-connector.js +163 -0
  15. package/dist/cli/commands/add-connector.js.map +1 -0
  16. package/dist/cli/commands/create-model.d.ts +1 -4
  17. package/dist/cli/commands/create-model.d.ts.map +1 -1
  18. package/dist/cli/commands/create-model.js +21 -82
  19. package/dist/cli/commands/create-model.js.map +1 -1
  20. package/dist/cli/commands/dev-seeds.d.ts +35 -0
  21. package/dist/cli/commands/dev-seeds.d.ts.map +1 -0
  22. package/dist/cli/commands/dev-seeds.js +292 -0
  23. package/dist/cli/commands/dev-seeds.js.map +1 -0
  24. package/dist/cli/commands/dev.d.ts +19 -0
  25. package/dist/cli/commands/dev.d.ts.map +1 -1
  26. package/dist/cli/commands/dev.js +476 -117
  27. package/dist/cli/commands/dev.js.map +1 -1
  28. package/dist/cli/commands/index.d.ts +1 -0
  29. package/dist/cli/commands/index.d.ts.map +1 -1
  30. package/dist/cli/commands/index.js +3 -1
  31. package/dist/cli/commands/index.js.map +1 -1
  32. package/dist/cli/commands/init.d.ts +13 -0
  33. package/dist/cli/commands/init.d.ts.map +1 -1
  34. package/dist/cli/commands/init.js +2627 -1708
  35. package/dist/cli/commands/init.js.map +1 -1
  36. package/dist/cli/commands/scaffold.d.ts +3 -0
  37. package/dist/cli/commands/scaffold.d.ts.map +1 -1
  38. package/dist/cli/commands/scaffold.js +617 -129
  39. package/dist/cli/commands/scaffold.js.map +1 -1
  40. package/dist/cli/index.d.ts +5 -1
  41. package/dist/cli/index.d.ts.map +1 -1
  42. package/dist/cli/index.js +164 -42
  43. package/dist/cli/index.js.map +1 -1
  44. package/dist/core/config.d.ts +8 -2
  45. package/dist/core/config.d.ts.map +1 -1
  46. package/dist/core/config.js +90 -4
  47. package/dist/core/config.js.map +1 -1
  48. package/dist/core/mock/connector-mock-server.d.ts +101 -0
  49. package/dist/core/mock/connector-mock-server.d.ts.map +1 -0
  50. package/dist/core/mock/connector-mock-server.js +480 -0
  51. package/dist/core/mock/connector-mock-server.js.map +1 -0
  52. package/dist/core/mock/zod-mock-generator.d.ts +14 -0
  53. package/dist/core/mock/zod-mock-generator.d.ts.map +1 -0
  54. package/dist/core/mock/zod-mock-generator.js +163 -0
  55. package/dist/core/mock/zod-mock-generator.js.map +1 -0
  56. package/dist/core/operations/create-model.d.ts +15 -0
  57. package/dist/core/operations/create-model.d.ts.map +1 -0
  58. package/dist/core/operations/create-model.js +171 -0
  59. package/dist/core/operations/create-model.js.map +1 -0
  60. package/dist/core/operations/runtime.d.ts +32 -0
  61. package/dist/core/operations/runtime.d.ts.map +1 -0
  62. package/dist/core/operations/runtime.js +225 -0
  63. package/dist/core/operations/runtime.js.map +1 -0
  64. package/dist/core/operations/scaffold-machine.d.ts +16 -0
  65. package/dist/core/operations/scaffold-machine.d.ts.map +1 -0
  66. package/dist/core/operations/scaffold-machine.js +63 -0
  67. package/dist/core/operations/scaffold-machine.js.map +1 -0
  68. package/dist/core/project/manifest.d.ts +92 -0
  69. package/dist/core/project/manifest.d.ts.map +1 -0
  70. package/dist/core/project/manifest.js +321 -0
  71. package/dist/core/project/manifest.js.map +1 -0
  72. package/dist/core/project/validation.d.ts +20 -0
  73. package/dist/core/project/validation.d.ts.map +1 -0
  74. package/dist/core/project/validation.js +204 -0
  75. package/dist/core/project/validation.js.map +1 -0
  76. package/dist/core/scaffold/auth-generator.d.ts +38 -0
  77. package/dist/core/scaffold/auth-generator.d.ts.map +1 -0
  78. package/dist/core/scaffold/auth-generator.js +1244 -0
  79. package/dist/core/scaffold/auth-generator.js.map +1 -0
  80. package/dist/core/scaffold/connector-functions-generator.d.ts +41 -0
  81. package/dist/core/scaffold/connector-functions-generator.d.ts.map +1 -0
  82. package/dist/core/scaffold/connector-functions-generator.js +1027 -0
  83. package/dist/core/scaffold/connector-functions-generator.js.map +1 -0
  84. package/dist/core/scaffold/functions-generator.d.ts +7 -1
  85. package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
  86. package/dist/core/scaffold/functions-generator.js +920 -213
  87. package/dist/core/scaffold/functions-generator.js.map +1 -1
  88. package/dist/core/scaffold/model-parser.d.ts +20 -1
  89. package/dist/core/scaffold/model-parser.d.ts.map +1 -1
  90. package/dist/core/scaffold/model-parser.js +329 -135
  91. package/dist/core/scaffold/model-parser.js.map +1 -1
  92. package/dist/core/scaffold/nextjs-generator.d.ts +8 -0
  93. package/dist/core/scaffold/nextjs-generator.d.ts.map +1 -1
  94. package/dist/core/scaffold/nextjs-generator.js +314 -182
  95. package/dist/core/scaffold/nextjs-generator.js.map +1 -1
  96. package/dist/core/scaffold/openapi-generator.d.ts +3 -0
  97. package/dist/core/scaffold/openapi-generator.d.ts.map +1 -0
  98. package/dist/core/scaffold/openapi-generator.js +190 -0
  99. package/dist/core/scaffold/openapi-generator.js.map +1 -0
  100. package/dist/core/scaffold/ui-generator.d.ts +10 -4
  101. package/dist/core/scaffold/ui-generator.d.ts.map +1 -1
  102. package/dist/core/scaffold/ui-generator.js +768 -663
  103. package/dist/core/scaffold/ui-generator.js.map +1 -1
  104. package/dist/database/base-model.d.ts +3 -3
  105. package/dist/database/base-model.js +3 -3
  106. package/dist/index.d.ts +2 -2
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +2 -1
  109. package/dist/index.js.map +1 -1
  110. package/dist/machine/contracts.d.ts +16 -0
  111. package/dist/machine/contracts.d.ts.map +1 -0
  112. package/dist/machine/contracts.js +3 -0
  113. package/dist/machine/contracts.js.map +1 -0
  114. package/dist/machine/errors.d.ts +11 -0
  115. package/dist/machine/errors.d.ts.map +1 -0
  116. package/dist/machine/errors.js +34 -0
  117. package/dist/machine/errors.js.map +1 -0
  118. package/dist/machine/index.d.ts +3 -0
  119. package/dist/machine/index.d.ts.map +1 -0
  120. package/dist/machine/index.js +156 -0
  121. package/dist/machine/index.js.map +1 -0
  122. package/dist/mcp/index.d.ts +25 -0
  123. package/dist/mcp/index.d.ts.map +1 -0
  124. package/dist/mcp/index.js +184 -0
  125. package/dist/mcp/index.js.map +1 -0
  126. package/dist/types/index.d.ts +65 -0
  127. package/dist/types/index.d.ts.map +1 -1
  128. package/dist/utils/package-manager.d.ts +109 -0
  129. package/dist/utils/package-manager.d.ts.map +1 -0
  130. package/dist/utils/package-manager.js +215 -0
  131. package/dist/utils/package-manager.js.map +1 -0
  132. package/package.json +85 -73
  133. package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +1139 -0
  134. package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +194 -0
  135. package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +532 -0
  136. package/src/__tests__/auth.test.ts +654 -0
  137. package/src/__tests__/config.test.ts +263 -0
  138. package/src/__tests__/connector-functions-generator.test.ts +288 -0
  139. package/src/__tests__/connector-mock-server.test.ts +439 -0
  140. package/src/__tests__/connector-model-bff.test.ts +162 -0
  141. package/src/__tests__/dev-seeds.test.ts +112 -0
  142. package/src/__tests__/dev.test.ts +154 -0
  143. package/src/__tests__/fixtures.ts +144 -0
  144. package/src/__tests__/functions-generator.test.ts +237 -0
  145. package/src/__tests__/init.test.ts +80 -0
  146. package/src/__tests__/machine.test.ts +212 -0
  147. package/src/__tests__/mcp.test.ts +56 -0
  148. package/src/__tests__/model-parser.test.ts +72 -0
  149. package/src/__tests__/nextjs-generator.test.ts +97 -0
  150. package/src/__tests__/openapi-generator.test.ts +43 -0
  151. package/src/__tests__/package-manager.test.ts +189 -0
  152. package/src/__tests__/scaffold.test.ts +39 -0
  153. package/src/__tests__/string-utils.test.ts +75 -0
  154. package/src/__tests__/ui-generator.test.ts +144 -0
  155. package/src/__tests__/zod-mock-generator.test.ts +132 -0
  156. package/src/cli/commands/add-auth.ts +500 -0
  157. package/src/cli/commands/add-connector.ts +158 -0
  158. package/src/cli/commands/create-model.ts +62 -0
  159. package/src/cli/commands/dev-seeds.ts +358 -0
  160. package/src/cli/commands/dev.ts +962 -0
  161. package/src/cli/commands/index.ts +9 -0
  162. package/src/cli/commands/init.ts +3371 -0
  163. package/src/cli/commands/provision.ts +193 -0
  164. package/src/cli/commands/scaffold.ts +1211 -0
  165. package/src/cli/index.ts +193 -0
  166. package/src/core/config.ts +308 -0
  167. package/src/core/mock/connector-mock-server.ts +555 -0
  168. package/src/core/mock/zod-mock-generator.ts +205 -0
  169. package/src/core/operations/create-model.ts +174 -0
  170. package/src/core/operations/runtime.ts +235 -0
  171. package/src/core/operations/scaffold-machine.ts +91 -0
  172. package/src/core/project/manifest.ts +402 -0
  173. package/src/core/project/validation.ts +221 -0
  174. package/src/core/scaffold/auth-generator.ts +1284 -0
  175. package/src/core/scaffold/connector-functions-generator.ts +1128 -0
  176. package/src/core/scaffold/functions-generator.ts +970 -0
  177. package/src/core/scaffold/model-parser.ts +841 -0
  178. package/src/core/scaffold/nextjs-generator.ts +370 -0
  179. package/src/core/scaffold/openapi-generator.ts +212 -0
  180. package/src/core/scaffold/ui-generator.ts +1061 -0
  181. package/src/database/base-model.ts +184 -0
  182. package/src/database/client.ts +140 -0
  183. package/src/database/repository.ts +104 -0
  184. package/src/database/runtime-check.ts +25 -0
  185. package/src/index.ts +27 -0
  186. package/src/machine/contracts.ts +17 -0
  187. package/src/machine/errors.ts +34 -0
  188. package/src/machine/index.ts +173 -0
  189. package/src/mcp/index.ts +185 -0
  190. package/src/types/index.ts +134 -0
  191. package/src/utils/package-manager.ts +229 -0
@@ -0,0 +1,193 @@
1
+ import { Command } from 'commander';
2
+ import { execSync } from 'child_process';
3
+ import * as fs from 'fs';
4
+ import * as path from 'path';
5
+ import prompts from 'prompts';
6
+ import { ensureSwallowKitProject } from '../../core/config';
7
+
8
+ export const provisionCommand = new Command('provision')
9
+ .description('Provision Azure resources using Bicep templates')
10
+ .requiredOption('-g, --resource-group <name>', 'Resource group name')
11
+ .option('--subscription <id>', 'Azure subscription ID (optional)')
12
+ .action(async (options) => {
13
+ // SwallowKit プロジェクトディレクトリかどうかを検証
14
+ ensureSwallowKitProject("provision");
15
+
16
+ console.log('🚀 Starting Azure resource provisioning...\n');
17
+
18
+ // Check if Azure CLI is installed
19
+ try {
20
+ execSync('az --version', { stdio: 'ignore' });
21
+ } catch {
22
+ console.error('❌ Azure CLI is not installed. Please install it first: https://aka.ms/azure-cli');
23
+ process.exit(1);
24
+ }
25
+
26
+ // Check if Bicep files exist
27
+ const infraDir = path.join(process.cwd(), 'infra');
28
+ const mainBicepPath = path.join(infraDir, 'main.bicep');
29
+ const parametersPath = path.join(infraDir, 'main.parameters.json');
30
+
31
+ if (!fs.existsSync(mainBicepPath)) {
32
+ console.error('❌ Bicep files not found. Run "swallowkit init" first to generate infrastructure files.');
33
+ process.exit(1);
34
+ }
35
+
36
+ try {
37
+ // Prompt for region selection
38
+ console.log('📍 Select Azure regions for your resources:\n');
39
+
40
+ const regionChoices = await prompts([
41
+ {
42
+ type: 'select',
43
+ name: 'primaryLocation',
44
+ message: 'Primary location for Functions and Cosmos DB',
45
+ choices: [
46
+ { title: 'Japan East (japaneast)', value: 'japaneast' },
47
+ { title: 'Japan West (japanwest)', value: 'japanwest' },
48
+ { title: 'East Asia (eastasia)', value: 'eastasia' },
49
+ { title: 'Southeast Asia (southeastasia)', value: 'southeastasia' },
50
+ { title: 'East US (eastus)', value: 'eastus' },
51
+ { title: 'East US 2 (eastus2)', value: 'eastus2' },
52
+ { title: 'West US 2 (westus2)', value: 'westus2' },
53
+ { title: 'Central US (centralus)', value: 'centralus' },
54
+ { title: 'West Europe (westeurope)', value: 'westeurope' },
55
+ ],
56
+ initial: 0, // Default to japaneast
57
+ },
58
+ {
59
+ type: 'select',
60
+ name: 'swaLocation',
61
+ message: 'Static Web App location (limited availability)',
62
+ choices: [
63
+ { title: 'East Asia (eastasia) - Recommended for Japan', value: 'eastasia' },
64
+ { title: 'West US 2 (westus2)', value: 'westus2' },
65
+ { title: 'Central US (centralus)', value: 'centralus' },
66
+ { title: 'East US 2 (eastus2)', value: 'eastus2' },
67
+ { title: 'West Europe (westeurope)', value: 'westeurope' },
68
+ ],
69
+ initial: 0, // Default to eastasia
70
+ },
71
+ ], {
72
+ onCancel: () => {
73
+ throw new Error('User cancelled');
74
+ }
75
+ });
76
+
77
+ if (!regionChoices.primaryLocation || !regionChoices.swaLocation) {
78
+ console.log('\n❌ Region selection cancelled.');
79
+ process.exit(1);
80
+ }
81
+
82
+ const primaryLocation = regionChoices.primaryLocation;
83
+ const swaLocation = regionChoices.swaLocation;
84
+
85
+ console.log(`\n✓ Primary location: ${primaryLocation}`);
86
+ console.log(`✓ Static Web App location: ${swaLocation}`);
87
+
88
+ // Confirmation prompt to prevent accidental wrong selection
89
+ const confirmation = await prompts({
90
+ type: 'confirm',
91
+ name: 'proceed',
92
+ message: `Proceed with deployment to ${primaryLocation} (primary) and ${swaLocation} (SWA)?`,
93
+ initial: true
94
+ }, {
95
+ onCancel: () => {
96
+ throw new Error('User cancelled');
97
+ }
98
+ });
99
+
100
+ if (!confirmation.proceed) {
101
+ console.log('\n❌ Deployment cancelled by user.');
102
+ process.exit(0);
103
+ }
104
+
105
+ console.log('');
106
+ // Set subscription if provided
107
+ if (options.subscription) {
108
+ console.log(`🔧 Setting subscription: ${options.subscription}`);
109
+ execSync(`az account set --subscription ${options.subscription}`, { stdio: 'inherit' });
110
+ }
111
+
112
+ // Create resource group if it doesn't exist (use primary location)
113
+ console.log(`🔧 Ensuring resource group exists: ${options.resourceGroup}`);
114
+ execSync(
115
+ `az group create --name ${options.resourceGroup} --location ${primaryLocation}`,
116
+ { stdio: 'inherit' }
117
+ );
118
+
119
+ // Deploy Bicep template with both locations
120
+ console.log('\n📦 Deploying resources (this may take several minutes)...\n');
121
+ const deployCommand = `az deployment group create --resource-group ${options.resourceGroup} --template-file "${mainBicepPath}" --parameters "${parametersPath}" --parameters location=${primaryLocation} --parameters swaLocation=${swaLocation}`;
122
+
123
+ const output = execSync(deployCommand, { encoding: 'utf-8', stdio: 'pipe' });
124
+ const deployment = JSON.parse(output);
125
+
126
+ // Display outputs
127
+ console.log('\n✅ Deployment completed successfully!\n');
128
+ console.log('📋 Resource Information:');
129
+
130
+ let swaName = '<swa-name>';
131
+ let functionAppName = '<function-name>';
132
+ if (deployment.properties?.outputs) {
133
+ const outputs = deployment.properties.outputs;
134
+ if (outputs.staticWebAppName) {
135
+ swaName = outputs.staticWebAppName.value;
136
+ console.log(` - Static Web App: ${swaName}`);
137
+ console.log(` - URL: https://${outputs.staticWebAppUrl.value}`);
138
+ }
139
+ if (outputs.functionsAppName) {
140
+ functionAppName = outputs.functionsAppName.value;
141
+ console.log(` - Function App: ${functionAppName}`);
142
+ console.log(` - URL: https://${outputs.functionsAppUrl.value}`);
143
+ }
144
+ if (outputs.cosmosDbAccountName) {
145
+ console.log(` - Cosmos DB: ${outputs.cosmosDbAccountName.value}`);
146
+ console.log(` - Database: ${outputs.cosmosDatabaseName.value}`);
147
+ }
148
+ }
149
+
150
+ // Next steps guidance
151
+ console.log('\n📝 Next Steps:');
152
+ console.log(' 1. Configure CI/CD secrets/variables:\n');
153
+
154
+ // Fetch SWA deployment token
155
+ console.log(' [AZURE_STATIC_WEB_APPS_API_TOKEN]');
156
+ try {
157
+ const swaToken = execSync(
158
+ `az staticwebapp secrets list --name ${swaName} --resource-group ${options.resourceGroup} --query "properties.apiKey" -o tsv`,
159
+ { encoding: 'utf-8', stdio: 'pipe' }
160
+ ).trim();
161
+ console.log(` ${swaToken}\n`);
162
+ } catch {
163
+ console.log(' ⚠️ Failed to retrieve. Run manually:');
164
+ console.log(` az staticwebapp secrets list --name ${swaName} --resource-group ${options.resourceGroup} --query "properties.apiKey" -o tsv\n`);
165
+ }
166
+
167
+ // Function App name (already known)
168
+ console.log(' [AZURE_FUNCTIONAPP_NAME]');
169
+ console.log(` ${functionAppName}\n`);
170
+
171
+ // Fetch Function App publish profile
172
+ console.log(' [AZURE_FUNCTIONAPP_PUBLISH_PROFILE]');
173
+ try {
174
+ const publishProfile = execSync(
175
+ `az webapp deployment list-publishing-profiles --name ${functionAppName} --resource-group ${options.resourceGroup} --xml`,
176
+ { encoding: 'utf-8', stdio: 'pipe' }
177
+ ).trim();
178
+ console.log(` ${publishProfile}\n`);
179
+ } catch {
180
+ console.log(' ⚠️ Failed to retrieve. Run manually:');
181
+ console.log(` az webapp deployment list-publishing-profiles --name ${functionAppName} --resource-group ${options.resourceGroup} --xml\n`);
182
+ }
183
+
184
+ console.log(' 2. Set up your CI/CD pipeline (GitHub Actions or Azure Pipelines)');
185
+ console.log(' 3. Manually trigger the first deployment in your CI/CD pipeline');
186
+ console.log(' (Automatic deployments will run on subsequent pushes)\n');
187
+
188
+ } catch (error: any) {
189
+ console.error('❌ Deployment failed:');
190
+ console.error(error.message);
191
+ process.exit(1);
192
+ }
193
+ });