@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
@@ -1,58 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
-
5
- /**
6
- * Resolve `segments` against `base` and make sure the result stays inside
7
- * `base` (or is `base` itself). Every path `frigg init` writes to goes
8
- * through here, so a crafted name or template entry can never make it write
9
- * outside the project directory.
10
- *
11
- * @param {string} base - Absolute directory the result must stay within
12
- * @param {...string} segments
13
- * @returns {string} Absolute, normalized path
14
- */
15
- function resolveInside(base, ...segments) {
16
- const root = path.resolve(base);
17
- const resolved = path.resolve(root, ...segments);
18
- const relative = path.relative(root, resolved);
19
- if (
20
- relative !== '' &&
21
- (relative.startsWith('..') || path.isAbsolute(relative))
22
- ) {
23
- throw new Error(`Refusing to use ${resolved}: it is outside ${root}`);
24
- }
25
- return resolved;
26
- }
27
-
28
- /**
29
- * Resolve the directory `frigg init <name>` creates.
30
- *
31
- * The argument may be a bare project name (`my-app`) or a path whose last
32
- * segment is the project name (`../apps/my-app`, `/tmp/my-app`). The parent
33
- * is resolved from the working directory and the project directory is
34
- * resolved inside that parent, so the last segment must be a plain name:
35
- * `.`, `..` and empty names are rejected (the npm package-name check in
36
- * initCommand rejects the rest).
37
- *
38
- * @param {string} input - CLI argument
39
- * @param {string} [cwd]
40
- * @returns {{ parentDir: string, projectDir: string, name: string }}
41
- */
42
- function resolveProjectTarget(input, cwd = process.cwd()) {
43
- if (typeof input !== 'string' || input.trim() === '') {
44
- throw new Error('A project name is required');
45
- }
46
- const parentDir = path.resolve(cwd, path.dirname(input));
47
- const name = path.basename(input);
48
- if (name === '' || name === '.' || name === '..') {
49
- throw new Error(`Invalid project name "${name}"`);
50
- }
51
- const projectDir = resolveInside(parentDir, name);
52
- if (projectDir === parentDir) {
53
- throw new Error(`Invalid project name "${name}"`);
54
- }
55
- return { parentDir, projectDir, name };
56
- }
57
-
58
- module.exports = { resolveInside, resolveProjectTarget };
@@ -1,202 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const semver = require('semver');
5
-
6
- /**
7
- * Lowest stable Frigg 2.x release that a scaffolded app may resolve to.
8
- *
9
- * `@friggframework/core@2.0.0` exists on npm but is a deprecated, broken build
10
- * (an accidental 2024 release on the old mongoose/aws-sdk v2 stack). A range
11
- * such as `^2.0.0` resolves straight to it, so scaffolded ranges must never
12
- * admit 2.0.0.
13
- */
14
- const MIN_STABLE_FRIGG_VERSION = '2.0.1';
15
-
16
- /**
17
- * The serverless plugins the composed infrastructure loads (see
18
- * `infrastructure/domains/shared/utilities/base-definition-factory.js`) plus
19
- * the `osls` CLI that `frigg start|build|deploy` spawn. Their versions are read
20
- * from devtools' own package.json so the scaffold never drifts from what
21
- * devtools is tested with.
22
- */
23
- const SERVERLESS_TOOLING = [
24
- 'osls',
25
- 'serverless-esbuild',
26
- 'serverless-offline',
27
- 'serverless-offline-sqs',
28
- 'serverless-dotenv-plugin',
29
- ];
30
-
31
- /**
32
- * Prisma packages: optional peer dependencies of `@friggframework/core` that a
33
- * Frigg app needs (`frigg db:setup` runs the Prisma CLI, and the generated
34
- * client loads `@prisma/client` at runtime).
35
- */
36
- const PRISMA_PACKAGES = ['@prisma/client', 'prisma'];
37
-
38
- /**
39
- * Where devtools' package.json sits when frigg-cli runs from inside
40
- * `@friggframework/devtools` (the normal case: `<devtools>/frigg-cli/init-command`).
41
- */
42
- const LOCAL_DEVTOOLS_PACKAGE_JSON = path.join(
43
- __dirname,
44
- '..',
45
- '..',
46
- 'package.json'
47
- );
48
- const DEVTOOLS_PACKAGE_JSON_SPECIFIER = '@friggframework/devtools/package.json';
49
-
50
- function isModuleNotFoundFor(error, specifier) {
51
- return (
52
- Boolean(error) &&
53
- error.code === 'MODULE_NOT_FOUND' &&
54
- typeof error.message === 'string' &&
55
- error.message.includes(specifier)
56
- );
57
- }
58
-
59
- /**
60
- * Read `@friggframework/devtools`' package.json.
61
- *
62
- * frigg-cli normally ships inside devtools, two levels below its package.json.
63
- * It is also published on its own as `@friggframework/frigg-cli` (with
64
- * devtools as a peer dependency); installed that way, two levels up is
65
- * `node_modules/@friggframework`, which has no package.json, so resolve
66
- * devtools as a module instead. Only that exact "file not found" takes the
67
- * fallback: a malformed package.json or any other failure is rethrown so the
68
- * real cause is not hidden.
69
- *
70
- * @param {object} [options]
71
- * @param {Function} [options.requireFn] - Test seam for `require`.
72
- * @returns {object} devtools' package.json.
73
- */
74
- function readDevtoolsPackageJson({ requireFn = require } = {}) {
75
- try {
76
- const pkg = requireFn(LOCAL_DEVTOOLS_PACKAGE_JSON);
77
- if (pkg && pkg.name === '@friggframework/devtools') {
78
- return pkg;
79
- }
80
- } catch (error) {
81
- if (!isModuleNotFoundFor(error, LOCAL_DEVTOOLS_PACKAGE_JSON)) {
82
- throw error;
83
- }
84
- }
85
- return requireFn(DEVTOOLS_PACKAGE_JSON_SPECIFIER);
86
- }
87
-
88
- function readCorePackageJson() {
89
- // eslint-disable-next-line global-require
90
- return require('@friggframework/core/package.json');
91
- }
92
-
93
- /**
94
- * Derive the semver range a scaffolded app should use for Frigg packages,
95
- * given the version of the devtools doing the scaffolding.
96
- *
97
- * - Prerelease (e.g. `2.0.0-next.115`): pin the exact version. A caret range
98
- * on a 2.0.0 prerelease also admits the deprecated stable 2.0.0; npm happens
99
- * to skip deprecated versions when it can, but other clients do not, and
100
- * the moment a newer prerelease is published an unpinned range drifts away
101
- * from the devtools that generated the app.
102
- * - Stable >= 2.0.1: `^<version>`, which can never resolve to 2.0.0.
103
- * - Stable below 2.0.1 (not expected): `^2.0.1`, the first good stable build.
104
- *
105
- * @param {string} version - Devtools version.
106
- * @returns {string} Range to write into the scaffolded package.json.
107
- */
108
- function getFriggVersionRange(version) {
109
- const parsed = semver.valid(version);
110
- if (!parsed) {
111
- throw new Error(`Invalid @friggframework/devtools version: ${version}`);
112
- }
113
- if (semver.prerelease(parsed)) {
114
- return parsed;
115
- }
116
- if (semver.lt(parsed, MIN_STABLE_FRIGG_VERSION)) {
117
- return `^${MIN_STABLE_FRIGG_VERSION}`;
118
- }
119
- return `^${parsed}`;
120
- }
121
-
122
- function pickVersions(names, ...sources) {
123
- const result = {};
124
- for (const name of names) {
125
- const source = sources.find((deps) => deps && deps[name]);
126
- if (!source) {
127
- throw new Error(
128
- `Cannot determine a version for "${name}" from @friggframework/devtools`
129
- );
130
- }
131
- result[name] = source[name];
132
- }
133
- return result;
134
- }
135
-
136
- /**
137
- * Dependencies for a scaffolded Frigg backend's package.json.
138
- *
139
- * @param {object} [overrides] - Test seam: package.json objects to read from.
140
- * @param {object} [overrides.devtoolsPackageJson]
141
- * @param {object} [overrides.corePackageJson]
142
- * @returns {{dependencies: object, devDependencies: object}}
143
- */
144
- function getScaffoldDependencies({
145
- devtoolsPackageJson = readDevtoolsPackageJson(),
146
- corePackageJson = readCorePackageJson(),
147
- } = {}) {
148
- const friggRange = getFriggVersionRange(devtoolsPackageJson.version);
149
-
150
- const dependencies = sortKeys({
151
- '@friggframework/core': friggRange,
152
- ...pickVersions(
153
- PRISMA_PACKAGES,
154
- corePackageJson.peerDependencies,
155
- corePackageJson.devDependencies
156
- ),
157
- });
158
-
159
- const devDependencies = sortKeys({
160
- '@friggframework/devtools': friggRange,
161
- '@friggframework/serverless-plugin': friggRange,
162
- ...pickVersions(
163
- SERVERLESS_TOOLING,
164
- devtoolsPackageJson.dependencies,
165
- devtoolsPackageJson.devDependencies
166
- ),
167
- jest: devtoolsPackageJson.devDependencies.jest,
168
- });
169
-
170
- return { dependencies, devDependencies };
171
- }
172
-
173
- function sortKeys(object) {
174
- return Object.fromEntries(
175
- Object.entries(object).sort(([a], [b]) => a.localeCompare(b))
176
- );
177
- }
178
-
179
- /**
180
- * Scripts for a scaffolded Frigg backend. They delegate to the `frigg` binary
181
- * provided by the `@friggframework/devtools` devDependency.
182
- */
183
- function getScaffoldScripts() {
184
- return {
185
- start: 'frigg start',
186
- build: 'frigg build',
187
- deploy: 'frigg deploy',
188
- 'db:setup': 'frigg db:setup',
189
- test: 'jest --passWithNoTests',
190
- };
191
- }
192
-
193
- module.exports = {
194
- MIN_STABLE_FRIGG_VERSION,
195
- SERVERLESS_TOOLING,
196
- PRISMA_PACKAGES,
197
- LOCAL_DEVTOOLS_PACKAGE_JSON,
198
- readDevtoolsPackageJson,
199
- getFriggVersionRange,
200
- getScaffoldDependencies,
201
- getScaffoldScripts,
202
- };
@@ -1,174 +0,0 @@
1
- const fs = require('fs');
2
- const { parse } = require('@babel/parser');
3
-
4
- const PARSE_OPTIONS = {
5
- sourceType: 'unambiguous',
6
- allowReturnOutsideFunction: true,
7
- plugins: ['jsx', 'classProperties', 'objectRestSpread'],
8
- };
9
-
10
- /**
11
- * Find the single `integrations: [...]` array literal in a parsed file.
12
- * Returns null unless there is exactly one, so an ambiguous file is never
13
- * edited.
14
- */
15
- function findIntegrationsArray(ast) {
16
- const found = [];
17
- const visit = (node) => {
18
- if (!node || typeof node.type !== 'string') return;
19
- if (
20
- (node.type === 'ObjectProperty' || node.type === 'Property') &&
21
- !node.computed &&
22
- ((node.key.type === 'Identifier' &&
23
- node.key.name === 'integrations') ||
24
- (node.key.type === 'StringLiteral' &&
25
- node.key.value === 'integrations')) &&
26
- node.value.type === 'ArrayExpression'
27
- ) {
28
- found.push(node.value);
29
- }
30
- for (const key of Object.keys(node)) {
31
- if (key === 'loc' || key === 'start' || key === 'end') continue;
32
- const child = node[key];
33
- if (Array.isArray(child)) child.forEach(visit);
34
- else if (child && typeof child.type === 'string') visit(child);
35
- }
36
- };
37
- visit(ast.program);
38
- return found.length === 1 ? found[0] : null;
39
- }
40
-
41
- function isRequireDeclaration(statement) {
42
- return (
43
- statement.type === 'VariableDeclaration' &&
44
- statement.declarations.some(
45
- (d) =>
46
- d.init &&
47
- d.init.type === 'CallExpression' &&
48
- d.init.callee.type === 'Identifier' &&
49
- d.init.callee.name === 'require'
50
- )
51
- );
52
- }
53
-
54
- function hasTopLevelRequire(ast) {
55
- return ast.program.body.some(isRequireDeclaration);
56
- }
57
-
58
- /** Offset just after the last top-level `require` declaration, or after 'use strict', or 0. */
59
- function findRequireInsertionPoint(ast) {
60
- let offset = null;
61
- for (const statement of ast.program.body) {
62
- if (isRequireDeclaration(statement)) {
63
- offset = statement.end;
64
- }
65
- }
66
- if (offset !== null) return offset;
67
- const directives = ast.program.directives || [];
68
- if (directives.length > 0) return directives[directives.length - 1].end;
69
- return 0;
70
- }
71
-
72
- function lineIndentAt(source, offset) {
73
- const lineStart = source.lastIndexOf('\n', offset - 1) + 1;
74
- const match = /^[ \t]*/.exec(source.slice(lineStart));
75
- return match ? match[0] : '';
76
- }
77
-
78
- /**
79
- * Register an integration class in the app definition file (`index.js`).
80
- *
81
- * Adds `const <ClassName> = require('<requirePath>');` after the last
82
- * top-level require and `<ClassName>,` as the first entry of the one
83
- * `integrations: [...]` array. The file is only written when it parses, has
84
- * exactly one `integrations` array literal, and still parses after the edit;
85
- * otherwise nothing is changed and the caller prints manual steps.
86
- *
87
- * @param {string} filePath - The app definition file (index.js)
88
- * @param {string} className - e.g. `HubSpotIntegration`
89
- * @param {string} requirePath - e.g. `./src/integrations/HubSpotIntegration`
90
- * @returns {{ status: 'registered'|'already-registered'|'manual', reason?: string }}
91
- */
92
- function registerIntegration(filePath, className, requirePath) {
93
- let source;
94
- try {
95
- source = fs.readFileSync(filePath, 'utf8');
96
- } catch (error) {
97
- return { status: 'manual', reason: `cannot read ${filePath}` };
98
- }
99
-
100
- let ast;
101
- try {
102
- ast = parse(source, PARSE_OPTIONS);
103
- } catch (error) {
104
- return { status: 'manual', reason: `cannot parse ${filePath}` };
105
- }
106
-
107
- const array = findIntegrationsArray(ast);
108
- if (!array) {
109
- return {
110
- status: 'manual',
111
- reason: 'expected exactly one `integrations: [...]` array literal',
112
- };
113
- }
114
-
115
- const alreadyListed = array.elements.some(
116
- (el) => el && el.type === 'Identifier' && el.name === className
117
- );
118
- const requireLine = `const ${className} = require('${requirePath}');`;
119
- const alreadyRequired = source.includes(`require('${requirePath}')`);
120
- if (alreadyListed && alreadyRequired) {
121
- return { status: 'already-registered' };
122
- }
123
- if (alreadyListed !== alreadyRequired) {
124
- return {
125
- status: 'manual',
126
- reason: `${className} is partly registered already`,
127
- };
128
- }
129
-
130
- const baseIndent = lineIndentAt(source, array.start);
131
- const itemIndent = `${baseIndent} `;
132
- const inner = source.slice(array.start + 1, array.end - 1);
133
- let arrayText;
134
- if (inner.trim() === '') {
135
- arrayText = `[\n${itemIndent}${className},\n${baseIndent}]`;
136
- } else {
137
- arrayText = `[\n${itemIndent}${className},${
138
- inner.startsWith('\n') ? '' : `\n${itemIndent}`
139
- }${inner}]`;
140
- }
141
-
142
- const at = findRequireInsertionPoint(ast);
143
- let requireText;
144
- if (at === 0) {
145
- requireText = `${requireLine}\n`;
146
- } else if (hasTopLevelRequire(ast)) {
147
- requireText = `\n${requireLine}`;
148
- } else {
149
- requireText = `\n\n${requireLine}`;
150
- }
151
-
152
- // Apply the later edit first so the earlier offset stays valid.
153
- const edits = [
154
- { start: array.start, end: array.end, text: arrayText },
155
- { start: at, end: at, text: requireText },
156
- ].sort((a, b) => b.start - a.start);
157
- let updated = source;
158
- for (const edit of edits) {
159
- updated =
160
- updated.slice(0, edit.start) + edit.text + updated.slice(edit.end);
161
- }
162
-
163
- try {
164
- const check = parse(updated, PARSE_OPTIONS);
165
- if (!findIntegrationsArray(check)) throw new Error('lost array');
166
- } catch (error) {
167
- return { status: 'manual', reason: 'the edited file would not parse' };
168
- }
169
-
170
- fs.writeFileSync(filePath, updated);
171
- return { status: 'registered' };
172
- }
173
-
174
- module.exports = { registerIntegration };
@@ -1,69 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- /**
5
- * Locate an installed API module from the app's point of view.
6
- *
7
- * Resolution starts at the app directory (`require.resolve` with
8
- * `paths: [projectDir]`), so it finds the copy npm just installed whether
9
- * node_modules sits in the app (a `frigg init` app) or is hoisted to a
10
- * workspace root (the older `backend/` layout).
11
- *
12
- * @param {string} packageName
13
- * @param {string} projectDir - Directory holding the app's package.json
14
- * @returns {{ entryPath: string, moduleDir: string }}
15
- */
16
- function resolveInstalledModule(packageName, projectDir) {
17
- const entryPath = require.resolve(packageName, { paths: [projectDir] });
18
-
19
- // Walk up from the entry file to the package root (its package.json).
20
- let dir = path.dirname(entryPath);
21
- while (dir !== path.dirname(dir)) {
22
- const pkgJson = path.join(dir, 'package.json');
23
- if (fs.existsSync(pkgJson)) {
24
- try {
25
- const { name } = JSON.parse(fs.readFileSync(pkgJson, 'utf8'));
26
- if (name === packageName) {
27
- return { entryPath, moduleDir: dir };
28
- }
29
- } catch (error) {
30
- // Not a readable package.json; keep walking.
31
- }
32
- }
33
- dir = path.dirname(dir);
34
- }
35
- return { entryPath, moduleDir: path.dirname(entryPath) };
36
- }
37
-
38
- /**
39
- * Load an installed API module and read what the integration scaffold needs.
40
- *
41
- * @returns {{ moduleName: string, label: string, description?: string,
42
- * detailsUrl?: string, icon?: string, categories?: string[] }}
43
- */
44
- function readModuleInfo(entryPath, packageName) {
45
- // eslint-disable-next-line global-require
46
- const mod = require(entryPath);
47
- const definition = mod && mod.Definition;
48
- if (!definition) {
49
- throw new Error(
50
- `${packageName} does not export a Definition, so it is not a Frigg API module.`
51
- );
52
- }
53
- const config = (mod && mod.Config) || {};
54
- const moduleName =
55
- (typeof definition.getName === 'function' && definition.getName()) ||
56
- definition.moduleName ||
57
- config.name ||
58
- packageName.replace(/^@friggframework\/api-module-/, '');
59
- return {
60
- moduleName,
61
- label: config.label || config.displayName || moduleName,
62
- description: config.description,
63
- detailsUrl: config.productUrl || config.detailsUrl,
64
- icon: config.logoUrl || config.icon,
65
- categories: config.categories,
66
- };
67
- }
68
-
69
- module.exports = { resolveInstalledModule, readModuleInfo };