contensis-cli 1.0.0-beta.5
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/.vscode/launch.json +15 -0
- package/README.md +631 -0
- package/cli.js +7 -0
- package/dist/commands/connect.js +44 -0
- package/dist/commands/connect.js.map +7 -0
- package/dist/commands/create.js +55 -0
- package/dist/commands/create.js.map +7 -0
- package/dist/commands/get.js +121 -0
- package/dist/commands/get.js.map +7 -0
- package/dist/commands/globalOptions.js +139 -0
- package/dist/commands/globalOptions.js.map +7 -0
- package/dist/commands/import.js +95 -0
- package/dist/commands/import.js.map +7 -0
- package/dist/commands/index.js +81 -0
- package/dist/commands/index.js.map +7 -0
- package/dist/commands/list.js +88 -0
- package/dist/commands/list.js.map +7 -0
- package/dist/commands/login.js +56 -0
- package/dist/commands/login.js.map +7 -0
- package/dist/commands/push.js +133 -0
- package/dist/commands/push.js.map +7 -0
- package/dist/commands/remove.js +77 -0
- package/dist/commands/remove.js.map +7 -0
- package/dist/commands/set.js +55 -0
- package/dist/commands/set.js.map +7 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +7 -0
- package/dist/localisation/en-GB.js +203 -0
- package/dist/localisation/en-GB.js.map +7 -0
- package/dist/models/AppError.d.js +2 -0
- package/dist/models/AppError.d.js.map +7 -0
- package/dist/models/Cache.d.js +2 -0
- package/dist/models/Cache.d.js.map +7 -0
- package/dist/models/JsModules.d.js +2 -0
- package/dist/models/JsModules.d.js.map +7 -0
- package/dist/providers/CredentialProvider.js +87 -0
- package/dist/providers/CredentialProvider.js.map +7 -0
- package/dist/providers/SessionCacheProvider.js +91 -0
- package/dist/providers/SessionCacheProvider.js.map +7 -0
- package/dist/providers/file-provider.js +113 -0
- package/dist/providers/file-provider.js.map +7 -0
- package/dist/services/ContensisAuthService.js +75 -0
- package/dist/services/ContensisAuthService.js.map +7 -0
- package/dist/services/ContensisCliService.js +1110 -0
- package/dist/services/ContensisCliService.js.map +7 -0
- package/dist/shell.js +261 -0
- package/dist/shell.js.map +7 -0
- package/dist/util/console.printer.js +194 -0
- package/dist/util/console.printer.js.map +7 -0
- package/dist/util/csv.formatter.js +50 -0
- package/dist/util/csv.formatter.js.map +7 -0
- package/dist/util/index.js +94 -0
- package/dist/util/index.js.map +7 -0
- package/dist/util/json.formatter.js +29 -0
- package/dist/util/json.formatter.js.map +7 -0
- package/dist/util/logger.js +184 -0
- package/dist/util/logger.js.map +7 -0
- package/dist/util/xml.formatter.js +51 -0
- package/dist/util/xml.formatter.js.map +7 -0
- package/dist/version.js +29 -0
- package/dist/version.js.map +7 -0
- package/esbuild.config.js +49 -0
- package/headless-setup.sh +7 -0
- package/package.json +59 -0
- package/patches/inquirer-command-prompt+0.1.0.patch +27 -0
- package/src/commands/connect.ts +23 -0
- package/src/commands/create.ts +41 -0
- package/src/commands/get.ts +139 -0
- package/src/commands/globalOptions.ts +126 -0
- package/src/commands/import.ts +89 -0
- package/src/commands/index.ts +72 -0
- package/src/commands/list.ts +90 -0
- package/src/commands/login.ts +33 -0
- package/src/commands/push.ts +120 -0
- package/src/commands/remove.ts +77 -0
- package/src/commands/set.ts +40 -0
- package/src/index.ts +19 -0
- package/src/localisation/en-GB.ts +211 -0
- package/src/models/AppError.d.ts +40 -0
- package/src/models/Cache.d.ts +25 -0
- package/src/models/JsModules.d.ts +1 -0
- package/src/providers/CredentialProvider.ts +88 -0
- package/src/providers/SessionCacheProvider.ts +74 -0
- package/src/providers/file-provider.ts +72 -0
- package/src/services/ContensisAuthService.ts +70 -0
- package/src/services/ContensisCliService.ts +1390 -0
- package/src/shell.ts +250 -0
- package/src/util/console.printer.ts +203 -0
- package/src/util/csv.formatter.ts +21 -0
- package/src/util/index.ts +67 -0
- package/src/util/json.formatter.ts +1 -0
- package/src/util/logger.ts +165 -0
- package/src/util/xml.formatter.ts +20 -0
- package/src/version.ts +1 -0
- package/tsconfig.json +22 -0
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "contensis-cli",
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
|
+
"description": "A fully featured Contensis command line interface with a shell UI provides simple and intuitive ways to manage or profile your content in any NodeJS terminal.",
|
|
5
|
+
"repository": "https://github.com/contensis/node-cli",
|
|
6
|
+
"homepage": "https://github.com/contensis/node-cli/tree/main/packages/contensis-cli#readme",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"contensis": "./cli.js",
|
|
10
|
+
"contensis-cli": "./cli.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"prestart": "npm run build",
|
|
14
|
+
"start": "npm run cli",
|
|
15
|
+
"dev:shell": "npm run prestart && nodemon --watch dist --inspect=9229 ./dist/shell.js",
|
|
16
|
+
"prebuild": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
|
|
17
|
+
"build": "node esbuild.config.js",
|
|
18
|
+
"build:watch": "node esbuild.config.js --watch",
|
|
19
|
+
"cli": "node --inspect=9229 ./cli.js",
|
|
20
|
+
"postinstall": "npx patch-package",
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
|
+
},
|
|
23
|
+
"author": "Zengenti",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"app-root-path": "^3.1.0",
|
|
27
|
+
"chalk": "^4.1.2",
|
|
28
|
+
"commander": "^9.4.1",
|
|
29
|
+
"csv": "^6.1.0",
|
|
30
|
+
"dayjs": "^1.11.6",
|
|
31
|
+
"figlet": "^1.5.2",
|
|
32
|
+
"flat": "^5.0.2",
|
|
33
|
+
"inquirer-command-prompt": "^0.1.0",
|
|
34
|
+
"json2csv": "^5.0.7",
|
|
35
|
+
"jsonpath-mapper": "^1.1.0",
|
|
36
|
+
"keytar": "^7.9.0",
|
|
37
|
+
"lodash": "^4.17.21",
|
|
38
|
+
"migratortron": "^1.0.0-beta.14",
|
|
39
|
+
"node-fetch": "^2.6.7",
|
|
40
|
+
"patch-package": "^6.4.7",
|
|
41
|
+
"xml2js": "^0.4.23"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/figlet": "^1.5.4",
|
|
45
|
+
"@types/flat": "^5.0.2",
|
|
46
|
+
"@types/inquirer": "^8.2.1",
|
|
47
|
+
"@types/json2csv": "^5.0.3",
|
|
48
|
+
"@types/lodash": "^4.14.182",
|
|
49
|
+
"@types/node-fetch": "^2.6.1",
|
|
50
|
+
"@types/xml2js": "^0.4.11",
|
|
51
|
+
"esbuild": "^0.14.43",
|
|
52
|
+
"esbuild-node-externals": "^1.4.1",
|
|
53
|
+
"esbuild-plugin-glob": "^1.1.2",
|
|
54
|
+
"nodemon": "^2.0.18",
|
|
55
|
+
"rimraf": "^3.0.2",
|
|
56
|
+
"tsc-alias": "^1.6.9",
|
|
57
|
+
"typescript": "^4.7.3"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
diff --git a/node_modules/inquirer-command-prompt/index.js b/node_modules/inquirer-command-prompt/index.js
|
|
2
|
+
index 9192101..6c1133f 100644
|
|
3
|
+
--- a/node_modules/inquirer-command-prompt/index.js
|
|
4
|
+
+++ b/node_modules/inquirer-command-prompt/index.js
|
|
5
|
+
@@ -46,7 +46,7 @@ class CommandPrompt extends InputPrompt {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async initAutoCompletion(context, autoCompletion) {
|
|
9
|
+
- if (!autoCompleters[context]) {
|
|
10
|
+
+ // if (!autoCompleters[context]) {
|
|
11
|
+
if (thiz.isAsyncFunc(autoCompletion)) {
|
|
12
|
+
autoCompleters[context] = async l => this.asyncAutoCompleter(l, autoCompletion)
|
|
13
|
+
} else if (autoCompletion) {
|
|
14
|
+
@@ -54,7 +54,7 @@ class CommandPrompt extends InputPrompt {
|
|
15
|
+
} else {
|
|
16
|
+
autoCompleters[context] = () => []
|
|
17
|
+
}
|
|
18
|
+
- }
|
|
19
|
+
+ // }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static addToHistory(context, value) {
|
|
23
|
+
@@ -394,4 +394,3 @@ class CommandPrompt extends InputPrompt {
|
|
24
|
+
let thiz = CommandPrompt
|
|
25
|
+
|
|
26
|
+
module.exports = CommandPrompt
|
|
27
|
+
-
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
|
+
import { shell } from '~/shell';
|
|
4
|
+
import { project } from './globalOptions';
|
|
5
|
+
|
|
6
|
+
export const makeConnectCommand = () => {
|
|
7
|
+
const connect = new Command()
|
|
8
|
+
.command('connect')
|
|
9
|
+
.argument('<alias>', 'the Contensis Cloud alias to connect with')
|
|
10
|
+
.addOption(project)
|
|
11
|
+
.usage('<alias>')
|
|
12
|
+
.addHelpText(
|
|
13
|
+
'after',
|
|
14
|
+
`
|
|
15
|
+
Example call:
|
|
16
|
+
> connect example-dev`
|
|
17
|
+
)
|
|
18
|
+
.action(async (alias, opts) => {
|
|
19
|
+
await cliCommand(['connect', alias], opts).Connect(alias);
|
|
20
|
+
await shell().start();
|
|
21
|
+
});
|
|
22
|
+
return connect;
|
|
23
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
|
+
import { shell } from '~/shell';
|
|
4
|
+
|
|
5
|
+
export const makeCreateCommand = () => {
|
|
6
|
+
const create = new Command()
|
|
7
|
+
.command('create')
|
|
8
|
+
.showHelpAfterError(true)
|
|
9
|
+
.exitOverride();
|
|
10
|
+
|
|
11
|
+
create
|
|
12
|
+
.command('project')
|
|
13
|
+
.argument('<projectId>', 'the id of the project to create')
|
|
14
|
+
.usage('<projectId>')
|
|
15
|
+
.action(async (projectId: string, opts: any) => {
|
|
16
|
+
const project = await cliCommand(
|
|
17
|
+
['create', 'project', projectId],
|
|
18
|
+
opts
|
|
19
|
+
).SetProject(projectId);
|
|
20
|
+
if (project) await shell().start();
|
|
21
|
+
});
|
|
22
|
+
create
|
|
23
|
+
.command('key')
|
|
24
|
+
.argument('<"key name">', 'the name of the key to create')
|
|
25
|
+
.argument('["description"]', 'provide a description for the key (optional)')
|
|
26
|
+
.usage('<"key name"> ["description"] (both args in "double quotes")')
|
|
27
|
+
.addHelpText(
|
|
28
|
+
'after',
|
|
29
|
+
`
|
|
30
|
+
Example call:
|
|
31
|
+
> create key "my new key" "Created key for demonstration"\n`
|
|
32
|
+
)
|
|
33
|
+
.action(async (name: string, description: string, opts: any) => {
|
|
34
|
+
await cliCommand(['create', 'key', name], opts).CreateApiKey(
|
|
35
|
+
name,
|
|
36
|
+
description
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return create;
|
|
41
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Argument, Command } from 'commander';
|
|
2
|
+
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
|
+
import { mapContensisOpts } from './globalOptions';
|
|
4
|
+
|
|
5
|
+
export const makeGetCommand = () => {
|
|
6
|
+
const program = new Command()
|
|
7
|
+
.command('get')
|
|
8
|
+
.showHelpAfterError(true)
|
|
9
|
+
.exitOverride();
|
|
10
|
+
|
|
11
|
+
program
|
|
12
|
+
.command('contenttype')
|
|
13
|
+
.argument('<contentTypeId>', 'the API id of the content type to get')
|
|
14
|
+
.addHelpText(
|
|
15
|
+
'after',
|
|
16
|
+
`
|
|
17
|
+
Example call:
|
|
18
|
+
> get contenttype {contentTypeId} -o content-type-backup.json
|
|
19
|
+
`
|
|
20
|
+
)
|
|
21
|
+
.action(async (contentTypeId: string, opts) => {
|
|
22
|
+
await cliCommand(['get', 'contenttype'], opts).PrintContentType(
|
|
23
|
+
contentTypeId
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
program
|
|
27
|
+
.command('component')
|
|
28
|
+
.argument('<componentId>', 'the API id of the component to get')
|
|
29
|
+
.addHelpText(
|
|
30
|
+
'after',
|
|
31
|
+
`
|
|
32
|
+
Example call:
|
|
33
|
+
> get component {componentId} -o component-backup.json
|
|
34
|
+
`
|
|
35
|
+
)
|
|
36
|
+
.action(async (componentId: string, opts) => {
|
|
37
|
+
await cliCommand(['get', 'component'], opts).PrintComponent(componentId);
|
|
38
|
+
});
|
|
39
|
+
program
|
|
40
|
+
.command('entries')
|
|
41
|
+
.argument(
|
|
42
|
+
'[search phrase]',
|
|
43
|
+
'get entries with the search phrase, use quotes for multiple words'
|
|
44
|
+
)
|
|
45
|
+
.option('-i --id <id...>', 'the entry id to get')
|
|
46
|
+
.option(
|
|
47
|
+
'-d, --dependents',
|
|
48
|
+
'find and return any dependencies of all found entries'
|
|
49
|
+
)
|
|
50
|
+
.option(
|
|
51
|
+
'-fi, --fields <fields...>',
|
|
52
|
+
'limit the output fields on returned entries'
|
|
53
|
+
)
|
|
54
|
+
.option(
|
|
55
|
+
'-q, --zenql <zenql>',
|
|
56
|
+
'get entries with a supplied ZenQL statement'
|
|
57
|
+
)
|
|
58
|
+
.addHelpText(
|
|
59
|
+
'after',
|
|
60
|
+
`
|
|
61
|
+
Example call:
|
|
62
|
+
> get entries --zenql "sys.contentTypeId = blog" --fields entryTitle entryDescription sys.id --output ./blog-posts.csv --format csv
|
|
63
|
+
`
|
|
64
|
+
)
|
|
65
|
+
.action(async (phrase: string, opts, cmd) => {
|
|
66
|
+
// console.log('phrase: ', phrase, '\nopts:', JSON.stringify(opts, null, 2));
|
|
67
|
+
// console.log('opts:', JSON.stringify(opts, null, 2));
|
|
68
|
+
await cliCommand(
|
|
69
|
+
['get', 'entries'],
|
|
70
|
+
opts,
|
|
71
|
+
mapContensisOpts({ phrase, ...opts })
|
|
72
|
+
).GetEntries({
|
|
73
|
+
withDependents: opts.dependents,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const block = program
|
|
78
|
+
.command('block')
|
|
79
|
+
.argument('[blockId]', 'the block to get version details for')
|
|
80
|
+
.argument(
|
|
81
|
+
'[branch]',
|
|
82
|
+
'the branch of the block to get version details for',
|
|
83
|
+
'main'
|
|
84
|
+
)
|
|
85
|
+
.argument(
|
|
86
|
+
'[version]',
|
|
87
|
+
'get a specific version of the block pushed to the specified branch'
|
|
88
|
+
)
|
|
89
|
+
.action(async (blockId: string, branch: string, version: string, opts) => {
|
|
90
|
+
await cliCommand(['get', 'block'], opts).PrintBlockVersions(
|
|
91
|
+
blockId,
|
|
92
|
+
branch,
|
|
93
|
+
version
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const dataCenter = new Argument(
|
|
98
|
+
'[dataCenter]',
|
|
99
|
+
'the datacentre of the block to get logs for'
|
|
100
|
+
)
|
|
101
|
+
.choices(['hq', 'london', 'manchester'])
|
|
102
|
+
.default('hq');
|
|
103
|
+
|
|
104
|
+
block
|
|
105
|
+
.command('logs')
|
|
106
|
+
.argument('[blockId]', 'the block to get version logs for')
|
|
107
|
+
.argument(
|
|
108
|
+
'[branch]',
|
|
109
|
+
'the branch of the block to get version details for',
|
|
110
|
+
'main'
|
|
111
|
+
)
|
|
112
|
+
.argument(
|
|
113
|
+
'[version]',
|
|
114
|
+
'the version of the block pushed to the branch to get logs for',
|
|
115
|
+
'latest'
|
|
116
|
+
)
|
|
117
|
+
.addArgument(dataCenter)
|
|
118
|
+
.usage('get block logs [blockId] [branch] [version] [dataCenter]')
|
|
119
|
+
.action(
|
|
120
|
+
async (
|
|
121
|
+
blockId: string,
|
|
122
|
+
branch: string,
|
|
123
|
+
version: string,
|
|
124
|
+
dataCenter: 'hq' | 'manchester' | 'london',
|
|
125
|
+
opts
|
|
126
|
+
) => {
|
|
127
|
+
await cliCommand(['get', 'block', 'logs'], opts).PrintBlockLogs(
|
|
128
|
+
blockId,
|
|
129
|
+
branch,
|
|
130
|
+
version,
|
|
131
|
+
dataCenter
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return program;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const get = makeGetCommand();
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Command, Option } from 'commander';
|
|
2
|
+
import { url } from '~/util';
|
|
3
|
+
|
|
4
|
+
export const mapContensisOpts = (opts: any = {}) => ({
|
|
5
|
+
source:
|
|
6
|
+
opts.sourceCms || opts.sourceProjectId
|
|
7
|
+
? {
|
|
8
|
+
url: opts.sourceCms
|
|
9
|
+
? url(opts.sourceCms, 'website').cms
|
|
10
|
+
: (undefined as any),
|
|
11
|
+
project: opts.sourceProjectId || (undefined as any),
|
|
12
|
+
}
|
|
13
|
+
: undefined,
|
|
14
|
+
query:
|
|
15
|
+
opts.id || opts.phrase || opts.fields
|
|
16
|
+
? {
|
|
17
|
+
fields: opts.fields,
|
|
18
|
+
includeIds: opts.id,
|
|
19
|
+
searchTerm: opts.phrase,
|
|
20
|
+
}
|
|
21
|
+
: undefined,
|
|
22
|
+
zenQL: opts.zenql,
|
|
23
|
+
transformGuids: !opts.preserveGuids,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/* Output options */
|
|
27
|
+
const output = new Option(
|
|
28
|
+
'-o, --output <output>',
|
|
29
|
+
'save output to a file e.g. --output ./output.txt'
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const format = new Option(
|
|
33
|
+
'-f, --format <format>',
|
|
34
|
+
'format output as csv, json, xml or table (default)'
|
|
35
|
+
).choices(['csv', 'json', 'xml', 'table']);
|
|
36
|
+
|
|
37
|
+
/* Connect options */
|
|
38
|
+
const alias = new Option(
|
|
39
|
+
'-a --alias <alias>',
|
|
40
|
+
'the cloud CMS alias to connect your request with'
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export const project = new Option(
|
|
44
|
+
'-p --project-id <projectId>',
|
|
45
|
+
'the projectId to make your request with'
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
/* Authentication options */
|
|
49
|
+
const user = new Option(
|
|
50
|
+
'-u --user <user>',
|
|
51
|
+
'the username to authenticate your request with'
|
|
52
|
+
);
|
|
53
|
+
const password = new Option(
|
|
54
|
+
'-pw --password <password>',
|
|
55
|
+
'the password to use to login with (optional/insecure)'
|
|
56
|
+
);
|
|
57
|
+
const clientId = new Option(
|
|
58
|
+
'-id --client-id <clientId>',
|
|
59
|
+
'the clientId to authenticate your request with'
|
|
60
|
+
);
|
|
61
|
+
const sharedSecret = new Option(
|
|
62
|
+
'-s --shared-secret <sharedSecret>',
|
|
63
|
+
'the shared secret to use when logging in with a client id'
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
/* Entry get options */
|
|
67
|
+
const zenql = new Option(
|
|
68
|
+
'-q, --zenql <zenql>',
|
|
69
|
+
'get entries with a supplied ZenQL statement'
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const entryId = new Option('-i --id <id...>', 'the entry id to get');
|
|
73
|
+
|
|
74
|
+
/* Import options */
|
|
75
|
+
export const fromFile = new Option(
|
|
76
|
+
'-file --from-file <fromFile>',
|
|
77
|
+
'file path to import asset(s) from'
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
export const fromCms = new Option(
|
|
81
|
+
'-source --source-alias <fromCms>',
|
|
82
|
+
'the cloud CMS alias to import asset(s) from'
|
|
83
|
+
);
|
|
84
|
+
export const fromProject = new Option(
|
|
85
|
+
'-sp --source-project-id <fromProject>',
|
|
86
|
+
'the id of the Contensis project to import asset(s) from (Default: [last connected project])'
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
export const commit = new Option(
|
|
90
|
+
'--commit',
|
|
91
|
+
'omit and only add this flag when you are happy with the preview of the import'
|
|
92
|
+
).default(false);
|
|
93
|
+
|
|
94
|
+
export const addConnectOptions = (program: Command) =>
|
|
95
|
+
program.addOption(alias.hideHelp()).addOption(project.hideHelp());
|
|
96
|
+
|
|
97
|
+
export const addAuthenticationOptions = (program: Command) =>
|
|
98
|
+
program
|
|
99
|
+
.addOption(user.hideHelp())
|
|
100
|
+
.addOption(password.hideHelp())
|
|
101
|
+
.addOption(clientId.hideHelp())
|
|
102
|
+
.addOption(sharedSecret.hideHelp());
|
|
103
|
+
|
|
104
|
+
const addOutputAndFormatOptions = (program: Command) =>
|
|
105
|
+
program.addOption(output).addOption(format);
|
|
106
|
+
|
|
107
|
+
export const addImportOptions = (program: Command) => {
|
|
108
|
+
for (const command of program.commands) {
|
|
109
|
+
command.addOption(fromFile).addOption(fromCms).addOption(fromProject);
|
|
110
|
+
}
|
|
111
|
+
return program;
|
|
112
|
+
};
|
|
113
|
+
export const addGetEntryOptions = (program: Command) => {
|
|
114
|
+
for (const command of program.commands) {
|
|
115
|
+
command.addOption(entryId).addOption(zenql);
|
|
116
|
+
}
|
|
117
|
+
return program;
|
|
118
|
+
};
|
|
119
|
+
export const addGlobalOptions = (program: Command) => {
|
|
120
|
+
for (const command of program.commands) {
|
|
121
|
+
addOutputAndFormatOptions(command);
|
|
122
|
+
addConnectOptions(command);
|
|
123
|
+
addAuthenticationOptions(command);
|
|
124
|
+
}
|
|
125
|
+
return program;
|
|
126
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Argument, Command } from 'commander';
|
|
2
|
+
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
|
+
import { url } from '~/util';
|
|
4
|
+
import { commit, mapContensisOpts } from './globalOptions';
|
|
5
|
+
|
|
6
|
+
export const makeImportCommand = () => {
|
|
7
|
+
const program = new Command()
|
|
8
|
+
.command('import')
|
|
9
|
+
.showHelpAfterError(true)
|
|
10
|
+
.exitOverride();
|
|
11
|
+
|
|
12
|
+
program
|
|
13
|
+
.command('contenttypes')
|
|
14
|
+
.argument(
|
|
15
|
+
'[contentTypeIds]',
|
|
16
|
+
'Optional list of API id(s) of the content type(s) to import'
|
|
17
|
+
)
|
|
18
|
+
.addHelpText(
|
|
19
|
+
'after',
|
|
20
|
+
`
|
|
21
|
+
Example call:
|
|
22
|
+
> import contenttypes {contentTypeIds} --from-file contenttypes-backup.json
|
|
23
|
+
> import contenttypes {contentTypeIds} --source-alias example-dev
|
|
24
|
+
`
|
|
25
|
+
)
|
|
26
|
+
.action(async (contentTypeIds: string[], opts) => {
|
|
27
|
+
await cliCommand(['import', 'contenttypes'], opts).ImportContentTypes(
|
|
28
|
+
{
|
|
29
|
+
fromFile: opts.fromFile,
|
|
30
|
+
commit: opts.commit,
|
|
31
|
+
},
|
|
32
|
+
contentTypeIds
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
program
|
|
37
|
+
.command('components')
|
|
38
|
+
.argument(
|
|
39
|
+
'[componentIds]',
|
|
40
|
+
'Optional list of API id(s) of the component(s) to import'
|
|
41
|
+
)
|
|
42
|
+
.addHelpText(
|
|
43
|
+
'after',
|
|
44
|
+
`
|
|
45
|
+
Example call:
|
|
46
|
+
> import components {componentIds} --from-file component-backup.json
|
|
47
|
+
> import components {componentIds} --source-alias example-dev
|
|
48
|
+
`
|
|
49
|
+
)
|
|
50
|
+
.action(async (componentIds: string[], opts) => {
|
|
51
|
+
await cliCommand(['import', 'component'], opts).ImportComponents(
|
|
52
|
+
{
|
|
53
|
+
fromFile: opts.fromFile,
|
|
54
|
+
commit: opts.commit,
|
|
55
|
+
},
|
|
56
|
+
componentIds
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
program
|
|
61
|
+
.command('entries')
|
|
62
|
+
.argument(
|
|
63
|
+
'[search phrase]',
|
|
64
|
+
'get entries with the search phrase, use quotes for multiple words'
|
|
65
|
+
)
|
|
66
|
+
.addOption(commit)
|
|
67
|
+
.option(
|
|
68
|
+
'-preserve, --preserve-guids',
|
|
69
|
+
'include this flag when you are importing entries that you have previously exported and wish to update'
|
|
70
|
+
)
|
|
71
|
+
.addHelpText(
|
|
72
|
+
'after',
|
|
73
|
+
`
|
|
74
|
+
Example call:
|
|
75
|
+
> import entries --source-cms example-dev --source-project-id microsite --zenql "sys.contentTypeId = blog"
|
|
76
|
+
`
|
|
77
|
+
)
|
|
78
|
+
.action(async (phrase: string, opts, cmd) => {
|
|
79
|
+
await cliCommand(
|
|
80
|
+
['import', 'entries'],
|
|
81
|
+
opts,
|
|
82
|
+
mapContensisOpts({ phrase, ...opts })
|
|
83
|
+
).ImportEntries({ commit: opts.commit, fromFile: opts.fromFile });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return program;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const get = makeImportCommand();
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { Logger } from '~/util/logger';
|
|
3
|
+
import { LIB_VERSION } from '~/version';
|
|
4
|
+
import { makeConnectCommand } from './connect';
|
|
5
|
+
import { makeCreateCommand } from './create';
|
|
6
|
+
import { makeGetCommand } from './get';
|
|
7
|
+
import {
|
|
8
|
+
addAuthenticationOptions,
|
|
9
|
+
addConnectOptions,
|
|
10
|
+
addGetEntryOptions,
|
|
11
|
+
addGlobalOptions,
|
|
12
|
+
addImportOptions,
|
|
13
|
+
} from './globalOptions';
|
|
14
|
+
import { makeImportCommand } from './import';
|
|
15
|
+
import { makeListCommand } from './list';
|
|
16
|
+
import { makeLoginCommand } from './login';
|
|
17
|
+
import { makePushCommand } from './push';
|
|
18
|
+
import { makeRemoveCommand } from './remove';
|
|
19
|
+
import { makeSetCommand } from './set';
|
|
20
|
+
|
|
21
|
+
const commands = () => {
|
|
22
|
+
const program = new Command()
|
|
23
|
+
.name('contensis')
|
|
24
|
+
.version(LIB_VERSION)
|
|
25
|
+
.configureOutput({
|
|
26
|
+
writeErr: str => {
|
|
27
|
+
return str.toLowerCase().includes('error')
|
|
28
|
+
? Logger.error(`Command ${str}`)
|
|
29
|
+
: str.trim() && Logger.help(str);
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
.exitOverride()
|
|
33
|
+
.showHelpAfterError(true);
|
|
34
|
+
|
|
35
|
+
program.addCommand(
|
|
36
|
+
addAuthenticationOptions(makeConnectCommand()).copyInheritedSettings(
|
|
37
|
+
program
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
program.addCommand(
|
|
41
|
+
addGlobalOptions(
|
|
42
|
+
addImportOptions(makeCreateCommand())
|
|
43
|
+
).copyInheritedSettings(program)
|
|
44
|
+
);
|
|
45
|
+
program.addCommand(
|
|
46
|
+
addGlobalOptions(makeGetCommand()).copyInheritedSettings(program)
|
|
47
|
+
);
|
|
48
|
+
program.addCommand(
|
|
49
|
+
addGlobalOptions(
|
|
50
|
+
addGetEntryOptions(addImportOptions(makeImportCommand()))
|
|
51
|
+
).copyInheritedSettings(program)
|
|
52
|
+
);
|
|
53
|
+
program.addCommand(
|
|
54
|
+
addGlobalOptions(makeListCommand()).copyInheritedSettings(program)
|
|
55
|
+
);
|
|
56
|
+
program.addCommand(
|
|
57
|
+
addConnectOptions(makeLoginCommand()).copyInheritedSettings(program)
|
|
58
|
+
);
|
|
59
|
+
program.addCommand(
|
|
60
|
+
addGlobalOptions(makePushCommand()).copyInheritedSettings(program)
|
|
61
|
+
);
|
|
62
|
+
program.addCommand(
|
|
63
|
+
addGlobalOptions(makeRemoveCommand()).copyInheritedSettings(program)
|
|
64
|
+
);
|
|
65
|
+
program.addCommand(
|
|
66
|
+
addConnectOptions(makeSetCommand()).copyInheritedSettings(program)
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return program;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default commands;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
|
+
|
|
4
|
+
// projects
|
|
5
|
+
// content types
|
|
6
|
+
// components
|
|
7
|
+
// api keys
|
|
8
|
+
// roles
|
|
9
|
+
// webhooks
|
|
10
|
+
export const makeListCommand = () => {
|
|
11
|
+
const list = new Command()
|
|
12
|
+
.command('list')
|
|
13
|
+
.showHelpAfterError(true)
|
|
14
|
+
.exitOverride();
|
|
15
|
+
|
|
16
|
+
list
|
|
17
|
+
.command('envs')
|
|
18
|
+
.addHelpText(
|
|
19
|
+
'after',
|
|
20
|
+
`
|
|
21
|
+
Example call:
|
|
22
|
+
> list envs
|
|
23
|
+
`
|
|
24
|
+
)
|
|
25
|
+
.action(opts => {
|
|
26
|
+
cliCommand(['list', 'envs'], opts).PrintEnvironments();
|
|
27
|
+
});
|
|
28
|
+
list.command('projects').action(async opts => {
|
|
29
|
+
await cliCommand(['list', 'projects'], opts).PrintProjects();
|
|
30
|
+
});
|
|
31
|
+
list
|
|
32
|
+
.command('contenttypes')
|
|
33
|
+
.addHelpText(
|
|
34
|
+
'after',
|
|
35
|
+
`
|
|
36
|
+
Example call:
|
|
37
|
+
> list contenttypes -o ./output.json -f json
|
|
38
|
+
`
|
|
39
|
+
)
|
|
40
|
+
.action(async opts => {
|
|
41
|
+
await cliCommand(['list', 'contenttypes'], opts).PrintContentTypes();
|
|
42
|
+
});
|
|
43
|
+
list
|
|
44
|
+
.command('components')
|
|
45
|
+
.addHelpText(
|
|
46
|
+
'after',
|
|
47
|
+
`
|
|
48
|
+
Example call:
|
|
49
|
+
> list components -o ./output.json -f json
|
|
50
|
+
`
|
|
51
|
+
)
|
|
52
|
+
.action(async opts => {
|
|
53
|
+
await cliCommand(['list', 'components'], opts).PrintComponents();
|
|
54
|
+
});
|
|
55
|
+
list
|
|
56
|
+
.command('blocks')
|
|
57
|
+
.addHelpText(
|
|
58
|
+
'after',
|
|
59
|
+
`
|
|
60
|
+
Example call:
|
|
61
|
+
> list blocks
|
|
62
|
+
`
|
|
63
|
+
)
|
|
64
|
+
.action(async opts => {
|
|
65
|
+
await cliCommand(['list', 'blocks'], opts).PrintBlocks();
|
|
66
|
+
});
|
|
67
|
+
list
|
|
68
|
+
.command('keys')
|
|
69
|
+
.addHelpText(
|
|
70
|
+
'after',
|
|
71
|
+
`
|
|
72
|
+
Example call:
|
|
73
|
+
> list keys
|
|
74
|
+
`
|
|
75
|
+
)
|
|
76
|
+
.action(async opts => {
|
|
77
|
+
await cliCommand(['list', 'keys'], opts).PrintApiKeys();
|
|
78
|
+
});
|
|
79
|
+
list
|
|
80
|
+
.command('webhooks')
|
|
81
|
+
.argument('[name]', 'find webhooks matching the supplied name')
|
|
82
|
+
.option('-i --id <id...>', 'the subscription id(s) to get')
|
|
83
|
+
.action(async (name?: string, { id, ...opts }: any = {}) => {
|
|
84
|
+
await cliCommand(['list', 'webhooks'], opts).PrintWebhookSubscriptions(
|
|
85
|
+
id,
|
|
86
|
+
name
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
return list;
|
|
90
|
+
};
|