@extrahorizon/exh-cli 1.12.0-dev-141-b72e89f → 1.12.0-dev-143-312ba3f
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/build/commands/tasks/createrepo.js +6 -47
- package/build/commands/tasks/delete.js +2 -14
- package/build/commands/tasks/list.js +2 -22
- package/build/commands/tasks/sync.js +6 -80
- package/build/commands/templates/delete.js +6 -26
- package/build/commands/templates/get.js +6 -16
- package/build/commands/templates/list.js +2 -18
- package/build/commands/templates/sync.d.ts +0 -1
- package/build/commands/templates/sync.js +7 -31
- package/build/repositories/functions.d.ts +1 -1
- package/build/services/tasks/createRepo.d.ts +5 -0
- package/build/services/tasks/createRepo.js +52 -0
- package/build/services/tasks/index.d.ts +5 -0
- package/build/services/tasks/index.js +50 -0
- package/build/services/tasks/sync.d.ts +1 -0
- package/build/services/tasks/sync.js +84 -0
- package/build/services/templates/index.d.ts +4 -0
- package/build/services/templates/index.js +66 -0
- package/build/services/templates/sync.d.ts +2 -0
- package/build/services/templates/sync.js +36 -0
- package/package.json +1 -1
- /package/build/{commands → services}/tasks/taskConfig.d.ts +0 -0
- /package/build/{commands → services}/tasks/taskConfig.js +0 -0
- /package/build/{commands → services}/tasks/util.d.ts +0 -0
- /package/build/{commands → services}/tasks/util.js +0 -0
- /package/build/{commands → services}/templates/util/buildTemplates.d.ts +0 -0
- /package/build/{commands → services}/templates/util/buildTemplates.js +0 -0
- /package/build/{commands → services}/templates/util/readTemplateFiles.d.ts +0 -0
- /package/build/{commands → services}/templates/util/readTemplateFiles.js +0 -0
- /package/build/{commands → services}/templates/util/uploadTemplate.d.ts +0 -0
- /package/build/{commands → services}/templates/util/uploadTemplate.js +0 -0
- /package/build/{commands → services}/templates/util/utils.d.ts +0 -0
- /package/build/{commands → services}/templates/util/utils.js +0 -0
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const promises_1 = require("fs/promises");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
4
|
const util_1 = require("../../helpers/util");
|
|
5
|
+
const tasksService = require("../../services/tasks");
|
|
7
6
|
exports.command = 'create-repo <name>';
|
|
8
7
|
exports.desc = 'Create a new task repository';
|
|
9
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
8
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
9
|
+
.positional('name', {
|
|
10
10
|
demandOption: true,
|
|
11
11
|
description: 'The name of the new repo/task',
|
|
12
12
|
type: 'string',
|
|
13
|
-
})
|
|
13
|
+
})
|
|
14
|
+
.options({
|
|
14
15
|
repo: {
|
|
15
16
|
description: 'repository template to clone',
|
|
16
17
|
type: 'string',
|
|
@@ -23,49 +24,7 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).positional('name', {
|
|
|
23
24
|
},
|
|
24
25
|
});
|
|
25
26
|
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, 2));
|
|
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.$schema = (0, util_1.getSwaggerDocumentationUrl)('config-json-schemas/TaskConfig.json');
|
|
38
|
-
taskConfig.name = name;
|
|
39
|
-
taskConfig.description = `${name} task`;
|
|
40
|
-
await (0, promises_1.writeFile)(`${name}/task-config.json`, JSON.stringify(taskConfig, null, 2));
|
|
41
|
-
}
|
|
42
|
-
catch (err) { }
|
|
43
|
-
}
|
|
44
27
|
const handler = async ({ name, repo, git }) => {
|
|
45
|
-
|
|
46
|
-
await (0, util_1.asyncExec)('git --version');
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
console.log(chalk.red('Git is not installed. Please install git first.'));
|
|
50
|
-
}
|
|
51
|
-
console.log(`Creating new repo ${chalk.green(name)}...`);
|
|
52
|
-
try {
|
|
53
|
-
await (0, util_1.asyncExec)(`git clone ${repo} ${name}`);
|
|
54
|
-
try {
|
|
55
|
-
await changePackageFile(name);
|
|
56
|
-
}
|
|
57
|
-
catch (err) { }
|
|
58
|
-
await (0, util_1.asyncExec)(`cd ${name} && rm -rf .git`);
|
|
59
|
-
if (git) {
|
|
60
|
-
console.log('Initializing git');
|
|
61
|
-
await (0, util_1.asyncExec)(`cd ${name} && git init . && git add . && git commit -m "First commit"`);
|
|
62
|
-
}
|
|
63
|
-
console.log('Done! 🎉');
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
await (0, util_1.asyncExec)(`rm -rf ${name}`);
|
|
67
|
-
console.log(chalk.red('Failed to create repo'));
|
|
68
|
-
console.log(err);
|
|
69
|
-
}
|
|
28
|
+
await tasksService.createRepo({ name, repo, git });
|
|
70
29
|
};
|
|
71
30
|
exports.handler = handler;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const chalk = require("chalk");
|
|
5
4
|
const util_1 = require("../../helpers/util");
|
|
6
|
-
const
|
|
5
|
+
const tasksService = require("../../services/tasks");
|
|
7
6
|
exports.command = 'delete';
|
|
8
7
|
exports.desc = 'Delete a task';
|
|
9
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs).option('name', {
|
|
@@ -13,17 +12,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).option('name', {
|
|
|
13
12
|
});
|
|
14
13
|
exports.builder = builder;
|
|
15
14
|
const handler = async ({ name }) => {
|
|
16
|
-
|
|
17
|
-
const response = await functionRepository.remove(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
|
-
}
|
|
15
|
+
await tasksService.remove(name);
|
|
28
16
|
};
|
|
29
17
|
exports.handler = handler;
|
|
@@ -2,32 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
4
|
const util_1 = require("../../helpers/util");
|
|
5
|
-
const
|
|
5
|
+
const taskService = require("../../services/tasks");
|
|
6
6
|
exports.command = 'list';
|
|
7
7
|
exports.desc = 'List all tasks';
|
|
8
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
9
9
|
exports.builder = builder;
|
|
10
10
|
const handler = async function list({ isTTY }) {
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
functions = await functionRepository.find();
|
|
14
|
-
}
|
|
15
|
-
catch (err) {
|
|
16
|
-
console.log(err);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (functions.length < 1) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (isTTY) {
|
|
23
|
-
console.table(functions.map((c) => ({
|
|
24
|
-
Name: c.name,
|
|
25
|
-
Description: c.description || '<none>',
|
|
26
|
-
'Last updated': c.updateTimestamp.toISOString(),
|
|
27
|
-
})));
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
functions.forEach((f) => (console.log(f.name)));
|
|
31
|
-
}
|
|
11
|
+
await taskService.list(isTTY);
|
|
32
12
|
};
|
|
33
13
|
exports.handler = handler;
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const fs = require("fs/promises");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
4
|
const constants_1 = require("../../constants");
|
|
7
5
|
const util_1 = require("../../helpers/util");
|
|
8
|
-
const
|
|
9
|
-
const taskConfig_1 = require("
|
|
10
|
-
const util_2 = require("./util");
|
|
6
|
+
const tasksService = require("../../services/tasks");
|
|
7
|
+
const taskConfig_1 = require("../../services/tasks/taskConfig");
|
|
11
8
|
exports.command = 'sync';
|
|
12
9
|
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)
|
|
10
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
11
|
+
.options({
|
|
14
12
|
path: {
|
|
15
13
|
demandOption: false,
|
|
16
14
|
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
|
-
|
|
15
|
+
If this option is not used, each parameter (name, code, entryPoint, runtime, ...) will need to be supplied separately`,
|
|
18
16
|
type: 'string',
|
|
19
17
|
},
|
|
20
18
|
name: {
|
|
@@ -72,78 +70,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
72
70
|
});
|
|
73
71
|
exports.builder = builder;
|
|
74
72
|
const handler = async ({ ...cmdLineParams }) => {
|
|
75
|
-
|
|
76
|
-
console.log('Syncing task', config.name, '...');
|
|
77
|
-
await syncSingleTask(config);
|
|
78
|
-
}
|
|
73
|
+
await tasksService.sync(cmdLineParams);
|
|
79
74
|
};
|
|
80
75
|
exports.handler = handler;
|
|
81
|
-
async function syncSingleTask(config) {
|
|
82
|
-
const uploadFilePath = await (0, util_2.zipFileFromDirectory)(config.path);
|
|
83
|
-
const file = await fs.readFile(uploadFilePath);
|
|
84
|
-
const allFunctions = await functionRepository.find();
|
|
85
|
-
const myFunction = allFunctions.find((f) => f.name === config.name);
|
|
86
|
-
const request = {
|
|
87
|
-
name: config.name,
|
|
88
|
-
description: config.description || 'none',
|
|
89
|
-
entryPoint: config.entryPoint,
|
|
90
|
-
code: file.toString('base64'),
|
|
91
|
-
runtime: config.runtime,
|
|
92
|
-
};
|
|
93
|
-
if (config.executionPermission || config.defaultPriority) {
|
|
94
|
-
request.executionOptions = {};
|
|
95
|
-
}
|
|
96
|
-
if (config.defaultPriority) {
|
|
97
|
-
request.executionOptions.defaultPriority = config.defaultPriority;
|
|
98
|
-
}
|
|
99
|
-
if (config.executionPermission) {
|
|
100
|
-
request.executionOptions.permissionMode = config.executionPermission;
|
|
101
|
-
}
|
|
102
|
-
if (config.timeLimit) {
|
|
103
|
-
request.timeLimit = config.timeLimit;
|
|
104
|
-
}
|
|
105
|
-
if (config.memoryLimit) {
|
|
106
|
-
request.memoryLimit = config.memoryLimit;
|
|
107
|
-
}
|
|
108
|
-
if (config.retryPolicy) {
|
|
109
|
-
request.retryPolicy = config.retryPolicy;
|
|
110
|
-
}
|
|
111
|
-
if (config.executionCredentials) {
|
|
112
|
-
const credentials = await (0, util_2.syncFunctionUser)({
|
|
113
|
-
taskName: config.name,
|
|
114
|
-
targetEmail: config.executionCredentials.email,
|
|
115
|
-
targetPermissions: config.executionCredentials.permissions,
|
|
116
|
-
});
|
|
117
|
-
config.environment = {
|
|
118
|
-
...config.environment,
|
|
119
|
-
API_HOST: process.env.API_HOST,
|
|
120
|
-
API_OAUTH_CONSUMER_KEY: process.env.API_OAUTH_CONSUMER_KEY,
|
|
121
|
-
API_OAUTH_CONSUMER_SECRET: process.env.API_OAUTH_CONSUMER_SECRET,
|
|
122
|
-
API_OAUTH_TOKEN: credentials.token,
|
|
123
|
-
API_OAUTH_TOKEN_SECRET: credentials.tokenSecret,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
if (config.environment) {
|
|
127
|
-
const environmentVariables = {};
|
|
128
|
-
for (const [key, value] of Object.entries(config.environment)) {
|
|
129
|
-
environmentVariables[key] = { value };
|
|
130
|
-
}
|
|
131
|
-
request.environmentVariables = environmentVariables;
|
|
132
|
-
}
|
|
133
|
-
if (myFunction === undefined) {
|
|
134
|
-
await functionRepository.create(request);
|
|
135
|
-
console.log(chalk.green('Successfully created task', config.name));
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
const existingFunction = await functionRepository.findByName(myFunction.name);
|
|
139
|
-
if (request.runtime === existingFunction.runtime) {
|
|
140
|
-
delete request.runtime;
|
|
141
|
-
}
|
|
142
|
-
const updateResponse = await functionRepository.update(request);
|
|
143
|
-
if (!updateResponse?.affectedRecords) {
|
|
144
|
-
throw new Error(`Failed to update task ${request.name}`);
|
|
145
|
-
}
|
|
146
|
-
console.log(chalk.green('Successfully updated task', config.name));
|
|
147
|
-
}
|
|
148
|
-
await fs.unlink(uploadFilePath);
|
|
149
|
-
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const chalk = require("chalk");
|
|
5
4
|
const util_1 = require("../../helpers/util");
|
|
6
|
-
const
|
|
5
|
+
const templateService = require("../../services/templates");
|
|
7
6
|
exports.command = 'delete';
|
|
8
7
|
exports.desc = 'Delete a template';
|
|
9
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
8
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
9
|
+
.options({
|
|
10
10
|
name: {
|
|
11
11
|
describe: 'Name of the template to delete',
|
|
12
12
|
type: 'string',
|
|
@@ -15,7 +15,8 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
15
15
|
describe: 'ID of the template to delete',
|
|
16
16
|
type: 'string',
|
|
17
17
|
},
|
|
18
|
-
})
|
|
18
|
+
})
|
|
19
|
+
.check(({ id, name }) => {
|
|
19
20
|
if ((!id && !name) || (id && name)) {
|
|
20
21
|
throw new Error('Either id or name needs to be provided');
|
|
21
22
|
}
|
|
@@ -23,27 +24,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
23
24
|
});
|
|
24
25
|
exports.builder = builder;
|
|
25
26
|
const handler = async function list({ name, id }) {
|
|
26
|
-
|
|
27
|
-
if (name) {
|
|
28
|
-
template = await templateRepository.findByName(name);
|
|
29
|
-
}
|
|
30
|
-
if (id) {
|
|
31
|
-
template = await templateRepository.findById(id);
|
|
32
|
-
}
|
|
33
|
-
if (!template) {
|
|
34
|
-
console.log(chalk.red('Template not found!'));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const { affectedRecords } = await templateRepository.remove(template.id);
|
|
39
|
-
if (!affectedRecords) {
|
|
40
|
-
console.log(chalk.red('Failed to remove template', name));
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
console.log('Template deleted');
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
console.log(chalk.red('Failed to remove template', name));
|
|
47
|
-
}
|
|
27
|
+
await templateService.remove(name, id);
|
|
48
28
|
};
|
|
49
29
|
exports.handler = handler;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const chalk = require("chalk");
|
|
5
4
|
const util_1 = require("../../helpers/util");
|
|
6
|
-
const
|
|
5
|
+
const templateService = require("../../services/templates");
|
|
7
6
|
exports.command = 'get';
|
|
8
7
|
exports.desc = 'Fetch a template';
|
|
9
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
8
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
9
|
+
.options({
|
|
10
10
|
name: {
|
|
11
11
|
describe: 'Name of the template',
|
|
12
12
|
type: 'string',
|
|
@@ -15,7 +15,8 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
15
15
|
describe: 'ID of the template',
|
|
16
16
|
type: 'string',
|
|
17
17
|
},
|
|
18
|
-
})
|
|
18
|
+
})
|
|
19
|
+
.check(({ name, id }) => {
|
|
19
20
|
if ((name && id) || (!name && !id)) {
|
|
20
21
|
throw new Error('Either name or id should be specified (but not both at the same time)');
|
|
21
22
|
}
|
|
@@ -23,17 +24,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
23
24
|
});
|
|
24
25
|
exports.builder = builder;
|
|
25
26
|
const handler = async function list({ name, id }) {
|
|
26
|
-
|
|
27
|
-
if (name) {
|
|
28
|
-
template = await templateRepository.findByName(name);
|
|
29
|
-
}
|
|
30
|
-
else if (id) {
|
|
31
|
-
template = await templateRepository.findById(id);
|
|
32
|
-
}
|
|
33
|
-
if (!template) {
|
|
34
|
-
console.log(chalk.red('Failed to get template!'));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
console.log(JSON.stringify(template, null, 4));
|
|
27
|
+
await templateService.get(name, id);
|
|
38
28
|
};
|
|
39
29
|
exports.handler = handler;
|
|
@@ -1,29 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const chalk = require("chalk");
|
|
5
4
|
const util_1 = require("../../helpers/util");
|
|
6
|
-
const
|
|
5
|
+
const templateService = require("../../services/templates");
|
|
7
6
|
exports.command = 'list';
|
|
8
7
|
exports.desc = 'List all templates';
|
|
9
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
10
9
|
exports.builder = builder;
|
|
11
10
|
const handler = async function list({ isTTY }) {
|
|
12
|
-
|
|
13
|
-
if (templates.length < 1) {
|
|
14
|
-
console.log(chalk.red('No templates found'));
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (isTTY) {
|
|
18
|
-
console.table(templates.map(template => ({
|
|
19
|
-
Id: template.id,
|
|
20
|
-
Name: template.name,
|
|
21
|
-
Description: template.description || '<none>',
|
|
22
|
-
'Last updated': template.updateTimestamp.toISOString(),
|
|
23
|
-
})));
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
templates.forEach(template => console.log(template));
|
|
27
|
-
}
|
|
11
|
+
await templateService.list(isTTY);
|
|
28
12
|
};
|
|
29
13
|
exports.handler = handler;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const ospath = require("path");
|
|
6
6
|
const util_1 = require("../../helpers/util");
|
|
7
|
-
const
|
|
8
|
-
const readTemplateFiles_1 = require("./util/readTemplateFiles");
|
|
9
|
-
const uploadTemplate_1 = require("./util/uploadTemplate");
|
|
10
|
-
const utils_1 = require("./util/utils");
|
|
7
|
+
const templateService = require("../../services/templates");
|
|
11
8
|
exports.command = 'sync';
|
|
12
9
|
exports.desc = 'Sync all templates in a directory with the ExH cloud';
|
|
13
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
10
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
11
|
+
.options({
|
|
14
12
|
path: {
|
|
15
13
|
demandOption: false,
|
|
16
14
|
describe: 'Directory containing the templates which need to be synced',
|
|
@@ -21,7 +19,8 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
21
19
|
describe: 'Template file to sync',
|
|
22
20
|
type: 'string',
|
|
23
21
|
},
|
|
24
|
-
})
|
|
22
|
+
})
|
|
23
|
+
.check(({ path, template }) => {
|
|
25
24
|
if (template && !fs.existsSync(ospath.join(process.cwd(), template))) {
|
|
26
25
|
throw new Error('please provide a valid file path for your template');
|
|
27
26
|
}
|
|
@@ -35,29 +34,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
35
34
|
});
|
|
36
35
|
exports.builder = builder;
|
|
37
36
|
const handler = async ({ path, template }) => {
|
|
38
|
-
|
|
39
|
-
await syncTargetDir(ospath.resolve(path));
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
let templ = null;
|
|
43
|
-
if (fs.statSync(ospath.join(process.cwd(), template)).isFile()) {
|
|
44
|
-
templ = await (0, readTemplateFiles_1.readTemplateJson)(template);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
templ = await (0, readTemplateFiles_1.readTemplateFolder)(template);
|
|
48
|
-
}
|
|
49
|
-
const templateName = (0, utils_1.removeFileNameExtension)(ospath.basename(template));
|
|
50
|
-
await buildAndUploadTemplates({ [templateName]: templ });
|
|
37
|
+
await templateService.sync(path, template);
|
|
51
38
|
};
|
|
52
39
|
exports.handler = handler;
|
|
53
|
-
async function buildAndUploadTemplates(templateObject) {
|
|
54
|
-
const templates = await (0, buildTemplates_1.buildTemplates)(templateObject);
|
|
55
|
-
for (const template of templates) {
|
|
56
|
-
await (0, uploadTemplate_1.uploadTemplate)(template);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function syncTargetDir(targetDir) {
|
|
60
|
-
const templateFilesByName = await (0, readTemplateFiles_1.readTemplateFiles)(targetDir);
|
|
61
|
-
await buildAndUploadTemplates(templateFilesByName);
|
|
62
|
-
}
|
|
63
|
-
exports.syncTargetDir = syncTargetDir;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRepo = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const util_1 = require("../../helpers/util");
|
|
7
|
+
async function createRepo({ name, repo, git }) {
|
|
8
|
+
try {
|
|
9
|
+
await (0, util_1.asyncExec)('git --version');
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
console.log(chalk.red('Git is not installed. Please install git first.'));
|
|
13
|
+
}
|
|
14
|
+
console.log(`Creating new repo ${chalk.green(name)}...`);
|
|
15
|
+
try {
|
|
16
|
+
await (0, util_1.asyncExec)(`git clone ${repo} ${name}`);
|
|
17
|
+
try {
|
|
18
|
+
await changePackageFile(name);
|
|
19
|
+
}
|
|
20
|
+
catch (err) { }
|
|
21
|
+
await (0, util_1.asyncExec)(`cd ${name} && rm -rf .git`);
|
|
22
|
+
if (git) {
|
|
23
|
+
console.log('Initializing git');
|
|
24
|
+
await (0, util_1.asyncExec)(`cd ${name} && git init . && git add . && git commit -m "First commit"`);
|
|
25
|
+
}
|
|
26
|
+
console.log('Done! 🎉');
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
await (0, util_1.asyncExec)(`rm -rf ${name}`);
|
|
30
|
+
console.log(chalk.red('Failed to create repo'));
|
|
31
|
+
console.log(err);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.createRepo = createRepo;
|
|
35
|
+
async function changePackageFile(name) {
|
|
36
|
+
try {
|
|
37
|
+
const pkg = JSON.parse((await (0, promises_1.readFile)(`${name}/package.json`)).toString());
|
|
38
|
+
pkg.name = name;
|
|
39
|
+
await (0, promises_1.writeFile)(`${name}/package.json`, JSON.stringify(pkg, null, 2));
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
console.log('WARN: package.json not found. (possibly not a javascript repository');
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const taskConfig = JSON.parse((await (0, promises_1.readFile)(`${name}/task-config.json`)).toString());
|
|
46
|
+
taskConfig.$schema = (0, util_1.getSwaggerDocumentationUrl)('config-json-schemas/TaskConfig.json');
|
|
47
|
+
taskConfig.name = name;
|
|
48
|
+
taskConfig.description = `${name} task`;
|
|
49
|
+
await (0, promises_1.writeFile)(`${name}/task-config.json`, JSON.stringify(taskConfig, null, 2));
|
|
50
|
+
}
|
|
51
|
+
catch (err) { }
|
|
52
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remove = exports.list = exports.assertExecutionPermission = exports.createRepo = exports.sync = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const functionRepository = require("../../repositories/functions");
|
|
6
|
+
var sync_1 = require("./sync");
|
|
7
|
+
Object.defineProperty(exports, "sync", { enumerable: true, get: function () { return sync_1.sync; } });
|
|
8
|
+
var createRepo_1 = require("./createRepo");
|
|
9
|
+
Object.defineProperty(exports, "createRepo", { enumerable: true, get: function () { return createRepo_1.createRepo; } });
|
|
10
|
+
var taskConfig_1 = require("./taskConfig");
|
|
11
|
+
Object.defineProperty(exports, "assertExecutionPermission", { enumerable: true, get: function () { return taskConfig_1.assertExecutionPermission; } });
|
|
12
|
+
async function list(isTTY) {
|
|
13
|
+
let functions;
|
|
14
|
+
try {
|
|
15
|
+
functions = await functionRepository.find();
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
console.log(err);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (functions.length < 1) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (isTTY) {
|
|
25
|
+
console.table(functions.map((c) => ({
|
|
26
|
+
Name: c.name,
|
|
27
|
+
Description: c.description || '<none>',
|
|
28
|
+
'Last updated': c.updateTimestamp.toISOString(),
|
|
29
|
+
})));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
functions.forEach((f) => (console.log(f.name)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.list = list;
|
|
36
|
+
async function remove(name) {
|
|
37
|
+
try {
|
|
38
|
+
const response = await functionRepository.remove(name);
|
|
39
|
+
if (response?.affectedRecords) {
|
|
40
|
+
console.log(chalk.green('Successfully deleted task', name));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.log(chalk.red('Failed to delete task', name));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
console.log(chalk.red('Failed to delete task:', err.message));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.remove = remove;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sync(cmdLineParams: any): Promise<void>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sync = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const functionRepository = require("../../repositories/functions");
|
|
7
|
+
const taskConfig_1 = require("../../services/tasks/taskConfig");
|
|
8
|
+
const util_1 = require("../../services/tasks/util");
|
|
9
|
+
async function sync(cmdLineParams) {
|
|
10
|
+
for await (const config of (0, taskConfig_1.getValidatedConfigIterator)(cmdLineParams)) {
|
|
11
|
+
console.log('Syncing task', config.name, '...');
|
|
12
|
+
await syncSingleTask(config);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.sync = sync;
|
|
16
|
+
async function syncSingleTask(config) {
|
|
17
|
+
const uploadFilePath = await (0, util_1.zipFileFromDirectory)(config.path);
|
|
18
|
+
const file = await fs.readFile(uploadFilePath);
|
|
19
|
+
const request = {
|
|
20
|
+
name: config.name,
|
|
21
|
+
description: config.description || 'none',
|
|
22
|
+
entryPoint: config.entryPoint,
|
|
23
|
+
code: file.toString('base64'),
|
|
24
|
+
runtime: config.runtime,
|
|
25
|
+
};
|
|
26
|
+
if (config.executionPermission || config.defaultPriority) {
|
|
27
|
+
request.executionOptions = {};
|
|
28
|
+
}
|
|
29
|
+
if (config.defaultPriority) {
|
|
30
|
+
request.executionOptions.defaultPriority = config.defaultPriority;
|
|
31
|
+
}
|
|
32
|
+
if (config.executionPermission) {
|
|
33
|
+
request.executionOptions.permissionMode = config.executionPermission;
|
|
34
|
+
}
|
|
35
|
+
if (config.timeLimit) {
|
|
36
|
+
request.timeLimit = config.timeLimit;
|
|
37
|
+
}
|
|
38
|
+
if (config.memoryLimit) {
|
|
39
|
+
request.memoryLimit = config.memoryLimit;
|
|
40
|
+
}
|
|
41
|
+
if (config.retryPolicy) {
|
|
42
|
+
request.retryPolicy = config.retryPolicy;
|
|
43
|
+
}
|
|
44
|
+
if (config.executionCredentials) {
|
|
45
|
+
const credentials = await (0, util_1.syncFunctionUser)({
|
|
46
|
+
taskName: config.name,
|
|
47
|
+
targetEmail: config.executionCredentials.email,
|
|
48
|
+
targetPermissions: config.executionCredentials.permissions,
|
|
49
|
+
});
|
|
50
|
+
config.environment = {
|
|
51
|
+
...config.environment,
|
|
52
|
+
API_HOST: process.env.API_HOST,
|
|
53
|
+
API_OAUTH_CONSUMER_KEY: process.env.API_OAUTH_CONSUMER_KEY,
|
|
54
|
+
API_OAUTH_CONSUMER_SECRET: process.env.API_OAUTH_CONSUMER_SECRET,
|
|
55
|
+
API_OAUTH_TOKEN: credentials.token,
|
|
56
|
+
API_OAUTH_TOKEN_SECRET: credentials.tokenSecret,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (config.environment) {
|
|
60
|
+
const environmentVariables = {};
|
|
61
|
+
for (const [key, value] of Object.entries(config.environment)) {
|
|
62
|
+
environmentVariables[key] = { value };
|
|
63
|
+
}
|
|
64
|
+
request.environmentVariables = environmentVariables;
|
|
65
|
+
}
|
|
66
|
+
const allFunctions = await functionRepository.find();
|
|
67
|
+
const myFunction = allFunctions.find((f) => f.name === config.name);
|
|
68
|
+
if (myFunction === undefined) {
|
|
69
|
+
await functionRepository.create(request);
|
|
70
|
+
console.log(chalk.green('Successfully created task', config.name));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const existingFunction = await functionRepository.findByName(myFunction.name);
|
|
74
|
+
if (request.runtime === existingFunction.runtime) {
|
|
75
|
+
delete request.runtime;
|
|
76
|
+
}
|
|
77
|
+
const updateResponse = await functionRepository.update(request);
|
|
78
|
+
if (!updateResponse?.affectedRecords) {
|
|
79
|
+
throw new Error(`Failed to update task ${request.name}`);
|
|
80
|
+
}
|
|
81
|
+
console.log(chalk.green('Successfully updated task', config.name));
|
|
82
|
+
}
|
|
83
|
+
await fs.unlink(uploadFilePath);
|
|
84
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remove = exports.get = exports.list = exports.sync = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const templateRepository = require("../../repositories/templates");
|
|
6
|
+
var sync_1 = require("./sync");
|
|
7
|
+
Object.defineProperty(exports, "sync", { enumerable: true, get: function () { return sync_1.sync; } });
|
|
8
|
+
async function list(isTTY) {
|
|
9
|
+
const templates = await templateRepository.findAll();
|
|
10
|
+
if (templates.length < 1) {
|
|
11
|
+
console.log(chalk.red('No templates found'));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (isTTY) {
|
|
15
|
+
console.table(templates.map(template => ({
|
|
16
|
+
Id: template.id,
|
|
17
|
+
Name: template.name,
|
|
18
|
+
Description: template.description || '<none>',
|
|
19
|
+
'Last updated': template.updateTimestamp.toISOString(),
|
|
20
|
+
})));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
templates.forEach(template => console.log(template));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.list = list;
|
|
27
|
+
async function get(name, id) {
|
|
28
|
+
let template;
|
|
29
|
+
if (name) {
|
|
30
|
+
template = await templateRepository.findByName(name);
|
|
31
|
+
}
|
|
32
|
+
else if (id) {
|
|
33
|
+
template = await templateRepository.findById(id);
|
|
34
|
+
}
|
|
35
|
+
if (!template) {
|
|
36
|
+
console.log(chalk.red('Failed to get template!'));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
console.log(JSON.stringify(template, null, 4));
|
|
40
|
+
}
|
|
41
|
+
exports.get = get;
|
|
42
|
+
async function remove(name, id) {
|
|
43
|
+
let template = null;
|
|
44
|
+
if (name) {
|
|
45
|
+
template = await templateRepository.findByName(name);
|
|
46
|
+
}
|
|
47
|
+
if (id) {
|
|
48
|
+
template = await templateRepository.findById(id);
|
|
49
|
+
}
|
|
50
|
+
if (!template) {
|
|
51
|
+
console.log(chalk.red('Template not found!'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const { affectedRecords } = await templateRepository.remove(template.id);
|
|
56
|
+
if (!affectedRecords) {
|
|
57
|
+
console.log(chalk.red('Failed to remove template', name));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
console.log('Template deleted');
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
console.log(chalk.red('Failed to remove template', name));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.remove = remove;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncTargetDir = exports.sync = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const ospath = require("path");
|
|
6
|
+
const buildTemplates_1 = require("./util/buildTemplates");
|
|
7
|
+
const readTemplateFiles_1 = require("./util/readTemplateFiles");
|
|
8
|
+
const uploadTemplate_1 = require("./util/uploadTemplate");
|
|
9
|
+
const utils_1 = require("./util/utils");
|
|
10
|
+
async function sync(path, template) {
|
|
11
|
+
if (path) {
|
|
12
|
+
await syncTargetDir(ospath.resolve(path));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let templ = null;
|
|
16
|
+
if (fs.statSync(ospath.join(process.cwd(), template)).isFile()) {
|
|
17
|
+
templ = await (0, readTemplateFiles_1.readTemplateJson)(template);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
templ = await (0, readTemplateFiles_1.readTemplateFolder)(template);
|
|
21
|
+
}
|
|
22
|
+
const templateName = (0, utils_1.removeFileNameExtension)(ospath.basename(template));
|
|
23
|
+
await buildAndUploadTemplates({ [templateName]: templ });
|
|
24
|
+
}
|
|
25
|
+
exports.sync = sync;
|
|
26
|
+
async function buildAndUploadTemplates(templateObject) {
|
|
27
|
+
const templates = await (0, buildTemplates_1.buildTemplates)(templateObject);
|
|
28
|
+
for (const template of templates) {
|
|
29
|
+
await (0, uploadTemplate_1.uploadTemplate)(template);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function syncTargetDir(targetDir) {
|
|
33
|
+
const templateFilesByName = await (0, readTemplateFiles_1.readTemplateFiles)(targetDir);
|
|
34
|
+
await buildAndUploadTemplates(templateFilesByName);
|
|
35
|
+
}
|
|
36
|
+
exports.syncTargetDir = syncTargetDir;
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|