@friggframework/devtools 2.0.0--canary.657.f16d20b.0 → 2.0.0--canary.737.83b4e17.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 +115 -31
- package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +33 -24
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
- package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
- package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
- package/frigg-cli/build-command/index.js +6 -0
- package/frigg-cli/deploy-command/index.js +6 -0
- package/frigg-cli/generate-command/index.js +1 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +22 -5
- package/frigg-cli/init-command/backend-first-handler.js +395 -551
- package/frigg-cli/init-command/deployment-modes.js +7 -0
- package/frigg-cli/init-command/index.js +82 -35
- package/frigg-cli/init-command/safe-path.js +58 -0
- package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
- package/frigg-cli/install-command/app-definition.js +174 -0
- package/frigg-cli/install-command/commit-changes.js +40 -8
- package/frigg-cli/install-command/environment-variables.js +15 -0
- package/frigg-cli/install-command/index.js +96 -21
- package/frigg-cli/install-command/install-package.js +77 -4
- package/frigg-cli/install-command/integration-file.js +20 -11
- package/frigg-cli/install-command/resolve-module.js +69 -0
- package/frigg-cli/install-command/template.js +102 -75
- package/frigg-cli/install-command/validate-package.js +36 -4
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/start-command/index.js +4 -0
- package/frigg-cli/start-command/start-command.test.js +3 -0
- package/frigg-cli/templates/backend/README.md +267 -0
- package/frigg-cli/templates/backend/env.example +20 -0
- package/frigg-cli/templates/backend/gitignore +10 -0
- package/frigg-cli/templates/backend/index.js +114 -0
- package/frigg-cli/templates/backend/infrastructure.js +20 -0
- package/frigg-cli/test/init-command.test.js +9 -2
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +443 -0
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +262 -0
- package/frigg-cli/validate-command/checks/config.js +504 -0
- package/frigg-cli/validate-command/checks/integrations.js +274 -0
- package/frigg-cli/validate-command/format-report.js +58 -0
- package/frigg-cli/validate-command/index.js +107 -0
- package/frigg-cli/validate-command/load-app-definition.js +105 -0
- package/frigg-cli/validate-command/schema-issues.js +154 -0
- package/frigg-cli/validate-command/validate-app-definition.js +60 -0
- package/infrastructure/README.md +32 -5
- package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +39 -0
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +284 -0
- package/infrastructure/__tests__/postgres-config.test.js +245 -836
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +151 -0
- package/infrastructure/__tests__/scoped-environment.test.js +3 -0
- package/infrastructure/__tests__/ssm-preload-node-options.test.js +3 -0
- package/infrastructure/__tests__/template-generation.test.js +39 -8
- package/infrastructure/app-definition-schema-contract.test.js +634 -0
- package/infrastructure/create-frigg-infrastructure.js +4 -1
- package/infrastructure/create-frigg-infrastructure.test.js +51 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +80 -98
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +8 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +52 -6
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- package/infrastructure/domains/database/migration-builder.js +21 -2
- package/infrastructure/domains/database/migration-builder.test.js +61 -6
- package/infrastructure/domains/database/migration-engines.js +93 -0
- package/infrastructure/domains/database/migration-engines.test.js +142 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
- package/infrastructure/domains/integration/integration-builder.js +2 -0
- package/infrastructure/domains/integration/integration-builder.test.js +22 -39
- package/infrastructure/domains/networking/vpc-builder.js +18 -8
- package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
- package/infrastructure/domains/scheduler/scheduler-builder.js +2 -19
- package/infrastructure/domains/scheduler/scheduler-builder.test.js +0 -99
- package/infrastructure/domains/security/iam-generator.js +112 -5
- package/infrastructure/domains/security/iam-generator.test.js +94 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
- package/infrastructure/domains/shared/environment-builder.js +31 -5
- package/infrastructure/domains/shared/environment-builder.test.js +93 -7
- package/infrastructure/domains/shared/lambda-architectures.js +113 -0
- package/infrastructure/domains/shared/lambda-architectures.test.js +164 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +39 -4
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +85 -17
- package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
- package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +92 -12
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +158 -6
- package/infrastructure/infrastructure-composer.js +12 -1
- package/infrastructure/infrastructure-composer.test.js +339 -794
- package/infrastructure/scripts/build-prisma-layer.js +136 -50
- package/infrastructure/scripts/build-prisma-layer.test.js +128 -7
- package/infrastructure/scripts/build-time-discovery.test.js +18 -3
- package/package.json +12 -10
- package/frigg-cli/index.test.js +0 -158
- package/infrastructure/integration.test.js +0 -381
|
@@ -1,21 +1,80 @@
|
|
|
1
1
|
const fs = require('fs-extra');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
-
const {
|
|
5
|
-
const { execSync } = require('child_process');
|
|
4
|
+
const { spawnSync } = require('child_process');
|
|
6
5
|
const spawn = require('cross-spawn');
|
|
6
|
+
const { resolveInside } = require('./safe-path');
|
|
7
7
|
const npmRegistry = require('../utils/npm-registry');
|
|
8
|
-
const {
|
|
8
|
+
const { runValidation } = require('../validate-command');
|
|
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';
|
|
9
22
|
|
|
10
23
|
/**
|
|
11
|
-
*
|
|
24
|
+
* Template files stored under a different name. npm strips `.gitignore` from
|
|
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.
|
|
12
49
|
*/
|
|
13
50
|
class BackendFirstHandler {
|
|
14
51
|
constructor(targetPath, options = {}) {
|
|
15
|
-
this.targetPath = targetPath;
|
|
16
|
-
this.appName = path.basename(targetPath);
|
|
52
|
+
this.targetPath = path.resolve(targetPath);
|
|
53
|
+
this.appName = path.basename(this.targetPath);
|
|
17
54
|
this.options = options;
|
|
18
55
|
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);
|
|
19
78
|
}
|
|
20
79
|
|
|
21
80
|
/**
|
|
@@ -23,34 +82,27 @@ class BackendFirstHandler {
|
|
|
23
82
|
*/
|
|
24
83
|
async initialize() {
|
|
25
84
|
console.log(chalk.blue('🚀 Welcome to Frigg - Integration Framework'));
|
|
26
|
-
console.log(
|
|
85
|
+
console.log(
|
|
86
|
+
chalk.gray('Creating a new Frigg backend application...\n')
|
|
87
|
+
);
|
|
27
88
|
|
|
28
|
-
// Get deployment mode
|
|
29
89
|
const deploymentMode = await this.selectDeploymentMode();
|
|
30
|
-
|
|
31
|
-
|
|
90
|
+
this.projectDir =
|
|
91
|
+
deploymentMode === 'embedded'
|
|
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
|
+
|
|
32
98
|
const config = await this.getProjectConfiguration(deploymentMode);
|
|
33
99
|
|
|
34
|
-
// Create project structure
|
|
35
100
|
await this.createProject(deploymentMode, config);
|
|
36
101
|
|
|
37
|
-
console.log(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
102
|
+
console.log(
|
|
103
|
+
chalk.green('\n✅ Frigg application created successfully!')
|
|
104
|
+
);
|
|
105
|
+
|
|
54
106
|
this.displayNextSteps(deploymentMode, config);
|
|
55
107
|
}
|
|
56
108
|
|
|
@@ -59,27 +111,32 @@ class BackendFirstHandler {
|
|
|
59
111
|
*/
|
|
60
112
|
async selectDeploymentMode() {
|
|
61
113
|
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
|
+
}
|
|
62
121
|
return this.options.mode;
|
|
63
122
|
}
|
|
64
123
|
|
|
65
|
-
|
|
124
|
+
return this.ask('select', {
|
|
66
125
|
message: 'How will you deploy this Frigg application?',
|
|
67
126
|
choices: [
|
|
68
|
-
{
|
|
69
|
-
name: 'Embedded - Integrate into existing application',
|
|
70
|
-
value: 'embedded',
|
|
71
|
-
description: 'Add Frigg as a library to your existing backend'
|
|
72
|
-
},
|
|
73
127
|
{
|
|
74
128
|
name: 'Standalone - Deploy as separate service',
|
|
75
129
|
value: 'standalone',
|
|
76
|
-
description: 'Run Frigg as an independent microservice'
|
|
77
|
-
}
|
|
130
|
+
description: 'Run Frigg as an independent microservice',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'Embedded - Add to an existing repository',
|
|
134
|
+
value: 'embedded',
|
|
135
|
+
description: `Scaffold the Frigg backend into ./${EMBEDDED_DIR} of an existing project`,
|
|
136
|
+
},
|
|
78
137
|
],
|
|
79
|
-
default:
|
|
138
|
+
default: DEFAULT_DEPLOYMENT_MODE,
|
|
80
139
|
});
|
|
81
|
-
|
|
82
|
-
return mode;
|
|
83
140
|
}
|
|
84
141
|
|
|
85
142
|
/**
|
|
@@ -88,154 +145,136 @@ class BackendFirstHandler {
|
|
|
88
145
|
async getProjectConfiguration(deploymentMode) {
|
|
89
146
|
const config = { deploymentMode };
|
|
90
147
|
|
|
91
|
-
|
|
92
|
-
config.appPurpose = await select({
|
|
148
|
+
config.appPurpose = await this.ask('select', {
|
|
93
149
|
message: 'What are you building with Frigg?',
|
|
94
150
|
choices: [
|
|
95
151
|
{
|
|
96
152
|
name: 'Integrations for my own application',
|
|
97
153
|
value: 'own-app',
|
|
98
|
-
description:
|
|
154
|
+
description:
|
|
155
|
+
'Build integrations that connect your app with third-party services',
|
|
99
156
|
},
|
|
100
157
|
{
|
|
101
158
|
name: 'Integration platform for multiple apps',
|
|
102
159
|
value: 'platform',
|
|
103
|
-
description:
|
|
160
|
+
description:
|
|
161
|
+
'Build a platform that provides integrations to other applications',
|
|
104
162
|
},
|
|
105
163
|
{
|
|
106
164
|
name: 'Just exploring Frigg',
|
|
107
165
|
value: 'exploring',
|
|
108
|
-
description:
|
|
109
|
-
|
|
110
|
-
|
|
166
|
+
description:
|
|
167
|
+
'Testing and learning about Frigg capabilities',
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
default: 'own-app',
|
|
111
171
|
});
|
|
112
172
|
|
|
113
|
-
// If building for own app, ask about creating custom API module
|
|
114
173
|
if (config.appPurpose === 'own-app') {
|
|
115
|
-
config.needsCustomApiModule = await confirm
|
|
116
|
-
message:
|
|
117
|
-
|
|
174
|
+
config.needsCustomApiModule = await this.ask('confirm', {
|
|
175
|
+
message:
|
|
176
|
+
'Do you need to create an API module for your own application?',
|
|
177
|
+
default: false,
|
|
118
178
|
});
|
|
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
|
-
}
|
|
124
179
|
}
|
|
125
180
|
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
181
|
+
// Selected modules are installed afterwards with `frigg install`,
|
|
182
|
+
// which installs the package and scaffolds the integration file.
|
|
183
|
+
config.includeIntegrations = await this.ask('confirm', {
|
|
184
|
+
message:
|
|
185
|
+
'Would you like to pick API modules to integrate with? (installed afterwards with `frigg install`)',
|
|
186
|
+
default: false,
|
|
130
187
|
});
|
|
131
188
|
|
|
132
189
|
if (config.includeIntegrations) {
|
|
133
|
-
|
|
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
|
-
}
|
|
190
|
+
config.starterIntegrations = await this.selectIntegrations();
|
|
173
191
|
}
|
|
174
192
|
|
|
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
|
|
217
193
|
if (deploymentMode === 'standalone') {
|
|
218
|
-
config.serverlessProvider = await select
|
|
194
|
+
config.serverlessProvider = await this.ask('select', {
|
|
219
195
|
message: 'Which cloud provider will you use?',
|
|
220
196
|
choices: [
|
|
221
197
|
{ name: 'AWS Lambda', value: 'aws' },
|
|
222
|
-
{ name: 'Local Development Only', value: 'local' }
|
|
198
|
+
{ name: 'Local Development Only', value: 'local' },
|
|
223
199
|
],
|
|
224
|
-
default: 'aws'
|
|
200
|
+
default: 'aws',
|
|
225
201
|
});
|
|
226
202
|
}
|
|
227
203
|
|
|
228
|
-
config.installDependencies =
|
|
229
|
-
|
|
230
|
-
|
|
204
|
+
config.installDependencies =
|
|
205
|
+
this.options.install === false
|
|
206
|
+
? false
|
|
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
|
+
});
|
|
231
250
|
});
|
|
232
251
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
252
|
+
if (choices.length === 0) {
|
|
253
|
+
console.log(
|
|
254
|
+
chalk.yellow(
|
|
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: [],
|
|
236
266
|
});
|
|
267
|
+
}
|
|
237
268
|
|
|
238
|
-
|
|
269
|
+
async getModulesByType() {
|
|
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
|
+
}
|
|
239
278
|
}
|
|
240
279
|
|
|
241
280
|
/**
|
|
@@ -244,313 +283,179 @@ class BackendFirstHandler {
|
|
|
244
283
|
async createProject(deploymentMode, config) {
|
|
245
284
|
console.log(chalk.blue('\n📁 Creating Frigg backend application...'));
|
|
246
285
|
|
|
247
|
-
|
|
248
|
-
|
|
286
|
+
const packageName =
|
|
287
|
+
deploymentMode === 'embedded'
|
|
288
|
+
? `${this.appName}-frigg-integration`
|
|
289
|
+
: this.appName;
|
|
249
290
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
291
|
+
await fs.ensureDir(this.projectDir);
|
|
292
|
+
await this.copyTemplate(this.projectDir, packageName);
|
|
293
|
+
await this.writePackageJson(this.projectDir, packageName);
|
|
294
|
+
await this.validateGeneratedAppDefinition(
|
|
295
|
+
resolveInside(this.projectDir, 'index.js')
|
|
296
|
+
);
|
|
255
297
|
|
|
256
|
-
// Initialize git if requested
|
|
257
298
|
if (config.initializeGit) {
|
|
258
299
|
await this.initializeGit();
|
|
259
300
|
}
|
|
260
301
|
|
|
261
|
-
// Install dependencies if requested
|
|
262
302
|
if (config.installDependencies) {
|
|
263
|
-
await this.installDependencies(
|
|
303
|
+
config.dependenciesInstalled = await this.installDependencies();
|
|
264
304
|
}
|
|
265
305
|
}
|
|
266
306
|
|
|
267
307
|
/**
|
|
268
|
-
*
|
|
308
|
+
* Copy the backend template into `dir`, substituting the project name and
|
|
309
|
+
* never overwriting a pre-existing README.md/.gitignore without --force.
|
|
269
310
|
*/
|
|
270
|
-
async
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
311
|
+
async copyTemplate(dir, packageName) {
|
|
312
|
+
const templateDir = resolveInside(this.templatesDir, 'backend');
|
|
313
|
+
const entries = await fs.readdir(templateDir);
|
|
314
|
+
|
|
315
|
+
for (const entry of entries) {
|
|
316
|
+
const destName = RENAMED_TEMPLATE_FILES[entry] || entry;
|
|
317
|
+
const dest = resolveInside(dir, destName);
|
|
318
|
+
|
|
319
|
+
if (
|
|
320
|
+
PRESERVED_FILES.includes(destName) &&
|
|
321
|
+
!this.options.force &&
|
|
322
|
+
(await fs.pathExists(dest))
|
|
323
|
+
) {
|
|
324
|
+
console.log(
|
|
325
|
+
chalk.gray(
|
|
326
|
+
`Keeping existing ${destName} (use --force to overwrite)`
|
|
327
|
+
)
|
|
328
|
+
);
|
|
329
|
+
continue;
|
|
289
330
|
}
|
|
290
|
-
};
|
|
291
|
-
|
|
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);
|
|
299
|
-
}
|
|
300
331
|
|
|
301
|
-
|
|
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
|
-
}
|
|
332
|
+
await fs.copy(resolveInside(templateDir, entry), dest);
|
|
306
333
|
}
|
|
307
334
|
|
|
308
|
-
await
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
335
|
+
await this.substituteInFile(
|
|
336
|
+
resolveInside(dir, 'index.js'),
|
|
337
|
+
TEMPLATE_APP_NAME,
|
|
338
|
+
`name: '${packageName}',`
|
|
339
|
+
);
|
|
340
|
+
await this.substituteInFile(
|
|
341
|
+
resolveInside(dir, 'README.md'),
|
|
342
|
+
TEMPLATE_README_TITLE,
|
|
343
|
+
`# ${packageName}`
|
|
312
344
|
);
|
|
313
345
|
|
|
314
|
-
//
|
|
315
|
-
|
|
316
|
-
|
|
346
|
+
// Seed a local .env from the example so `frigg start` has a
|
|
347
|
+
// DATABASE_URL to work with. .env is git-ignored.
|
|
348
|
+
const envExample = resolveInside(dir, '.env.example');
|
|
349
|
+
const env = resolveInside(dir, '.env');
|
|
350
|
+
if ((await fs.pathExists(envExample)) && !(await fs.pathExists(env))) {
|
|
351
|
+
await fs.copy(envExample, env);
|
|
317
352
|
}
|
|
353
|
+
}
|
|
318
354
|
|
|
319
|
-
|
|
320
|
-
const
|
|
321
|
-
await
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
await this.configureAWSServerless();
|
|
326
|
-
}
|
|
355
|
+
async substituteInFile(file, search, replacement) {
|
|
356
|
+
const filePath = resolveInside(this.targetPath, file);
|
|
357
|
+
if (!(await fs.pathExists(filePath))) return;
|
|
358
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
359
|
+
if (!content.includes(search)) return;
|
|
360
|
+
await fs.writeFile(filePath, content.replace(search, replacement));
|
|
327
361
|
}
|
|
328
362
|
|
|
329
363
|
/**
|
|
330
|
-
*
|
|
364
|
+
* Write package.json with the `frigg` scripts and the dependencies the
|
|
365
|
+
* composed serverless configuration needs.
|
|
331
366
|
*/
|
|
332
|
-
async
|
|
333
|
-
|
|
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
|
|
367
|
+
async writePackageJson(dir, packageName) {
|
|
368
|
+
const { dependencies, devDependencies } = getScaffoldDependencies();
|
|
394
369
|
const packageJson = {
|
|
395
|
-
name:
|
|
370
|
+
name: packageName,
|
|
396
371
|
version: '0.1.0',
|
|
397
372
|
private: true,
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
373
|
+
main: 'index.js',
|
|
374
|
+
scripts: getScaffoldScripts(),
|
|
375
|
+
dependencies,
|
|
376
|
+
devDependencies,
|
|
401
377
|
};
|
|
402
378
|
|
|
403
|
-
await fs.writeJSON(
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
{ spaces: 2 }
|
|
407
|
-
);
|
|
379
|
+
await fs.writeJSON(resolveInside(dir, 'package.json'), packageJson, {
|
|
380
|
+
spaces: 2,
|
|
381
|
+
});
|
|
408
382
|
}
|
|
409
383
|
|
|
410
384
|
/**
|
|
411
|
-
*
|
|
385
|
+
* Ensure the directory the backend is written to is missing or empty
|
|
386
|
+
* (apart from a few harmless files), unless --force is given.
|
|
412
387
|
*/
|
|
413
|
-
async
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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);
|
|
388
|
+
async ensureSafeDirectory(directory = this.targetPath) {
|
|
389
|
+
const dir = resolveInside(this.targetPath, directory);
|
|
390
|
+
if (!(await fs.pathExists(dir))) {
|
|
391
|
+
return;
|
|
423
392
|
}
|
|
424
393
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
|
394
|
+
const files = await fs.readdir(dir);
|
|
395
|
+
const conflictingFiles = files.filter(
|
|
396
|
+
(f) => !ALLOWED_EXISTING_FILES.includes(f)
|
|
467
397
|
);
|
|
468
|
-
}
|
|
469
398
|
|
|
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
|
-
|
|
498
399
|
if (conflictingFiles.length > 0 && !this.options.force) {
|
|
499
|
-
console.log(chalk.red(
|
|
500
|
-
console.log(
|
|
400
|
+
console.log(chalk.red(`\n❌ Directory is not empty: ${dir}`));
|
|
401
|
+
console.log(
|
|
402
|
+
chalk.yellow('Found files:'),
|
|
403
|
+
conflictingFiles.join(', ')
|
|
404
|
+
);
|
|
501
405
|
console.log(chalk.gray('Use --force to override\n'));
|
|
502
406
|
throw new Error('Directory not empty');
|
|
503
407
|
}
|
|
504
408
|
}
|
|
505
409
|
|
|
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
|
-
|
|
518
410
|
/**
|
|
519
411
|
* Initialize git repository
|
|
520
412
|
*/
|
|
521
413
|
async initializeGit() {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
414
|
+
// Argument arrays, no shell: nothing here is parsed by a shell.
|
|
415
|
+
const git = (args) =>
|
|
416
|
+
spawnSync('git', args, {
|
|
417
|
+
cwd: this.projectDir,
|
|
418
|
+
stdio: 'ignore',
|
|
419
|
+
shell: false,
|
|
528
420
|
});
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
421
|
+
// Git is a convenience: a missing git or git identity is not fatal.
|
|
422
|
+
for (const args of [
|
|
423
|
+
['init'],
|
|
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
|
+
}
|
|
532
431
|
}
|
|
432
|
+
console.log(chalk.gray('Git repository initialized'));
|
|
533
433
|
}
|
|
534
434
|
|
|
535
435
|
/**
|
|
536
436
|
* Install dependencies
|
|
437
|
+
* @returns {boolean} whether the install succeeded
|
|
537
438
|
*/
|
|
538
|
-
async installDependencies(
|
|
439
|
+
async installDependencies() {
|
|
539
440
|
console.log(chalk.blue('\n📦 Installing dependencies...'));
|
|
540
|
-
|
|
441
|
+
|
|
541
442
|
const useYarn = this.isUsingYarn();
|
|
542
443
|
const command = useYarn ? 'yarn' : 'npm';
|
|
543
444
|
const args = useYarn ? [] : ['install'];
|
|
544
445
|
|
|
545
446
|
const proc = spawn.sync(command, args, {
|
|
546
|
-
cwd: this.
|
|
547
|
-
stdio: 'inherit'
|
|
447
|
+
cwd: this.projectDir,
|
|
448
|
+
stdio: 'inherit',
|
|
548
449
|
});
|
|
549
450
|
|
|
550
451
|
if (proc.status !== 0) {
|
|
551
452
|
console.log(chalk.yellow('\n⚠️ Dependency installation failed'));
|
|
552
|
-
console.log(
|
|
453
|
+
console.log(
|
|
454
|
+
chalk.gray(`You can install manually with: ${command} install`)
|
|
455
|
+
);
|
|
456
|
+
return false;
|
|
553
457
|
}
|
|
458
|
+
return true;
|
|
554
459
|
}
|
|
555
460
|
|
|
556
461
|
/**
|
|
@@ -561,147 +466,61 @@ To integrate Frigg into your production application:
|
|
|
561
466
|
}
|
|
562
467
|
|
|
563
468
|
/**
|
|
564
|
-
*
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
return [];
|
|
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
|
|
469
|
+
* Validate the generated app definition with the same code path as
|
|
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
|
|
651
477
|
*/
|
|
652
478
|
async validateGeneratedAppDefinition(appDefPath) {
|
|
479
|
+
if (this.options.verbose) {
|
|
480
|
+
console.log(chalk.gray('🔍 Validating app definition...'));
|
|
481
|
+
}
|
|
653
482
|
try {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
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');
|
|
666
|
-
}
|
|
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'
|
|
483
|
+
const report = runValidation({ cwd: path.dirname(appDefPath) });
|
|
484
|
+
const issues = [...report.errors, ...report.warnings];
|
|
485
|
+
if (issues.length === 0) {
|
|
486
|
+
if (this.options.verbose) {
|
|
487
|
+
console.log(
|
|
488
|
+
chalk.green('✅ App definition passes validation')
|
|
489
|
+
);
|
|
686
490
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
if (
|
|
494
|
+
report.errors.length === 1 &&
|
|
495
|
+
report.errors[0].code === 'load-failed'
|
|
496
|
+
) {
|
|
497
|
+
// Before `npm install`, index.js cannot load its dependencies yet.
|
|
693
498
|
if (this.options.verbose) {
|
|
694
|
-
console.log(
|
|
499
|
+
console.log(
|
|
500
|
+
chalk.gray(
|
|
501
|
+
'App definition not validated yet: run `frigg validate` after `npm install`.'
|
|
502
|
+
)
|
|
503
|
+
);
|
|
695
504
|
}
|
|
696
505
|
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;
|
|
701
506
|
}
|
|
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;
|
|
702
519
|
} catch (error) {
|
|
703
520
|
if (this.options.verbose) {
|
|
704
|
-
console.log(
|
|
521
|
+
console.log(
|
|
522
|
+
chalk.yellow(`⚠️ Validation skipped: ${error.message}`)
|
|
523
|
+
);
|
|
705
524
|
}
|
|
706
525
|
return true; // Don't fail the process for validation issues
|
|
707
526
|
}
|
|
@@ -711,46 +530,71 @@ To integrate Frigg into your production application:
|
|
|
711
530
|
* Display next steps
|
|
712
531
|
*/
|
|
713
532
|
displayNextSteps(deploymentMode, config) {
|
|
714
|
-
const relativePath = path.relative(process.cwd(), this.
|
|
533
|
+
const relativePath = path.relative(process.cwd(), this.projectDir);
|
|
715
534
|
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
|
+
};
|
|
716
541
|
|
|
717
542
|
console.log(chalk.bold('\n📋 Next Steps:\n'));
|
|
718
543
|
|
|
719
|
-
|
|
720
|
-
console.log(chalk.cyan(` cd ${cdPath}\n`));
|
|
544
|
+
printStep('Navigate to your project:', `cd ${cdPath}`);
|
|
721
545
|
|
|
722
|
-
if (
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
console.log(`3. Open the Frigg UI for development:`);
|
|
727
|
-
console.log(chalk.cyan(` frigg ui\n`));
|
|
546
|
+
if (!config.dependenciesInstalled) {
|
|
547
|
+
printStep('Install dependencies:', 'npm install');
|
|
548
|
+
}
|
|
728
549
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
550
|
+
printStep(
|
|
551
|
+
'Start PostgreSQL and check DATABASE_URL in .env:',
|
|
552
|
+
'docker run --name frigg-postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:16'
|
|
553
|
+
);
|
|
554
|
+
printStep('Set up the database:', 'npm run db:setup');
|
|
555
|
+
printStep('Start the development server:', 'npm start');
|
|
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
|
+
);
|
|
733
565
|
} else {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
566
|
+
printStep(
|
|
567
|
+
'Add an integration from the API module library (adds src/integrations/<Name>Integration.js and lists it in index.js):',
|
|
568
|
+
'npx frigg install <module> # e.g. npx frigg install hubspot'
|
|
569
|
+
);
|
|
570
|
+
}
|
|
739
571
|
|
|
740
|
-
|
|
741
|
-
|
|
572
|
+
if (config.serverlessProvider === 'aws') {
|
|
573
|
+
printStep(
|
|
574
|
+
'Deploy to AWS Lambda with a hosted PostgreSQL (DATABASE_URL comes from your shell, not .env; see README.md):',
|
|
575
|
+
"DATABASE_URL='postgresql://...?sslmode=require' npm run deploy -- --stage prod"
|
|
576
|
+
);
|
|
742
577
|
}
|
|
743
578
|
|
|
744
|
-
if (config.
|
|
745
|
-
console.log(
|
|
746
|
-
|
|
747
|
-
|
|
579
|
+
if (config.needsCustomApiModule) {
|
|
580
|
+
console.log(
|
|
581
|
+
chalk.gray(
|
|
582
|
+
'To build an API module for your own application, see https://docs.friggframework.org (API modules).'
|
|
583
|
+
)
|
|
584
|
+
);
|
|
748
585
|
}
|
|
749
586
|
|
|
750
587
|
console.log(chalk.green('\n🎉 Happy integrating with Frigg!\n'));
|
|
751
|
-
console.log(
|
|
752
|
-
|
|
588
|
+
console.log(
|
|
589
|
+
chalk.gray('Documentation: https://docs.friggframework.org')
|
|
590
|
+
);
|
|
591
|
+
console.log(
|
|
592
|
+
chalk.gray(
|
|
593
|
+
'Support: https://github.com/friggframework/frigg/issues'
|
|
594
|
+
)
|
|
595
|
+
);
|
|
753
596
|
}
|
|
754
597
|
}
|
|
755
598
|
|
|
756
|
-
module.exports = BackendFirstHandler;
|
|
599
|
+
module.exports = BackendFirstHandler;
|
|
600
|
+
module.exports.EMBEDDED_DIR = EMBEDDED_DIR;
|