zcatalyst-cli 1.15.2 → 1.16.1
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/README.md +11 -0
- package/docs/fn-utils/lib/ensure-java-userconfig.toml +15 -0
- package/lib/authentication/login.js +3 -3
- package/lib/command_needs/auth.js +2 -2
- package/lib/command_needs/rc.js +7 -2
- package/lib/commands/iac/import.js +1 -1
- package/lib/commands/init.js +3 -1
- package/lib/commands/project/use.js +4 -0
- package/lib/commands/pull.js +8 -1
- package/lib/commands/serve.js +1 -1
- package/lib/deploy/features/functions/index.js +5 -0
- package/lib/express_middlewares/unknownReqProxy.js +4 -0
- package/lib/fn-utils/lib/ensure-java-userconfig.js +151 -0
- package/lib/fn-utils/lib/java.js +109 -49
- package/lib/internal/credential.js +7 -0
- package/lib/pull/features/apig.js +16 -3
- package/lib/pull/features/client.js +16 -3
- package/lib/pull/features/functions/index.js +62 -32
- package/lib/serve/index.js +12 -1
- package/lib/serve/server/lib/java/index.js +7 -2
- package/lib/serve/server/lib/master.js +32 -7
- package/lib/serve/server/lib/node/server/index.js +1 -1
- package/lib/serve/server/lib/python/index.js +6 -2
- package/lib/serve/server/lib/web_client/server.js +1 -1
- package/lib/shell/dependencies/http-functions.js +19 -6
- package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +4 -6
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +3 -4
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -5
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +2 -2
- package/lib/shell/dependencies/local-function.js +7 -3
- package/lib/shell/prepare/languages/java.js +2 -2
- package/lib/userConfig.js +1 -1
- package/lib/util_modules/constants/lib/apig-rules.js +5 -5
- package/lib/util_modules/constants/lib/plugin.js +1 -1
- package/lib/util_modules/constants/lib/scopes.js +3 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -80,6 +80,10 @@ Command | Description
|
|
|
80
80
|
**project:reset** | Clear an active project selection and reset to the base project.
|
|
81
81
|
**init** | Initialize a Catalyst project, function, and client resources in the local directory.
|
|
82
82
|
**pull** | Pull resources of your project from the remote console to the local directory.
|
|
83
|
+
**iac:pack** | Creates a import ready zip file.
|
|
84
|
+
**iac:import** | Deploy the iac zip file to console and create a new project with it.
|
|
85
|
+
**iac:export** | Create a zip file out of existing project in console.
|
|
86
|
+
**iac:status** | Displays the status of iac schedule progress.
|
|
83
87
|
**apig:status** | Obtain the current status of API Gateway for your project and the schedule progress.
|
|
84
88
|
**apig:enable** | Enable API Gateway for your project. *In both Console and Local*.
|
|
85
89
|
**apig:disable** | Disable API Gateway for your project. *In both Console and Local*.
|
|
@@ -93,14 +97,21 @@ Command | Description
|
|
|
93
97
|
**functions:shell** | Launch a node shell to test emulated functions of any stack or type, other than Advanced I/O functions.
|
|
94
98
|
**functions:config** | Perform advanced configurations such as memory allocation on a function in your project.
|
|
95
99
|
**functions:delete** | Delete a function from the remote console or the local directory.
|
|
100
|
+
**appsail:add** | Link an already existing AppSail service to Catalyst Project.
|
|
101
|
+
**codelib:install** | Install the code library functionalities into your project.
|
|
96
102
|
**event:generate \| generate:event** | Generate sample payloads from different components or custom event sources to test Event functions.
|
|
97
103
|
**event:generate:integ** | Generate sample payloads for the required integration service to test Integration functions.
|
|
98
104
|
**serve** | Serve Basic I/O and Advanced I/O functions, and the client, to test them locally.
|
|
99
105
|
**deploy** | Deploy the Catalyst project and project resources to the remote console from the local directory.
|
|
100
106
|
**help** | Display the command reference or help for a specific command.
|
|
101
107
|
**run-script \| run** | Run a particular command script defined in *catalyst.json*.
|
|
108
|
+
**config:set** | Set catalyst configuration as a key value pair.
|
|
109
|
+
**config:get** | Get catalyst config value for the specified key.
|
|
110
|
+
**config:delete** | Delete a key from catalyst config.
|
|
111
|
+
**config:list** | List all your catalyst configurations.
|
|
102
112
|
**logout** | Log the CLI out of your Catalyst account.
|
|
103
113
|
|
|
114
|
+
|
|
104
115
|
---
|
|
105
116
|
|
|
106
117
|
## Migration
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[JAVACONFIG-1]
|
|
2
|
+
context = '''Unable to check the javac version using the given binary path.'''
|
|
3
|
+
aid = '''Please provide a valid java binary path for the config key ${arg[0]} to serve or deploy the function[${arg[1]}].'''
|
|
4
|
+
|
|
5
|
+
[JAVACONFIG-2]
|
|
6
|
+
context = '''Unable to locate the java binary path in your system.'''
|
|
7
|
+
aid = '''Please provide a valid java binary path for the config key ${arg[0]} to serve or deploy the function[${arg[1]}].'''
|
|
8
|
+
|
|
9
|
+
[JAVACONFIG-3]
|
|
10
|
+
context = '''Provided JDK version[${arg[0]}] for the config key ${arg[1]} is lesser than the compatible JDK version[${arg[2]}]'''
|
|
11
|
+
aid = '''Please provide a valid java binary path for the config key ${arg[1]} that is compatible with the JDK version[${arg[2]}] to serve or deploy the function[${arg[3]}].'''
|
|
12
|
+
|
|
13
|
+
[JAVACONFIG-4]
|
|
14
|
+
context = '''Unable to verify the java binary path'''
|
|
15
|
+
aid = '''Please re-check and provide a valid java binary path for the config key ${arg[0]} to serve or deploy the function[${arg[1]}].'''
|
|
@@ -32,8 +32,8 @@ const js_1 = require("../util_modules/js");
|
|
|
32
32
|
const logger_1 = require("../util_modules/logger");
|
|
33
33
|
const option_1 = require("../util_modules/option");
|
|
34
34
|
exports.missingScopes = {
|
|
35
|
-
[constants_1.DC_TYPE.au.value]: ['
|
|
36
|
-
[constants_1.DC_TYPE.eu.value]: ['
|
|
35
|
+
[constants_1.DC_TYPE.au.value]: ['quick_ml'],
|
|
36
|
+
[constants_1.DC_TYPE.eu.value]: ['quick_ml']
|
|
37
37
|
};
|
|
38
38
|
class Login {
|
|
39
39
|
constructor(localhost = true, user = true) {
|
|
@@ -348,7 +348,7 @@ class Login {
|
|
|
348
348
|
}
|
|
349
349
|
}));
|
|
350
350
|
const destroyer = new server_js_1.ConnectionDestroyer(server);
|
|
351
|
-
server.listen(port, () => {
|
|
351
|
+
server.listen(port, '127.0.0.1', () => {
|
|
352
352
|
(0, logger_1.info)();
|
|
353
353
|
(0, logger_1.info)('Visit this URL on this device to log in:');
|
|
354
354
|
(0, logger_1.info)(ansi_colors_1.bold.underline(authUrl));
|
|
@@ -53,6 +53,6 @@ exports.default = (inScopes = []) => {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
runtime_store_1.default.set('auth_scopes', requiredScopes);
|
|
56
|
-
runtime_store_1.default.set('user', config_store_1.default.get(`${activeDC}.user
|
|
57
|
-
runtime_store_1.default.set('credential', credential_1.default.
|
|
56
|
+
runtime_store_1.default.set('user', config_store_1.default.get(`${activeDC}.user`));
|
|
57
|
+
runtime_store_1.default.set('credential', credential_1.default.initToken(tokenObj.token, tokenObj.temp));
|
|
58
58
|
};
|
package/lib/command_needs/rc.js
CHANGED
|
@@ -26,9 +26,14 @@ const option_1 = require("../util_modules/option");
|
|
|
26
26
|
const project_2 = require("../util_modules/project");
|
|
27
27
|
const config_store_1 = __importDefault(require("../config-store"));
|
|
28
28
|
const dc_1 = require("../dc");
|
|
29
|
+
const env_1 = require("../util_modules/env");
|
|
29
30
|
exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck = true } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
31
|
+
const globOrgOpt = (0, option_1.getGlobalOptionValue)('org', null);
|
|
32
|
+
const orgOpt = globOrgOpt ? globOrgOpt : (0, env_1.getEnvVariable)('CATALYST_ORG', null);
|
|
33
|
+
const globProjectOpt = (0, option_1.getGlobalOptionValue)('project', null);
|
|
34
|
+
const projectOpt = globProjectOpt
|
|
35
|
+
? globProjectOpt
|
|
36
|
+
: (0, env_1.getEnvVariable)('CATALYST_PROJECT', null);
|
|
32
37
|
if (projectOpt !== null && orgOpt === null) {
|
|
33
38
|
throw new error_1.default('Org option is needed when project option is supplied', {
|
|
34
39
|
exit: 2
|
|
@@ -106,7 +106,7 @@ const ensureUserAction = (deployRes) => __awaiter(void 0, void 0, void 0, functi
|
|
|
106
106
|
}
|
|
107
107
|
}));
|
|
108
108
|
const destroyer = new server_js_1.ConnectionDestroyer(server);
|
|
109
|
-
server.listen(callbackPort, () => {
|
|
109
|
+
server.listen(callbackPort, '127.0.0.1', () => {
|
|
110
110
|
const urlString = accessUrl.toString();
|
|
111
111
|
(0, logger_1.info)();
|
|
112
112
|
(0, logger_1.info)('Visit this URL on this device to proceed:');
|
package/lib/commands/init.js
CHANGED
|
@@ -103,7 +103,9 @@ exports.default = new command_1.default('init [feature]')
|
|
|
103
103
|
(0, logger_1.message)('Aborted by user.');
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
if (feature !== 'project') {
|
|
107
|
+
yield (0, features_1.project)();
|
|
108
|
+
}
|
|
107
109
|
const featureAns = yield prompt_1.default.ask(prompt_1.default.question('features', 'Which are the features you want to setup for this folder?\n This step is optional! Press ' +
|
|
108
110
|
(0, ansi_colors_1.cyan)('<return> ') +
|
|
109
111
|
'to proceed.\n', {
|
|
@@ -27,6 +27,10 @@ const makeActive = (currentProjectId, optedProject) => __awaiter(void 0, void 0,
|
|
|
27
27
|
active: true,
|
|
28
28
|
base: js_1.JS.isNull(currentProjectId)
|
|
29
29
|
});
|
|
30
|
+
const optedProjectEnv = optedProject.env_details;
|
|
31
|
+
yield (0, project_2.upsertEnv)(optedProject.id, optedProjectEnv[0], {
|
|
32
|
+
active: true
|
|
33
|
+
});
|
|
30
34
|
(0, logger_1.success)('Successfully made project active');
|
|
31
35
|
});
|
|
32
36
|
exports.default = new command_1.default('project:use [name_or_project_id]')
|
package/lib/commands/pull.js
CHANGED
|
@@ -136,5 +136,12 @@ exports.default = new command_1.default('pull [feature]')
|
|
|
136
136
|
yield config.save();
|
|
137
137
|
(0, logger_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been successfully updated with feature details.');
|
|
138
138
|
(0, logger_1.info)();
|
|
139
|
-
(
|
|
139
|
+
if ((runtime_store_1.default.get('payload.functions.status') ||
|
|
140
|
+
runtime_store_1.default.get('payload.client.status') ||
|
|
141
|
+
runtime_store_1.default.get('payload.apig.status')) === 1) {
|
|
142
|
+
(0, logger_1.success)('Catalyst pull partially completed!');
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
(0, logger_1.success)('Catalyst pull completed!');
|
|
146
|
+
}
|
|
140
147
|
}));
|
package/lib/commands/serve.js
CHANGED
|
@@ -49,7 +49,7 @@ exports.default = new command_1.default('serve')
|
|
|
49
49
|
.option('--except <targets>', 'serve all targets except specified (e.g. "client")')
|
|
50
50
|
.option('--ignore-scripts', 'ignore the pre and post lifescycle scripts')
|
|
51
51
|
.option('--no-open', 'disable opening the client automatically when served')
|
|
52
|
-
.needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.functions_execution, constants_1.SCOPE.webapp])
|
|
52
|
+
.needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.functions_execution, constants_1.SCOPE.webapp, constants_1.SCOPE.pdf_shot])
|
|
53
53
|
.needs('config')
|
|
54
54
|
.needs('rc')
|
|
55
55
|
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -99,6 +99,11 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
99
99
|
})));
|
|
100
100
|
}
|
|
101
101
|
const allTargets = refinedTargets.filter((target) => {
|
|
102
|
+
if (target.compilationWarning) {
|
|
103
|
+
target.compilationWarning.forEach((message) => {
|
|
104
|
+
(0, logger_1.warning)(message);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
102
107
|
if (!target.valid) {
|
|
103
108
|
(0, logger_1.warning)('skipping deploy of target [' + target.name + '] since ' + target.failure_reason);
|
|
104
109
|
}
|
|
@@ -9,6 +9,10 @@ exports.default = (proxyInstance, customProxyUrl) => (req, res) => {
|
|
|
9
9
|
if (req.url.length === 1 && req.url.startsWith('/')) {
|
|
10
10
|
res.redirect('/app/');
|
|
11
11
|
}
|
|
12
|
+
else if (req.url.match(/accounts\/p\/[0-9]+\/clientidprequest/g)) {
|
|
13
|
+
res.redirect(308, `https://${req.headers['x-zc-project-domain']}${req.url}`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
12
16
|
else if (typeof customProxyUrl === 'string' &&
|
|
13
17
|
!req.url.match(/^(\/baas|\/app|\/server|\/oauthorize|\/__catalyst).*/g)) {
|
|
14
18
|
(0, logger_1.debug)(`proxying "${req.url}" to "${customProxyUrl}"`);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getJavaSpawnCommand = exports.ensureJava = exports.stackVsVersions = void 0;
|
|
16
|
+
const semver_1 = require("semver");
|
|
17
|
+
const error_1 = __importDefault(require("../../error"));
|
|
18
|
+
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
19
|
+
const userConfig_1 = __importDefault(require("../../userConfig"));
|
|
20
|
+
const env_1 = require("../../util_modules/env");
|
|
21
|
+
const shell_1 = require("../../util_modules/shell");
|
|
22
|
+
const java_1 = require("./java");
|
|
23
|
+
exports.stackVsVersions = {
|
|
24
|
+
java8: {
|
|
25
|
+
version: '1.8.0',
|
|
26
|
+
target: '1.8'
|
|
27
|
+
},
|
|
28
|
+
java11: {
|
|
29
|
+
version: '11.0.0',
|
|
30
|
+
target: '11'
|
|
31
|
+
},
|
|
32
|
+
java17: {
|
|
33
|
+
version: '17.0.0',
|
|
34
|
+
target: '17'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function ensureJava(target) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const configKey = `${target.stack}.bin`;
|
|
40
|
+
const spawnCommand = userConfig_1.default.get(configKey);
|
|
41
|
+
let usingJavaDefaultPath = false;
|
|
42
|
+
if (!spawnCommand) {
|
|
43
|
+
runtime_store_1.default.set(`context.java.isUsingJavaDefaultPath_${target.stack}`, true);
|
|
44
|
+
usingJavaDefaultPath = true;
|
|
45
|
+
}
|
|
46
|
+
let javacVersion = '';
|
|
47
|
+
const currentStackVersion = exports.stackVsVersions[target.stack].version;
|
|
48
|
+
try {
|
|
49
|
+
const javacSpawnCommand = getJavaSpawnCommand(spawnCommand, 'javac', target.stack);
|
|
50
|
+
javacVersion = yield validateJavaPath(javacSpawnCommand);
|
|
51
|
+
if (!javacVersion) {
|
|
52
|
+
if (spawnCommand) {
|
|
53
|
+
throw new error_1.default(`unable to check the javac version using the given binary path. Kindly re-check. Please provide a valid java binary path for the config key ${target.stack}.bin to serve or deploy the function[${target.name}].`, {
|
|
54
|
+
exit: 0,
|
|
55
|
+
errorId: 'JAVACONFIG-1',
|
|
56
|
+
arg: [
|
|
57
|
+
target.stack,
|
|
58
|
+
target.name,
|
|
59
|
+
`jdk-${exports.stackVsVersions[target.stack]
|
|
60
|
+
.target}`
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new error_1.default(`unable to locate the java binary path in your system. Kindly re-check. Please provide the valid java binary path for the config key ${target.stack}.bin to serve or deploy the function[${target.name}].`, {
|
|
66
|
+
exit: 0,
|
|
67
|
+
errorId: 'JAVACONFIG-2',
|
|
68
|
+
arg: [`${target.stack}.bin`, target.name]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (_a) {
|
|
74
|
+
throw new error_1.default(`error while validating java binary path. Please provide a valid java binary path for the config key ${target.stack}.bin to serve or deploy the function[${target.name}].`, {
|
|
75
|
+
exit: 0,
|
|
76
|
+
errorId: 'JAVACONFIG-4',
|
|
77
|
+
arg: [`${target.stack}.bin`, target.name]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if ((0, semver_1.satisfies)(currentStackVersion, `>${javacVersion}`)) {
|
|
81
|
+
if (usingJavaDefaultPath === false) {
|
|
82
|
+
throw new error_1.default(`provided JDK version[jdk-${javacVersion}] for the config key ${target.stack}.bin is lesser than the compatible JDK version[jdk-${exports.stackVsVersions[target.stack].target}]. Please provide a valid java binary path for the config key ${target.stack}.bin to serve or deploy the function[${target.name}].`, {
|
|
83
|
+
exit: 0,
|
|
84
|
+
skipHelp: true,
|
|
85
|
+
errorId: 'JAVACONFIG-3',
|
|
86
|
+
arg: [
|
|
87
|
+
`jdk-${javacVersion}`,
|
|
88
|
+
target.stack,
|
|
89
|
+
`jdk-${exports.stackVsVersions[target.stack].target}`,
|
|
90
|
+
target.name
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
throw new error_1.default(`provided JDK version[jdk-${javacVersion}] is lesser than the compatible JDK version[jdk-${exports.stackVsVersions[target.stack].target}]. Please provide a valid java binary path for the config key ${target.stack}.bin to serve or deploy the function[${target.name}].`, {
|
|
95
|
+
exit: 0,
|
|
96
|
+
skipHelp: true,
|
|
97
|
+
errorId: 'JAVACONFIG-3',
|
|
98
|
+
arg: [
|
|
99
|
+
`jdk-${javacVersion}`,
|
|
100
|
+
target.stack,
|
|
101
|
+
`jdk-${exports.stackVsVersions[target.stack].target}`,
|
|
102
|
+
target.name
|
|
103
|
+
]
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const majorVersion = target.stack === 'java8' ? '' : currentStackVersion.split('.')[0];
|
|
107
|
+
if (!(((0, semver_1.satisfies)(javacVersion, `>=${majorVersion}.0.0`) &&
|
|
108
|
+
(0, semver_1.satisfies)(javacVersion, `<=${majorVersion}.x.x`)) ||
|
|
109
|
+
(target.stack === 'java8' &&
|
|
110
|
+
(0, semver_1.satisfies)(javacVersion, '>=1.8.0') &&
|
|
111
|
+
(0, semver_1.satisfies)(javacVersion, '<=1.8.x')))) {
|
|
112
|
+
const warningMessage = [];
|
|
113
|
+
warningMessage.push(`Warning : Your function[${target.name}] stack is ${target.stack}. But you are using jdk ${javacVersion} to compile source files. Please use jdk ${exports.stackVsVersions[target.stack].target} for better compilation`);
|
|
114
|
+
target.compilationWarning = warningMessage;
|
|
115
|
+
}
|
|
116
|
+
if (!spawnCommand) {
|
|
117
|
+
runtime_store_1.default.set(`context.java.isUsingJavaDefaultPath_${target.stack}`, true);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
exports.ensureJava = ensureJava;
|
|
122
|
+
function validateJavaPath(spawnCommand) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const spawnOpts = ['-version'];
|
|
125
|
+
const javacVersionChild = (0, shell_1.spawn)(spawnCommand, spawnOpts, {
|
|
126
|
+
cwd: runtime_store_1.default.get('cwd'),
|
|
127
|
+
stdio: 'pipe'
|
|
128
|
+
}).RAW();
|
|
129
|
+
let javacVersionDetails = yield (0, java_1.extractAllData)(javacVersionChild, 'stdout');
|
|
130
|
+
javacVersionDetails =
|
|
131
|
+
javacVersionDetails === ''
|
|
132
|
+
? yield (0, java_1.extractAllData)(javacVersionChild, 'stderr')
|
|
133
|
+
: javacVersionDetails;
|
|
134
|
+
const javacVersion = (0, semver_1.valid)((0, semver_1.coerce)(javacVersionDetails.split(' ')[1]));
|
|
135
|
+
return javacVersion;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function getJavaSpawnCommand(spawnCommand, process, stack) {
|
|
139
|
+
const isUsingJavaDefaultPath = runtime_store_1.default.get(`context.java.isUsingJavaDefaultPath_${stack}`);
|
|
140
|
+
if (isUsingJavaDefaultPath === true) {
|
|
141
|
+
return process;
|
|
142
|
+
}
|
|
143
|
+
if (env_1.isWindows) {
|
|
144
|
+
spawnCommand = `"${spawnCommand}\\${process}"`;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
spawnCommand = `${spawnCommand}/${process}`;
|
|
148
|
+
}
|
|
149
|
+
return spawnCommand;
|
|
150
|
+
}
|
|
151
|
+
exports.getJavaSpawnCommand = getJavaSpawnCommand;
|
package/lib/fn-utils/lib/java.js
CHANGED
|
@@ -12,10 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getTemplatePath = exports.validate = exports.projectFileValidation = exports.ensureJavaInvoker = exports.compileTarget = exports.normaliseClasspath = exports.rewriteClasspath = exports.isValidClassName = exports.containsKeyWord = exports.classPathSep = void 0;
|
|
15
|
+
exports.getTargetVersion = exports.getTemplatePath = exports.validate = exports.extractAllData = exports.projectFileValidation = exports.ensureJavaInvoker = exports.compileTarget = exports.normaliseClasspath = exports.rewriteClasspath = exports.isValidClassName = exports.containsKeyWord = exports.classPathSep = exports.FN_TYPE = void 0;
|
|
16
16
|
const ansi_colors_1 = require("ansi-colors");
|
|
17
17
|
const path_1 = require("path");
|
|
18
|
-
const semver_1 = require("semver");
|
|
19
18
|
const xml2js_1 = __importDefault(require("xml2js"));
|
|
20
19
|
const error_1 = __importDefault(require("../../error"));
|
|
21
20
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
@@ -24,9 +23,13 @@ const constants_1 = require("../../util_modules/constants");
|
|
|
24
23
|
const env_1 = require("../../util_modules/env");
|
|
25
24
|
const fs_1 = require("../../util_modules/fs");
|
|
26
25
|
const js_1 = require("../../util_modules/js");
|
|
27
|
-
const logger_1 = require("../../util_modules/logger");
|
|
28
26
|
const option_1 = require("../../util_modules/option");
|
|
29
27
|
const shell_1 = require("../../util_modules/shell");
|
|
28
|
+
const userConfig_1 = __importDefault(require("../../userConfig"));
|
|
29
|
+
const logger_1 = require("../../util_modules/logger");
|
|
30
|
+
const ensure_java_userconfig_1 = require("./ensure-java-userconfig");
|
|
31
|
+
var constants_2 = require("../../util_modules/constants");
|
|
32
|
+
Object.defineProperty(exports, "FN_TYPE", { enumerable: true, get: function () { return constants_2.FN_TYPE; } });
|
|
30
33
|
const keyWords = [
|
|
31
34
|
'abstract',
|
|
32
35
|
'assert',
|
|
@@ -82,6 +85,10 @@ const keyWords = [
|
|
|
82
85
|
'volatile',
|
|
83
86
|
'while'
|
|
84
87
|
];
|
|
88
|
+
const warningMessages = [
|
|
89
|
+
'warning: [options] bootstrap class path not set in conjunction with -source 8',
|
|
90
|
+
'warning: [options] system modules path not set in conjunction with -source 11'
|
|
91
|
+
];
|
|
85
92
|
exports.classPathSep = env_1.isWindows ? ';' : ':';
|
|
86
93
|
function containsKeyWord(name) {
|
|
87
94
|
return keyWords.some((keyWord) => {
|
|
@@ -200,6 +207,9 @@ function compileTarget(target) {
|
|
|
200
207
|
const outputFolder = (0, path_1.join)(targetSource, constants_1.FOLDERNAME.output);
|
|
201
208
|
const integ = target.integ_config;
|
|
202
209
|
const entries = [(0, path_1.join)(targetSource, ((_a = target.index) === null || _a === void 0 ? void 0 : _a.replace(/\./g, path_1.sep)) + '.java')];
|
|
210
|
+
const configKey = `${target.stack}.bin`;
|
|
211
|
+
const userConfigCmd = userConfig_1.default.get(configKey);
|
|
212
|
+
const spawnCommand = (0, ensure_java_userconfig_1.getJavaSpawnCommand)(userConfigCmd, 'javac', target.stack);
|
|
203
213
|
if (integ && integ.length > 0) {
|
|
204
214
|
integ.forEach((integConf) => {
|
|
205
215
|
const handlers = integConf.handlers;
|
|
@@ -225,18 +235,20 @@ function compileTarget(target) {
|
|
|
225
235
|
return fs_1.ASYNC.copyFile(file.path, (0, path_1.join)(outputFolder, targetPth));
|
|
226
236
|
}));
|
|
227
237
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
const targetVersion = getTargetVersion(target.stack);
|
|
239
|
+
yield Promise.all(entries.map((file) => compileJavaFiles(file, spawnCommand, targetVersion, targetSource, outputFolder)
|
|
240
|
+
.then((result) => {
|
|
241
|
+
const code = result[2];
|
|
242
|
+
if (code === 1) {
|
|
243
|
+
const error = [];
|
|
244
|
+
error === null || error === void 0 ? void 0 : error.push(result[1]);
|
|
245
|
+
target.valid = false;
|
|
246
|
+
target.compilationError = error;
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
.catch((error) => {
|
|
250
|
+
target.failure_reason = error.message;
|
|
251
|
+
})));
|
|
240
252
|
const currentCommand = (0, option_1.getCurrentCommand)();
|
|
241
253
|
switch (currentCommand) {
|
|
242
254
|
case 'pull':
|
|
@@ -256,20 +268,84 @@ function compileTarget(target) {
|
|
|
256
268
|
});
|
|
257
269
|
}
|
|
258
270
|
exports.compileTarget = compileTarget;
|
|
259
|
-
function
|
|
271
|
+
function compileJavaFiles(file, spawnCommand, targetVersion, targetSource, outputFolder) {
|
|
272
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
(0, logger_1.info)('Compiling ' + file);
|
|
274
|
+
return new Promise((resolve, reject) => {
|
|
275
|
+
var _a, _b;
|
|
276
|
+
const child = (0, shell_1.spawn)(spawnCommand, [
|
|
277
|
+
'-target',
|
|
278
|
+
targetVersion,
|
|
279
|
+
'-source',
|
|
280
|
+
targetVersion,
|
|
281
|
+
'-cp',
|
|
282
|
+
'*' + module.exports.classPathSep + '.',
|
|
283
|
+
'-g',
|
|
284
|
+
'-Xprefer:source',
|
|
285
|
+
file.replace(targetSource, outputFolder)
|
|
286
|
+
], {
|
|
287
|
+
cwd: outputFolder,
|
|
288
|
+
stdio: 'pipe'
|
|
289
|
+
}).RAW();
|
|
290
|
+
let stdout = '';
|
|
291
|
+
let stderr = '';
|
|
292
|
+
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
293
|
+
stdout += data.toString();
|
|
294
|
+
});
|
|
295
|
+
(_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
296
|
+
const err = data.toString();
|
|
297
|
+
let newErr = '';
|
|
298
|
+
warningMessages.forEach((element) => {
|
|
299
|
+
if (err.includes(element)) {
|
|
300
|
+
newErr += err.replace(element, '');
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
if (!newErr) {
|
|
304
|
+
newErr += err;
|
|
305
|
+
}
|
|
306
|
+
stderr += newErr;
|
|
307
|
+
});
|
|
308
|
+
child.on('error', (error) => {
|
|
309
|
+
reject(error);
|
|
310
|
+
});
|
|
311
|
+
child.on('close', (code) => {
|
|
312
|
+
resolve([stdout, stderr, code]);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function ensureJavaInvoker(pth, invoker, target) {
|
|
318
|
+
const configKey = `${target.stack}.bin`;
|
|
319
|
+
const userConfigCmd = userConfig_1.default.get(configKey);
|
|
320
|
+
const spawnCommand = (0, ensure_java_userconfig_1.getJavaSpawnCommand)(userConfigCmd, 'javac', target.stack);
|
|
260
321
|
const classPth = pth + '.class';
|
|
322
|
+
const targetVersion = getTargetVersion(target.stack);
|
|
261
323
|
if (fs_1.SYNC.fileExists(classPth)) {
|
|
262
324
|
return true;
|
|
263
325
|
}
|
|
264
326
|
fs_1.SYNC.ensureDir((0, path_1.dirname)(classPth));
|
|
265
|
-
(0, shell_1.spawn)(
|
|
327
|
+
const child = (0, shell_1.spawn)(spawnCommand, [
|
|
328
|
+
'-target',
|
|
329
|
+
targetVersion,
|
|
330
|
+
'-source',
|
|
331
|
+
targetVersion,
|
|
266
332
|
'-cp',
|
|
267
333
|
(0, path_1.join)('lib', '*') + module.exports.classPathSep + '.',
|
|
268
334
|
'-g',
|
|
269
335
|
'-d',
|
|
270
336
|
(0, path_1.dirname)(classPth),
|
|
271
337
|
(0, path_1.basename)(invoker)
|
|
272
|
-
], { cwd: (0, path_1.dirname)(invoker) }).SYNC();
|
|
338
|
+
], { cwd: (0, path_1.dirname)(invoker), stdio: 'pipe' }).SYNC();
|
|
339
|
+
if (child.status === 1) {
|
|
340
|
+
const errorResponse = [];
|
|
341
|
+
const err = child.stderr.toString();
|
|
342
|
+
warningMessages.forEach((element) => {
|
|
343
|
+
if (err.includes(element)) {
|
|
344
|
+
errorResponse.push(err.replace(element, ''));
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
target.compilationError = errorResponse;
|
|
348
|
+
}
|
|
273
349
|
fs_1.SYNC.copyDir((0, path_1.join)((0, path_1.dirname)(invoker), 'lib'), (0, path_1.join)((0, path_1.dirname)(classPth), 'lib'));
|
|
274
350
|
return true;
|
|
275
351
|
}
|
|
@@ -316,34 +392,7 @@ function extractAllData(child, name) {
|
|
|
316
392
|
});
|
|
317
393
|
});
|
|
318
394
|
}
|
|
319
|
-
|
|
320
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
-
const javacVersionChild = (0, shell_1.spawn)('javac', ['-version'], {
|
|
322
|
-
cwd: runtime_store_1.default.get('cwd'),
|
|
323
|
-
stdio: 'pipe'
|
|
324
|
-
}).RAW();
|
|
325
|
-
let javacVersionDetails = yield extractAllData(javacVersionChild, 'stdout');
|
|
326
|
-
javacVersionDetails =
|
|
327
|
-
javacVersionDetails === ''
|
|
328
|
-
? yield extractAllData(javacVersionChild, 'stderr')
|
|
329
|
-
: javacVersionDetails;
|
|
330
|
-
const javacVersion = (0, semver_1.valid)((0, semver_1.coerce)(javacVersionDetails.split(' ')[1]));
|
|
331
|
-
if (javacVersion === '' || javacVersion === null) {
|
|
332
|
-
throw new error_1.default('Unable to check the javac version', {
|
|
333
|
-
exit: 0,
|
|
334
|
-
errorId: 'JAVA-4',
|
|
335
|
-
arg: [(0, ansi_colors_1.bold)('javac')]
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
if ((0, semver_1.gtr)(javacVersion, new semver_1.Range('<1.9', { includePrerelease: true }))) {
|
|
339
|
-
throw new error_1.default('javac version is above the compatible version', {
|
|
340
|
-
exit: 0,
|
|
341
|
-
errorId: 'JAVA-5',
|
|
342
|
-
arg: [(0, ansi_colors_1.bold)('javac'), (0, ansi_colors_1.bold)('1.8.x'), (0, ansi_colors_1.bold)('1.8')]
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
}
|
|
395
|
+
exports.extractAllData = extractAllData;
|
|
347
396
|
function validate(targets, idx) {
|
|
348
397
|
var _a;
|
|
349
398
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -377,7 +426,7 @@ function validate(targets, idx) {
|
|
|
377
426
|
}
|
|
378
427
|
yield normaliseClasspath(classpath, libFolder);
|
|
379
428
|
yield projectFileValidation(projectPath, currentTarget);
|
|
380
|
-
yield
|
|
429
|
+
yield (0, ensure_java_userconfig_1.ensureJava)(currentTarget);
|
|
381
430
|
yield compileTarget(currentTarget).catch((err) => {
|
|
382
431
|
throw new error_1.default('there was a compilation error!', {
|
|
383
432
|
exit: 1,
|
|
@@ -386,8 +435,15 @@ function validate(targets, idx) {
|
|
|
386
435
|
skipHelp: !!(0, option_1.getOptionValue)('watch', false)
|
|
387
436
|
});
|
|
388
437
|
});
|
|
389
|
-
currentTarget.valid
|
|
390
|
-
|
|
438
|
+
if (currentTarget.valid === true && !currentTarget.failure_reason) {
|
|
439
|
+
currentTarget.valid = true;
|
|
440
|
+
return validate(targets, ++idx);
|
|
441
|
+
}
|
|
442
|
+
throw new error_1.default('there was a compilation error!', {
|
|
443
|
+
exit: 1,
|
|
444
|
+
errorId: 'JAVA-7',
|
|
445
|
+
skipHelp: !!(0, option_1.getOptionValue)('watch', false)
|
|
446
|
+
});
|
|
391
447
|
}
|
|
392
448
|
catch (err) {
|
|
393
449
|
currentTarget.valid = false;
|
|
@@ -452,3 +508,7 @@ function getTemplatePath(fnType, add) {
|
|
|
452
508
|
}
|
|
453
509
|
}
|
|
454
510
|
exports.getTemplatePath = getTemplatePath;
|
|
511
|
+
function getTargetVersion(stack) {
|
|
512
|
+
return ensure_java_userconfig_1.stackVsVersions[stack].target;
|
|
513
|
+
}
|
|
514
|
+
exports.getTargetVersion = getTargetVersion;
|
|
@@ -182,6 +182,13 @@ class Credential {
|
|
|
182
182
|
get createdTime() {
|
|
183
183
|
return this.cTime;
|
|
184
184
|
}
|
|
185
|
+
static initToken(token, temp = false) {
|
|
186
|
+
if (token.slice(1, 2) !== '_' && !Credential.crypt.isEncrypted(token)) {
|
|
187
|
+
Credential.oneTimeToken = token;
|
|
188
|
+
return Credential.oneTimeToken;
|
|
189
|
+
}
|
|
190
|
+
return this.init(token, temp);
|
|
191
|
+
}
|
|
185
192
|
static init(token, temp = false) {
|
|
186
193
|
let tokenObj;
|
|
187
194
|
if (typeof token === 'string') {
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const ansi_colors_1 = require("ansi-colors");
|
|
16
16
|
const apig_utils_1 = require("../../apig-utils");
|
|
17
17
|
const endpoints_1 = require("../../endpoints");
|
|
18
|
+
const error_1 = __importDefault(require("../../error"));
|
|
18
19
|
const prompt_1 = __importDefault(require("../../prompt"));
|
|
19
20
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
20
21
|
const config_1 = require("../../util_modules/config");
|
|
@@ -61,8 +62,20 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
61
62
|
(0, logger_1.info)('No rules found in remote console');
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
try {
|
|
66
|
+
const fileContent = JSON.stringify(rulesArr, null, 2) + '\n';
|
|
67
|
+
yield fs_1.ASYNC.writeFile(apigDirPath, fileContent);
|
|
68
|
+
yield apig_utils_1.apigUtils.validate();
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
runtime_store_1.default.set('payload.apig.status', 1);
|
|
72
|
+
if (err instanceof error_1.default) {
|
|
73
|
+
throw new error_1.default(err.message, {
|
|
74
|
+
exit: err.exit,
|
|
75
|
+
errorId: err.errorId
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
67
80
|
runtime_store_1.default.set('payload.apig.source', apigDirPath);
|
|
68
81
|
});
|
|
@@ -16,6 +16,7 @@ const ansi_colors_1 = require("ansi-colors");
|
|
|
16
16
|
const archiver_1 = __importDefault(require("../../archiver"));
|
|
17
17
|
const client_utils_1 = require("../../client-utils");
|
|
18
18
|
const endpoints_1 = require("../../endpoints");
|
|
19
|
+
const error_1 = __importDefault(require("../../error"));
|
|
19
20
|
const prompt_1 = __importDefault(require("../../prompt"));
|
|
20
21
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
21
22
|
const config_1 = require("../../util_modules/config");
|
|
@@ -58,9 +59,21 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
58
59
|
type: 'list',
|
|
59
60
|
choices
|
|
60
61
|
}));
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
try {
|
|
63
|
+
const clientZip = (yield webappAPI.download(historyAns.history));
|
|
64
|
+
yield new archiver_1.default().load(clientZip).extract(clientDirPath).finalize();
|
|
65
|
+
yield client_utils_1.clientUtils.validate();
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
runtime_store_1.default.set('payload.client.status', 1);
|
|
69
|
+
if (err instanceof error_1.default) {
|
|
70
|
+
throw new error_1.default(err.message, {
|
|
71
|
+
exit: err.exit,
|
|
72
|
+
errorId: err.errorId
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
64
77
|
runtime_store_1.default.set('payload.client', runtime_store_1.default.get('context.client'));
|
|
65
78
|
runtime_store_1.default.set('payload.client.source', (0, project_1.resolveProjectPath)(clientDirName));
|
|
66
79
|
});
|