@friggframework/devtools 2.0.0--canary.705.f070722.0 → 2.0.0--canary.662.6d3931c.0
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/frigg-cli/README.md +31 -115
- package/frigg-cli/__tests__/unit/commands/build.test.js +0 -3
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +24 -33
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +6 -10
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
- package/frigg-cli/__tests__/unit/commands/install.test.js +341 -601
- package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
- package/frigg-cli/build-command/index.js +0 -6
- package/frigg-cli/deploy-command/index.js +0 -6
- package/frigg-cli/generate-command/index.js +0 -1
- package/frigg-cli/generate-iam-command.js +0 -1
- package/frigg-cli/index.js +5 -22
- package/frigg-cli/index.test.js +158 -0
- package/frigg-cli/init-command/backend-first-handler.js +551 -395
- package/frigg-cli/init-command/index.js +35 -82
- package/frigg-cli/install-command/commit-changes.js +8 -40
- package/frigg-cli/install-command/environment-variables.js +0 -15
- package/frigg-cli/install-command/index.js +21 -96
- package/frigg-cli/install-command/install-package.js +4 -77
- package/frigg-cli/install-command/integration-file.js +11 -20
- package/frigg-cli/install-command/template.js +75 -102
- package/frigg-cli/install-command/validate-package.js +4 -36
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/start-command/index.js +0 -4
- package/frigg-cli/start-command/start-command.test.js +0 -3
- package/frigg-cli/test/init-command.test.js +2 -9
- package/infrastructure/__tests__/postgres-config.test.js +835 -241
- package/infrastructure/__tests__/template-generation.test.js +8 -36
- package/infrastructure/create-frigg-infrastructure.js +1 -4
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +98 -80
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -6
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -30
- package/infrastructure/domains/database/aurora-builder.js +2 -13
- package/infrastructure/domains/database/aurora-builder.test.js +0 -22
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +8 -12
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +7 -19
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +8 -12
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +18 -17
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +2 -12
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +1 -8
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +2 -4
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +0 -10
- package/infrastructure/domains/networking/vpc-builder.js +8 -18
- package/infrastructure/domains/networking/vpc-builder.test.js +12 -26
- package/infrastructure/domains/security/iam-generator.js +5 -112
- package/infrastructure/domains/security/iam-generator.test.js +0 -94
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +2 -26
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +1 -34
- package/infrastructure/infrastructure-composer.test.js +794 -268
- package/infrastructure/integration.test.js +381 -0
- package/infrastructure/scripts/build-prisma-layer.test.js +7 -28
- package/infrastructure/scripts/build-time-discovery.test.js +3 -18
- package/package.json +8 -10
- package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +0 -92
- package/frigg-cli/init-command/deployment-modes.js +0 -7
- package/frigg-cli/init-command/safe-path.js +0 -58
- package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
- package/frigg-cli/install-command/app-definition.js +0 -174
- package/frigg-cli/install-command/resolve-module.js +0 -69
- package/frigg-cli/templates/backend/README.md +0 -267
- package/frigg-cli/templates/backend/env.example +0 -20
- package/frigg-cli/templates/backend/gitignore +0 -10
- package/frigg-cli/templates/backend/index.js +0 -114
- package/frigg-cli/templates/backend/infrastructure.js +0 -20
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +0 -63
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +0 -133
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +0 -443
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +0 -262
- package/frigg-cli/validate-command/checks/config.js +0 -504
- package/frigg-cli/validate-command/checks/integrations.js +0 -274
- package/frigg-cli/validate-command/format-report.js +0 -58
- package/frigg-cli/validate-command/index.js +0 -107
- package/frigg-cli/validate-command/load-app-definition.js +0 -105
- package/frigg-cli/validate-command/schema-issues.js +0 -154
- package/frigg-cli/validate-command/validate-app-definition.js +0 -60
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -281
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
- package/infrastructure/app-definition-schema-contract.test.js +0 -629
- package/infrastructure/create-frigg-infrastructure.test.js +0 -51
|
@@ -1,80 +1,21 @@
|
|
|
1
1
|
const fs = require('fs-extra');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
-
const {
|
|
4
|
+
const { select, confirm, multiselect } = require('@inquirer/prompts');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
5
6
|
const spawn = require('cross-spawn');
|
|
6
|
-
const { resolveInside } = require('./safe-path');
|
|
7
7
|
const npmRegistry = require('../utils/npm-registry');
|
|
8
|
-
const {
|
|
9
|
-
const { formatReport } = require('../validate-command/format-report');
|
|
10
|
-
const {
|
|
11
|
-
getScaffoldDependencies,
|
|
12
|
-
getScaffoldScripts,
|
|
13
|
-
} = require('./scaffold-dependencies');
|
|
14
|
-
|
|
15
|
-
const {
|
|
16
|
-
DEPLOYMENT_MODES,
|
|
17
|
-
DEFAULT_DEPLOYMENT_MODE,
|
|
18
|
-
} = require('./deployment-modes');
|
|
19
|
-
|
|
20
|
-
/** Sub-directory that holds the Frigg backend in embedded mode. */
|
|
21
|
-
const EMBEDDED_DIR = 'frigg-integration';
|
|
8
|
+
const { validateAppDefinition, formatErrors } = require('@friggframework/schemas');
|
|
22
9
|
|
|
23
10
|
/**
|
|
24
|
-
*
|
|
25
|
-
* published packages, and dotfiles are easy to lose, so they are renamed when
|
|
26
|
-
* copied into the new project.
|
|
27
|
-
*/
|
|
28
|
-
const RENAMED_TEMPLATE_FILES = {
|
|
29
|
-
gitignore: '.gitignore',
|
|
30
|
-
'env.example': '.env.example',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Files that may already exist in the target directory. They are kept (not
|
|
35
|
-
* overwritten) unless --force is given.
|
|
36
|
-
*/
|
|
37
|
-
const PRESERVED_FILES = ['README.md', '.gitignore'];
|
|
38
|
-
const ALLOWED_EXISTING_FILES = ['.git', '.DS_Store', ...PRESERVED_FILES];
|
|
39
|
-
|
|
40
|
-
const TEMPLATE_APP_NAME = "name: 'frigg-app',";
|
|
41
|
-
const TEMPLATE_README_TITLE = '# Frigg Backend';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Scaffolds a new Frigg backend application.
|
|
45
|
-
*
|
|
46
|
-
* Prompts are interactive only when stdin is a TTY and --yes was not given;
|
|
47
|
-
* otherwise every prompt resolves to its default, so `frigg init` works in CI
|
|
48
|
-
* and scripts.
|
|
11
|
+
* Backend-first template handler that treats frontend as optional demonstration
|
|
49
12
|
*/
|
|
50
13
|
class BackendFirstHandler {
|
|
51
14
|
constructor(targetPath, options = {}) {
|
|
52
|
-
this.targetPath =
|
|
53
|
-
this.appName = path.basename(
|
|
15
|
+
this.targetPath = targetPath;
|
|
16
|
+
this.appName = path.basename(targetPath);
|
|
54
17
|
this.options = options;
|
|
55
18
|
this.templatesDir = path.join(__dirname, '..', 'templates');
|
|
56
|
-
this.interactive =
|
|
57
|
-
options.interactive !== undefined
|
|
58
|
-
? Boolean(options.interactive)
|
|
59
|
-
: !options.yes && Boolean(process.stdin.isTTY);
|
|
60
|
-
// Test seam: inject prompt implementations.
|
|
61
|
-
this.prompts = options.prompts || null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Ask a question, or return its default when running non-interactively.
|
|
66
|
-
*
|
|
67
|
-
* @param {'select'|'confirm'|'checkbox'} type - @inquirer/prompts function.
|
|
68
|
-
* @param {object} config - Prompt config; `default` is used when
|
|
69
|
-
* non-interactive.
|
|
70
|
-
*/
|
|
71
|
-
async ask(type, config) {
|
|
72
|
-
if (!this.interactive) {
|
|
73
|
-
return config.default;
|
|
74
|
-
}
|
|
75
|
-
// eslint-disable-next-line global-require
|
|
76
|
-
const prompts = this.prompts || require('@inquirer/prompts');
|
|
77
|
-
return prompts[type](config);
|
|
78
19
|
}
|
|
79
20
|
|
|
80
21
|
/**
|
|
@@ -82,27 +23,34 @@ class BackendFirstHandler {
|
|
|
82
23
|
*/
|
|
83
24
|
async initialize() {
|
|
84
25
|
console.log(chalk.blue('🚀 Welcome to Frigg - Integration Framework'));
|
|
85
|
-
console.log(
|
|
86
|
-
chalk.gray('Creating a new Frigg backend application...\n')
|
|
87
|
-
);
|
|
26
|
+
console.log(chalk.gray('Creating a new Frigg backend application...\n'));
|
|
88
27
|
|
|
28
|
+
// Get deployment mode
|
|
89
29
|
const deploymentMode = await this.selectDeploymentMode();
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
? resolveInside(this.targetPath, EMBEDDED_DIR)
|
|
93
|
-
: this.targetPath;
|
|
94
|
-
|
|
95
|
-
// Fail fast, before asking anything else, if the target is not empty.
|
|
96
|
-
await this.ensureSafeDirectory(this.projectDir);
|
|
97
|
-
|
|
30
|
+
|
|
31
|
+
// Get project configuration
|
|
98
32
|
const config = await this.getProjectConfiguration(deploymentMode);
|
|
99
33
|
|
|
34
|
+
// Create project structure
|
|
100
35
|
await this.createProject(deploymentMode, config);
|
|
101
36
|
|
|
102
|
-
console.log(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
37
|
+
console.log(chalk.green('\n✅ Frigg application created successfully!'));
|
|
38
|
+
|
|
39
|
+
// If user needs custom API module, prompt to create it
|
|
40
|
+
if (config.needsCustomApiModule) {
|
|
41
|
+
console.log(chalk.cyan('\n🔧 Now let\'s create your custom API module...'));
|
|
42
|
+
const createModule = await confirm({
|
|
43
|
+
message: 'Would you like to create your custom API module now?',
|
|
44
|
+
default: true
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (createModule) {
|
|
48
|
+
console.log(chalk.gray('\n Run this command after setup:'));
|
|
49
|
+
console.log(chalk.cyan(` cd ${path.relative(process.cwd(), this.targetPath)}`));
|
|
50
|
+
console.log(chalk.cyan(' frigg generate:api-module\n'));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
106
54
|
this.displayNextSteps(deploymentMode, config);
|
|
107
55
|
}
|
|
108
56
|
|
|
@@ -111,32 +59,27 @@ class BackendFirstHandler {
|
|
|
111
59
|
*/
|
|
112
60
|
async selectDeploymentMode() {
|
|
113
61
|
if (this.options.mode) {
|
|
114
|
-
if (!DEPLOYMENT_MODES.includes(this.options.mode)) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
`Invalid --mode "${
|
|
117
|
-
this.options.mode
|
|
118
|
-
}". Expected one of: ${DEPLOYMENT_MODES.join(', ')}`
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
62
|
return this.options.mode;
|
|
122
63
|
}
|
|
123
64
|
|
|
124
|
-
|
|
65
|
+
const mode = await select({
|
|
125
66
|
message: 'How will you deploy this Frigg application?',
|
|
126
67
|
choices: [
|
|
127
68
|
{
|
|
128
|
-
name: '
|
|
129
|
-
value: 'standalone',
|
|
130
|
-
description: 'Run Frigg as an independent microservice',
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
name: 'Embedded - Add to an existing repository',
|
|
69
|
+
name: 'Embedded - Integrate into existing application',
|
|
134
70
|
value: 'embedded',
|
|
135
|
-
description:
|
|
71
|
+
description: 'Add Frigg as a library to your existing backend'
|
|
136
72
|
},
|
|
73
|
+
{
|
|
74
|
+
name: 'Standalone - Deploy as separate service',
|
|
75
|
+
value: 'standalone',
|
|
76
|
+
description: 'Run Frigg as an independent microservice'
|
|
77
|
+
}
|
|
137
78
|
],
|
|
138
|
-
default:
|
|
79
|
+
default: 'standalone'
|
|
139
80
|
});
|
|
81
|
+
|
|
82
|
+
return mode;
|
|
140
83
|
}
|
|
141
84
|
|
|
142
85
|
/**
|
|
@@ -145,136 +88,154 @@ class BackendFirstHandler {
|
|
|
145
88
|
async getProjectConfiguration(deploymentMode) {
|
|
146
89
|
const config = { deploymentMode };
|
|
147
90
|
|
|
148
|
-
|
|
91
|
+
// Ask about the purpose of this Frigg application
|
|
92
|
+
config.appPurpose = await select({
|
|
149
93
|
message: 'What are you building with Frigg?',
|
|
150
94
|
choices: [
|
|
151
95
|
{
|
|
152
96
|
name: 'Integrations for my own application',
|
|
153
97
|
value: 'own-app',
|
|
154
|
-
description:
|
|
155
|
-
'Build integrations that connect your app with third-party services',
|
|
98
|
+
description: 'Build integrations that connect your app with third-party services'
|
|
156
99
|
},
|
|
157
100
|
{
|
|
158
101
|
name: 'Integration platform for multiple apps',
|
|
159
102
|
value: 'platform',
|
|
160
|
-
description:
|
|
161
|
-
'Build a platform that provides integrations to other applications',
|
|
103
|
+
description: 'Build a platform that provides integrations to other applications'
|
|
162
104
|
},
|
|
163
105
|
{
|
|
164
106
|
name: 'Just exploring Frigg',
|
|
165
107
|
value: 'exploring',
|
|
166
|
-
description:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
],
|
|
170
|
-
default: 'own-app',
|
|
108
|
+
description: 'Testing and learning about Frigg capabilities'
|
|
109
|
+
}
|
|
110
|
+
]
|
|
171
111
|
});
|
|
172
112
|
|
|
113
|
+
// If building for own app, ask about creating custom API module
|
|
173
114
|
if (config.appPurpose === 'own-app') {
|
|
174
|
-
config.needsCustomApiModule = await
|
|
175
|
-
message:
|
|
176
|
-
|
|
177
|
-
default: false,
|
|
115
|
+
config.needsCustomApiModule = await confirm({
|
|
116
|
+
message: 'Do you need to create an API module for your own application?',
|
|
117
|
+
default: true
|
|
178
118
|
});
|
|
119
|
+
|
|
120
|
+
if (config.needsCustomApiModule) {
|
|
121
|
+
console.log(chalk.cyan('\n💡 We\'ll help you create a custom API module after setup'));
|
|
122
|
+
console.log(chalk.gray(' This will allow other integrations to connect with your API\n'));
|
|
123
|
+
}
|
|
179
124
|
}
|
|
180
125
|
|
|
181
|
-
//
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
'Would you like to pick API modules to integrate with? (installed afterwards with `frigg install`)',
|
|
186
|
-
default: false,
|
|
126
|
+
// Ask about initial integrations
|
|
127
|
+
config.includeIntegrations = await confirm({
|
|
128
|
+
message: 'Would you like to create integrations with available API modules?',
|
|
129
|
+
default: true
|
|
187
130
|
});
|
|
188
131
|
|
|
189
132
|
if (config.includeIntegrations) {
|
|
190
|
-
|
|
133
|
+
console.log(chalk.gray('\n🔍 Discovering available API modules from npm...'));
|
|
134
|
+
|
|
135
|
+
// Fetch available modules from npm
|
|
136
|
+
const availableModules = await this.getAvailableModules();
|
|
137
|
+
|
|
138
|
+
if (availableModules.length === 0) {
|
|
139
|
+
console.log(chalk.yellow('⚠️ Could not fetch modules from npm. Using default list.'));
|
|
140
|
+
config.starterIntegrations = await this.selectDefaultIntegrations();
|
|
141
|
+
} else {
|
|
142
|
+
// Group modules by category for better UX
|
|
143
|
+
const groupedModules = await npmRegistry.getModulesByType();
|
|
144
|
+
const choices = [];
|
|
145
|
+
|
|
146
|
+
Object.entries(groupedModules).forEach(([category, modules]) => {
|
|
147
|
+
if (modules.length > 0) {
|
|
148
|
+
choices.push({ name: `--- ${category} ---`, value: null, disabled: true });
|
|
149
|
+
modules.forEach(mod => {
|
|
150
|
+
const name = mod.integrationName;
|
|
151
|
+
const value = mod.name.replace('@friggframework/api-module-', '');
|
|
152
|
+
choices.push({
|
|
153
|
+
name: `${name} - ${mod.description || 'No description'}`,
|
|
154
|
+
value: value,
|
|
155
|
+
short: name
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
config.starterIntegrations = await multiselect({
|
|
162
|
+
message: 'Select API modules to integrate (space to select, enter to confirm):',
|
|
163
|
+
choices,
|
|
164
|
+
instructions: '\n Press <space> to select, <a> to toggle all, <enter> to confirm\n',
|
|
165
|
+
validate: (answer) => {
|
|
166
|
+
if (answer.length === 0) {
|
|
167
|
+
return 'Please select at least one integration or press Ctrl+C to skip';
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
191
173
|
}
|
|
192
174
|
|
|
175
|
+
// Ask about demo frontend only if not explicitly disabled
|
|
176
|
+
if (this.options.frontend !== false) {
|
|
177
|
+
config.includeDemoFrontend = await confirm({
|
|
178
|
+
message: 'Include a demo frontend to showcase integration capabilities?',
|
|
179
|
+
default: false
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if (config.includeDemoFrontend) {
|
|
183
|
+
console.log(chalk.yellow('\n📝 Note: The demo frontend is for demonstration purposes only.'));
|
|
184
|
+
console.log(chalk.yellow(' For production, integrate Frigg into your existing application'));
|
|
185
|
+
console.log(chalk.yellow(' or use "frigg ui" for development and management.\n'));
|
|
186
|
+
|
|
187
|
+
config.frontendFramework = await select({
|
|
188
|
+
message: 'Which framework for the demo frontend?',
|
|
189
|
+
choices: [
|
|
190
|
+
{ name: 'React - Modern React with Vite', value: 'react' },
|
|
191
|
+
{ name: 'Vue 3 - Vue with Composition API', value: 'vue' },
|
|
192
|
+
{ name: 'Svelte - SvelteKit application', value: 'svelte' },
|
|
193
|
+
{ name: 'Angular - Angular with standalone components', value: 'angular' }
|
|
194
|
+
]
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
config.demoAuthMode = await select({
|
|
198
|
+
message: 'Demo authentication mode:',
|
|
199
|
+
choices: [
|
|
200
|
+
{
|
|
201
|
+
name: 'Mock Login - Simple username/password for demo',
|
|
202
|
+
value: 'mock',
|
|
203
|
+
description: 'Basic auth for demonstration'
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: 'API Credentials - Use your app\'s actual auth',
|
|
207
|
+
value: 'real',
|
|
208
|
+
description: 'Configure with your authentication system'
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
default: 'mock'
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Serverless configuration for standalone mode
|
|
193
217
|
if (deploymentMode === 'standalone') {
|
|
194
|
-
config.serverlessProvider = await
|
|
218
|
+
config.serverlessProvider = await select({
|
|
195
219
|
message: 'Which cloud provider will you use?',
|
|
196
220
|
choices: [
|
|
197
221
|
{ name: 'AWS Lambda', value: 'aws' },
|
|
198
|
-
{ name: 'Local Development Only', value: 'local' }
|
|
222
|
+
{ name: 'Local Development Only', value: 'local' }
|
|
199
223
|
],
|
|
200
|
-
default: 'aws'
|
|
224
|
+
default: 'aws'
|
|
201
225
|
});
|
|
202
226
|
}
|
|
203
227
|
|
|
204
|
-
config.installDependencies =
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
: await this.ask('confirm', {
|
|
208
|
-
message: 'Install dependencies now?',
|
|
209
|
-
default: true,
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
// Embedded mode lives inside an existing repository.
|
|
213
|
-
config.initializeGit =
|
|
214
|
-
deploymentMode === 'embedded' || this.options.git === false
|
|
215
|
-
? false
|
|
216
|
-
: await this.ask('confirm', {
|
|
217
|
-
message: 'Initialize Git repository?',
|
|
218
|
-
default: true,
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
return config;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Let the user pick API modules. Only names are collected; the next-steps
|
|
226
|
-
* output tells the user to run `frigg install <name>` for each.
|
|
227
|
-
*/
|
|
228
|
-
async selectIntegrations() {
|
|
229
|
-
console.log(
|
|
230
|
-
chalk.gray('\n🔍 Discovering available API modules from npm...')
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
const groupedModules = await this.getModulesByType();
|
|
234
|
-
const choices = [];
|
|
235
|
-
// eslint-disable-next-line global-require
|
|
236
|
-
const { Separator } = this.prompts || require('@inquirer/prompts');
|
|
237
|
-
|
|
238
|
-
Object.entries(groupedModules).forEach(([category, modules]) => {
|
|
239
|
-
if (modules.length === 0) return;
|
|
240
|
-
choices.push(new Separator(`--- ${category} ---`));
|
|
241
|
-
modules.forEach((mod) => {
|
|
242
|
-
choices.push({
|
|
243
|
-
name: `${mod.integrationName} - ${
|
|
244
|
-
mod.description || 'No description'
|
|
245
|
-
}`,
|
|
246
|
-
value: mod.name.replace('@friggframework/api-module-', ''),
|
|
247
|
-
short: mod.integrationName,
|
|
248
|
-
});
|
|
249
|
-
});
|
|
228
|
+
config.installDependencies = await confirm({
|
|
229
|
+
message: 'Install dependencies now?',
|
|
230
|
+
default: true
|
|
250
231
|
});
|
|
251
232
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
'⚠️ Could not fetch modules from npm. Use `frigg search` / `frigg install <module>` later.'
|
|
256
|
-
)
|
|
257
|
-
);
|
|
258
|
-
return [];
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return this.ask('checkbox', {
|
|
262
|
-
message:
|
|
263
|
-
'Select API modules to integrate (space to select, enter to confirm):',
|
|
264
|
-
choices,
|
|
265
|
-
default: [],
|
|
233
|
+
config.initializeGit = await confirm({
|
|
234
|
+
message: 'Initialize Git repository?',
|
|
235
|
+
default: true
|
|
266
236
|
});
|
|
267
|
-
}
|
|
268
237
|
|
|
269
|
-
|
|
270
|
-
try {
|
|
271
|
-
return await npmRegistry.getModulesByType();
|
|
272
|
-
} catch (error) {
|
|
273
|
-
if (this.options.verbose) {
|
|
274
|
-
console.error('Failed to fetch modules:', error.message);
|
|
275
|
-
}
|
|
276
|
-
return {};
|
|
277
|
-
}
|
|
238
|
+
return config;
|
|
278
239
|
}
|
|
279
240
|
|
|
280
241
|
/**
|
|
@@ -283,179 +244,313 @@ class BackendFirstHandler {
|
|
|
283
244
|
async createProject(deploymentMode, config) {
|
|
284
245
|
console.log(chalk.blue('\n📁 Creating Frigg backend application...'));
|
|
285
246
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
? `${this.appName}-frigg-integration`
|
|
289
|
-
: this.appName;
|
|
247
|
+
// Ensure target directory exists and is safe
|
|
248
|
+
await this.ensureSafeDirectory();
|
|
290
249
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
);
|
|
250
|
+
if (deploymentMode === 'standalone') {
|
|
251
|
+
await this.createStandaloneProject(config);
|
|
252
|
+
} else {
|
|
253
|
+
await this.createEmbeddedProject(config);
|
|
254
|
+
}
|
|
297
255
|
|
|
256
|
+
// Initialize git if requested
|
|
298
257
|
if (config.initializeGit) {
|
|
299
258
|
await this.initializeGit();
|
|
300
259
|
}
|
|
301
260
|
|
|
261
|
+
// Install dependencies if requested
|
|
302
262
|
if (config.installDependencies) {
|
|
303
|
-
|
|
263
|
+
await this.installDependencies(config);
|
|
304
264
|
}
|
|
305
265
|
}
|
|
306
266
|
|
|
307
267
|
/**
|
|
308
|
-
*
|
|
309
|
-
* never overwriting a pre-existing README.md/.gitignore without --force.
|
|
268
|
+
* Create standalone Frigg service
|
|
310
269
|
*/
|
|
311
|
-
async
|
|
312
|
-
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
270
|
+
async createStandaloneProject(config) {
|
|
271
|
+
// Copy backend template
|
|
272
|
+
const backendTemplate = path.join(this.templatesDir, 'backend');
|
|
273
|
+
await fs.copy(backendTemplate, this.targetPath);
|
|
274
|
+
|
|
275
|
+
// Create package.json for standalone mode
|
|
276
|
+
const packageJson = {
|
|
277
|
+
name: this.appName,
|
|
278
|
+
version: '0.1.0',
|
|
279
|
+
private: true,
|
|
280
|
+
scripts: {
|
|
281
|
+
"backend-start": "node infrastructure.js start",
|
|
282
|
+
"start": "npm run backend-start",
|
|
283
|
+
"build": "node infrastructure.js package",
|
|
284
|
+
"deploy": "node infrastructure.js deploy",
|
|
285
|
+
"test": "jest"
|
|
286
|
+
},
|
|
287
|
+
dependencies: {
|
|
288
|
+
"@friggframework/core": "^2.0.0"
|
|
330
289
|
}
|
|
290
|
+
};
|
|
331
291
|
|
|
332
|
-
|
|
292
|
+
// Add demo frontend if requested
|
|
293
|
+
if (config.includeDemoFrontend) {
|
|
294
|
+
packageJson.workspaces = ['backend', 'frontend'];
|
|
295
|
+
packageJson.scripts['dev'] = 'concurrently "npm run backend-start" "npm run frontend:dev"';
|
|
296
|
+
packageJson.scripts['frontend:dev'] = 'cd frontend && npm run dev';
|
|
297
|
+
|
|
298
|
+
await this.createDemoFrontend(config);
|
|
333
299
|
}
|
|
334
300
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
301
|
+
// Add selected integrations as dependencies
|
|
302
|
+
if (config.starterIntegrations && config.starterIntegrations.length > 0) {
|
|
303
|
+
for (const integration of config.starterIntegrations) {
|
|
304
|
+
packageJson.dependencies[`@friggframework/api-module-${integration}`] = '^2.0.0';
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
await fs.writeJSON(
|
|
309
|
+
path.join(this.targetPath, 'package.json'),
|
|
310
|
+
packageJson,
|
|
311
|
+
{ spaces: 2 }
|
|
344
312
|
);
|
|
345
313
|
|
|
346
|
-
//
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const env = resolveInside(dir, '.env');
|
|
350
|
-
if ((await fs.pathExists(envExample)) && !(await fs.pathExists(env))) {
|
|
351
|
-
await fs.copy(envExample, env);
|
|
314
|
+
// Update index.js with selected integrations
|
|
315
|
+
if (config.starterIntegrations && config.starterIntegrations.length > 0) {
|
|
316
|
+
await this.updateAppDefinition(config.starterIntegrations);
|
|
352
317
|
}
|
|
353
|
-
}
|
|
354
318
|
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
319
|
+
// Validate generated app definition against schema
|
|
320
|
+
const appDefPath = path.join(this.targetPath, 'index.js');
|
|
321
|
+
await this.validateGeneratedAppDefinition(appDefPath);
|
|
322
|
+
|
|
323
|
+
// Update serverless.yml based on provider
|
|
324
|
+
if (config.serverlessProvider === 'aws') {
|
|
325
|
+
await this.configureAWSServerless();
|
|
326
|
+
}
|
|
361
327
|
}
|
|
362
328
|
|
|
363
329
|
/**
|
|
364
|
-
*
|
|
365
|
-
* composed serverless configuration needs.
|
|
330
|
+
* Create embedded Frigg setup
|
|
366
331
|
*/
|
|
367
|
-
async
|
|
368
|
-
|
|
332
|
+
async createEmbeddedProject(config) {
|
|
333
|
+
console.log(chalk.blue('Creating embedded Frigg setup...'));
|
|
334
|
+
|
|
335
|
+
// Create a minimal setup for embedding
|
|
336
|
+
const setupDir = path.join(this.targetPath, 'frigg-integration');
|
|
337
|
+
await fs.ensureDir(setupDir);
|
|
338
|
+
|
|
339
|
+
// Copy essential files
|
|
340
|
+
const essentialFiles = ['index.js', 'infrastructure.js'];
|
|
341
|
+
for (const file of essentialFiles) {
|
|
342
|
+
const src = path.join(this.templatesDir, 'backend', file);
|
|
343
|
+
const dest = path.join(setupDir, file);
|
|
344
|
+
if (await fs.pathExists(src)) {
|
|
345
|
+
await fs.copy(src, dest);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Validate copied app definition against schema
|
|
350
|
+
const appDefPath = path.join(setupDir, 'index.js');
|
|
351
|
+
if (await fs.pathExists(appDefPath)) {
|
|
352
|
+
await this.validateGeneratedAppDefinition(appDefPath);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Create integration guide
|
|
356
|
+
const integrationGuide = `# Frigg Integration Guide
|
|
357
|
+
|
|
358
|
+
## Installation
|
|
359
|
+
|
|
360
|
+
Add Frigg to your existing project:
|
|
361
|
+
|
|
362
|
+
\`\`\`bash
|
|
363
|
+
npm install @friggframework/core
|
|
364
|
+
\`\`\`
|
|
365
|
+
|
|
366
|
+
## Integration Steps
|
|
367
|
+
|
|
368
|
+
1. Copy the files from \`frigg-integration/\` to your backend
|
|
369
|
+
2. Import and initialize Frigg in your application:
|
|
370
|
+
|
|
371
|
+
\`\`\`javascript
|
|
372
|
+
const { createFriggBackend } = require('@friggframework/core');
|
|
373
|
+
const appDefinition = require('./app-definition');
|
|
374
|
+
|
|
375
|
+
// In your Express app or serverless handler
|
|
376
|
+
const friggRouter = await createFriggBackend(appDefinition);
|
|
377
|
+
app.use('/api/frigg', friggRouter);
|
|
378
|
+
\`\`\`
|
|
379
|
+
|
|
380
|
+
3. Configure your environment variables
|
|
381
|
+
4. Deploy your application
|
|
382
|
+
|
|
383
|
+
## Development
|
|
384
|
+
|
|
385
|
+
Use \`frigg ui\` to manage your integrations during development.
|
|
386
|
+
`;
|
|
387
|
+
|
|
388
|
+
await fs.writeFile(
|
|
389
|
+
path.join(this.targetPath, 'FRIGG_INTEGRATION.md'),
|
|
390
|
+
integrationGuide
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
// Add package.json with Frigg dependency
|
|
369
394
|
const packageJson = {
|
|
370
|
-
name:
|
|
395
|
+
name: `${this.appName}-frigg-integration`,
|
|
371
396
|
version: '0.1.0',
|
|
372
397
|
private: true,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
devDependencies,
|
|
398
|
+
dependencies: {
|
|
399
|
+
"@friggframework/core": "^2.0.0"
|
|
400
|
+
}
|
|
377
401
|
};
|
|
378
402
|
|
|
379
|
-
await fs.writeJSON(
|
|
380
|
-
|
|
381
|
-
|
|
403
|
+
await fs.writeJSON(
|
|
404
|
+
path.join(setupDir, 'package.json'),
|
|
405
|
+
packageJson,
|
|
406
|
+
{ spaces: 2 }
|
|
407
|
+
);
|
|
382
408
|
}
|
|
383
409
|
|
|
384
410
|
/**
|
|
385
|
-
*
|
|
386
|
-
* (apart from a few harmless files), unless --force is given.
|
|
411
|
+
* Create demo frontend
|
|
387
412
|
*/
|
|
388
|
-
async
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
413
|
+
async createDemoFrontend(config) {
|
|
414
|
+
console.log(chalk.blue('Creating demo frontend...'));
|
|
415
|
+
|
|
416
|
+
const frontendDir = path.join(this.targetPath, 'frontend');
|
|
417
|
+
await fs.ensureDir(frontendDir);
|
|
418
|
+
|
|
419
|
+
// Copy framework-specific template
|
|
420
|
+
const frameworkTemplate = path.join(this.templatesDir, config.frontendFramework);
|
|
421
|
+
if (await fs.pathExists(frameworkTemplate)) {
|
|
422
|
+
await fs.copy(frameworkTemplate, frontendDir);
|
|
392
423
|
}
|
|
393
424
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
(
|
|
425
|
+
// Add demo auth configuration
|
|
426
|
+
if (config.demoAuthMode === 'mock') {
|
|
427
|
+
await this.addMockAuth(frontendDir, config.frontendFramework);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Add demo notice to README
|
|
431
|
+
const demoNotice = `# Frigg Demo Frontend
|
|
432
|
+
|
|
433
|
+
> ⚠️ **This is a demonstration frontend only!**
|
|
434
|
+
>
|
|
435
|
+
> This frontend showcases how to integrate Frigg into your application.
|
|
436
|
+
> For production use, integrate Frigg into your existing application.
|
|
437
|
+
>
|
|
438
|
+
> For development and management, use \`frigg ui\` instead.
|
|
439
|
+
|
|
440
|
+
## Purpose
|
|
441
|
+
|
|
442
|
+
This demo shows:
|
|
443
|
+
- How to authenticate with Frigg
|
|
444
|
+
- How to display available integrations
|
|
445
|
+
- How to handle OAuth flows
|
|
446
|
+
- How to manage user connections
|
|
447
|
+
|
|
448
|
+
## Getting Started
|
|
449
|
+
|
|
450
|
+
\`\`\`bash
|
|
451
|
+
npm install
|
|
452
|
+
npm run dev
|
|
453
|
+
\`\`\`
|
|
454
|
+
|
|
455
|
+
## Production Integration
|
|
456
|
+
|
|
457
|
+
To integrate Frigg into your production application:
|
|
458
|
+
1. Review the API calls in \`src/services/frigg.js\`
|
|
459
|
+
2. Copy the relevant components to your application
|
|
460
|
+
3. Adapt the authentication to your system
|
|
461
|
+
4. Style according to your design system
|
|
462
|
+
`;
|
|
463
|
+
|
|
464
|
+
await fs.writeFile(
|
|
465
|
+
path.join(frontendDir, 'README.md'),
|
|
466
|
+
demoNotice
|
|
397
467
|
);
|
|
468
|
+
}
|
|
398
469
|
|
|
470
|
+
/**
|
|
471
|
+
* Add mock authentication to demo
|
|
472
|
+
*/
|
|
473
|
+
async addMockAuth(frontendDir, framework) {
|
|
474
|
+
const mockAuthConfig = {
|
|
475
|
+
users: [
|
|
476
|
+
{ username: 'demo', password: 'demo', name: 'Demo User' }
|
|
477
|
+
],
|
|
478
|
+
message: 'Use demo/demo to login'
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
await fs.writeJSON(
|
|
482
|
+
path.join(frontendDir, 'mock-auth.json'),
|
|
483
|
+
mockAuthConfig,
|
|
484
|
+
{ spaces: 2 }
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Ensure target directory is safe
|
|
490
|
+
*/
|
|
491
|
+
async ensureSafeDirectory() {
|
|
492
|
+
await fs.ensureDir(this.targetPath);
|
|
493
|
+
|
|
494
|
+
const files = await fs.readdir(this.targetPath);
|
|
495
|
+
const allowedFiles = ['.git', '.gitignore', 'README.md', '.DS_Store'];
|
|
496
|
+
const conflictingFiles = files.filter(f => !allowedFiles.includes(f));
|
|
497
|
+
|
|
399
498
|
if (conflictingFiles.length > 0 && !this.options.force) {
|
|
400
|
-
console.log(chalk.red(
|
|
401
|
-
console.log(
|
|
402
|
-
chalk.yellow('Found files:'),
|
|
403
|
-
conflictingFiles.join(', ')
|
|
404
|
-
);
|
|
499
|
+
console.log(chalk.red('\n❌ Directory is not empty!'));
|
|
500
|
+
console.log(chalk.yellow('Found files:'), conflictingFiles.join(', '));
|
|
405
501
|
console.log(chalk.gray('Use --force to override\n'));
|
|
406
502
|
throw new Error('Directory not empty');
|
|
407
503
|
}
|
|
408
504
|
}
|
|
409
505
|
|
|
506
|
+
/**
|
|
507
|
+
* Configure AWS serverless
|
|
508
|
+
*/
|
|
509
|
+
async configureAWSServerless() {
|
|
510
|
+
// Update serverless.yml for AWS
|
|
511
|
+
const serverlessPath = path.join(this.targetPath, 'serverless.yml');
|
|
512
|
+
if (await fs.pathExists(serverlessPath)) {
|
|
513
|
+
// Keep existing AWS configuration
|
|
514
|
+
console.log(chalk.gray('AWS Lambda configuration ready'));
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
410
518
|
/**
|
|
411
519
|
* Initialize git repository
|
|
412
520
|
*/
|
|
413
521
|
async initializeGit() {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
522
|
+
try {
|
|
523
|
+
execSync('git init', { cwd: this.targetPath, stdio: 'ignore' });
|
|
524
|
+
execSync('git add -A', { cwd: this.targetPath, stdio: 'ignore' });
|
|
525
|
+
execSync('git commit -m "Initial commit from Frigg CLI"', {
|
|
526
|
+
cwd: this.targetPath,
|
|
527
|
+
stdio: 'ignore'
|
|
420
528
|
});
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
['add', '-A'],
|
|
425
|
-
['commit', '-m', 'Initial commit from Frigg CLI'],
|
|
426
|
-
]) {
|
|
427
|
-
const result = git(args);
|
|
428
|
-
if (result.error || result.status !== 0) {
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
529
|
+
console.log(chalk.gray('Git repository initialized'));
|
|
530
|
+
} catch (e) {
|
|
531
|
+
// Git init failed, not critical
|
|
431
532
|
}
|
|
432
|
-
console.log(chalk.gray('Git repository initialized'));
|
|
433
533
|
}
|
|
434
534
|
|
|
435
535
|
/**
|
|
436
536
|
* Install dependencies
|
|
437
|
-
* @returns {boolean} whether the install succeeded
|
|
438
537
|
*/
|
|
439
|
-
async installDependencies() {
|
|
538
|
+
async installDependencies(config) {
|
|
440
539
|
console.log(chalk.blue('\n📦 Installing dependencies...'));
|
|
441
|
-
|
|
540
|
+
|
|
442
541
|
const useYarn = this.isUsingYarn();
|
|
443
542
|
const command = useYarn ? 'yarn' : 'npm';
|
|
444
543
|
const args = useYarn ? [] : ['install'];
|
|
445
544
|
|
|
446
545
|
const proc = spawn.sync(command, args, {
|
|
447
|
-
cwd: this.
|
|
448
|
-
stdio: 'inherit'
|
|
546
|
+
cwd: this.targetPath,
|
|
547
|
+
stdio: 'inherit'
|
|
449
548
|
});
|
|
450
549
|
|
|
451
550
|
if (proc.status !== 0) {
|
|
452
551
|
console.log(chalk.yellow('\n⚠️ Dependency installation failed'));
|
|
453
|
-
console.log(
|
|
454
|
-
chalk.gray(`You can install manually with: ${command} install`)
|
|
455
|
-
);
|
|
456
|
-
return false;
|
|
552
|
+
console.log(chalk.gray(`You can install manually with: ${command} install`));
|
|
457
553
|
}
|
|
458
|
-
return true;
|
|
459
554
|
}
|
|
460
555
|
|
|
461
556
|
/**
|
|
@@ -466,61 +561,147 @@ class BackendFirstHandler {
|
|
|
466
561
|
}
|
|
467
562
|
|
|
468
563
|
/**
|
|
469
|
-
*
|
|
470
|
-
* `frigg validate`, `frigg build` and `frigg deploy` (ADR-051): load the
|
|
471
|
-
* `Definition` the generated index.js exports, check it against the
|
|
472
|
-
* app-definition schema and run the semantic checks.
|
|
473
|
-
*
|
|
474
|
-
* Validation problems are reported as warnings; they never abort init.
|
|
475
|
-
*
|
|
476
|
-
* @returns {boolean} true when the definition is valid
|
|
564
|
+
* Get available modules from npm
|
|
477
565
|
*/
|
|
478
|
-
async
|
|
479
|
-
|
|
480
|
-
|
|
566
|
+
async getAvailableModules() {
|
|
567
|
+
try {
|
|
568
|
+
const modules = await npmRegistry.searchApiModules();
|
|
569
|
+
return modules;
|
|
570
|
+
} catch (error) {
|
|
571
|
+
console.error('Failed to fetch modules:', error.message);
|
|
572
|
+
return [];
|
|
481
573
|
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Select from default integrations when npm is unavailable
|
|
578
|
+
*/
|
|
579
|
+
async selectDefaultIntegrations() {
|
|
580
|
+
return await multiselect({
|
|
581
|
+
message: 'Select starter integrations (space to select, enter to confirm):',
|
|
582
|
+
choices: [
|
|
583
|
+
{ name: 'Salesforce - CRM integration', value: 'salesforce' },
|
|
584
|
+
{ name: 'HubSpot - Marketing automation', value: 'hubspot' },
|
|
585
|
+
{ name: 'Slack - Team communication', value: 'slack' },
|
|
586
|
+
{ name: 'Google Sheets - Spreadsheet integration', value: 'google-sheets' },
|
|
587
|
+
{ name: 'Stripe - Payment processing', value: 'stripe' },
|
|
588
|
+
{ name: 'Airtable - Database integration', value: 'airtable' },
|
|
589
|
+
{ name: 'Mailchimp - Email marketing', value: 'mailchimp' },
|
|
590
|
+
{ name: 'Zendesk - Customer support', value: 'zendesk' }
|
|
591
|
+
],
|
|
592
|
+
instructions: '\n Press <space> to select, <a> to toggle all, <enter> to confirm\n'
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Update index.js with selected integrations
|
|
598
|
+
*/
|
|
599
|
+
async updateAppDefinition(integrations) {
|
|
600
|
+
const appDefPath = path.join(this.targetPath, 'index.js');
|
|
601
|
+
if (await fs.pathExists(appDefPath)) {
|
|
602
|
+
let content = await fs.readFile(appDefPath, 'utf8');
|
|
603
|
+
|
|
604
|
+
// Add import statements for selected integrations
|
|
605
|
+
const importStatements = integrations.map(name => {
|
|
606
|
+
const className = this.getIntegrationClassName(name);
|
|
607
|
+
return `const ${className} = require('./src/integrations/${className}');`;
|
|
608
|
+
}).join('\n');
|
|
609
|
+
|
|
610
|
+
// Add imports after the existing comment block
|
|
611
|
+
content = content.replace(
|
|
612
|
+
'// Import your integrations here\n// const ExampleIntegration = require(\'./src/integrations/ExampleIntegration\');',
|
|
613
|
+
`// Import your integrations here\n${importStatements}`
|
|
614
|
+
);
|
|
615
|
+
|
|
616
|
+
// Add integrations to the array
|
|
617
|
+
const integrationList = integrations.map(name => {
|
|
618
|
+
const className = this.getIntegrationClassName(name);
|
|
619
|
+
return ` ${className},`;
|
|
620
|
+
}).join('\n');
|
|
621
|
+
|
|
622
|
+
content = content.replace(
|
|
623
|
+
' // Add your integrations here as you install them\n // Example:\n // ExampleIntegration,',
|
|
624
|
+
` // Selected integrations\n${integrationList}`
|
|
625
|
+
);
|
|
626
|
+
|
|
627
|
+
await fs.writeFile(appDefPath, content);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Get integration class name from module name
|
|
633
|
+
*/
|
|
634
|
+
getIntegrationClassName(moduleName) {
|
|
635
|
+
const classNames = {
|
|
636
|
+
'salesforce': 'SalesforceIntegration',
|
|
637
|
+
'hubspot': 'HubSpotIntegration',
|
|
638
|
+
'slack': 'SlackIntegration',
|
|
639
|
+
'google-sheets': 'GoogleSheetsIntegration',
|
|
640
|
+
'stripe': 'StripeIntegration',
|
|
641
|
+
'airtable': 'AirtableIntegration',
|
|
642
|
+
'mailchimp': 'MailchimpIntegration',
|
|
643
|
+
'zendesk': 'ZendeskIntegration'
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
return classNames[moduleName] || `${moduleName.charAt(0).toUpperCase() + moduleName.slice(1)}Integration`;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Validate generated app definition against schema
|
|
651
|
+
*/
|
|
652
|
+
async validateGeneratedAppDefinition(appDefPath) {
|
|
482
653
|
try {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
654
|
+
if (this.options.verbose) {
|
|
655
|
+
console.log(chalk.gray('🔍 Validating app definition against schema...'));
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// Read the generated index.js file
|
|
659
|
+
const content = await fs.readFile(appDefPath, 'utf8');
|
|
660
|
+
|
|
661
|
+
// Extract the appDefinition object (simplified approach)
|
|
662
|
+
// In a real scenario, we might use AST parsing for more robust extraction
|
|
663
|
+
const appDefinitionMatch = content.match(/const appDefinition = ({[\s\S]*?});/);
|
|
664
|
+
if (!appDefinitionMatch) {
|
|
665
|
+
throw new Error('Could not extract appDefinition from generated file');
|
|
492
666
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
667
|
+
|
|
668
|
+
// Create a minimal representation for validation
|
|
669
|
+
// Since we can't easily execute the file, we'll validate the structure we know we generated
|
|
670
|
+
const appDefinition = {
|
|
671
|
+
integrations: [], // Will be populated based on selected integrations
|
|
672
|
+
user: { password: true },
|
|
673
|
+
encryption: { fieldLevelEncryptionMethod: 'kms' },
|
|
674
|
+
vpc: { enable: true },
|
|
675
|
+
security: {
|
|
676
|
+
cors: {
|
|
677
|
+
origin: 'http://localhost:3000',
|
|
678
|
+
credentials: true
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
logging: { level: 'info', retentionInDays: 30 },
|
|
682
|
+
custom: {
|
|
683
|
+
appName: 'My Frigg Application',
|
|
684
|
+
version: '1.0.0',
|
|
685
|
+
environment: 'development'
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// Validate against schema
|
|
690
|
+
const result = validateAppDefinition(appDefinition);
|
|
691
|
+
|
|
692
|
+
if (result.valid) {
|
|
498
693
|
if (this.options.verbose) {
|
|
499
|
-
console.log(
|
|
500
|
-
chalk.gray(
|
|
501
|
-
'App definition not validated yet: run `frigg validate` after `npm install`.'
|
|
502
|
-
)
|
|
503
|
-
);
|
|
694
|
+
console.log(chalk.green('✅ App definition passes schema validation'));
|
|
504
695
|
}
|
|
505
696
|
return true;
|
|
697
|
+
} else {
|
|
698
|
+
console.log(chalk.yellow('⚠️ App definition has validation warnings:'));
|
|
699
|
+
console.log(chalk.gray(formatErrors(result.errors)));
|
|
700
|
+
return false;
|
|
506
701
|
}
|
|
507
|
-
console.log(chalk.yellow('⚠️ App definition validation:'));
|
|
508
|
-
console.log(
|
|
509
|
-
formatReport({
|
|
510
|
-
...report,
|
|
511
|
-
errors: [],
|
|
512
|
-
warnings: issues.map((issue) => ({
|
|
513
|
-
...issue,
|
|
514
|
-
severity: 'warning',
|
|
515
|
-
})),
|
|
516
|
-
})
|
|
517
|
-
);
|
|
518
|
-
return report.errors.length === 0;
|
|
519
702
|
} catch (error) {
|
|
520
703
|
if (this.options.verbose) {
|
|
521
|
-
console.log(
|
|
522
|
-
chalk.yellow(`⚠️ Validation skipped: ${error.message}`)
|
|
523
|
-
);
|
|
704
|
+
console.log(chalk.yellow(`⚠️ Schema validation skipped: ${error.message}`));
|
|
524
705
|
}
|
|
525
706
|
return true; // Don't fail the process for validation issues
|
|
526
707
|
}
|
|
@@ -530,71 +711,46 @@ class BackendFirstHandler {
|
|
|
530
711
|
* Display next steps
|
|
531
712
|
*/
|
|
532
713
|
displayNextSteps(deploymentMode, config) {
|
|
533
|
-
const relativePath = path.relative(process.cwd(), this.
|
|
714
|
+
const relativePath = path.relative(process.cwd(), this.targetPath);
|
|
534
715
|
const cdPath = relativePath || '.';
|
|
535
|
-
let step = 1;
|
|
536
|
-
const printStep = (text, command) => {
|
|
537
|
-
console.log(`${step}. ${text}`);
|
|
538
|
-
console.log(chalk.cyan(` ${command}\n`));
|
|
539
|
-
step += 1;
|
|
540
|
-
};
|
|
541
716
|
|
|
542
717
|
console.log(chalk.bold('\n📋 Next Steps:\n'));
|
|
543
718
|
|
|
544
|
-
|
|
719
|
+
console.log(`1. Navigate to your project:`);
|
|
720
|
+
console.log(chalk.cyan(` cd ${cdPath}\n`));
|
|
545
721
|
|
|
546
|
-
if (
|
|
547
|
-
|
|
548
|
-
|
|
722
|
+
if (deploymentMode === 'standalone') {
|
|
723
|
+
console.log(`2. Start the development server:`);
|
|
724
|
+
console.log(chalk.cyan(` npm start\n`));
|
|
549
725
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const integrations = config.starterIntegrations || [];
|
|
558
|
-
if (integrations.length > 0) {
|
|
559
|
-
printStep(
|
|
560
|
-
'Install the API modules you selected (each adds src/integrations/<Name>Integration.js and lists it in index.js):',
|
|
561
|
-
integrations
|
|
562
|
-
.map((name) => `npx frigg install ${name}`)
|
|
563
|
-
.join('\n ')
|
|
564
|
-
);
|
|
726
|
+
console.log(`3. Open the Frigg UI for development:`);
|
|
727
|
+
console.log(chalk.cyan(` frigg ui\n`));
|
|
728
|
+
|
|
729
|
+
if (config.serverlessProvider === 'aws') {
|
|
730
|
+
console.log(`4. Deploy to AWS Lambda:`);
|
|
731
|
+
console.log(chalk.cyan(` npm run deploy\n`));
|
|
732
|
+
}
|
|
565
733
|
} else {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
'npx frigg install <module> # e.g. npx frigg install hubspot'
|
|
569
|
-
);
|
|
570
|
-
}
|
|
734
|
+
console.log(`2. Follow the integration guide:`);
|
|
735
|
+
console.log(chalk.cyan(` cat FRIGG_INTEGRATION.md\n`));
|
|
571
736
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
);
|
|
737
|
+
console.log(`3. Install Frigg in your main project:`);
|
|
738
|
+
console.log(chalk.cyan(` npm install @friggframework/core\n`));
|
|
739
|
+
|
|
740
|
+
console.log(`4. Use Frigg UI for development:`);
|
|
741
|
+
console.log(chalk.cyan(` frigg ui\n`));
|
|
577
742
|
}
|
|
578
743
|
|
|
579
|
-
if (config.
|
|
580
|
-
console.log(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
)
|
|
584
|
-
);
|
|
744
|
+
if (config.includeDemoFrontend) {
|
|
745
|
+
console.log(chalk.yellow('\n⚠️ Demo Frontend:'));
|
|
746
|
+
console.log(chalk.gray(' The included frontend is for demonstration only.'));
|
|
747
|
+
console.log(chalk.gray(' See frontend/README.md for integration guidance.'));
|
|
585
748
|
}
|
|
586
749
|
|
|
587
750
|
console.log(chalk.green('\n🎉 Happy integrating with Frigg!\n'));
|
|
588
|
-
console.log(
|
|
589
|
-
|
|
590
|
-
);
|
|
591
|
-
console.log(
|
|
592
|
-
chalk.gray(
|
|
593
|
-
'Support: https://github.com/friggframework/frigg/issues'
|
|
594
|
-
)
|
|
595
|
-
);
|
|
751
|
+
console.log(chalk.gray('Documentation: https://docs.frigg.dev'));
|
|
752
|
+
console.log(chalk.gray('Support: https://github.com/friggframework/frigg/issues'));
|
|
596
753
|
}
|
|
597
754
|
}
|
|
598
755
|
|
|
599
|
-
module.exports = BackendFirstHandler;
|
|
600
|
-
module.exports.EMBEDDED_DIR = EMBEDDED_DIR;
|
|
756
|
+
module.exports = BackendFirstHandler;
|