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.
- package/LICENSE +21 -21
- package/README.ja.md +312 -215
- package/README.md +369 -216
- package/dist/__tests__/fixtures.d.ts +22 -0
- package/dist/__tests__/fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures.js +146 -0
- package/dist/__tests__/fixtures.js.map +1 -0
- package/dist/cli/commands/add-auth.d.ts +10 -0
- package/dist/cli/commands/add-auth.d.ts.map +1 -0
- package/dist/cli/commands/add-auth.js +444 -0
- package/dist/cli/commands/add-auth.js.map +1 -0
- package/dist/cli/commands/add-connector.d.ts +20 -0
- package/dist/cli/commands/add-connector.d.ts.map +1 -0
- package/dist/cli/commands/add-connector.js +163 -0
- package/dist/cli/commands/add-connector.js.map +1 -0
- package/dist/cli/commands/create-model.d.ts +1 -4
- package/dist/cli/commands/create-model.d.ts.map +1 -1
- package/dist/cli/commands/create-model.js +21 -82
- package/dist/cli/commands/create-model.js.map +1 -1
- package/dist/cli/commands/dev-seeds.d.ts +35 -0
- package/dist/cli/commands/dev-seeds.d.ts.map +1 -0
- package/dist/cli/commands/dev-seeds.js +292 -0
- package/dist/cli/commands/dev-seeds.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +19 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +476 -117
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +3 -1
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +13 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +2627 -1708
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +3 -0
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +617 -129
- package/dist/cli/commands/scaffold.js.map +1 -1
- package/dist/cli/index.d.ts +5 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +164 -42
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts +8 -2
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +90 -4
- package/dist/core/config.js.map +1 -1
- package/dist/core/mock/connector-mock-server.d.ts +101 -0
- package/dist/core/mock/connector-mock-server.d.ts.map +1 -0
- package/dist/core/mock/connector-mock-server.js +480 -0
- package/dist/core/mock/connector-mock-server.js.map +1 -0
- package/dist/core/mock/zod-mock-generator.d.ts +14 -0
- package/dist/core/mock/zod-mock-generator.d.ts.map +1 -0
- package/dist/core/mock/zod-mock-generator.js +163 -0
- package/dist/core/mock/zod-mock-generator.js.map +1 -0
- package/dist/core/operations/create-model.d.ts +15 -0
- package/dist/core/operations/create-model.d.ts.map +1 -0
- package/dist/core/operations/create-model.js +171 -0
- package/dist/core/operations/create-model.js.map +1 -0
- package/dist/core/operations/runtime.d.ts +32 -0
- package/dist/core/operations/runtime.d.ts.map +1 -0
- package/dist/core/operations/runtime.js +225 -0
- package/dist/core/operations/runtime.js.map +1 -0
- package/dist/core/operations/scaffold-machine.d.ts +16 -0
- package/dist/core/operations/scaffold-machine.d.ts.map +1 -0
- package/dist/core/operations/scaffold-machine.js +63 -0
- package/dist/core/operations/scaffold-machine.js.map +1 -0
- package/dist/core/project/manifest.d.ts +92 -0
- package/dist/core/project/manifest.d.ts.map +1 -0
- package/dist/core/project/manifest.js +321 -0
- package/dist/core/project/manifest.js.map +1 -0
- package/dist/core/project/validation.d.ts +20 -0
- package/dist/core/project/validation.d.ts.map +1 -0
- package/dist/core/project/validation.js +204 -0
- package/dist/core/project/validation.js.map +1 -0
- package/dist/core/scaffold/auth-generator.d.ts +38 -0
- package/dist/core/scaffold/auth-generator.d.ts.map +1 -0
- package/dist/core/scaffold/auth-generator.js +1244 -0
- package/dist/core/scaffold/auth-generator.js.map +1 -0
- package/dist/core/scaffold/connector-functions-generator.d.ts +41 -0
- package/dist/core/scaffold/connector-functions-generator.d.ts.map +1 -0
- package/dist/core/scaffold/connector-functions-generator.js +1027 -0
- package/dist/core/scaffold/connector-functions-generator.js.map +1 -0
- package/dist/core/scaffold/functions-generator.d.ts +7 -1
- package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
- package/dist/core/scaffold/functions-generator.js +920 -213
- package/dist/core/scaffold/functions-generator.js.map +1 -1
- package/dist/core/scaffold/model-parser.d.ts +20 -1
- package/dist/core/scaffold/model-parser.d.ts.map +1 -1
- package/dist/core/scaffold/model-parser.js +329 -135
- package/dist/core/scaffold/model-parser.js.map +1 -1
- package/dist/core/scaffold/nextjs-generator.d.ts +8 -0
- package/dist/core/scaffold/nextjs-generator.d.ts.map +1 -1
- package/dist/core/scaffold/nextjs-generator.js +314 -182
- package/dist/core/scaffold/nextjs-generator.js.map +1 -1
- package/dist/core/scaffold/openapi-generator.d.ts +3 -0
- package/dist/core/scaffold/openapi-generator.d.ts.map +1 -0
- package/dist/core/scaffold/openapi-generator.js +190 -0
- package/dist/core/scaffold/openapi-generator.js.map +1 -0
- package/dist/core/scaffold/ui-generator.d.ts +10 -4
- package/dist/core/scaffold/ui-generator.d.ts.map +1 -1
- package/dist/core/scaffold/ui-generator.js +768 -663
- package/dist/core/scaffold/ui-generator.js.map +1 -1
- package/dist/database/base-model.d.ts +3 -3
- package/dist/database/base-model.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/machine/contracts.d.ts +16 -0
- package/dist/machine/contracts.d.ts.map +1 -0
- package/dist/machine/contracts.js +3 -0
- package/dist/machine/contracts.js.map +1 -0
- package/dist/machine/errors.d.ts +11 -0
- package/dist/machine/errors.d.ts.map +1 -0
- package/dist/machine/errors.js +34 -0
- package/dist/machine/errors.js.map +1 -0
- package/dist/machine/index.d.ts +3 -0
- package/dist/machine/index.d.ts.map +1 -0
- package/dist/machine/index.js +156 -0
- package/dist/machine/index.js.map +1 -0
- package/dist/mcp/index.d.ts +25 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +184 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/types/index.d.ts +65 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/package-manager.d.ts +109 -0
- package/dist/utils/package-manager.d.ts.map +1 -0
- package/dist/utils/package-manager.js +215 -0
- package/dist/utils/package-manager.js.map +1 -0
- package/package.json +85 -73
- package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +1139 -0
- package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +194 -0
- package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +532 -0
- package/src/__tests__/auth.test.ts +654 -0
- package/src/__tests__/config.test.ts +263 -0
- package/src/__tests__/connector-functions-generator.test.ts +288 -0
- package/src/__tests__/connector-mock-server.test.ts +439 -0
- package/src/__tests__/connector-model-bff.test.ts +162 -0
- package/src/__tests__/dev-seeds.test.ts +112 -0
- package/src/__tests__/dev.test.ts +154 -0
- package/src/__tests__/fixtures.ts +144 -0
- package/src/__tests__/functions-generator.test.ts +237 -0
- package/src/__tests__/init.test.ts +80 -0
- package/src/__tests__/machine.test.ts +212 -0
- package/src/__tests__/mcp.test.ts +56 -0
- package/src/__tests__/model-parser.test.ts +72 -0
- package/src/__tests__/nextjs-generator.test.ts +97 -0
- package/src/__tests__/openapi-generator.test.ts +43 -0
- package/src/__tests__/package-manager.test.ts +189 -0
- package/src/__tests__/scaffold.test.ts +39 -0
- package/src/__tests__/string-utils.test.ts +75 -0
- package/src/__tests__/ui-generator.test.ts +144 -0
- package/src/__tests__/zod-mock-generator.test.ts +132 -0
- package/src/cli/commands/add-auth.ts +500 -0
- package/src/cli/commands/add-connector.ts +158 -0
- package/src/cli/commands/create-model.ts +62 -0
- package/src/cli/commands/dev-seeds.ts +358 -0
- package/src/cli/commands/dev.ts +962 -0
- package/src/cli/commands/index.ts +9 -0
- package/src/cli/commands/init.ts +3371 -0
- package/src/cli/commands/provision.ts +193 -0
- package/src/cli/commands/scaffold.ts +1211 -0
- package/src/cli/index.ts +193 -0
- package/src/core/config.ts +308 -0
- package/src/core/mock/connector-mock-server.ts +555 -0
- package/src/core/mock/zod-mock-generator.ts +205 -0
- package/src/core/operations/create-model.ts +174 -0
- package/src/core/operations/runtime.ts +235 -0
- package/src/core/operations/scaffold-machine.ts +91 -0
- package/src/core/project/manifest.ts +402 -0
- package/src/core/project/validation.ts +221 -0
- package/src/core/scaffold/auth-generator.ts +1284 -0
- package/src/core/scaffold/connector-functions-generator.ts +1128 -0
- package/src/core/scaffold/functions-generator.ts +970 -0
- package/src/core/scaffold/model-parser.ts +841 -0
- package/src/core/scaffold/nextjs-generator.ts +370 -0
- package/src/core/scaffold/openapi-generator.ts +212 -0
- package/src/core/scaffold/ui-generator.ts +1061 -0
- package/src/database/base-model.ts +184 -0
- package/src/database/client.ts +140 -0
- package/src/database/repository.ts +104 -0
- package/src/database/runtime-check.ts +25 -0
- package/src/index.ts +27 -0
- package/src/machine/contracts.ts +17 -0
- package/src/machine/errors.ts +34 -0
- package/src/machine/index.ts +173 -0
- package/src/mcp/index.ts +185 -0
- package/src/types/index.ts +134 -0
- 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
|
+
});
|