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
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import clone from 'lodash/cloneDeep';
|
|
4
|
+
import mergeWith from 'lodash/mergeWith';
|
|
5
|
+
import unionBy from 'lodash/unionBy';
|
|
6
|
+
import { isJson, tryParse, tryStringify } from '~/util';
|
|
7
|
+
import { Logger } from '~/util/logger';
|
|
8
|
+
|
|
9
|
+
class SessionCacheProvider {
|
|
10
|
+
private localFilePath: string;
|
|
11
|
+
private cache = {} as SessionCache;
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
this.localFilePath = path.join(__dirname, '../../environments.json');
|
|
15
|
+
this.cache = {
|
|
16
|
+
currentTimestamp: new Date().toISOString(),
|
|
17
|
+
environments: {},
|
|
18
|
+
history: [],
|
|
19
|
+
};
|
|
20
|
+
this.ReadCacheFromDisk();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private ReadCacheFromDisk = () => {
|
|
24
|
+
try {
|
|
25
|
+
if (fs.existsSync(this.localFilePath)) {
|
|
26
|
+
const raw = fs.readFileSync(this.localFilePath, 'utf-8');
|
|
27
|
+
if (isJson(raw)) this.cache = tryParse(raw);
|
|
28
|
+
} else {
|
|
29
|
+
this.WriteCacheToDisk();
|
|
30
|
+
}
|
|
31
|
+
} catch (ex) {
|
|
32
|
+
// Problem reading or parsing cache file
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
private WriteCacheToDisk = () => {
|
|
37
|
+
try {
|
|
38
|
+
fs.writeFileSync(this.localFilePath, JSON.stringify(this.cache, null, 2));
|
|
39
|
+
} catch (ex) {
|
|
40
|
+
// Problem writing session cache to file
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
Get = () => clone(this.cache);
|
|
45
|
+
|
|
46
|
+
Update = (updateContent: Partial<SessionCache>) => {
|
|
47
|
+
try {
|
|
48
|
+
this.cache = mergeWith(this.cache, updateContent, (val, src, key) => {
|
|
49
|
+
if (
|
|
50
|
+
key === 'history' &&
|
|
51
|
+
((src?.[0] &&
|
|
52
|
+
typeof src[0] === 'object' &&
|
|
53
|
+
'createdDate' in src[0]) ||
|
|
54
|
+
(val?.[0] && typeof val[0] === 'object' && 'createdDate' in val[0]))
|
|
55
|
+
) {
|
|
56
|
+
return unionBy(val, src, 'createdDate');
|
|
57
|
+
}
|
|
58
|
+
if (key === 'projects')
|
|
59
|
+
return Array.isArray(val) ? [...new Set([...val, ...src])] : src;
|
|
60
|
+
|
|
61
|
+
if (Array.isArray(val)) return val.concat(src);
|
|
62
|
+
});
|
|
63
|
+
this.cache.currentTimestamp = new Date().toISOString();
|
|
64
|
+
this.WriteCacheToDisk();
|
|
65
|
+
} catch (ex: any) {
|
|
66
|
+
// Problem merging cache data for update
|
|
67
|
+
Logger.error(`Problem updating environments.json`);
|
|
68
|
+
Logger.error(ex);
|
|
69
|
+
}
|
|
70
|
+
return this.Get();
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default SessionCacheProvider;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { path as appRoot } from 'app-root-path';
|
|
4
|
+
import { tryParse } from '~/util';
|
|
5
|
+
|
|
6
|
+
export const readJsonFile = <T>(filePath: string) => {
|
|
7
|
+
const file = readFile(filePath);
|
|
8
|
+
if (file) return tryParse(file) as T | string;
|
|
9
|
+
return undefined;
|
|
10
|
+
};
|
|
11
|
+
export const readFile = (filePath: string) => {
|
|
12
|
+
const directoryPath = localPath(filePath);
|
|
13
|
+
if (fs.existsSync(directoryPath)) {
|
|
14
|
+
const file = fs.readFileSync(directoryPath, 'utf8');
|
|
15
|
+
return file;
|
|
16
|
+
} else {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const readFiles = (directory: string) => {
|
|
22
|
+
const directoryPath = localPath(directory);
|
|
23
|
+
if (fs.existsSync(directoryPath)) {
|
|
24
|
+
const files = fs.readdirSync(directoryPath);
|
|
25
|
+
return files;
|
|
26
|
+
} else {
|
|
27
|
+
fs.mkdirSync(directoryPath, { recursive: true });
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const writeFile = (filePath: string, content: string) => {
|
|
33
|
+
const directoryPath = localPath(filePath);
|
|
34
|
+
fs.writeFileSync(directoryPath, content, { encoding: 'utf-8' });
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const removeFile = (filePath: string) => {
|
|
38
|
+
const directoryPath = localPath(filePath);
|
|
39
|
+
if (fs.existsSync(directoryPath)) {
|
|
40
|
+
fs.rmSync(directoryPath);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const moveFile = (file: string, fromPath: string, toPath: string) => {
|
|
45
|
+
const from = path.join(appRoot, `${fromPath}${file}`);
|
|
46
|
+
const to = path.join(appRoot, `${toPath}${file}`);
|
|
47
|
+
if (fs.existsSync(from)) {
|
|
48
|
+
checkDir(toPath);
|
|
49
|
+
// if (!fs.existsSync(toPath)) fs.mkdirSync(toPath, { recursive: true });
|
|
50
|
+
|
|
51
|
+
fs.rename(from, to, err => {
|
|
52
|
+
if (err)
|
|
53
|
+
console.error(
|
|
54
|
+
`Could not rename file "${file}" from: ${fromPath} to: ${toPath}`,
|
|
55
|
+
err
|
|
56
|
+
);
|
|
57
|
+
console.info(`Renamed file "${file}" from: ${fromPath} to: ${toPath}`);
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
console.error(
|
|
61
|
+
`Could not rename file "${file}" from: ${fromPath} to: ${toPath}\nFile does not exist!`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const checkDir = (filePath: string) => {
|
|
67
|
+
const directoryPath = path.dirname(localPath(filePath));
|
|
68
|
+
if (!fs.existsSync(directoryPath))
|
|
69
|
+
fs.mkdirSync(directoryPath, { recursive: true });
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const localPath = (filePath: string) => path.join(appRoot, filePath);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { NodejsClient } from 'contensis-management-api/lib/client';
|
|
2
|
+
import { ClientGrants, ClientGrantType } from 'contensis-core-api';
|
|
3
|
+
|
|
4
|
+
class ContensisAuthService {
|
|
5
|
+
private client: NodejsClient;
|
|
6
|
+
|
|
7
|
+
constructor({
|
|
8
|
+
clientId = '',
|
|
9
|
+
clientSecret = '',
|
|
10
|
+
username,
|
|
11
|
+
password,
|
|
12
|
+
refreshToken,
|
|
13
|
+
projectId,
|
|
14
|
+
rootUrl,
|
|
15
|
+
}: {
|
|
16
|
+
clientId?: string;
|
|
17
|
+
clientSecret?: string;
|
|
18
|
+
username?: string;
|
|
19
|
+
password?: string;
|
|
20
|
+
refreshToken?: string;
|
|
21
|
+
projectId: string;
|
|
22
|
+
rootUrl: string;
|
|
23
|
+
}) {
|
|
24
|
+
let credentials: {
|
|
25
|
+
clientType: ClientGrantType;
|
|
26
|
+
clientDetails: ClientGrants;
|
|
27
|
+
};
|
|
28
|
+
if (username && password) {
|
|
29
|
+
credentials = {
|
|
30
|
+
clientType: 'contensis_classic',
|
|
31
|
+
clientDetails: {
|
|
32
|
+
username,
|
|
33
|
+
password,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
} else if (refreshToken) {
|
|
37
|
+
credentials = {
|
|
38
|
+
clientType: 'contensis_classic_refresh_token',
|
|
39
|
+
clientDetails: {
|
|
40
|
+
refreshToken,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
credentials = {
|
|
45
|
+
clientType: 'client_credentials',
|
|
46
|
+
clientDetails: {
|
|
47
|
+
clientId,
|
|
48
|
+
clientSecret,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.client = NodejsClient.create({
|
|
54
|
+
...credentials,
|
|
55
|
+
projectId,
|
|
56
|
+
rootUrl,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
BearerToken = async () =>
|
|
61
|
+
this.client.bearerToken || (await this.client.ensureBearerToken());
|
|
62
|
+
RefreshToken = async () =>
|
|
63
|
+
!this.client.isRefreshTokenExpired() ? this.client.refreshToken : null;
|
|
64
|
+
|
|
65
|
+
/* PROJECTS */
|
|
66
|
+
ProjectId = () => this.client.clientConfig.projectId;
|
|
67
|
+
RootUrl = () => this.client.clientConfig.rootUrl;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default ContensisAuthService;
|