@extrahorizon/exh-cli 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/LICENSE +21 -0
- package/README.md +66 -0
- package/build/commands/completion.d.ts +5 -0
- package/build/commands/completion.js +38 -0
- package/build/commands/data/schemas/delete.d.ts +10 -0
- package/build/commands/data/schemas/delete.js +29 -0
- package/build/commands/data/schemas/list.d.ts +8 -0
- package/build/commands/data/schemas/list.js +20 -0
- package/build/commands/data/schemas/sync/statusHelpers.d.ts +3 -0
- package/build/commands/data/schemas/sync/statusHelpers.js +49 -0
- package/build/commands/data/schemas/sync.d.ts +35 -0
- package/build/commands/data/schemas/sync.js +72 -0
- package/build/commands/data/schemas/util/listFilesInDir.d.ts +1 -0
- package/build/commands/data/schemas/util/listFilesInDir.js +25 -0
- package/build/commands/data/schemas/util/metaschema.json +455 -0
- package/build/commands/data/schemas/util/readJson.d.ts +1 -0
- package/build/commands/data/schemas/util/readJson.js +11 -0
- package/build/commands/data/schemas/util/schemaverify.d.ts +28 -0
- package/build/commands/data/schemas/util/schemaverify.js +202 -0
- package/build/commands/data/schemas/util/syncSchema.d.ts +20 -0
- package/build/commands/data/schemas/util/syncSchema.js +276 -0
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.d.ts +1 -0
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.js +40 -0
- package/build/commands/data/schemas/verify.d.ts +18 -0
- package/build/commands/data/schemas/verify.js +82 -0
- package/build/commands/data/schemas.d.ts +5 -0
- package/build/commands/data/schemas.js +10 -0
- package/build/commands/data.d.ts +5 -0
- package/build/commands/data.js +10 -0
- package/build/commands/dispatchers/sync.d.ts +21 -0
- package/build/commands/dispatchers/sync.js +24 -0
- package/build/commands/dispatchers.d.ts +5 -0
- package/build/commands/dispatchers.js +10 -0
- package/build/commands/login.d.ts +37 -0
- package/build/commands/login.js +59 -0
- package/build/commands/sync.d.ts +55 -0
- package/build/commands/sync.js +107 -0
- package/build/commands/tasks/createrepo.d.ts +22 -0
- package/build/commands/tasks/createrepo.js +70 -0
- package/build/commands/tasks/delete.d.ts +10 -0
- package/build/commands/tasks/delete.js +29 -0
- package/build/commands/tasks/list.d.ts +8 -0
- package/build/commands/tasks/list.js +27 -0
- package/build/commands/tasks/sync.d.ts +56 -0
- package/build/commands/tasks/sync.js +122 -0
- package/build/commands/tasks/taskConfig.d.ts +24 -0
- package/build/commands/tasks/taskConfig.js +169 -0
- package/build/commands/tasks/util.d.ts +1 -0
- package/build/commands/tasks/util.js +27 -0
- package/build/commands/tasks.d.ts +5 -0
- package/build/commands/tasks.js +10 -0
- package/build/commands/templates/delete.d.ts +19 -0
- package/build/commands/templates/delete.js +48 -0
- package/build/commands/templates/get.d.ts +19 -0
- package/build/commands/templates/get.js +37 -0
- package/build/commands/templates/list.d.ts +9 -0
- package/build/commands/templates/list.js +25 -0
- package/build/commands/templates/sync.d.ts +22 -0
- package/build/commands/templates/sync.js +65 -0
- package/build/commands/templates/util/buildTemplates.d.ts +2 -0
- package/build/commands/templates/util/buildTemplates.js +50 -0
- package/build/commands/templates/util/readTemplateFiles.d.ts +3 -0
- package/build/commands/templates/util/readTemplateFiles.js +52 -0
- package/build/commands/templates/util/templateService.d.ts +8 -0
- package/build/commands/templates/util/templateService.js +18 -0
- package/build/commands/templates/util/uploadTemplate.d.ts +2 -0
- package/build/commands/templates/util/uploadTemplate.js +20 -0
- package/build/commands/templates/util/utils.d.ts +4 -0
- package/build/commands/templates/util/utils.js +22 -0
- package/build/commands/templates.d.ts +5 -0
- package/build/commands/templates.js +10 -0
- package/build/constants.d.ts +13 -0
- package/build/constants.js +37 -0
- package/build/exh.d.ts +3 -0
- package/build/exh.js +65 -0
- package/build/helpers/error.d.ts +2 -0
- package/build/helpers/error.js +6 -0
- package/build/helpers/repoConfig.d.ts +2 -0
- package/build/helpers/repoConfig.js +60 -0
- package/build/helpers/util.d.ts +3 -0
- package/build/helpers/util.js +36 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +33 -0
- package/build/repositories/dispatchers.d.ts +8 -0
- package/build/repositories/dispatchers.js +31 -0
- package/build/repositories/functions.d.ts +24 -0
- package/build/repositories/functions.js +28 -0
- package/build/repositories/schemas.d.ts +44 -0
- package/build/repositories/schemas.js +86 -0
- package/build/services/dispatchers.d.ts +3 -0
- package/build/services/dispatchers.js +132 -0
- package/package.json +53 -0
|
@@ -0,0 +1,10 @@
|
|
|
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 = 'data <command>';
|
|
6
|
+
exports.desc = 'Manage data';
|
|
7
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('data');
|
|
8
|
+
exports.builder = builder;
|
|
9
|
+
const handler = () => { };
|
|
10
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
2
|
+
import { Argv } from 'yargs';
|
|
3
|
+
export declare const command = "sync";
|
|
4
|
+
export declare const desc = "Synchronize Dispatchers, if a declared Dispatcher does not exist, it will be created";
|
|
5
|
+
export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "file" | "clean"> & import("yargs").InferredOptionTypes<{
|
|
6
|
+
file: {
|
|
7
|
+
demandOption: true;
|
|
8
|
+
describe: string;
|
|
9
|
+
type: "string";
|
|
10
|
+
};
|
|
11
|
+
clean: {
|
|
12
|
+
demandOption: false;
|
|
13
|
+
describe: string;
|
|
14
|
+
type: "boolean";
|
|
15
|
+
};
|
|
16
|
+
}>>;
|
|
17
|
+
export declare const handler: ({ sdk, file, clean }: {
|
|
18
|
+
sdk: OAuth1Client;
|
|
19
|
+
file: string;
|
|
20
|
+
clean: boolean;
|
|
21
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const dispatchersService = require("../../services/dispatchers");
|
|
6
|
+
exports.command = 'sync';
|
|
7
|
+
exports.desc = 'Synchronize Dispatchers, if a declared Dispatcher does not exist, it will be created';
|
|
8
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
9
|
+
file: {
|
|
10
|
+
demandOption: true,
|
|
11
|
+
describe: 'Path to the file containing the Dispatcher(s) configuration',
|
|
12
|
+
type: 'string',
|
|
13
|
+
},
|
|
14
|
+
clean: {
|
|
15
|
+
demandOption: false,
|
|
16
|
+
describe: 'Delete Dispatchers created using the CLI, that are no longer present in the local Dispatcher file',
|
|
17
|
+
type: 'boolean',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
exports.builder = builder;
|
|
21
|
+
const handler = async ({ sdk, file, clean }) => {
|
|
22
|
+
await dispatchersService.sync(sdk, file, clean);
|
|
23
|
+
};
|
|
24
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 = 'dispatchers <command>';
|
|
6
|
+
exports.desc = 'Manage Dispatchers within Extra Horizon';
|
|
7
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('dispatchers');
|
|
8
|
+
exports.builder = builder;
|
|
9
|
+
const handler = () => { };
|
|
10
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
export declare const command = "login";
|
|
3
|
+
export declare const desc = "Retrieve credentials from ExH";
|
|
4
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "password" | "host" | "email" | "consumerKey" | "consumerSecret"> & import("yargs").InferredOptionTypes<{
|
|
5
|
+
host: {
|
|
6
|
+
demandOption: true;
|
|
7
|
+
type: "string";
|
|
8
|
+
describe: string;
|
|
9
|
+
};
|
|
10
|
+
email: {
|
|
11
|
+
demandOption: true;
|
|
12
|
+
type: "string";
|
|
13
|
+
describe: string;
|
|
14
|
+
};
|
|
15
|
+
password: {
|
|
16
|
+
demandOption: true;
|
|
17
|
+
type: "string";
|
|
18
|
+
describe: string;
|
|
19
|
+
};
|
|
20
|
+
consumerKey: {
|
|
21
|
+
demandOption: true;
|
|
22
|
+
type: "string";
|
|
23
|
+
describe: string;
|
|
24
|
+
};
|
|
25
|
+
consumerSecret: {
|
|
26
|
+
demandOption: true;
|
|
27
|
+
type: "string";
|
|
28
|
+
describe: string;
|
|
29
|
+
};
|
|
30
|
+
}>>;
|
|
31
|
+
export declare const handler: ({ host, email, password, consumerKey, consumerSecret }: {
|
|
32
|
+
host: string;
|
|
33
|
+
email: string;
|
|
34
|
+
password: string;
|
|
35
|
+
consumerKey: string;
|
|
36
|
+
consumerSecret: string;
|
|
37
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 exh_1 = require("../exh");
|
|
8
|
+
const util_1 = require("../helpers/util");
|
|
9
|
+
exports.command = 'login';
|
|
10
|
+
exports.desc = 'Retrieve credentials from ExH';
|
|
11
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
12
|
+
host: {
|
|
13
|
+
demandOption: true,
|
|
14
|
+
type: 'string',
|
|
15
|
+
describe: 'the address of your ExH cloud instance (eg. https://api.dev.my-instance.extrahorizon.io)',
|
|
16
|
+
},
|
|
17
|
+
email: {
|
|
18
|
+
demandOption: true,
|
|
19
|
+
type: 'string',
|
|
20
|
+
describe: 'email address of your ExH account',
|
|
21
|
+
},
|
|
22
|
+
password: {
|
|
23
|
+
demandOption: true,
|
|
24
|
+
type: 'string',
|
|
25
|
+
describe: 'password of your ExH account',
|
|
26
|
+
},
|
|
27
|
+
consumerKey: {
|
|
28
|
+
demandOption: true,
|
|
29
|
+
type: 'string',
|
|
30
|
+
describe: 'Consumer key',
|
|
31
|
+
},
|
|
32
|
+
consumerSecret: {
|
|
33
|
+
demandOption: true,
|
|
34
|
+
type: 'string',
|
|
35
|
+
describe: 'Consumer secret',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
exports.builder = builder;
|
|
39
|
+
const handler = async ({ host, email, password, consumerKey, consumerSecret }) => {
|
|
40
|
+
const sdk = (0, exh_1.sdkInitOnly)(host, consumerKey, consumerSecret);
|
|
41
|
+
const response = await sdk.auth.authenticate({
|
|
42
|
+
email,
|
|
43
|
+
password,
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
await fs.stat(constants_1.EXH_CONFIG_FILE_DIR);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
await fs.mkdir(constants_1.EXH_CONFIG_FILE_DIR);
|
|
50
|
+
}
|
|
51
|
+
await fs.writeFile(constants_1.EXH_CONFIG_FILE, `API_HOST=${host}
|
|
52
|
+
API_OAUTH_CONSUMER_KEY=${consumerKey}
|
|
53
|
+
API_OAUTH_CONSUMER_SECRET=${consumerSecret}
|
|
54
|
+
API_OAUTH_TOKEN=${response.token}
|
|
55
|
+
API_OAUTH_TOKEN_SECRET=${response.tokenSecret}
|
|
56
|
+
`);
|
|
57
|
+
console.log(chalk.green('Wrote credentials to', constants_1.EXH_CONFIG_FILE));
|
|
58
|
+
};
|
|
59
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
export declare const command = "sync";
|
|
3
|
+
export declare const desc = "Upload all schemas, templates & tasks to the cloud environment";
|
|
4
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "path" | "schemas" | "tasks" | "dispatchers" | "templates" | "cleanDispatchers" | "ignoreSchemaVerificationErrors"> & import("yargs").InferredOptionTypes<{
|
|
5
|
+
path: {
|
|
6
|
+
demandOption: false;
|
|
7
|
+
describe: string;
|
|
8
|
+
type: "string";
|
|
9
|
+
};
|
|
10
|
+
schemas: {
|
|
11
|
+
demandOption: false;
|
|
12
|
+
describe: string;
|
|
13
|
+
type: "boolean";
|
|
14
|
+
default: boolean;
|
|
15
|
+
};
|
|
16
|
+
tasks: {
|
|
17
|
+
demandOption: false;
|
|
18
|
+
describe: string;
|
|
19
|
+
type: "boolean";
|
|
20
|
+
default: boolean;
|
|
21
|
+
};
|
|
22
|
+
templates: {
|
|
23
|
+
demandOption: false;
|
|
24
|
+
describe: string;
|
|
25
|
+
type: "boolean";
|
|
26
|
+
default: boolean;
|
|
27
|
+
};
|
|
28
|
+
dispatchers: {
|
|
29
|
+
demandOption: false;
|
|
30
|
+
describe: string;
|
|
31
|
+
type: "boolean";
|
|
32
|
+
default: boolean;
|
|
33
|
+
};
|
|
34
|
+
cleanDispatchers: {
|
|
35
|
+
demandOption: false;
|
|
36
|
+
describe: string;
|
|
37
|
+
type: "boolean";
|
|
38
|
+
};
|
|
39
|
+
ignoreSchemaVerificationErrors: {
|
|
40
|
+
demandOption: false;
|
|
41
|
+
describe: string;
|
|
42
|
+
type: "boolean";
|
|
43
|
+
default: boolean;
|
|
44
|
+
};
|
|
45
|
+
}>>;
|
|
46
|
+
export declare const handler: ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, ignoreSchemaVerificationErrors }: {
|
|
47
|
+
sdk: any;
|
|
48
|
+
path: any;
|
|
49
|
+
schemas: any;
|
|
50
|
+
tasks: any;
|
|
51
|
+
templates: any;
|
|
52
|
+
dispatchers: any;
|
|
53
|
+
cleanDispatchers: any;
|
|
54
|
+
ignoreSchemaVerificationErrors: any;
|
|
55
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const fs = require("fs/promises");
|
|
6
|
+
const ospath = require("path");
|
|
7
|
+
const chalk = require("chalk");
|
|
8
|
+
const repoConfig_1 = require("../helpers/repoConfig");
|
|
9
|
+
const util_1 = require("../helpers/util");
|
|
10
|
+
const dispatchers_1 = require("../services/dispatchers");
|
|
11
|
+
const sync_1 = require("./data/schemas/sync");
|
|
12
|
+
const sync_2 = require("./tasks/sync");
|
|
13
|
+
const sync_3 = require("./templates/sync");
|
|
14
|
+
exports.command = 'sync';
|
|
15
|
+
exports.desc = 'Upload all schemas, templates & tasks to the cloud environment';
|
|
16
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
17
|
+
.options({
|
|
18
|
+
path: {
|
|
19
|
+
demandOption: false,
|
|
20
|
+
describe: `Path to folder which needs to be synchronized. The target folder should contain a ${repoConfig_1.REPO_CONFIG_FILE} file.
|
|
21
|
+
If not, the local directory is assumed with a default configuration which assumes tasks are in a 'tasks' folder, schemas in a 'schemas' folder and templates in a 'templates' folder`,
|
|
22
|
+
type: 'string',
|
|
23
|
+
},
|
|
24
|
+
schemas: {
|
|
25
|
+
demandOption: false,
|
|
26
|
+
describe: 'Sync schemas only',
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
default: false,
|
|
29
|
+
},
|
|
30
|
+
tasks: {
|
|
31
|
+
demandOption: false,
|
|
32
|
+
describe: 'Sync tasks only',
|
|
33
|
+
type: 'boolean',
|
|
34
|
+
default: false,
|
|
35
|
+
},
|
|
36
|
+
templates: {
|
|
37
|
+
demandOption: false,
|
|
38
|
+
describe: 'Sync templates only',
|
|
39
|
+
type: 'boolean',
|
|
40
|
+
default: false,
|
|
41
|
+
},
|
|
42
|
+
dispatchers: {
|
|
43
|
+
demandOption: false,
|
|
44
|
+
describe: 'Sync Dispatchers only',
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
default: false,
|
|
47
|
+
},
|
|
48
|
+
cleanDispatchers: {
|
|
49
|
+
demandOption: false,
|
|
50
|
+
describe: 'Delete Dispatchers created using the CLI, that are no longer present in the local Dispatcher file',
|
|
51
|
+
type: 'boolean',
|
|
52
|
+
},
|
|
53
|
+
ignoreSchemaVerificationErrors: {
|
|
54
|
+
demandOption: false,
|
|
55
|
+
describe: 'Allow schema synchronization to proceed with validation errors.',
|
|
56
|
+
type: 'boolean',
|
|
57
|
+
default: false,
|
|
58
|
+
},
|
|
59
|
+
}).check(async ({ path }) => {
|
|
60
|
+
if (path !== undefined) {
|
|
61
|
+
try {
|
|
62
|
+
await fs.access(ospath.join(process.cwd(), path, repoConfig_1.REPO_CONFIG_FILE));
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
throw new Error(`Repository config file not found at ${path}`);
|
|
66
|
+
}
|
|
67
|
+
if (!(await fs.stat(ospath.join(process.cwd(), path, repoConfig_1.REPO_CONFIG_FILE))).isFile()) {
|
|
68
|
+
throw new Error('please provide a valid repository config file');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
});
|
|
73
|
+
exports.builder = builder;
|
|
74
|
+
const handler = async ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, ignoreSchemaVerificationErrors }) => {
|
|
75
|
+
const targetPath = ospath.join(process.cwd(), path || '.');
|
|
76
|
+
const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath, true);
|
|
77
|
+
const syncAll = !(schemas || tasks || templates || dispatchers);
|
|
78
|
+
if ((syncAll || schemas) && cfg.schemas) {
|
|
79
|
+
console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
|
|
80
|
+
for (const schema of cfg.schemas) {
|
|
81
|
+
await (0, sync_1.syncTargetDir)(sdk, ospath.join(targetPath, schema), undefined, ignoreSchemaVerificationErrors);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if ((syncAll || templates) && cfg.templates) {
|
|
85
|
+
console.log(chalk.green('\n ⚙️ Syncing templates...'));
|
|
86
|
+
for (const template of cfg.templates) {
|
|
87
|
+
await (0, sync_3.handler)({ sdk, path: ospath.join(targetPath, template), template: null });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if ((syncAll || tasks) && cfg.tasks) {
|
|
91
|
+
console.log(chalk.green('\n ⚙️ Syncing tasks...'));
|
|
92
|
+
for (const task of cfg.tasks) {
|
|
93
|
+
await (0, sync_2.handler)({ sdk, path: ospath.join(targetPath, task) });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if ((syncAll || dispatchers)) {
|
|
97
|
+
const dispatchersPath = ospath.join(targetPath, 'dispatchers.json');
|
|
98
|
+
const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
|
|
99
|
+
if (isValidPath) {
|
|
100
|
+
await (0, dispatchers_1.sync)(sdk, dispatchersPath, cleanDispatchers);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
console.log(chalk.yellow('Warning: dispatchers.json not found'));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
export declare const command = "create-repo <name>";
|
|
3
|
+
export declare const desc = "Create a new task repository";
|
|
4
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{
|
|
5
|
+
name: string;
|
|
6
|
+
}, "repo" | "git"> & import("yargs").InferredOptionTypes<{
|
|
7
|
+
repo: {
|
|
8
|
+
description: string;
|
|
9
|
+
type: "string";
|
|
10
|
+
default: string;
|
|
11
|
+
};
|
|
12
|
+
git: {
|
|
13
|
+
description: string;
|
|
14
|
+
type: "boolean";
|
|
15
|
+
default: boolean;
|
|
16
|
+
};
|
|
17
|
+
}>>;
|
|
18
|
+
export declare const handler: ({ name, repo, git }: {
|
|
19
|
+
name: any;
|
|
20
|
+
repo: any;
|
|
21
|
+
git: any;
|
|
22
|
+
}) => Promise<void>;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +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>;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +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>;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +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>;
|