@extrahorizon/exh-cli 1.5.0 → 1.5.1-dev-31-9c0409d
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/CHANGELOG.md +56 -53
- package/README.md +0 -12
- package/build/commands/completion.d.ts +5 -5
- package/build/commands/completion.js +38 -38
- package/build/commands/data/schemas/delete.d.ts +10 -10
- package/build/commands/data/schemas/delete.js +29 -29
- package/build/commands/data/schemas/list.d.ts +8 -8
- package/build/commands/data/schemas/list.js +20 -20
- package/build/commands/data/schemas/sync/statusHelpers.d.ts +3 -3
- package/build/commands/data/schemas/sync/statusHelpers.js +49 -49
- package/build/commands/data/schemas/sync.d.ts +35 -35
- package/build/commands/data/schemas/sync.js +72 -72
- package/build/commands/data/schemas/util/listFilesInDir.d.ts +1 -1
- package/build/commands/data/schemas/util/listFilesInDir.js +25 -25
- package/build/commands/data/schemas/util/metaschema.json +455 -455
- package/build/commands/data/schemas/util/readJson.d.ts +1 -1
- package/build/commands/data/schemas/util/readJson.js +11 -11
- package/build/commands/data/schemas/util/schemaverify.d.ts +28 -28
- package/build/commands/data/schemas/util/schemaverify.js +202 -202
- package/build/commands/data/schemas/util/syncSchema.d.ts +20 -20
- package/build/commands/data/schemas/util/syncSchema.js +276 -276
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.d.ts +1 -1
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.js +40 -40
- package/build/commands/data/schemas/verify.d.ts +18 -18
- package/build/commands/data/schemas/verify.js +82 -82
- package/build/commands/data/schemas.d.ts +5 -5
- package/build/commands/data/schemas.js +10 -10
- package/build/commands/data.d.ts +5 -5
- package/build/commands/data.js +10 -10
- package/build/commands/dispatchers/sync.d.ts +21 -21
- package/build/commands/dispatchers/sync.js +24 -24
- package/build/commands/dispatchers.d.ts +5 -5
- package/build/commands/dispatchers.js +10 -10
- package/build/commands/localizations/sync.d.ts +29 -0
- package/build/commands/localizations/sync.js +59 -0
- package/build/commands/localizations/utils/assertValidKey.d.ts +1 -0
- package/build/commands/localizations/utils/assertValidKey.js +10 -0
- package/build/commands/localizations/utils/assertValidLanguageCode.d.ts +2 -0
- package/build/commands/localizations/utils/assertValidLanguageCode.js +21 -0
- package/build/commands/localizations/utils/fetchLocalizations.d.ts +2 -0
- package/build/commands/localizations/utils/fetchLocalizations.js +20 -0
- package/build/commands/localizations/utils/readLocalizationFiles.d.ts +6 -0
- package/build/commands/localizations/utils/readLocalizationFiles.js +39 -0
- package/build/commands/localizations/utils/syncLocalizations.d.ts +2 -0
- package/build/commands/localizations/utils/syncLocalizations.js +46 -0
- package/build/commands/login.d.ts +37 -37
- package/build/commands/login.js +59 -59
- package/build/commands/sync.d.ts +55 -55
- package/build/commands/sync.js +107 -107
- package/build/commands/tasks/createrepo.d.ts +22 -22
- package/build/commands/tasks/createrepo.js +70 -70
- package/build/commands/tasks/delete.d.ts +10 -10
- package/build/commands/tasks/delete.js +29 -29
- package/build/commands/tasks/list.d.ts +8 -8
- package/build/commands/tasks/list.js +27 -27
- package/build/commands/tasks/sync.d.ts +56 -56
- package/build/commands/tasks/sync.js +122 -122
- package/build/commands/tasks/taskConfig.d.ts +24 -24
- package/build/commands/tasks/taskConfig.js +169 -169
- package/build/commands/tasks/util.d.ts +1 -1
- package/build/commands/tasks/util.js +27 -27
- package/build/commands/tasks.d.ts +5 -5
- package/build/commands/tasks.js +10 -10
- package/build/commands/templates/delete.d.ts +19 -19
- package/build/commands/templates/delete.js +48 -48
- package/build/commands/templates/get.d.ts +19 -19
- package/build/commands/templates/get.js +37 -37
- package/build/commands/templates/list.d.ts +9 -9
- package/build/commands/templates/list.js +25 -25
- package/build/commands/templates/sync.d.ts +22 -22
- package/build/commands/templates/sync.js +65 -65
- package/build/commands/templates/util/buildTemplates.d.ts +2 -2
- package/build/commands/templates/util/buildTemplates.js +50 -50
- package/build/commands/templates/util/readTemplateFiles.d.ts +3 -3
- package/build/commands/templates/util/readTemplateFiles.js +52 -52
- package/build/commands/templates/util/templateService.d.ts +8 -8
- package/build/commands/templates/util/templateService.js +18 -18
- package/build/commands/templates/util/uploadTemplate.d.ts +2 -2
- package/build/commands/templates/util/uploadTemplate.js +20 -20
- package/build/commands/templates/util/utils.d.ts +4 -4
- package/build/commands/templates/util/utils.js +22 -22
- package/build/commands/templates.d.ts +5 -5
- package/build/commands/templates.js +10 -10
- package/build/constants.d.ts +13 -13
- package/build/constants.js +37 -37
- package/build/exh.d.ts +3 -3
- package/build/exh.js +65 -65
- package/build/helpers/error.d.ts +2 -2
- package/build/helpers/error.js +6 -6
- package/build/helpers/repoConfig.d.ts +2 -2
- package/build/helpers/repoConfig.js +60 -60
- package/build/helpers/util.d.ts +4 -3
- package/build/helpers/util.js +42 -36
- package/build/index.d.ts +2 -2
- package/build/index.js +33 -33
- package/build/repositories/dispatchers.d.ts +8 -8
- package/build/repositories/dispatchers.js +31 -31
- package/build/repositories/functions.d.ts +24 -24
- package/build/repositories/functions.js +28 -28
- package/build/repositories/schemas.d.ts +44 -44
- package/build/repositories/schemas.js +86 -86
- package/build/services/dispatchers.d.ts +3 -3
- package/build/services/dispatchers.js +132 -132
- package/package.json +53 -53
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const promises_1 = require("fs/promises");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
const util_1 = require("../../helpers/util");
|
|
7
|
-
exports.command = 'create-repo <name>';
|
|
8
|
-
exports.desc = 'Create a new task repository';
|
|
9
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs).positional('name', {
|
|
10
|
-
demandOption: true,
|
|
11
|
-
description: 'The name of the new repo/task',
|
|
12
|
-
type: 'string',
|
|
13
|
-
}).options({
|
|
14
|
-
repo: {
|
|
15
|
-
description: 'repository template to clone',
|
|
16
|
-
type: 'string',
|
|
17
|
-
default: 'https://github.com/ExtraHorizon/template-task',
|
|
18
|
-
},
|
|
19
|
-
git: {
|
|
20
|
-
description: 'also initializes the cloned repository as a fresh git repository',
|
|
21
|
-
type: 'boolean',
|
|
22
|
-
default: false,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
exports.builder = builder;
|
|
26
|
-
async function changePackageFile(name) {
|
|
27
|
-
try {
|
|
28
|
-
const pkg = JSON.parse((await (0, promises_1.readFile)(`${name}/package.json`)).toString());
|
|
29
|
-
pkg.name = name;
|
|
30
|
-
await (0, promises_1.writeFile)(`${name}/package.json`, JSON.stringify(pkg, null, 4));
|
|
31
|
-
}
|
|
32
|
-
catch (err) {
|
|
33
|
-
console.log('WARN: package.json not found. (possibly not a javascript repository');
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
const taskConfig = JSON.parse((await (0, promises_1.readFile)(`${name}/task-config.json`)).toString());
|
|
37
|
-
taskConfig.name = name;
|
|
38
|
-
taskConfig.description = `${name} task`;
|
|
39
|
-
await (0, promises_1.writeFile)(`${name}/task-config.json`, JSON.stringify(taskConfig, null, 4));
|
|
40
|
-
}
|
|
41
|
-
catch (err) { }
|
|
42
|
-
}
|
|
43
|
-
const handler = async ({ name, repo, git }) => {
|
|
44
|
-
try {
|
|
45
|
-
await (0, util_1.asyncExec)('git --version');
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
console.log(chalk.red('Git is not installed. Please install git first.'));
|
|
49
|
-
}
|
|
50
|
-
console.log(`Creating new repo ${chalk.green(name)}...`);
|
|
51
|
-
try {
|
|
52
|
-
await (0, util_1.asyncExec)(`git clone ${repo} ${name}`);
|
|
53
|
-
try {
|
|
54
|
-
await changePackageFile(name);
|
|
55
|
-
}
|
|
56
|
-
catch (err) { }
|
|
57
|
-
await (0, util_1.asyncExec)(`cd ${name} && rm -rf .git`);
|
|
58
|
-
if (git) {
|
|
59
|
-
console.log('Initializing git');
|
|
60
|
-
await (0, util_1.asyncExec)(`cd ${name} && git init . && git add . && git commit -m "First commit"`);
|
|
61
|
-
}
|
|
62
|
-
console.log('Done! 🎉');
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
await (0, util_1.asyncExec)(`rm -rf ${name}`);
|
|
66
|
-
console.log(chalk.red('Failed to create repo'));
|
|
67
|
-
console.log(err);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
exports.handler = handler;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const util_1 = require("../../helpers/util");
|
|
7
|
+
exports.command = 'create-repo <name>';
|
|
8
|
+
exports.desc = 'Create a new task repository';
|
|
9
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).positional('name', {
|
|
10
|
+
demandOption: true,
|
|
11
|
+
description: 'The name of the new repo/task',
|
|
12
|
+
type: 'string',
|
|
13
|
+
}).options({
|
|
14
|
+
repo: {
|
|
15
|
+
description: 'repository template to clone',
|
|
16
|
+
type: 'string',
|
|
17
|
+
default: 'https://github.com/ExtraHorizon/template-task',
|
|
18
|
+
},
|
|
19
|
+
git: {
|
|
20
|
+
description: 'also initializes the cloned repository as a fresh git repository',
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
default: false,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
exports.builder = builder;
|
|
26
|
+
async function changePackageFile(name) {
|
|
27
|
+
try {
|
|
28
|
+
const pkg = JSON.parse((await (0, promises_1.readFile)(`${name}/package.json`)).toString());
|
|
29
|
+
pkg.name = name;
|
|
30
|
+
await (0, promises_1.writeFile)(`${name}/package.json`, JSON.stringify(pkg, null, 4));
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
console.log('WARN: package.json not found. (possibly not a javascript repository');
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const taskConfig = JSON.parse((await (0, promises_1.readFile)(`${name}/task-config.json`)).toString());
|
|
37
|
+
taskConfig.name = name;
|
|
38
|
+
taskConfig.description = `${name} task`;
|
|
39
|
+
await (0, promises_1.writeFile)(`${name}/task-config.json`, JSON.stringify(taskConfig, null, 4));
|
|
40
|
+
}
|
|
41
|
+
catch (err) { }
|
|
42
|
+
}
|
|
43
|
+
const handler = async ({ name, repo, git }) => {
|
|
44
|
+
try {
|
|
45
|
+
await (0, util_1.asyncExec)('git --version');
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
console.log(chalk.red('Git is not installed. Please install git first.'));
|
|
49
|
+
}
|
|
50
|
+
console.log(`Creating new repo ${chalk.green(name)}...`);
|
|
51
|
+
try {
|
|
52
|
+
await (0, util_1.asyncExec)(`git clone ${repo} ${name}`);
|
|
53
|
+
try {
|
|
54
|
+
await changePackageFile(name);
|
|
55
|
+
}
|
|
56
|
+
catch (err) { }
|
|
57
|
+
await (0, util_1.asyncExec)(`cd ${name} && rm -rf .git`);
|
|
58
|
+
if (git) {
|
|
59
|
+
console.log('Initializing git');
|
|
60
|
+
await (0, util_1.asyncExec)(`cd ${name} && git init . && git add . && git commit -m "First commit"`);
|
|
61
|
+
}
|
|
62
|
+
console.log('Done! 🎉');
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
await (0, util_1.asyncExec)(`rm -rf ${name}`);
|
|
66
|
+
console.log(chalk.red('Failed to create repo'));
|
|
67
|
+
console.log(err);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.handler = handler;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/// <reference types="yargs" />
|
|
2
|
-
export declare const command = "delete";
|
|
3
|
-
export declare const desc = "Delete a task";
|
|
4
|
-
export declare const builder: (yargs: any) => import("yargs").Argv<{
|
|
5
|
-
name: string;
|
|
6
|
-
}>;
|
|
7
|
-
export declare const handler: ({ sdk, name }: {
|
|
8
|
-
sdk: any;
|
|
9
|
-
name: any;
|
|
10
|
-
}) => Promise<void>;
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
export declare const command = "delete";
|
|
3
|
+
export declare const desc = "Delete a task";
|
|
4
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<{
|
|
5
|
+
name: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const handler: ({ sdk, name }: {
|
|
8
|
+
sdk: any;
|
|
9
|
+
name: any;
|
|
10
|
+
}) => Promise<void>;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const chalk = require("chalk");
|
|
5
|
-
const util_1 = require("../../helpers/util");
|
|
6
|
-
const functionRepository = require("../../repositories/functions");
|
|
7
|
-
exports.command = 'delete';
|
|
8
|
-
exports.desc = 'Delete a task';
|
|
9
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs).option('name', {
|
|
10
|
-
demandOption: true,
|
|
11
|
-
description: 'The name of the task',
|
|
12
|
-
type: 'string',
|
|
13
|
-
});
|
|
14
|
-
exports.builder = builder;
|
|
15
|
-
const handler = async ({ sdk, name }) => {
|
|
16
|
-
try {
|
|
17
|
-
const response = await functionRepository.remove(sdk, name);
|
|
18
|
-
if (response?.affectedRecords) {
|
|
19
|
-
console.log(chalk.green('Successfully deleted task', name));
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
console.log(chalk.red('Failed to delete task', name));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
catch (err) {
|
|
26
|
-
console.log(chalk.red('Failed to delete task:', err.message));
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
exports.handler = handler;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const util_1 = require("../../helpers/util");
|
|
6
|
+
const functionRepository = require("../../repositories/functions");
|
|
7
|
+
exports.command = 'delete';
|
|
8
|
+
exports.desc = 'Delete a task';
|
|
9
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).option('name', {
|
|
10
|
+
demandOption: true,
|
|
11
|
+
description: 'The name of the task',
|
|
12
|
+
type: 'string',
|
|
13
|
+
});
|
|
14
|
+
exports.builder = builder;
|
|
15
|
+
const handler = async ({ sdk, name }) => {
|
|
16
|
+
try {
|
|
17
|
+
const response = await functionRepository.remove(sdk, name);
|
|
18
|
+
if (response?.affectedRecords) {
|
|
19
|
+
console.log(chalk.green('Successfully deleted task', name));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.log(chalk.red('Failed to delete task', name));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.log(chalk.red('Failed to delete task:', err.message));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.handler = handler;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/// <reference types="yargs" />
|
|
2
|
-
export declare const command = "list";
|
|
3
|
-
export declare const desc = "List all tasks";
|
|
4
|
-
export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
|
|
5
|
-
export declare const handler: ({ sdk, isTTY }: {
|
|
6
|
-
sdk: any;
|
|
7
|
-
isTTY: any;
|
|
8
|
-
}) => Promise<void>;
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
export declare const command = "list";
|
|
3
|
+
export declare const desc = "List all tasks";
|
|
4
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
|
|
5
|
+
export declare const handler: ({ sdk, isTTY }: {
|
|
6
|
+
sdk: any;
|
|
7
|
+
isTTY: any;
|
|
8
|
+
}) => Promise<void>;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const util_1 = require("../../helpers/util");
|
|
5
|
-
exports.command = 'list';
|
|
6
|
-
exports.desc = 'List all tasks';
|
|
7
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
8
|
-
exports.builder = builder;
|
|
9
|
-
const handler = async function list({ sdk, isTTY }) {
|
|
10
|
-
let functionResponse;
|
|
11
|
-
try {
|
|
12
|
-
functionResponse = await sdk.raw.get('/tasks/v1/functions');
|
|
13
|
-
}
|
|
14
|
-
catch (err) {
|
|
15
|
-
console.log(err);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (functionResponse.data.data.length !== 0) {
|
|
19
|
-
if (isTTY) {
|
|
20
|
-
console.table(functionResponse.data.data.map((c) => ({ Name: c.name, Description: c.Description || '<none>', 'Last updated': c.updateTimestamp.toISOString() })));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
functionResponse.data.data.forEach((f) => (console.log(f.name)));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
exports.handler = handler;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const util_1 = require("../../helpers/util");
|
|
5
|
+
exports.command = 'list';
|
|
6
|
+
exports.desc = 'List all tasks';
|
|
7
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
8
|
+
exports.builder = builder;
|
|
9
|
+
const handler = async function list({ sdk, isTTY }) {
|
|
10
|
+
let functionResponse;
|
|
11
|
+
try {
|
|
12
|
+
functionResponse = await sdk.raw.get('/tasks/v1/functions');
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
console.log(err);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (functionResponse.data.data.length !== 0) {
|
|
19
|
+
if (isTTY) {
|
|
20
|
+
console.table(functionResponse.data.data.map((c) => ({ Name: c.name, Description: c.Description || '<none>', 'Last updated': c.updateTimestamp.toISOString() })));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
functionResponse.data.data.forEach((f) => (console.log(f.name)));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.handler = handler;
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
/// <reference types="yargs" />
|
|
2
|
-
export declare const command = "sync";
|
|
3
|
-
export declare const desc = "Sync a task. Will create the task first if it doesn't exist yet";
|
|
4
|
-
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "description" | "code" | "name" | "path" | "env" | "entryPoint" | "runtime" | "timeLimit" | "memoryLimit" | "executionPermission"> & import("yargs").InferredOptionTypes<{
|
|
5
|
-
path: {
|
|
6
|
-
demandOption: false;
|
|
7
|
-
describe: string;
|
|
8
|
-
type: "string";
|
|
9
|
-
};
|
|
10
|
-
name: {
|
|
11
|
-
demandOption: false;
|
|
12
|
-
describe: string;
|
|
13
|
-
type: "string";
|
|
14
|
-
};
|
|
15
|
-
code: {
|
|
16
|
-
demandOption: false;
|
|
17
|
-
describe: string;
|
|
18
|
-
type: "string";
|
|
19
|
-
};
|
|
20
|
-
entryPoint: {
|
|
21
|
-
demandOption: false;
|
|
22
|
-
describe: string;
|
|
23
|
-
type: "string";
|
|
24
|
-
};
|
|
25
|
-
runtime: {
|
|
26
|
-
demandOption: false;
|
|
27
|
-
describe: string;
|
|
28
|
-
choices: string[];
|
|
29
|
-
type: "string";
|
|
30
|
-
};
|
|
31
|
-
description: {
|
|
32
|
-
describe: string;
|
|
33
|
-
type: "string";
|
|
34
|
-
default: string;
|
|
35
|
-
};
|
|
36
|
-
timeLimit: {
|
|
37
|
-
describe: string;
|
|
38
|
-
type: "number";
|
|
39
|
-
};
|
|
40
|
-
memoryLimit: {
|
|
41
|
-
describe: string;
|
|
42
|
-
type: "number";
|
|
43
|
-
};
|
|
44
|
-
env: {
|
|
45
|
-
describe: string;
|
|
46
|
-
type: "string";
|
|
47
|
-
default: any[];
|
|
48
|
-
};
|
|
49
|
-
executionPermission: {
|
|
50
|
-
type: "string";
|
|
51
|
-
};
|
|
52
|
-
}>>;
|
|
53
|
-
export declare const handler: ({ sdk, ...cmdLineParams }: {
|
|
54
|
-
[x: string]: any;
|
|
55
|
-
sdk: any;
|
|
56
|
-
}) => Promise<void>;
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
export declare const command = "sync";
|
|
3
|
+
export declare const desc = "Sync a task. Will create the task first if it doesn't exist yet";
|
|
4
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "description" | "code" | "name" | "path" | "env" | "entryPoint" | "runtime" | "timeLimit" | "memoryLimit" | "executionPermission"> & import("yargs").InferredOptionTypes<{
|
|
5
|
+
path: {
|
|
6
|
+
demandOption: false;
|
|
7
|
+
describe: string;
|
|
8
|
+
type: "string";
|
|
9
|
+
};
|
|
10
|
+
name: {
|
|
11
|
+
demandOption: false;
|
|
12
|
+
describe: string;
|
|
13
|
+
type: "string";
|
|
14
|
+
};
|
|
15
|
+
code: {
|
|
16
|
+
demandOption: false;
|
|
17
|
+
describe: string;
|
|
18
|
+
type: "string";
|
|
19
|
+
};
|
|
20
|
+
entryPoint: {
|
|
21
|
+
demandOption: false;
|
|
22
|
+
describe: string;
|
|
23
|
+
type: "string";
|
|
24
|
+
};
|
|
25
|
+
runtime: {
|
|
26
|
+
demandOption: false;
|
|
27
|
+
describe: string;
|
|
28
|
+
choices: string[];
|
|
29
|
+
type: "string";
|
|
30
|
+
};
|
|
31
|
+
description: {
|
|
32
|
+
describe: string;
|
|
33
|
+
type: "string";
|
|
34
|
+
default: string;
|
|
35
|
+
};
|
|
36
|
+
timeLimit: {
|
|
37
|
+
describe: string;
|
|
38
|
+
type: "number";
|
|
39
|
+
};
|
|
40
|
+
memoryLimit: {
|
|
41
|
+
describe: string;
|
|
42
|
+
type: "number";
|
|
43
|
+
};
|
|
44
|
+
env: {
|
|
45
|
+
describe: string;
|
|
46
|
+
type: "string";
|
|
47
|
+
default: any[];
|
|
48
|
+
};
|
|
49
|
+
executionPermission: {
|
|
50
|
+
type: "string";
|
|
51
|
+
};
|
|
52
|
+
}>>;
|
|
53
|
+
export declare const handler: ({ sdk, ...cmdLineParams }: {
|
|
54
|
+
[x: string]: any;
|
|
55
|
+
sdk: any;
|
|
56
|
+
}) => Promise<void>;
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const fs = require("fs/promises");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
const constants_1 = require("../../constants");
|
|
7
|
-
const util_1 = require("../../helpers/util");
|
|
8
|
-
const functionRepository = require("../../repositories/functions");
|
|
9
|
-
const taskConfig_1 = require("./taskConfig");
|
|
10
|
-
const util_2 = require("./util");
|
|
11
|
-
exports.command = 'sync';
|
|
12
|
-
exports.desc = 'Sync a task. Will create the task first if it doesn\'t exist yet';
|
|
13
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
14
|
-
path: {
|
|
15
|
-
demandOption: false,
|
|
16
|
-
describe: `Path of the configuration json file containing task parameters. If a directory is given instead, all sub-directories will be searched for a task-config.json file & synced.
|
|
17
|
-
If this option is not used, each parameter (name, code, entryPoint, runtime, ...) will need to be supplied separately`,
|
|
18
|
-
type: 'string',
|
|
19
|
-
},
|
|
20
|
-
name: {
|
|
21
|
-
demandOption: false,
|
|
22
|
-
describe: 'Name of the task',
|
|
23
|
-
type: 'string',
|
|
24
|
-
},
|
|
25
|
-
code: {
|
|
26
|
-
demandOption: false,
|
|
27
|
-
describe: 'The path to a directory containing the built task. exh-cli will compress the directory and upload it',
|
|
28
|
-
type: 'string',
|
|
29
|
-
},
|
|
30
|
-
entryPoint: {
|
|
31
|
-
demandOption: false,
|
|
32
|
-
describe: "The code function that should be invoked. For example 'index.handler' for Nodejs",
|
|
33
|
-
type: 'string',
|
|
34
|
-
},
|
|
35
|
-
runtime: {
|
|
36
|
-
demandOption: false,
|
|
37
|
-
describe: 'Runtime to use for the task',
|
|
38
|
-
choices: constants_1.runtimeChoices,
|
|
39
|
-
type: 'string',
|
|
40
|
-
},
|
|
41
|
-
description: {
|
|
42
|
-
describe: 'A description for this task',
|
|
43
|
-
type: 'string',
|
|
44
|
-
default: '',
|
|
45
|
-
},
|
|
46
|
-
timeLimit: {
|
|
47
|
-
describe: 'The execution time limit for this task (in seconds). Min: 3 max: 900',
|
|
48
|
-
type: 'number',
|
|
49
|
-
},
|
|
50
|
-
memoryLimit: {
|
|
51
|
-
describe: 'The allocated memory for this task (in MB). Min: 128 max: 10240',
|
|
52
|
-
type: 'number',
|
|
53
|
-
},
|
|
54
|
-
env: {
|
|
55
|
-
describe: 'Environment Variables set for this task. This option can be used multiple times.',
|
|
56
|
-
type: 'string',
|
|
57
|
-
default: [],
|
|
58
|
-
},
|
|
59
|
-
executionPermission: {
|
|
60
|
-
type: 'string',
|
|
61
|
-
},
|
|
62
|
-
})
|
|
63
|
-
.check(async ({ path, entryPoint, runtime, name, code, executionPermission }) => {
|
|
64
|
-
if (!path && (!name || !code || !runtime || !entryPoint)) {
|
|
65
|
-
throw new Error('Need to specify either a task config file or all parameters separately');
|
|
66
|
-
}
|
|
67
|
-
(0, taskConfig_1.assertExecutionPermission)(executionPermission);
|
|
68
|
-
return true;
|
|
69
|
-
});
|
|
70
|
-
exports.builder = builder;
|
|
71
|
-
const handler = async ({ sdk, ...cmdLineParams }) => {
|
|
72
|
-
for await (const config of (0, taskConfig_1.getValidatedConfigIterator)(cmdLineParams)) {
|
|
73
|
-
console.log('Syncing task', config.name, '...');
|
|
74
|
-
await syncSingleTask(sdk, config);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
exports.handler = handler;
|
|
78
|
-
async function syncSingleTask(sdk, config) {
|
|
79
|
-
const uploadFilePath = await (0, util_2.zipFileFromDirectory)(config.path);
|
|
80
|
-
const file = await fs.readFile(uploadFilePath);
|
|
81
|
-
const allFunctions = await functionRepository.find(sdk);
|
|
82
|
-
const myFunction = allFunctions.find((f) => f.name === config.name);
|
|
83
|
-
const request = {
|
|
84
|
-
name: config.name,
|
|
85
|
-
description: config.description || 'none',
|
|
86
|
-
entryPoint: config.entryPoint,
|
|
87
|
-
code: file.toString('base64'),
|
|
88
|
-
runtime: config.runtime,
|
|
89
|
-
};
|
|
90
|
-
if (config.executionPermission) {
|
|
91
|
-
request.executionOptions = { permissionMode: config.executionPermission };
|
|
92
|
-
}
|
|
93
|
-
if (config.timeLimit) {
|
|
94
|
-
request.timeLimit = config.timeLimit;
|
|
95
|
-
}
|
|
96
|
-
if (config.memoryLimit) {
|
|
97
|
-
request.memoryLimit = config.memoryLimit;
|
|
98
|
-
}
|
|
99
|
-
if (config.environment) {
|
|
100
|
-
request.environmentVariables =
|
|
101
|
-
Object.entries(config.environment).reduce((prev, curr) => ({ ...prev, [curr[0]]: { value: curr[1] } }), {});
|
|
102
|
-
}
|
|
103
|
-
if (config.retryPolicy) {
|
|
104
|
-
request.retryPolicy = config.retryPolicy;
|
|
105
|
-
}
|
|
106
|
-
if (myFunction === undefined) {
|
|
107
|
-
await functionRepository.create(sdk, request);
|
|
108
|
-
console.log(chalk.green('Successfully created task', config.name));
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
const existingFunction = await functionRepository.findByName(sdk, myFunction.name);
|
|
112
|
-
if (request.runtime === existingFunction.runtime) {
|
|
113
|
-
delete request.runtime;
|
|
114
|
-
}
|
|
115
|
-
const updateResponse = await functionRepository.update(sdk, request);
|
|
116
|
-
if (!updateResponse?.affectedRecords) {
|
|
117
|
-
throw new Error(`Failed to update task ${request.name}`);
|
|
118
|
-
}
|
|
119
|
-
console.log(chalk.green('Successfully updated task', config.name));
|
|
120
|
-
}
|
|
121
|
-
await fs.unlink(uploadFilePath);
|
|
122
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const constants_1 = require("../../constants");
|
|
7
|
+
const util_1 = require("../../helpers/util");
|
|
8
|
+
const functionRepository = require("../../repositories/functions");
|
|
9
|
+
const taskConfig_1 = require("./taskConfig");
|
|
10
|
+
const util_2 = require("./util");
|
|
11
|
+
exports.command = 'sync';
|
|
12
|
+
exports.desc = 'Sync a task. Will create the task first if it doesn\'t exist yet';
|
|
13
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
14
|
+
path: {
|
|
15
|
+
demandOption: false,
|
|
16
|
+
describe: `Path of the configuration json file containing task parameters. If a directory is given instead, all sub-directories will be searched for a task-config.json file & synced.
|
|
17
|
+
If this option is not used, each parameter (name, code, entryPoint, runtime, ...) will need to be supplied separately`,
|
|
18
|
+
type: 'string',
|
|
19
|
+
},
|
|
20
|
+
name: {
|
|
21
|
+
demandOption: false,
|
|
22
|
+
describe: 'Name of the task',
|
|
23
|
+
type: 'string',
|
|
24
|
+
},
|
|
25
|
+
code: {
|
|
26
|
+
demandOption: false,
|
|
27
|
+
describe: 'The path to a directory containing the built task. exh-cli will compress the directory and upload it',
|
|
28
|
+
type: 'string',
|
|
29
|
+
},
|
|
30
|
+
entryPoint: {
|
|
31
|
+
demandOption: false,
|
|
32
|
+
describe: "The code function that should be invoked. For example 'index.handler' for Nodejs",
|
|
33
|
+
type: 'string',
|
|
34
|
+
},
|
|
35
|
+
runtime: {
|
|
36
|
+
demandOption: false,
|
|
37
|
+
describe: 'Runtime to use for the task',
|
|
38
|
+
choices: constants_1.runtimeChoices,
|
|
39
|
+
type: 'string',
|
|
40
|
+
},
|
|
41
|
+
description: {
|
|
42
|
+
describe: 'A description for this task',
|
|
43
|
+
type: 'string',
|
|
44
|
+
default: '',
|
|
45
|
+
},
|
|
46
|
+
timeLimit: {
|
|
47
|
+
describe: 'The execution time limit for this task (in seconds). Min: 3 max: 900',
|
|
48
|
+
type: 'number',
|
|
49
|
+
},
|
|
50
|
+
memoryLimit: {
|
|
51
|
+
describe: 'The allocated memory for this task (in MB). Min: 128 max: 10240',
|
|
52
|
+
type: 'number',
|
|
53
|
+
},
|
|
54
|
+
env: {
|
|
55
|
+
describe: 'Environment Variables set for this task. This option can be used multiple times.',
|
|
56
|
+
type: 'string',
|
|
57
|
+
default: [],
|
|
58
|
+
},
|
|
59
|
+
executionPermission: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
.check(async ({ path, entryPoint, runtime, name, code, executionPermission }) => {
|
|
64
|
+
if (!path && (!name || !code || !runtime || !entryPoint)) {
|
|
65
|
+
throw new Error('Need to specify either a task config file or all parameters separately');
|
|
66
|
+
}
|
|
67
|
+
(0, taskConfig_1.assertExecutionPermission)(executionPermission);
|
|
68
|
+
return true;
|
|
69
|
+
});
|
|
70
|
+
exports.builder = builder;
|
|
71
|
+
const handler = async ({ sdk, ...cmdLineParams }) => {
|
|
72
|
+
for await (const config of (0, taskConfig_1.getValidatedConfigIterator)(cmdLineParams)) {
|
|
73
|
+
console.log('Syncing task', config.name, '...');
|
|
74
|
+
await syncSingleTask(sdk, config);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
exports.handler = handler;
|
|
78
|
+
async function syncSingleTask(sdk, config) {
|
|
79
|
+
const uploadFilePath = await (0, util_2.zipFileFromDirectory)(config.path);
|
|
80
|
+
const file = await fs.readFile(uploadFilePath);
|
|
81
|
+
const allFunctions = await functionRepository.find(sdk);
|
|
82
|
+
const myFunction = allFunctions.find((f) => f.name === config.name);
|
|
83
|
+
const request = {
|
|
84
|
+
name: config.name,
|
|
85
|
+
description: config.description || 'none',
|
|
86
|
+
entryPoint: config.entryPoint,
|
|
87
|
+
code: file.toString('base64'),
|
|
88
|
+
runtime: config.runtime,
|
|
89
|
+
};
|
|
90
|
+
if (config.executionPermission) {
|
|
91
|
+
request.executionOptions = { permissionMode: config.executionPermission };
|
|
92
|
+
}
|
|
93
|
+
if (config.timeLimit) {
|
|
94
|
+
request.timeLimit = config.timeLimit;
|
|
95
|
+
}
|
|
96
|
+
if (config.memoryLimit) {
|
|
97
|
+
request.memoryLimit = config.memoryLimit;
|
|
98
|
+
}
|
|
99
|
+
if (config.environment) {
|
|
100
|
+
request.environmentVariables =
|
|
101
|
+
Object.entries(config.environment).reduce((prev, curr) => ({ ...prev, [curr[0]]: { value: curr[1] } }), {});
|
|
102
|
+
}
|
|
103
|
+
if (config.retryPolicy) {
|
|
104
|
+
request.retryPolicy = config.retryPolicy;
|
|
105
|
+
}
|
|
106
|
+
if (myFunction === undefined) {
|
|
107
|
+
await functionRepository.create(sdk, request);
|
|
108
|
+
console.log(chalk.green('Successfully created task', config.name));
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const existingFunction = await functionRepository.findByName(sdk, myFunction.name);
|
|
112
|
+
if (request.runtime === existingFunction.runtime) {
|
|
113
|
+
delete request.runtime;
|
|
114
|
+
}
|
|
115
|
+
const updateResponse = await functionRepository.update(sdk, request);
|
|
116
|
+
if (!updateResponse?.affectedRecords) {
|
|
117
|
+
throw new Error(`Failed to update task ${request.name}`);
|
|
118
|
+
}
|
|
119
|
+
console.log(chalk.green('Successfully updated task', config.name));
|
|
120
|
+
}
|
|
121
|
+
await fs.unlink(uploadFilePath);
|
|
122
|
+
}
|