@friggframework/devtools 2.0.0--canary.711.f8b6445.0 → 2.0.0--canary.667.f74cf3b.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 +30 -77
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
- package/frigg-cli/__tests__/unit/commands/install.test.js +341 -594
- package/frigg-cli/generate-command/index.js +0 -1
- package/frigg-cli/generate-iam-command.js +0 -1
- package/frigg-cli/index.js +4 -9
- package/frigg-cli/init-command/backend-first-handler.js +554 -397
- package/frigg-cli/init-command/index.js +35 -82
- package/frigg-cli/install-command/commit-changes.js +8 -40
- package/frigg-cli/install-command/environment-variables.js +0 -15
- package/frigg-cli/install-command/index.js +21 -96
- package/frigg-cli/install-command/install-package.js +4 -77
- package/frigg-cli/install-command/integration-file.js +11 -20
- package/frigg-cli/install-command/template.js +75 -102
- package/frigg-cli/install-command/validate-package.js +4 -36
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/test/init-command.test.js +2 -9
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +281 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +1 -21
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -6
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -30
- package/infrastructure/domains/database/aurora-builder.js +2 -13
- package/infrastructure/domains/database/aurora-builder.test.js +0 -22
- package/infrastructure/domains/security/iam-generator.js +5 -112
- package/infrastructure/domains/security/iam-generator.test.js +0 -94
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +21 -7
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +13 -22
- package/package.json +8 -10
- package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
- package/frigg-cli/init-command/deployment-modes.js +0 -7
- package/frigg-cli/init-command/safe-path.js +0 -58
- package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
- package/frigg-cli/install-command/app-definition.js +0 -174
- package/frigg-cli/install-command/resolve-module.js +0 -69
- package/frigg-cli/templates/backend/README.md +0 -267
- package/frigg-cli/templates/backend/env.example +0 -20
- package/frigg-cli/templates/backend/gitignore +0 -10
- package/frigg-cli/templates/backend/index.js +0 -114
- package/frigg-cli/templates/backend/infrastructure.js +0 -20
- package/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(
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const { logInfo } = require('./logger');
|
|
4
3
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
2
|
-
const
|
|
3
|
-
const {
|
|
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
|
|
72
|
-
|
|
73
|
-
|
|
26
|
+
const modulePath = resolve(
|
|
27
|
+
backendPath,
|
|
28
|
+
`../../node_modules/${packageName}`
|
|
74
29
|
);
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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,
|
|
46
|
+
await handleEnvVariables(backendPath, modulePath);
|
|
122
47
|
}
|
|
123
48
|
} catch (error) {
|
|
124
49
|
logError('An error occurred:', error);
|
|
@@ -1,86 +1,13 @@
|
|
|
1
|
-
const
|
|
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
|
-
|
|
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
|
|
15
|
+
const integrationFilePath = path.join(
|
|
24
16
|
integrationDir,
|
|
25
|
-
`${
|
|
17
|
+
`${apiModuleName}Integration.js`
|
|
18
|
+
);
|
|
19
|
+
logInfo(`Writing integration file: ${integrationFilePath}`);
|
|
20
|
+
const integrationTemplate = getIntegrationTemplate(
|
|
21
|
+
apiModuleName,
|
|
22
|
+
backendPath,
|
|
23
|
+
ApiClass
|
|
26
24
|
);
|
|
27
|
-
|
|
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
|
};
|