contensis-cli 1.0.0-beta.10 → 1.0.0-beta.100
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/README.md +1146 -78
- package/cli.js +3 -0
- package/dist/commands/connect.js +3 -3
- package/dist/commands/connect.js.map +2 -2
- package/dist/commands/create.js +45 -10
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/dev.js +71 -0
- package/dist/commands/dev.js.map +7 -0
- package/dist/commands/diff.js +57 -0
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/execute.js +103 -0
- package/dist/commands/execute.js.map +7 -0
- package/dist/commands/get.js +169 -32
- package/dist/commands/get.js.map +3 -3
- package/dist/commands/globalOptions.js +37 -12
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +65 -12
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/index.js +22 -2
- package/dist/commands/index.js.map +2 -2
- package/dist/commands/list.js +53 -10
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/login.js +2 -2
- package/dist/commands/login.js.map +2 -2
- package/dist/commands/push.js +17 -13
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/remove.js +51 -8
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +139 -12
- package/dist/commands/set.js.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/localisation/en-GB.js +297 -49
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js +56 -0
- package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js.map +7 -0
- package/dist/mappers/DevInit-to-CIWorkflow.js +374 -0
- package/dist/mappers/DevInit-to-CIWorkflow.js.map +7 -0
- package/dist/mappers/DevInit-to-RolePermissions.js +56 -0
- package/dist/mappers/DevInit-to-RolePermissions.js.map +7 -0
- package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js +56 -0
- package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js.map +7 -0
- package/dist/models/CliService.d.js +17 -0
- package/dist/models/CliService.d.js.map +7 -0
- package/dist/models/DevService.d.js +17 -0
- package/dist/models/DevService.d.js.map +7 -0
- package/dist/providers/CredentialProvider.js +46 -14
- package/dist/providers/CredentialProvider.js.map +3 -3
- package/dist/providers/SessionCacheProvider.js +21 -1
- package/dist/providers/SessionCacheProvider.js.map +2 -2
- package/dist/providers/file-provider.js +12 -6
- package/dist/providers/file-provider.js.map +3 -3
- package/dist/services/ContensisCliService.js +1211 -420
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/services/ContensisDevService.js +368 -0
- package/dist/services/ContensisDevService.js.map +7 -0
- package/dist/services/ContensisRoleService.js +114 -0
- package/dist/services/ContensisRoleService.js.map +7 -0
- package/dist/shell.js +58 -18
- package/dist/shell.js.map +3 -3
- package/dist/util/console.printer.js +171 -55
- package/dist/util/console.printer.js.map +2 -2
- package/dist/util/diff.js +116 -0
- package/dist/util/diff.js.map +7 -0
- package/dist/util/dotenv.js +57 -0
- package/dist/util/dotenv.js.map +7 -0
- package/dist/util/find.js +31 -0
- package/dist/util/find.js.map +7 -0
- package/dist/util/git.js +128 -0
- package/dist/util/git.js.map +7 -0
- package/dist/util/index.js +8 -2
- package/dist/util/index.js.map +3 -3
- package/dist/util/logger.js +90 -29
- package/dist/util/logger.js.map +3 -3
- package/dist/util/os.js +42 -0
- package/dist/util/os.js.map +7 -0
- package/dist/util/timers.js +49 -0
- package/dist/util/timers.js.map +7 -0
- package/dist/util/yaml.js +45 -0
- package/dist/util/yaml.js.map +7 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/esbuild.config.js +3 -1
- package/package.json +14 -3
- package/src/commands/connect.ts +3 -2
- package/src/commands/create.ts +61 -8
- package/src/commands/dev.ts +69 -0
- package/src/commands/diff.ts +41 -0
- package/src/commands/execute.ts +117 -0
- package/src/commands/get.ts +242 -28
- package/src/commands/globalOptions.ts +42 -12
- package/src/commands/import.ts +83 -8
- package/src/commands/index.ts +22 -1
- package/src/commands/list.ts +85 -11
- package/src/commands/login.ts +2 -1
- package/src/commands/push.ts +18 -11
- package/src/commands/remove.ts +66 -4
- package/src/commands/set.ts +189 -9
- package/src/index.ts +1 -4
- package/src/localisation/en-GB.ts +428 -66
- package/src/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.ts +44 -0
- package/src/mappers/DevInit-to-CIWorkflow.ts +526 -0
- package/src/mappers/DevInit-to-RolePermissions.ts +32 -0
- package/src/mappers/DevRequests-to-RequestHanderSiteConfigYaml.ts +44 -0
- package/src/models/CliService.d.ts +36 -0
- package/src/models/DevService.d.ts +40 -0
- package/src/models/JsModules.d.ts +2 -0
- package/src/providers/CredentialProvider.ts +51 -18
- package/src/providers/SessionCacheProvider.ts +29 -2
- package/src/providers/file-provider.ts +17 -6
- package/src/services/ContensisCliService.ts +1532 -508
- package/src/services/ContensisDevService.ts +434 -0
- package/src/services/ContensisRoleService.ts +108 -0
- package/src/shell.ts +68 -18
- package/src/util/console.printer.ts +240 -78
- package/src/util/diff.ts +124 -0
- package/src/util/dotenv.ts +37 -0
- package/src/util/find.ts +8 -0
- package/src/util/git.ts +131 -0
- package/src/util/index.ts +16 -7
- package/src/util/logger.ts +145 -31
- package/src/util/os.ts +12 -0
- package/src/util/timers.ts +24 -0
- package/src/util/yaml.ts +13 -0
- package/src/version.ts +1 -1
package/src/util/find.ts
ADDED
package/src/util/git.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import giturl from 'giturl';
|
|
2
|
+
import hostedGitInfo from 'hosted-git-info';
|
|
3
|
+
import parseGitConfig from 'parse-git-config';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
import { linuxSlash } from './os';
|
|
7
|
+
import { readFile, readFiles } from '~/providers/file-provider';
|
|
8
|
+
|
|
9
|
+
const GITLAB_CI_FILENAME = '.gitlab-ci.yml';
|
|
10
|
+
|
|
11
|
+
type GitConfig = parseGitConfig.Config;
|
|
12
|
+
|
|
13
|
+
export type GitTypes = hostedGitInfo.Hosts;
|
|
14
|
+
|
|
15
|
+
export class GitHelper {
|
|
16
|
+
private gitRepoPath: string;
|
|
17
|
+
private ciFile?: string;
|
|
18
|
+
|
|
19
|
+
config = {} as GitConfig;
|
|
20
|
+
info: hostedGitInfo | undefined;
|
|
21
|
+
home: string | undefined;
|
|
22
|
+
|
|
23
|
+
set ciFileName(fileName: string) {
|
|
24
|
+
this.ciFile = fileName;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get ciFileName() {
|
|
28
|
+
return (
|
|
29
|
+
this.ciFile ||
|
|
30
|
+
(this.workflows
|
|
31
|
+
? this.type === 'github'
|
|
32
|
+
? this.workflows.length > 1
|
|
33
|
+
? '[multiple workflows]'
|
|
34
|
+
: this.workflows?.[0]
|
|
35
|
+
: GITLAB_CI_FILENAME
|
|
36
|
+
: '[unknown]')
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
get ciFilePath() {
|
|
40
|
+
return `${this.gitRepoPath}/${this.ciFileName}`;
|
|
41
|
+
}
|
|
42
|
+
get name() {
|
|
43
|
+
return (
|
|
44
|
+
this.info?.project || this.home?.split('/').pop() || '[set arg --name]'
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
get originUrl() {
|
|
48
|
+
return this.config.remote.origin.url;
|
|
49
|
+
}
|
|
50
|
+
get secretsUri() {
|
|
51
|
+
return `${
|
|
52
|
+
this.type === 'github'
|
|
53
|
+
? `${this.home}/settings/secrets/actions`
|
|
54
|
+
: `${this.home}/-/settings/ci_cd`
|
|
55
|
+
}`;
|
|
56
|
+
}
|
|
57
|
+
get type() {
|
|
58
|
+
return this.info?.type || this.hostType();
|
|
59
|
+
}
|
|
60
|
+
get workflows() {
|
|
61
|
+
return this.type === 'github'
|
|
62
|
+
? this.githubWorkflows()
|
|
63
|
+
: this.gitlabWorkflow();
|
|
64
|
+
}
|
|
65
|
+
constructor(gitRepoPath: string = process.cwd()) {
|
|
66
|
+
this.gitRepoPath = gitRepoPath;
|
|
67
|
+
this.config = this.gitConfig();
|
|
68
|
+
this.home = giturl.parse(this.originUrl);
|
|
69
|
+
this.info = this.gitInfo();
|
|
70
|
+
// console.log(this.config);
|
|
71
|
+
// console.log(this.home);
|
|
72
|
+
// console.log(this.info);
|
|
73
|
+
}
|
|
74
|
+
gitcwd = () => path.join(this.gitRepoPath);
|
|
75
|
+
gitInfo = (url: string = this.originUrl) => hostedGitInfo.fromUrl(url);
|
|
76
|
+
hostType = (url: string = this.originUrl): GitTypes => {
|
|
77
|
+
if (url.includes('github.com')) return 'github';
|
|
78
|
+
return 'gitlab';
|
|
79
|
+
// if (url.includes('gitlab.com')) return 'gl';
|
|
80
|
+
// if (url.includes('gitlab.zengenti.com')) return 'gl';
|
|
81
|
+
};
|
|
82
|
+
gitConfig = (cwd = this.gitRepoPath) => {
|
|
83
|
+
// Find .git/config in project cwd
|
|
84
|
+
const config = parseGitConfig.sync({
|
|
85
|
+
path: '.git/config',
|
|
86
|
+
expandKeys: true,
|
|
87
|
+
});
|
|
88
|
+
// console.log(cwd, config);
|
|
89
|
+
if (Object.keys(config || {}).length) return config;
|
|
90
|
+
|
|
91
|
+
// Recursively check the directory heirarchy for existance of a .git/config
|
|
92
|
+
const pathParts = linuxSlash(cwd).split('/');
|
|
93
|
+
for (let i = 1; i <= pathParts.length; i++) {
|
|
94
|
+
const relPath = `${Array(i).fill('..').join('/')}/.git/config`;
|
|
95
|
+
// Does not appear to work when using a shortened cwd, using relative path instead
|
|
96
|
+
const config = parseGitConfig.sync({
|
|
97
|
+
path: relPath,
|
|
98
|
+
expandKeys: true,
|
|
99
|
+
});
|
|
100
|
+
// console.log(relPath, config);
|
|
101
|
+
if (Object.keys(config || {}).length) {
|
|
102
|
+
this.gitRepoPath = path.join(
|
|
103
|
+
this.gitRepoPath,
|
|
104
|
+
Array(i).fill('..').join('/')
|
|
105
|
+
);
|
|
106
|
+
return config;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return config;
|
|
110
|
+
};
|
|
111
|
+
githubWorkflows = () => {
|
|
112
|
+
const workflowPath = path.join(this.gitcwd(), '.github/workflows');
|
|
113
|
+
const workflowFiles = readFiles(workflowPath, false);
|
|
114
|
+
const addFolderSuffix = (files: string[]) =>
|
|
115
|
+
files.map(f => `.github/workflows/${f}`);
|
|
116
|
+
|
|
117
|
+
if (workflowFiles.some(f => f.includes('build'))) {
|
|
118
|
+
return addFolderSuffix(workflowFiles.filter(f => f.includes('build')));
|
|
119
|
+
} else {
|
|
120
|
+
return addFolderSuffix(workflowFiles);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
gitlabWorkflow = (ciFileName = GITLAB_CI_FILENAME) => {
|
|
124
|
+
const workflowPath = this.gitcwd();
|
|
125
|
+
const workflowFilePath = path.join(workflowPath, ciFileName);
|
|
126
|
+
const workflowFile = readFile(workflowFilePath);
|
|
127
|
+
// console.log(ciFileName, workflowFile);
|
|
128
|
+
|
|
129
|
+
return workflowFile;
|
|
130
|
+
};
|
|
131
|
+
}
|
package/src/util/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import mergeWith from 'lodash/mergeWith';
|
|
2
2
|
import { Logger } from './logger';
|
|
3
|
+
import { LogMessages as enGB } from '../localisation/en-GB.js';
|
|
3
4
|
|
|
4
5
|
export const isSharedSecret = (str = '') =>
|
|
5
6
|
str.length > 80 && str.split('-').length === 3 ? str : undefined;
|
|
@@ -7,7 +8,7 @@ export const isSharedSecret = (str = '') =>
|
|
|
7
8
|
export const isPassword = (str = '') =>
|
|
8
9
|
!isSharedSecret(str) ? str : undefined;
|
|
9
10
|
|
|
10
|
-
export const tryParse = (str:
|
|
11
|
+
export const tryParse = (str: any) => {
|
|
11
12
|
try {
|
|
12
13
|
return typeof str === 'object' ? str : JSON.parse(str);
|
|
13
14
|
} catch (e) {
|
|
@@ -26,6 +27,9 @@ export const tryStringify = (obj: any) => {
|
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
|
|
30
|
+
export const isSysError = (error: any): error is Error =>
|
|
31
|
+
error?.message !== undefined && error.stack;
|
|
32
|
+
|
|
29
33
|
export const isUuid = (str: string) => {
|
|
30
34
|
// Regular expression to check if string is a valid UUID
|
|
31
35
|
const regexExp =
|
|
@@ -50,12 +54,17 @@ export const url = (alias: string, project: string) => {
|
|
|
50
54
|
};
|
|
51
55
|
|
|
52
56
|
export const Logging = async (language = 'en-GB') => {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
const defaultMessages = enGB;
|
|
58
|
+
// const { LogMessages: defaultMessages } = await import(
|
|
59
|
+
// `../localisation/en-GB.js`
|
|
60
|
+
// );
|
|
61
|
+
let localisedMessages = defaultMessages;
|
|
62
|
+
|
|
63
|
+
if (language === 'en-GB') {
|
|
64
|
+
// Using a variable import e.g. `import(`../localisation/${language}.js`);`
|
|
65
|
+
// does not play well with packaged executables
|
|
66
|
+
// So we have to hard code the import for each language individually
|
|
67
|
+
}
|
|
59
68
|
return {
|
|
60
69
|
messages: mergeWith(
|
|
61
70
|
localisedMessages,
|
package/src/util/logger.ts
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import dateFormat from 'dateformat';
|
|
4
4
|
import deepCleaner from 'deep-cleaner';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import { ansiEscapeCodes, first, strlen } from 'printable-characters';
|
|
6
|
+
// import ProgressBar from 'progress';
|
|
7
|
+
import { isSysError, tryStringify } from '.';
|
|
7
8
|
|
|
8
9
|
type LogMethod = (content: string) => void;
|
|
9
|
-
type LogErrorMethod = (content: string, err?: any) => void;
|
|
10
|
-
type LogJsonMethod = (content: any) => void;
|
|
10
|
+
type LogErrorMethod = (content: string, err?: any, newline?: string) => void;
|
|
11
|
+
type LogJsonMethod = (content: any, depth?: number, indent?: string) => void;
|
|
12
|
+
type LogJsonDepthMethod = (content: any, depth?: number) => void;
|
|
11
13
|
type LogArrayMethod = (contentArray: string[]) => void;
|
|
12
14
|
type LogErrorFunc = (
|
|
13
15
|
err: any,
|
|
@@ -36,12 +38,16 @@ export class Logger {
|
|
|
36
38
|
)} ${content}`;
|
|
37
39
|
console.log(message);
|
|
38
40
|
};
|
|
39
|
-
static error: LogErrorMethod = (content, err) => {
|
|
41
|
+
static error: LogErrorMethod = (content, err, newline = '\n') => {
|
|
40
42
|
const message = `${Logger.getPrefix()} ${Logger.errorText(
|
|
41
43
|
`${Logger.isUserTerminal ? '❌' : '[ERROR]'} ${content}${
|
|
42
|
-
err
|
|
44
|
+
err
|
|
45
|
+
? `\n\n${Logger.infoText(
|
|
46
|
+
isSysError(err) ? err.toString() : JSON.stringify(err, null, 2)
|
|
47
|
+
)}`
|
|
48
|
+
: ''
|
|
43
49
|
}`
|
|
44
|
-
)}
|
|
50
|
+
)}${newline}`;
|
|
45
51
|
if (progress.active) progress.current.interrupt(message);
|
|
46
52
|
else console.log(message);
|
|
47
53
|
};
|
|
@@ -83,7 +89,16 @@ export class Logger {
|
|
|
83
89
|
else console.log(message);
|
|
84
90
|
progress.current.interrupt(message);
|
|
85
91
|
};
|
|
86
|
-
static
|
|
92
|
+
static debug: LogMethod = content => {
|
|
93
|
+
if (['true', '1'].includes(process.env.debug || '')) {
|
|
94
|
+
const message = `${Logger.getPrefix()} ${
|
|
95
|
+
Logger.isUserTerminal ? chalk.bgGrey(' ⚙ ') : '[DEBUG]'
|
|
96
|
+
} ${Logger.infoText(content)}`;
|
|
97
|
+
if (progress.active) progress.current.interrupt(message);
|
|
98
|
+
else console.log(message);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
static json: LogJsonDepthMethod = (content, depth = 9) =>
|
|
87
102
|
console.dir(deepCleaner(content), { colors: true, depth });
|
|
88
103
|
static mixed: LogArrayMethod = contentArray =>
|
|
89
104
|
console.log(`${Logger.getPrefix()} ${contentArray.join(' ')}`);
|
|
@@ -91,13 +106,44 @@ export class Logger {
|
|
|
91
106
|
Logger.raw(` ${Logger.infoText(`-------------------------------------`)}`);
|
|
92
107
|
|
|
93
108
|
static object: LogJsonMethod = content => {
|
|
94
|
-
for (const [key, value] of Object.entries(content)) {
|
|
109
|
+
for (const [key, value] of Object.entries(content || {})) {
|
|
95
110
|
if (value && typeof value === 'object') {
|
|
96
111
|
Logger.raw(` ${chalk.bold.grey(key)}:`);
|
|
97
112
|
if (key === 'fields' && Array.isArray(value)) {
|
|
98
113
|
for (const field of value || []) {
|
|
99
114
|
Logger.raw(
|
|
100
|
-
` ${chalk.bold(field.id)}
|
|
115
|
+
` ${chalk.bold(field.id)}${
|
|
116
|
+
field.id === content.entryTitleField
|
|
117
|
+
? '**'
|
|
118
|
+
: field.validations.minCount?.value ||
|
|
119
|
+
typeof field.validations.required?.message !== 'undefined'
|
|
120
|
+
? '*'
|
|
121
|
+
: ''
|
|
122
|
+
}: ${chalk.grey(
|
|
123
|
+
`${field.dataType}${
|
|
124
|
+
field.dataFormat
|
|
125
|
+
? `<${
|
|
126
|
+
Array.isArray(
|
|
127
|
+
field.validations.allowedFieldTypes?.fields
|
|
128
|
+
)
|
|
129
|
+
? `composer[${field.validations.allowedFieldTypes.fields
|
|
130
|
+
.map((f: any) => f.id)
|
|
131
|
+
.join(' | ')}]`
|
|
132
|
+
: field.dataFormat
|
|
133
|
+
}${
|
|
134
|
+
field.dataFormat === 'entry'
|
|
135
|
+
? `, ${field.validations.allowedContentTypes.contentTypes.join(
|
|
136
|
+
' | '
|
|
137
|
+
)}`
|
|
138
|
+
: ''
|
|
139
|
+
}>`
|
|
140
|
+
: ''
|
|
141
|
+
}${
|
|
142
|
+
field.validations.maxLength?.value
|
|
143
|
+
? `(${field.validations.maxLength.value})`
|
|
144
|
+
: ''
|
|
145
|
+
}`
|
|
146
|
+
)}`
|
|
101
147
|
);
|
|
102
148
|
}
|
|
103
149
|
} else if (key === 'groups' && Array.isArray(value)) {
|
|
@@ -114,20 +160,63 @@ export class Logger {
|
|
|
114
160
|
);
|
|
115
161
|
}
|
|
116
162
|
} else {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
163
|
+
Logger.objectRecurse(value, 3, ' ');
|
|
164
|
+
// for (const [innerkey, innervalue] of Object.entries(value)) {
|
|
165
|
+
// if (innervalue && typeof innervalue === 'object') {
|
|
166
|
+
// Logger.raw(` ${chalk.bold.grey(innerkey)}:`);
|
|
167
|
+
// console.table(innervalue);
|
|
168
|
+
// } else if (
|
|
169
|
+
// typeof innervalue !== 'undefined' &&
|
|
170
|
+
// innervalue !== null
|
|
171
|
+
// ) {
|
|
172
|
+
// Logger.raw(` ${chalk.bold.grey(innerkey)}: ${innervalue}`);
|
|
173
|
+
// }
|
|
174
|
+
// }
|
|
175
|
+
}
|
|
176
|
+
} else if (typeof value !== 'undefined' && value !== null) {
|
|
177
|
+
const valueText =
|
|
178
|
+
key === 'id' && typeof value === 'string'
|
|
179
|
+
? Logger.highlightText(value)
|
|
180
|
+
: value;
|
|
181
|
+
Logger.raw(` ${chalk.bold.grey(key)}: ${valueText}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
static objectRecurse: LogJsonMethod = (content, depth = 3, indent = '') => {
|
|
187
|
+
if (Array.isArray(content)) {
|
|
188
|
+
for (const item of content) {
|
|
189
|
+
if (item && typeof item === 'object') {
|
|
190
|
+
if (Array.isArray(item) && depth > 3)
|
|
191
|
+
Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
|
|
192
|
+
else Logger.objectRecurse(item, depth + 1, `${indent} `);
|
|
193
|
+
} else Logger.raw(`${indent}${item}`);
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
let pos = 0;
|
|
197
|
+
for (const [key, value] of Object.entries(content)) {
|
|
198
|
+
const thisIndent =
|
|
199
|
+
pos === 0 ? `${indent.substring(0, indent.length - 2)}- ` : indent;
|
|
200
|
+
if (Array.isArray(value)) {
|
|
201
|
+
if (value.length) Logger.raw(`${thisIndent}${chalk.bold.grey(key)}:`);
|
|
202
|
+
for (const item of value) {
|
|
203
|
+
if (item && typeof item === 'object') {
|
|
204
|
+
if (Array.isArray(item) && depth > 3)
|
|
205
|
+
Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
|
|
206
|
+
else Logger.objectRecurse(item, depth + 1, `${indent} `);
|
|
207
|
+
} else {
|
|
208
|
+
Logger.raw(`${indent} ${item}`);
|
|
126
209
|
}
|
|
127
210
|
}
|
|
211
|
+
} else if (value && typeof value === 'object') {
|
|
212
|
+
Logger.raw(`${indent}${chalk.bold.grey(key)}:`);
|
|
213
|
+
|
|
214
|
+
Logger.objectRecurse(value, depth + 1, `${indent} `);
|
|
215
|
+
// console.table(value);
|
|
216
|
+
} else if (typeof value !== 'undefined' && value !== null) {
|
|
217
|
+
Logger.raw(`${thisIndent}${chalk.bold.grey(key)}: ${value}`);
|
|
128
218
|
}
|
|
129
|
-
|
|
130
|
-
Logger.raw(` ${chalk.bold.grey(key)}: ${value}`);
|
|
219
|
+
pos++;
|
|
131
220
|
}
|
|
132
221
|
}
|
|
133
222
|
};
|
|
@@ -135,6 +224,26 @@ export class Logger {
|
|
|
135
224
|
if (progress.active) progress.current.interrupt(content);
|
|
136
225
|
else console.log(content);
|
|
137
226
|
};
|
|
227
|
+
|
|
228
|
+
static limits = (content: string, displayLength = 30) => {
|
|
229
|
+
const consoleWidth = process.stdout.columns;
|
|
230
|
+
console.info(
|
|
231
|
+
consoleWidth
|
|
232
|
+
? content
|
|
233
|
+
.split('\n')
|
|
234
|
+
.slice(0, consoleWidth ? displayLength : undefined)
|
|
235
|
+
.map((line: string) =>
|
|
236
|
+
consoleWidth && strlen(line) > consoleWidth
|
|
237
|
+
? first(line, consoleWidth)
|
|
238
|
+
: line
|
|
239
|
+
)
|
|
240
|
+
.join('\n')
|
|
241
|
+
: content.replace(ansiEscapeCodes, '')
|
|
242
|
+
);
|
|
243
|
+
const tableArray = content.split('\n');
|
|
244
|
+
if (consoleWidth && tableArray.length > displayLength)
|
|
245
|
+
console.info(`\n`, `- and ${tableArray.length - displayLength} more...`);
|
|
246
|
+
};
|
|
138
247
|
}
|
|
139
248
|
|
|
140
249
|
export const logError: LogErrorFunc = (
|
|
@@ -144,22 +253,27 @@ export const logError: LogErrorFunc = (
|
|
|
144
253
|
) => {
|
|
145
254
|
Logger[level](msg || err.message || err?.data?.message || err.Message);
|
|
146
255
|
(Array.isArray(err) ? err : [err]).map((error: AppError) => {
|
|
147
|
-
if ('
|
|
256
|
+
if (typeof error === 'string') {
|
|
257
|
+
Logger.raw(`${Logger.infoText(error)}\n`);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if ('stack' in error) Logger.raw(` ${Logger.infoText(error.stack)}\n`);
|
|
148
261
|
if ('data' in error)
|
|
149
|
-
Logger.raw(` ${Logger.infoText(tryStringify(error.data))}`);
|
|
262
|
+
Logger.raw(` ${Logger.infoText(tryStringify(error.data))}\n`);
|
|
150
263
|
});
|
|
151
264
|
//Logger.line();
|
|
152
265
|
return null;
|
|
153
266
|
};
|
|
154
267
|
|
|
155
268
|
export const progress = {
|
|
269
|
+
current: { interrupt: (x: string) => {} },
|
|
156
270
|
active: false,
|
|
157
|
-
done: () => new ProgressBar('', 0),
|
|
158
|
-
colours: { green: '\u001b[42m \u001b[0m', red: '\u001b[41m \u001b[0m' },
|
|
159
|
-
current: new ProgressBar(`:bar`, {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}),
|
|
271
|
+
// done: () => new ProgressBar('', 0),
|
|
272
|
+
// colours: { green: '\u001b[42m \u001b[0m', red: '\u001b[41m \u001b[0m' },
|
|
273
|
+
// current: new ProgressBar(`:bar`, {
|
|
274
|
+
// complete: '=',
|
|
275
|
+
// incomplete: ' ',
|
|
276
|
+
// width: 20,
|
|
277
|
+
// total: 100,
|
|
278
|
+
// }),
|
|
165
279
|
};
|
package/src/util/os.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
|
|
3
|
+
export const winSlash = (str: string) =>
|
|
4
|
+
os.platform() === 'win32' ? str.replaceAll('/', '\\') : str;
|
|
5
|
+
|
|
6
|
+
export const linuxSlash = (str: string) =>
|
|
7
|
+
os.platform() === 'win32' ? str.replaceAll('\\', '/') : str;
|
|
8
|
+
|
|
9
|
+
export const normaliseLineEndings = (
|
|
10
|
+
str: string,
|
|
11
|
+
lineEnd = os.platform() === 'win32' ? '\r\n' : 'n'
|
|
12
|
+
) => str.replace(/\r?\n/g, lineEnd);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const promiseDelay = (delay: number, value: any) => {
|
|
2
|
+
let timeout: NodeJS.Timeout | null;
|
|
3
|
+
let _reject: PromiseRejectionEvent['reason'];
|
|
4
|
+
|
|
5
|
+
const wait = () =>
|
|
6
|
+
new Promise((resolve, reject) => {
|
|
7
|
+
_reject = reject;
|
|
8
|
+
timeout = setTimeout(resolve, delay, value);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const promise = wait();
|
|
12
|
+
return {
|
|
13
|
+
promise,
|
|
14
|
+
cancel() {
|
|
15
|
+
if (timeout) {
|
|
16
|
+
clearTimeout(timeout);
|
|
17
|
+
timeout = null;
|
|
18
|
+
_reject();
|
|
19
|
+
_reject = null;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
wait,
|
|
23
|
+
};
|
|
24
|
+
};
|
package/src/util/yaml.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { validateWorkflow } from '@action-validator/core';
|
|
2
|
+
|
|
3
|
+
import { parse, parseDocument, stringify } from 'yaml';
|
|
4
|
+
|
|
5
|
+
export const parseYaml = parse;
|
|
6
|
+
export const parseYamlDocument = parseDocument;
|
|
7
|
+
export const stringifyYaml = stringify;
|
|
8
|
+
|
|
9
|
+
export const validateWorkflowYaml = (yaml: string) => {
|
|
10
|
+
const { actionType, errors } = validateWorkflow(yaml);
|
|
11
|
+
if (actionType && errors.length === 0) return true;
|
|
12
|
+
return errors;
|
|
13
|
+
};
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "1.0.0-beta.
|
|
1
|
+
export const LIB_VERSION = "1.0.0-beta.100";
|