@friggframework/devtools 2.0.0--canary.710.91495fa.0 → 2.0.0--canary.702.ef0dc8c.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.
Files changed (86) hide show
  1. package/README.md +1 -0
  2. package/frigg-cli/README.md +76 -78
  3. package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
  4. package/frigg-cli/__tests__/unit/commands/deploy.test.js +27 -30
  5. package/frigg-cli/__tests__/unit/commands/doctor.test.js +6 -10
  6. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
  7. package/frigg-cli/__tests__/unit/commands/install.test.js +341 -601
  8. package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
  9. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
  10. package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
  11. package/frigg-cli/build-command/index.js +6 -0
  12. package/frigg-cli/deploy-command/index.js +6 -0
  13. package/frigg-cli/generate-command/index.js +0 -1
  14. package/frigg-cli/generate-iam-command.js +0 -1
  15. package/frigg-cli/index.js +23 -10
  16. package/frigg-cli/index.test.js +158 -0
  17. package/frigg-cli/init-command/backend-first-handler.js +531 -395
  18. package/frigg-cli/init-command/index.js +35 -82
  19. package/frigg-cli/install-command/commit-changes.js +8 -40
  20. package/frigg-cli/install-command/environment-variables.js +0 -15
  21. package/frigg-cli/install-command/index.js +21 -96
  22. package/frigg-cli/install-command/install-package.js +4 -77
  23. package/frigg-cli/install-command/integration-file.js +11 -20
  24. package/frigg-cli/install-command/template.js +75 -102
  25. package/frigg-cli/install-command/validate-package.js +4 -36
  26. package/frigg-cli/package.json +1 -1
  27. package/frigg-cli/start-command/index.js +4 -0
  28. package/frigg-cli/start-command/start-command.test.js +3 -0
  29. package/frigg-cli/test/init-command.test.js +2 -9
  30. package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
  31. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
  32. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +326 -0
  33. package/frigg-cli/validate-command/__tests__/validate-command.test.js +241 -0
  34. package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +119 -0
  35. package/frigg-cli/validate-command/checks/config.js +468 -0
  36. package/frigg-cli/validate-command/checks/integrations.js +274 -0
  37. package/frigg-cli/validate-command/fixtures/bad-module/index.js +18 -0
  38. package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +76 -0
  39. package/frigg-cli/validate-command/fixtures/fathom-module/index.js +6 -0
  40. package/frigg-cli/validate-command/format-report.js +60 -0
  41. package/frigg-cli/validate-command/index.js +151 -0
  42. package/frigg-cli/validate-command/load-app-definition.js +93 -0
  43. package/frigg-cli/validate-command/load-module-definition.js +64 -0
  44. package/frigg-cli/validate-command/schema-issues.js +154 -0
  45. package/frigg-cli/validate-command/validate-app-definition.js +60 -0
  46. package/frigg-cli/validate-command/validate-module-definition.js +46 -0
  47. package/infrastructure/__tests__/postgres-config.test.js +835 -241
  48. package/infrastructure/__tests__/template-generation.test.js +8 -36
  49. package/infrastructure/app-definition-schema-contract.test.js +607 -0
  50. package/infrastructure/create-frigg-infrastructure.js +4 -1
  51. package/infrastructure/create-frigg-infrastructure.test.js +51 -0
  52. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +60 -118
  53. package/infrastructure/domains/database/aurora-builder.js +2 -13
  54. package/infrastructure/domains/database/aurora-builder.test.js +0 -22
  55. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +8 -12
  56. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +7 -19
  57. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +8 -12
  58. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +18 -17
  59. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +2 -12
  60. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +1 -8
  61. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +2 -4
  62. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +0 -10
  63. package/infrastructure/domains/networking/vpc-builder.js +8 -18
  64. package/infrastructure/domains/networking/vpc-builder.test.js +13 -32
  65. package/infrastructure/domains/security/iam-generator.js +5 -112
  66. package/infrastructure/domains/security/iam-generator.test.js +0 -94
  67. package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
  68. package/infrastructure/domains/shared/utilities/base-definition-factory.js +2 -7
  69. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +0 -21
  70. package/infrastructure/infrastructure-composer.test.js +794 -268
  71. package/infrastructure/integration.test.js +381 -0
  72. package/infrastructure/scripts/build-prisma-layer.test.js +7 -28
  73. package/infrastructure/scripts/build-time-discovery.test.js +3 -18
  74. package/package.json +8 -10
  75. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
  76. package/frigg-cli/init-command/deployment-modes.js +0 -7
  77. package/frigg-cli/init-command/safe-path.js +0 -58
  78. package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
  79. package/frigg-cli/install-command/app-definition.js +0 -174
  80. package/frigg-cli/install-command/resolve-module.js +0 -69
  81. package/frigg-cli/templates/backend/README.md +0 -267
  82. package/frigg-cli/templates/backend/env.example +0 -20
  83. package/frigg-cli/templates/backend/gitignore +0 -10
  84. package/frigg-cli/templates/backend/index.js +0 -114
  85. package/frigg-cli/templates/backend/infrastructure.js +0 -20
  86. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
@@ -7,12 +7,11 @@
7
7
 
8
8
  'use strict';
9
9
 
10
+ const path = require('path');
10
11
  const chalk = require('chalk');
11
12
  const validateProjectName = require('validate-npm-package-name');
12
13
  const semver = require('semver');
13
14
  const BackendFirstHandler = require('./backend-first-handler');
14
- const { resolveProjectTarget } = require('./safe-path');
15
- const { DEPLOYMENT_MODES } = require('./deployment-modes');
16
15
 
17
16
  function checkAppName(appName) {
18
17
  const validationResult = validateProjectName(appName);
@@ -27,7 +26,7 @@ function checkAppName(appName) {
27
26
  [
28
27
  ...(validationResult.errors || []),
29
28
  ...(validationResult.warnings || []),
30
- ].forEach((error) => {
29
+ ].forEach(error => {
31
30
  console.error(chalk.red(` * ${error}`));
32
31
  });
33
32
  console.error(chalk.red('\nPlease choose a different project name.'));
@@ -45,96 +44,50 @@ function checkNodeVersion() {
45
44
  console.log(
46
45
  chalk.yellow(
47
46
  `You are using Node ${process.version} so the project will be bootstrapped with an old unsupported version of tools.\n\n` +
48
- `Please update to Node 14 or higher for a better, fully supported experience.\n`
47
+ `Please update to Node 14 or higher for a better, fully supported experience.\n`
49
48
  )
50
49
  );
51
50
  }
52
51
  }
53
52
 
54
- async function initCommand(projectName, options = {}) {
53
+ async function initCommand(projectName, options) {
55
54
  const verbose = options.verbose || false;
56
55
  const force = options.force || false;
57
-
56
+
58
57
  checkNodeVersion();
59
58
 
60
- // The legacy template system was removed; reject it before doing anything.
61
- if (options.template) {
62
- console.log();
63
- console.log(
64
- chalk.red('Legacy template system is no longer supported.')
65
- );
66
- console.log(
67
- chalk.yellow(
68
- `Run ${chalk.cyan(
69
- 'frigg init <project-name>'
70
- )} without --template.`
71
- )
72
- );
73
- console.log();
74
- process.exit(1);
75
- return;
76
- }
77
-
78
- // Accept the project name from the positional argument or the --name flag.
79
- const targetName = projectName || options.name;
80
- if (!targetName) {
81
- console.error(
82
- chalk.red(
83
- 'Please specify a project name:\n' +
84
- ` ${chalk.cyan('frigg init')} ${chalk.green(
85
- '<project-name>'
86
- )}\n`
87
- )
88
- );
89
- process.exit(1);
90
- return;
91
- }
92
-
93
- if (options.mode && !DEPLOYMENT_MODES.includes(options.mode)) {
94
- console.error(
95
- chalk.red(
96
- `Invalid --mode "${
97
- options.mode
98
- }". Expected one of: ${DEPLOYMENT_MODES.join(', ')}`
99
- )
100
- );
101
- process.exit(1);
102
- return;
103
- }
104
-
105
- // The last path segment is the project (and npm package) name; the
106
- // project directory is resolved inside its parent directory.
107
- let root;
108
- let appName;
109
- try {
110
- ({ projectDir: root, name: appName } =
111
- resolveProjectTarget(targetName));
112
- } catch (error) {
113
- console.error(chalk.red(error.message));
114
- process.exit(1);
115
- return;
116
- }
59
+ const root = path.resolve(projectName);
60
+ const appName = path.basename(root);
117
61
 
118
62
  checkAppName(appName);
119
-
120
- try {
121
- const handler = new BackendFirstHandler(root, {
122
- force,
123
- verbose,
124
- mode: options.mode,
125
- yes: options.yes || false,
126
- install: options.install,
127
- git: options.git,
128
- });
129
-
130
- await handler.initialize();
131
- } catch (error) {
132
- console.log();
133
- console.log(chalk.red('Aborting installation.'));
134
- console.log(chalk.red('Error:'), error.message);
135
- console.log();
136
- process.exit(1);
63
+
64
+ // Use backend-first handler by default
65
+ if (!options.template && !options.legacyFrontend) {
66
+ try {
67
+ const handler = new BackendFirstHandler(root, {
68
+ force,
69
+ verbose,
70
+ mode: options.mode,
71
+ frontend: options.frontend
72
+ });
73
+
74
+ await handler.initialize();
75
+ return;
76
+ } catch (error) {
77
+ console.log();
78
+ console.log(chalk.red('Aborting installation.'));
79
+ console.log(chalk.red('Error:'), error.message);
80
+ console.log();
81
+ process.exit(1);
82
+ }
137
83
  }
84
+
85
+ // If we get here, show an error for legacy options
86
+ console.log();
87
+ console.log(chalk.red('Legacy template system is no longer supported.'));
88
+ console.log(chalk.yellow('Please use the new backend-first approach.'));
89
+ console.log();
90
+ process.exit(1);
138
91
  }
139
92
 
140
- module.exports = { initCommand };
93
+ module.exports = { initCommand };
@@ -1,46 +1,14 @@
1
- const spawn = require('cross-spawn');
1
+ const { execSync } = require('child_process');
2
2
  const path = require('path');
3
- const { logInfo } = require('./logger');
4
3
 
5
- function git(args, cwd) {
6
- return spawn.sync('git', args, { cwd, stdio: 'ignore' });
7
- }
8
-
9
- /**
10
- * Commit the files `frigg install` changed, and only those
11
- * (`git commit -- <paths>` leaves anything else the user has staged alone).
12
- *
13
- * Committing is a convenience: outside a git repository, or when the commit
14
- * fails (e.g. no git identity configured), the install still succeeds and the
15
- * changes are left in the working tree.
16
- *
17
- * @param {string} backendPath - Path to the app's package.json
18
- * @param {string} label - Integration label, for the commit message
19
- * @param {string[]} files - Absolute paths of the files to commit
20
- * @returns {boolean} whether a commit was made
21
- */
22
- function commitChanges(backendPath, label, files = []) {
23
- const cwd = path.dirname(backendPath);
24
- const inRepo = git(['rev-parse', '--is-inside-work-tree'], cwd);
25
- if (inRepo.error || inRepo.status !== 0 || files.length === 0) {
26
- return false;
27
- }
28
- const relative = files.map((file) => path.relative(cwd, file));
29
- const add = git(['add', '--', ...relative], cwd);
30
- const commit =
31
- add.status === 0 &&
32
- git(
33
- ['commit', '-m', `Add ${label} integration`, '--', ...relative],
34
- cwd
35
- );
36
- if (!commit || commit.status !== 0) {
37
- logInfo(
38
- 'Could not commit the changes; they are left in your working tree.'
39
- );
40
- return false;
4
+ function commitChanges(backendPath, apiModuleName) {
5
+ const apiModulePath = path.join(path.dirname(backendPath), 'src', 'integrations', `${apiModuleName}Integration.js`);
6
+ try {
7
+ execSync(`git add ${apiModulePath}`);
8
+ execSync(`git commit -m "Add ${apiModuleName}Integration to ${apiModuleName}Integration.js"`);
9
+ } catch (error) {
10
+ throw new Error('Failed to commit changes:', error);
41
11
  }
42
- logInfo(`Committed: Add ${label} integration`);
43
- return true;
44
12
  }
45
13
 
46
14
  module.exports = {
@@ -43,12 +43,6 @@ const extractRawEnvVariables = (modulePath) => {
43
43
  return envVariables;
44
44
  };
45
45
  const handleEnvVariables = async (backendPath, modulePath) => {
46
- if (!existsSync(resolve(modulePath, 'definition.js'))) {
47
- logInfo(
48
- 'This module has no definition.js; check its README for the environment variables it needs.'
49
- );
50
- return;
51
- }
52
46
  logInfo('Searching for missing environment variables...');
53
47
  const Definition = { env: extractRawEnvVariables(modulePath) };
54
48
  if (Definition && Definition.env) {
@@ -86,15 +80,6 @@ const handleEnvVariables = async (backendPath, modulePath) => {
86
80
 
87
81
  logInfo(`Missing environment variables: ${missingEnvVars.join(', ')}`);
88
82
 
89
- if (missingEnvVars.length > 0 && !process.stdin.isTTY) {
90
- logInfo(
91
- `Set these in .env for local development: ${missingEnvVars.join(
92
- ', '
93
- )}`
94
- );
95
- return;
96
- }
97
-
98
83
  if (missingEnvVars.length > 0) {
99
84
  const addEnvVars = await confirm({
100
85
  message: `The following environment variables are required: ${missingEnvVars.join(
@@ -1,14 +1,7 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { getInstallSpec, installPackage } = require('./install-package');
4
- const {
5
- createIntegrationFile,
6
- INTEGRATIONS_DIR,
7
- } = require('./integration-file');
1
+ const { installPackage } = require('./install-package');
2
+ const { createIntegrationFile } = require('./integration-file');
3
+ const { resolve } = require('node:path');
8
4
  const { updateBackendJsFile } = require('./backend-js');
9
- const { registerIntegration } = require('./app-definition');
10
- const { resolveInstalledModule, readModuleInfo } = require('./resolve-module');
11
- const { toIdentifier } = require('./template');
12
5
  const { logInfo, logError } = require('./logger');
13
6
  const { commitChanges } = require('./commit-changes');
14
7
  const { handleEnvVariables } = require('./environment-variables');
@@ -16,39 +9,8 @@ const {
16
9
  validatePackageExists,
17
10
  searchAndSelectPackage,
18
11
  } = require('./validate-package');
19
- const {
20
- findNearestBackendPackageJson,
21
- validateBackendPath,
22
- } = require('@friggframework/core/utils');
23
-
24
- /**
25
- * Print what to do by hand when the app definition could not be edited.
26
- */
27
- function printManualSteps({ className, requirePath, definitionFile, reason }) {
28
- logInfo(
29
- `\nCould not add ${className} to ${definitionFile} automatically (${reason}). Add it by hand:\n` +
30
- ` 1. At the top of ${definitionFile}:\n` +
31
- ` const ${className} = require('${requirePath}');\n` +
32
- ` 2. In the app definition's integrations array:\n` +
33
- ` integrations: [${className}],\n`
34
- );
35
- }
12
+ const { findNearestBackendPackageJson, validateBackendPath } = require('@friggframework/core/utils');
36
13
 
37
- /**
38
- * `frigg install <module>`: install an API module and scaffold an
39
- * integration for it.
40
- *
41
- * 1. `npm install` the module in the app directory (the `@next` tag for apps
42
- * on a Frigg 2.x prerelease).
43
- * 2. Resolve it from the app directory (`require.resolve` with
44
- * `paths: [appDir]`).
45
- * 3. Write `src/integrations/<Label>Integration.js`.
46
- * 4. Register it: in a `frigg init` app, in index.js's `integrations` array
47
- * (or print the manual steps when that cannot be done safely); in an older
48
- * app with a backend.js, in backend.js as before.
49
- * 5. Commit the changed files when inside a git repository.
50
- * 6. Report (or prompt for) environment variables the module reads.
51
- */
52
14
  const installCommand = async (apiModuleName) => {
53
15
  try {
54
16
  const packageNames = await searchAndSelectPackage(apiModuleName);
@@ -56,69 +18,32 @@ const installCommand = async (apiModuleName) => {
56
18
 
57
19
  const backendPath = findNearestBackendPackageJson();
58
20
  validateBackendPath(backendPath);
59
- const projectDir = path.dirname(backendPath);
60
- const backendJsPath = path.join(projectDir, 'backend.js');
61
- const indexJsPath = path.join(projectDir, 'index.js');
62
- const hasBackendJs = fs.existsSync(backendJsPath);
63
21
 
64
22
  for (const packageName of packageNames) {
65
23
  await validatePackageExists(packageName);
66
- installPackage(
67
- backendPath,
68
- getInstallSpec(packageName, projectDir)
69
- );
24
+ installPackage(backendPath, packageName);
70
25
 
71
- const { entryPath, moduleDir } = resolveInstalledModule(
72
- packageName,
73
- projectDir
26
+ const modulePath = resolve(
27
+ backendPath,
28
+ `../../node_modules/${packageName}`
74
29
  );
75
- const info = readModuleInfo(entryPath, packageName);
76
- const baseName = toIdentifier(info.label);
77
- const className = `${baseName}Integration`;
78
- const requirePath = `./${INTEGRATIONS_DIR}/${className}`;
79
-
80
- const { filePath } = createIntegrationFile(backendPath, {
81
- className,
82
- packageName,
83
- ...info,
84
- });
85
- const changedFiles = [filePath];
86
-
87
- if (hasBackendJs) {
88
- // Older layout: the app definition lives in backend.js.
89
- updateBackendJsFile(backendPath, baseName);
90
- changedFiles.push(backendJsPath);
91
- } else {
92
- const result = registerIntegration(
93
- indexJsPath,
94
- className,
95
- requirePath
96
- );
97
- if (result.status === 'registered') {
98
- logInfo(`Added ${className} to index.js`);
99
- changedFiles.push(indexJsPath);
100
- } else if (result.status === 'already-registered') {
101
- logInfo(`${className} is already in index.js`);
102
- } else {
103
- printManualSteps({
104
- className,
105
- requirePath,
106
- definitionFile: 'index.js',
107
- reason: result.reason,
108
- });
109
- }
110
- }
111
-
112
- for (const file of ['package.json', 'package-lock.json']) {
113
- const full = path.join(projectDir, file);
114
- if (fs.existsSync(full)) changedFiles.push(full);
115
- }
116
- commitChanges(backendPath, info.label, changedFiles);
30
+ const {
31
+ Config: { label },
32
+ Api: ApiClass,
33
+ } = require(modulePath);
34
+
35
+ const sanitizedLabel = label.replace(
36
+ /[<>:"/\\|?*\x00-\x1F\s]/g,
37
+ ''
38
+ ); // Remove invalid characters and spaces console.log('Installing integration for:', sanitizedLabel);
39
+ createIntegrationFile(backendPath, sanitizedLabel, ApiClass);
40
+ updateBackendJsFile(backendPath, sanitizedLabel);
41
+ commitChanges(backendPath, sanitizedLabel);
117
42
  logInfo(
118
43
  `Successfully installed ${packageName} and updated the project.`
119
44
  );
120
45
 
121
- await handleEnvVariables(backendPath, moduleDir);
46
+ await handleEnvVariables(backendPath, modulePath);
122
47
  }
123
48
  } catch (error) {
124
49
  logError('An error occurred:', error);
@@ -1,86 +1,13 @@
1
- const fs = require('fs');
1
+ const { execSync } = require('child_process');
2
2
  const path = require('path');
3
- const spawn = require('cross-spawn');
4
- const semver = require('semver');
5
3
 
6
- /**
7
- * The npm spec to install an API module with, for the app in `projectDir`.
8
- *
9
- * An app on a Frigg 2.x prerelease (e.g. `@friggframework/core@2.0.0-next.115`,
10
- * what `frigg init` scaffolds today) needs the API modules published under the
11
- * `next` dist-tag: npm's `latest` for most modules is still a 1.x release that
12
- * depends on `@friggframework/core@^1`. Anything else installs the default
13
- * (`latest`) version.
14
- *
15
- * @param {string} packageName - e.g. `@friggframework/api-module-hubspot`
16
- * @param {string} projectDir - Directory holding the app's package.json
17
- * @returns {string} npm install spec
18
- */
19
- function getInstallSpec(packageName, projectDir) {
20
- const version = getCoreVersion(projectDir);
21
- if (version && version.major >= 2 && version.prerelease.length > 0) {
22
- return `${packageName}@next`;
23
- }
24
- return packageName;
25
- }
26
-
27
- /**
28
- * The app's `@friggframework/core` version: the installed copy if there is
29
- * one (this also covers `file:` and `link:` dependencies), otherwise the
30
- * lowest version its package.json range admits.
31
- *
32
- * @returns {semver.SemVer|null}
33
- */
34
- function getCoreVersion(projectDir) {
35
- try {
36
- const installed = require.resolve('@friggframework/core/package.json', {
37
- paths: [projectDir],
38
- });
39
- const { version } = JSON.parse(fs.readFileSync(installed, 'utf8'));
40
- const parsed = semver.parse(version);
41
- if (parsed) return parsed;
42
- } catch (error) {
43
- // Not installed yet; fall back to the declared range.
44
- }
45
- try {
46
- const pkg = JSON.parse(
47
- fs.readFileSync(path.join(projectDir, 'package.json'), 'utf8')
48
- );
49
- const range =
50
- (pkg.dependencies && pkg.dependencies['@friggframework/core']) ||
51
- (pkg.devDependencies &&
52
- pkg.devDependencies['@friggframework/core']);
53
- return range && semver.validRange(range)
54
- ? semver.minVersion(range)
55
- : null;
56
- } catch (error) {
57
- return null;
58
- }
59
- }
60
-
61
- /**
62
- * `npm install <spec>` in the app directory. Arguments are passed as an
63
- * array (no shell), so a package name can never be interpreted as a command.
64
- *
65
- * @param {string} backendPath - Path to the app's package.json
66
- * @param {string} spec - npm install spec
67
- */
68
- function installPackage(backendPath, spec) {
69
- const result = spawn.sync('npm', ['install', spec], {
4
+ function installPackage(backendPath, packageName) {
5
+ execSync(`npm install ${packageName}`, {
70
6
  cwd: path.dirname(backendPath),
71
7
  stdio: 'inherit',
72
8
  });
73
- if (result.error) {
74
- throw result.error;
75
- }
76
- if (result.status !== 0) {
77
- throw new Error(
78
- `npm install ${spec} exited with code ${result.status}`
79
- );
80
- }
81
9
  }
82
10
 
83
11
  module.exports = {
84
- getInstallSpec,
85
12
  installPackage,
86
- };
13
+ };
@@ -2,38 +2,29 @@ const fs = require('fs-extra');
2
2
  const path = require('path');
3
3
  const { logInfo } = require('./logger');
4
4
  const { getIntegrationTemplate } = require('./template');
5
-
6
5
  const INTEGRATIONS_DIR = 'src/integrations';
7
6
 
8
- /**
9
- * Write `src/integrations/<ClassName>.js` next to the app's package.json.
10
- * An existing file is left untouched (it may hold the user's work).
11
- *
12
- * @param {string} backendPath - Path to the app's package.json
13
- * @param {object} templateParams - See getIntegrationTemplate
14
- * @returns {{ filePath: string, created: boolean }}
15
- */
16
- function createIntegrationFile(backendPath, templateParams) {
7
+ function createIntegrationFile(backendPath, apiModuleName, ApiClass) {
17
8
  const integrationDir = path.join(
18
9
  path.dirname(backendPath),
19
10
  INTEGRATIONS_DIR
20
11
  );
12
+ logInfo(`Ensuring directory exists: ${integrationDir}`);
21
13
  fs.ensureDirSync(integrationDir);
22
14
 
23
- const filePath = path.join(
15
+ const integrationFilePath = path.join(
24
16
  integrationDir,
25
- `${templateParams.className}.js`
17
+ `${apiModuleName}Integration.js`
18
+ );
19
+ logInfo(`Writing integration file: ${integrationFilePath}`);
20
+ const integrationTemplate = getIntegrationTemplate(
21
+ apiModuleName,
22
+ backendPath,
23
+ ApiClass
26
24
  );
27
- if (fs.existsSync(filePath)) {
28
- logInfo(`Keeping existing integration file: ${filePath}`);
29
- return { filePath, created: false };
30
- }
31
- logInfo(`Writing integration file: ${filePath}`);
32
- fs.writeFileSync(filePath, getIntegrationTemplate(templateParams));
33
- return { filePath, created: true };
25
+ fs.writeFileSync(integrationFilePath, integrationTemplate);
34
26
  }
35
27
 
36
28
  module.exports = {
37
- INTEGRATIONS_DIR,
38
29
  createIntegrationFile,
39
30
  };