@hahnpro/flow-cli 2.14.1 → 2.14.3
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/lib/auth.mjs +10 -3
- package/lib/cli.mjs +20 -28
- package/lib/utils.mjs +11 -0
- package/package.json +14 -15
package/lib/auth.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import getPort from 'get-port';
|
|
4
|
+
import HttpsProxyAgent from 'https-proxy-agent';
|
|
4
5
|
import nconf from 'nconf';
|
|
5
6
|
import open from 'open';
|
|
6
|
-
import openidClient from 'openid-client';
|
|
7
|
+
import openidClient, { custom } from 'openid-client';
|
|
7
8
|
import { dirname, join } from 'node:path';
|
|
8
9
|
import { fileURLToPath } from 'node:url';
|
|
9
10
|
|
|
@@ -21,6 +22,12 @@ const viewsPath = join(__dirname, 'views');
|
|
|
21
22
|
let server = null;
|
|
22
23
|
nconf.file({ file: join(__dirname, 'config') });
|
|
23
24
|
|
|
25
|
+
if (process.env.https_proxy || process.env.http_proxy) {
|
|
26
|
+
custom.setHttpOptionsDefaults({
|
|
27
|
+
agent: HttpsProxyAgent(process.env.https_proxy || process.env.http_proxy),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
export async function getAccessToken(baseUrl = BASE_URL, realm = REALM) {
|
|
25
32
|
checkEnvironment([
|
|
26
33
|
['BASE_URL', baseUrl],
|
|
@@ -38,8 +45,8 @@ export async function getAccessToken(baseUrl = BASE_URL, realm = REALM) {
|
|
|
38
45
|
const kcIssuer = await openidClient.Issuer.discover(`${baseUrl}/auth/realms/${realm}/`);
|
|
39
46
|
const client = new kcIssuer.Client({ client_id: CLIENT_ID, client_secret: CLIENT_SECRET });
|
|
40
47
|
const tokenSet = await client.grant({ grant_type: 'client_credentials' });
|
|
48
|
+
|
|
41
49
|
nconf.set(baseUrl.replace(/:/g, ''), tokenSet);
|
|
42
|
-
server.close();
|
|
43
50
|
nconf.save((error) => {
|
|
44
51
|
if (error) {
|
|
45
52
|
logger.error(error);
|
|
@@ -135,6 +142,6 @@ function checkEnvironment(values) {
|
|
|
135
142
|
}
|
|
136
143
|
}
|
|
137
144
|
if (missing) {
|
|
138
|
-
throw new Error('Missing environment
|
|
145
|
+
throw new Error('Missing environment variables');
|
|
139
146
|
}
|
|
140
147
|
}
|
package/lib/cli.mjs
CHANGED
|
@@ -15,25 +15,29 @@ import fs from 'node:fs';
|
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
16
|
import path from 'node:path';
|
|
17
17
|
import ora from 'ora';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
18
19
|
|
|
19
20
|
import { getAccessToken, login, logout } from './auth.mjs';
|
|
20
|
-
import { handleConvertedOutput, logger, prepareTsFile } from './utils.mjs';
|
|
21
|
+
import { handleApiError, handleConvertedOutput, logger, prepareTsFile } from './utils.mjs';
|
|
21
22
|
|
|
22
23
|
const require = createRequire(import.meta.url);
|
|
23
24
|
const BASE_URL = process.env.BASE_URL || process.env.PLATFORM_URL;
|
|
24
25
|
const BUILD_DIR = process.env.BUILD_DIR || 'dist';
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
28
|
+
const __dirname = path.dirname(__filename);
|
|
29
|
+
|
|
30
|
+
let axios = Axios;
|
|
27
31
|
if (process.env.https_proxy || process.env.http_proxy) {
|
|
28
32
|
const httpsAgent = HttpsProxyAgent(process.env.https_proxy || process.env.http_proxy);
|
|
29
33
|
axios = Axios.create({ httpsAgent, proxy: false });
|
|
30
|
-
} else {
|
|
31
|
-
axios = Axios;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
let apiToken;
|
|
35
37
|
let projectsRoot = 'modules';
|
|
36
38
|
|
|
39
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json')));
|
|
40
|
+
|
|
37
41
|
const CMD = {
|
|
38
42
|
AUDIT: 'audit',
|
|
39
43
|
BUILD: 'build',
|
|
@@ -48,7 +52,7 @@ const CMD = {
|
|
|
48
52
|
const program = new Command();
|
|
49
53
|
|
|
50
54
|
program
|
|
51
|
-
.version(
|
|
55
|
+
.version(packageJson.version, '-v, --version')
|
|
52
56
|
.usage('[command] [options]')
|
|
53
57
|
.description('Flow Module Management Tool')
|
|
54
58
|
.on('--help', () => {});
|
|
@@ -114,11 +118,7 @@ program
|
|
|
114
118
|
.description('Lint project files')
|
|
115
119
|
.action(async (projectName) => {
|
|
116
120
|
try {
|
|
117
|
-
|
|
118
|
-
if (projectName === 'all') {
|
|
119
|
-
project = { location: '.' };
|
|
120
|
-
}
|
|
121
|
-
project = await findProject(projectName);
|
|
121
|
+
const project = await findProject(projectName);
|
|
122
122
|
await exec(CMD.LINT, project);
|
|
123
123
|
} catch (error) {
|
|
124
124
|
if (error) logger.log(error);
|
|
@@ -126,10 +126,11 @@ program
|
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
+
// if BASE_URL is not given and --url is not specified this correctly throws an error
|
|
129
130
|
program
|
|
130
131
|
.command('login')
|
|
131
|
-
.
|
|
132
|
-
.
|
|
132
|
+
.requiredOption('--url <url>', 'URL of target platform', process.env.BASE_URL)
|
|
133
|
+
.requiredOption('-r, --realm <realm>', 'Auth realm of target platform', process.env.REALM)
|
|
133
134
|
.description('Authenticate against platform')
|
|
134
135
|
.action(async (options) => {
|
|
135
136
|
try {
|
|
@@ -143,7 +144,7 @@ program
|
|
|
143
144
|
|
|
144
145
|
program
|
|
145
146
|
.command('logout')
|
|
146
|
-
.
|
|
147
|
+
.requiredOption('--url <url>', 'URL of target platform', process.env.BASE_URL)
|
|
147
148
|
.description('Remove authentication data')
|
|
148
149
|
.action(async (options) => {
|
|
149
150
|
try {
|
|
@@ -188,8 +189,8 @@ program
|
|
|
188
189
|
|
|
189
190
|
program
|
|
190
191
|
.command('publish-module [projectName]')
|
|
191
|
-
.
|
|
192
|
-
.
|
|
192
|
+
.requiredOption('--url <url>', 'URL of target platform', process.env.BASE_URL)
|
|
193
|
+
.requiredOption('-r, --realm <realm>', 'Auth realm of target platform', process.env.REALM)
|
|
193
194
|
.option('-f, --functions', 'publish flow functions')
|
|
194
195
|
.option('-u, --update', 'update existing flow functions')
|
|
195
196
|
.option('-s, --skip', 'skip modules that already exists with the current version')
|
|
@@ -242,8 +243,8 @@ program
|
|
|
242
243
|
|
|
243
244
|
program
|
|
244
245
|
.command('publish-functions [projectName]')
|
|
245
|
-
.
|
|
246
|
-
.
|
|
246
|
+
.requiredOption('--url <url>', 'URL of target platform', process.env.BASE_URL)
|
|
247
|
+
.requiredOption('-r, --realm <realm>', 'Auth realm of target platform', process.env.REALM)
|
|
247
248
|
.option('-u, --update', 'update existing flow functions')
|
|
248
249
|
.description('Publishes all Flow Functions inside specified Module to Cloud Platform')
|
|
249
250
|
.action(async (projectName, options) => {
|
|
@@ -532,6 +533,8 @@ async function publishModule(project, baseUrl = BASE_URL) {
|
|
|
532
533
|
...form.getHeaders(),
|
|
533
534
|
Authorization: `Bearer ${apiToken}`,
|
|
534
535
|
},
|
|
536
|
+
maxBodyLength: Number.POSITIVE_INFINITY,
|
|
537
|
+
maxContentLength: Number.POSITIVE_INFINITY,
|
|
535
538
|
});
|
|
536
539
|
|
|
537
540
|
logger.ok(`Module "${project.name}" published!`);
|
|
@@ -610,17 +613,6 @@ async function publishFunctions(project, update, baseUrl = BASE_URL) {
|
|
|
610
613
|
});
|
|
611
614
|
}
|
|
612
615
|
|
|
613
|
-
function handleApiError(error) {
|
|
614
|
-
if (error.isAxiosError && error.response) {
|
|
615
|
-
logger.error(`${error.response.status} ${error.response.statusText}`);
|
|
616
|
-
if (error.response.data) {
|
|
617
|
-
logger.error(JSON.stringify(error.response.data));
|
|
618
|
-
}
|
|
619
|
-
} else {
|
|
620
|
-
logger.error(error);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
616
|
function zipDirectory(source, out) {
|
|
625
617
|
const archive = archiver('zip', { zlib: { level: 8 } });
|
|
626
618
|
const stream = fs.createWriteStream(out);
|
package/lib/utils.mjs
CHANGED
|
@@ -192,6 +192,17 @@ export const logger = {
|
|
|
192
192
|
/* eslint-enable no-console */
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
+
export function handleApiError(error) {
|
|
196
|
+
if (error.isAxiosError && error.response) {
|
|
197
|
+
logger.error(`${error.response.status} ${error.response.statusText}`);
|
|
198
|
+
if (error.response.data) {
|
|
199
|
+
logger.error(JSON.stringify(error.response.data));
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
logger.error(error);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
195
206
|
function blockDefinitionIncludes(block, value) {
|
|
196
207
|
return block.trim().split('\n', 1)[0].includes(value);
|
|
197
208
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hahnpro/flow-cli",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.3",
|
|
4
4
|
"description": "CLI for managing Flow Modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,38 +27,38 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"archiver": "^5.3.1",
|
|
30
|
-
"axios": "
|
|
30
|
+
"axios": "~0.27.2",
|
|
31
31
|
"chalk": "^5.0.1",
|
|
32
32
|
"class-transformer": "0.5.1",
|
|
33
33
|
"class-validator": "~0.13.2",
|
|
34
34
|
"class-validator-jsonschema": "^3.1.0",
|
|
35
35
|
"commander": "^9.2.0",
|
|
36
36
|
"copyfiles": "^2.4.1",
|
|
37
|
-
"dotenv": "^16.0.
|
|
38
|
-
"ejs": "^3.1.
|
|
37
|
+
"dotenv": "^16.0.1",
|
|
38
|
+
"ejs": "^3.1.8",
|
|
39
39
|
"execa": "^6.1.0",
|
|
40
|
-
"express": "^4.
|
|
40
|
+
"express": "^4.18.1",
|
|
41
41
|
"form-data": "^4.0.0",
|
|
42
42
|
"get-port": "^6.1.2",
|
|
43
|
-
"glob": "^8.0.
|
|
43
|
+
"glob": "^8.0.3",
|
|
44
44
|
"https-proxy-agent": "^5.0.1",
|
|
45
45
|
"nconf": "^0.12.0",
|
|
46
46
|
"open": "^8.4.0",
|
|
47
|
-
"openid-client": "^5.1.
|
|
47
|
+
"openid-client": "^5.1.6",
|
|
48
48
|
"ora": "^6.1.0",
|
|
49
49
|
"reflect-metadata": "^0.1.13",
|
|
50
|
-
"ts-node": "^10.
|
|
50
|
+
"ts-node": "^10.8.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/express": "^4.17.13",
|
|
54
|
-
"@types/jest": "^27.
|
|
54
|
+
"@types/jest": "^27.5.1",
|
|
55
55
|
"@types/nconf": "^0.10.2",
|
|
56
|
-
"@types/node": "^16.11.
|
|
57
|
-
"eslint": "^8.
|
|
56
|
+
"@types/node": "^16.11.36",
|
|
57
|
+
"eslint": "^8.16.0",
|
|
58
58
|
"eslint-plugin-unicorn": "^42.0.0",
|
|
59
|
-
"jest": "^
|
|
59
|
+
"jest": "^28.1.0",
|
|
60
60
|
"prettier": "^2.6.2",
|
|
61
|
-
"typescript": "^4.
|
|
61
|
+
"typescript": "^4.7.2"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": "^14.13.1 || >=16.0.0"
|
|
@@ -83,6 +83,5 @@
|
|
|
83
83
|
"format": "prettier --write .",
|
|
84
84
|
"lint": "eslint '**/*.{js,mjs}'",
|
|
85
85
|
"test": "jest"
|
|
86
|
-
}
|
|
87
|
-
"readme": "# `@hahnpro/flow-cli`\n\nhttps://github.com/hahnprojects/flow\n\n```shell\nflow-cli --help\nflow-cli [command] --help\n```\n\n# Commands\n\n## `build [projectName]`\n\nBuilds specified Project.\n\n## `install [projectName]`\n\nInstalls the dependencies of the specified Project.\n\n## `format`\n\nFormats all typescript files according to prettier configuration.\n\n## `name [projectName]`\n\nInstalls Dependencies and Builds the specified Project.\n\n## `package [projectName]`\n\nBuilds specified Module and packages it as .zip File for manual upload to the platform.\n\n## `publish-module [projectName]`\n\nPublishes specified Module to Cloud Platform.\n\n- `-f`, `--functions` Publish flow functions.\n- `-u`, `--update` Update existing flow functions.\n\n## `publish-functions [projectName]`\n\nPublishes all Flow Functions inside specified Module to Cloud Platform.\n\n- `-u`, `--update` Update existing flow functions.\n\n## `serve [projectName]`\n\nBuilds and serves your Project. Rebuilding on file changes.\n\n## `start [projectName]`\n\nRuns your project.\n\n## `test [projectName]`\n\nRuns tests for your Project.\n\n## `generate-schemas [projectName]`\n\nGenerates Input, Output and Properties-Schemas for the specified project.\n\n- `--verbose` Output more information about what is being done.\n- `-h`, `--hide` Hide warnings if Input/OutputProperties classes can´t be found.\n This command generates the schemas and puts them in the `inputStreams` and `outputStreams`\n fields in the json-files of each Flow-Function. It always assumes the properties defined\n in the `Input/OutPutProperties` classes are meant for the default input/output streams.\n If your Function uses different streams you may have to change stream name manually.\n"
|
|
86
|
+
}
|
|
88
87
|
}
|