@rainbow-o23/n1 0.1.1

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.
Files changed (40) hide show
  1. package/.babelrc +11 -0
  2. package/.eslintrc +23 -0
  3. package/README.md +233 -0
  4. package/index.cjs +760 -0
  5. package/index.d.ts +3 -0
  6. package/index.js +732 -0
  7. package/lib/pipeline/envs.d.ts +1 -0
  8. package/lib/pipeline/index.d.ts +6 -0
  9. package/lib/pipeline/pipeline-execution.d.ts +38 -0
  10. package/lib/pipeline/pipeline-step.d.ts +41 -0
  11. package/lib/pipeline/pipeline.d.ts +47 -0
  12. package/lib/pipeline/step-helpers-utils.d.ts +41 -0
  13. package/lib/pipeline/step-helpers.d.ts +31 -0
  14. package/lib/repo/index.d.ts +1 -0
  15. package/lib/repo/pipeline-repository.d.ts +11 -0
  16. package/lib/utils/config.d.ts +16 -0
  17. package/lib/utils/error.d.ts +21 -0
  18. package/lib/utils/index.d.ts +4 -0
  19. package/lib/utils/logger.d.ts +50 -0
  20. package/lib/utils/types.d.ts +7 -0
  21. package/package.json +41 -0
  22. package/rollup.config.base.js +30 -0
  23. package/rollup.config.ci.js +3 -0
  24. package/rollup.config.js +3 -0
  25. package/src/index.ts +4 -0
  26. package/src/lib/pipeline/envs.ts +20 -0
  27. package/src/lib/pipeline/index.ts +7 -0
  28. package/src/lib/pipeline/pipeline-execution.ts +137 -0
  29. package/src/lib/pipeline/pipeline-step.ts +79 -0
  30. package/src/lib/pipeline/pipeline.ts +148 -0
  31. package/src/lib/pipeline/step-helpers-utils.ts +143 -0
  32. package/src/lib/pipeline/step-helpers.ts +77 -0
  33. package/src/lib/repo/index.ts +1 -0
  34. package/src/lib/repo/pipeline-repository.ts +53 -0
  35. package/src/lib/utils/config.ts +110 -0
  36. package/src/lib/utils/error.ts +41 -0
  37. package/src/lib/utils/index.ts +6 -0
  38. package/src/lib/utils/logger.ts +292 -0
  39. package/src/lib/utils/types.ts +11 -0
  40. package/tsconfig.json +36 -0
@@ -0,0 +1,292 @@
1
+ export type LoggerLevel = 'debug' | 'verbose' | 'log' | 'warn' | 'error';
2
+ export type LoggerName = `${string}.${LoggerLevel}`;
3
+ export type LoggerEnablement = Record<LoggerName, boolean>;
4
+
5
+ export interface Logger {
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ log(message: any, ...optionalParams: any[]): any;
8
+
9
+ /**
10
+ * Write an 'error' level log.
11
+ */
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ error(message: any, ...optionalParams: any[]): any;
14
+
15
+ /**
16
+ * Write a 'warn' level log.
17
+ */
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ warn(message: any, ...optionalParams: any[]): any;
20
+
21
+ /**
22
+ * Write a 'debug' level log.
23
+ */
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ debug?(message: any, ...optionalParams: any[]): any;
26
+
27
+ /**
28
+ * Write a 'verbose' level log.
29
+ */
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ verbose?(message: any, ...optionalParams: any[]): any;
32
+ }
33
+
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ type RedressedOutputParams = { key?: string, message: any, optionalParams: any[] };
36
+
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ const buildOutput = (message: any, ...optionalParams: any[]): RedressedOutputParams => {
39
+ if (optionalParams == null || optionalParams.length === 0) {
40
+ return {message, optionalParams};
41
+ }
42
+ const key = optionalParams.pop();
43
+ if (typeof key === 'string') {
44
+ return {key, message, optionalParams};
45
+ } else {
46
+ return {message, optionalParams: [...optionalParams, key]};
47
+ }
48
+ };
49
+
50
+ export class EnhancedLogger implements Logger {
51
+ private static ENABLED_LEVELS: Array<LoggerLevel> = ['warn', 'error'];
52
+ // noinspection SpellCheckingInspection
53
+ private static ENABLEMENTS: LoggerEnablement = {};
54
+ private _logger: Logger;
55
+
56
+ constructor(logger: Logger) {
57
+ this._logger = logger;
58
+ }
59
+
60
+ // noinspection JSUnusedGlobalSymbols
61
+ public getInternalLogger(): Logger {
62
+ return this._logger;
63
+ }
64
+
65
+ public static enableLevel(level: LoggerLevel) {
66
+ if (EnhancedLogger.ENABLED_LEVELS.includes(level)) {
67
+ // already enabled, do nothing
68
+ } else {
69
+ const levels: Array<LoggerLevel> = ['debug', 'verbose', 'log', 'warn', 'error'];
70
+ const foundIndex = levels.indexOf(level);
71
+ EnhancedLogger.ENABLED_LEVELS = levels.filter((_level, index) => {
72
+ return index >= foundIndex;
73
+ });
74
+ }
75
+ }
76
+
77
+ public static disableLevel(level: LoggerLevel) {
78
+ if (!EnhancedLogger.ENABLED_LEVELS.includes(level)) {
79
+ // already disabled, do nothing
80
+ } else {
81
+ const levels: Array<LoggerLevel> = ['debug', 'verbose', 'log', 'warn', 'error'];
82
+ const foundIndex = levels.indexOf(level);
83
+ EnhancedLogger.ENABLED_LEVELS = levels.filter((_level, index) => {
84
+ return index > foundIndex;
85
+ });
86
+ }
87
+ }
88
+
89
+ public static isLevelEnabled(level: LoggerLevel): boolean {
90
+ return EnhancedLogger.ENABLED_LEVELS.includes(level);
91
+ }
92
+
93
+ public static enable(name: LoggerName | string) {
94
+ if (['debug', 'verbose', 'log', 'warn', 'error'].some(level => name.endsWith(`.${level}`))) {
95
+ EnhancedLogger.ENABLEMENTS[name] = true;
96
+ } else {
97
+ ['debug', 'verbose', 'log', 'warn', 'error'].forEach(level => {
98
+ EnhancedLogger.ENABLEMENTS[`${name}.${level}`] = true;
99
+ });
100
+ }
101
+ }
102
+
103
+ public static disable(name: LoggerName | string) {
104
+ if (['debug', 'verbose', 'log', 'warn', 'error'].some(level => name.endsWith(`.${level}`))) {
105
+ EnhancedLogger.ENABLEMENTS[name] = false;
106
+ } else {
107
+ ['debug', 'verbose', 'log', 'warn', 'error'].forEach(level => {
108
+ EnhancedLogger.ENABLEMENTS[`${name}.${level}`] = false;
109
+ });
110
+ }
111
+ }
112
+
113
+ public static isEnabled(name: LoggerName): boolean {
114
+ if (EnhancedLogger.ENABLEMENTS[name] === false) {
115
+ // indicated as disabled
116
+ return false;
117
+ } else if (EnhancedLogger.ENABLEMENTS[name] === true) {
118
+ // indicated as enabled
119
+ return true;
120
+ } else { // noinspection RedundantIfStatementJS
121
+ if (this.ENABLED_LEVELS.some(level => name.endsWith(`.${level}`))) {
122
+ // corresponded level is enabled
123
+ return true;
124
+ } else {
125
+ return false;
126
+ }
127
+ }
128
+ }
129
+
130
+ // noinspection JSUnusedGlobalSymbols
131
+ public takeover(to: Logger): void {
132
+ this._logger = to ?? console;
133
+ }
134
+
135
+ public restore(): void {
136
+ this._logger = console;
137
+ }
138
+
139
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
140
+ public debug(message: any, ...optionalParams: any[]): any {
141
+ const {key} = buildOutput(message, ...optionalParams);
142
+ if (key != null && EnhancedLogger.isEnabled(`${key}.debug`)) {
143
+ return this._logger.debug(message, ...optionalParams);
144
+ } else if (EnhancedLogger.isLevelEnabled('debug')) {
145
+ return this._logger.debug(message, ...optionalParams);
146
+ }
147
+ }
148
+
149
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
150
+ public verbose(message: any, ...optionalParams: any[]): any {
151
+ const {key} = buildOutput(message, ...optionalParams);
152
+ if (key != null && EnhancedLogger.isEnabled(`${key}.verbose`)) {
153
+ return this._logger.verbose(message, ...optionalParams);
154
+ } else if (EnhancedLogger.isLevelEnabled('verbose')) {
155
+ return this._logger.verbose(message, ...optionalParams);
156
+ }
157
+ }
158
+
159
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
160
+ public log(message: any, ...optionalParams: any[]): any {
161
+ const {key} = buildOutput(message, ...optionalParams);
162
+ if (key != null && EnhancedLogger.isEnabled(`${key}.log`)) {
163
+ return this._logger.log(message, ...optionalParams);
164
+ } else if (EnhancedLogger.isLevelEnabled('log')) {
165
+ return this._logger.log(message, ...optionalParams);
166
+ }
167
+ }
168
+
169
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
170
+ public warn(message: any, ...optionalParams: any[]): any {
171
+ const {key} = buildOutput(message, ...optionalParams);
172
+ if (key != null && EnhancedLogger.isEnabled(`${key}.warn`)) {
173
+ return this._logger.warn(message, ...optionalParams);
174
+ } else if (EnhancedLogger.isLevelEnabled('warn')) {
175
+ return this._logger.warn(message, ...optionalParams);
176
+ }
177
+ }
178
+
179
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
180
+ public error(message: any, ...optionalParams: any[]): any {
181
+ const {key} = buildOutput(message, ...optionalParams);
182
+ if (key != null && EnhancedLogger.isEnabled(`${key}.error`)) {
183
+ return this._logger.error(message, ...optionalParams);
184
+ } else if (EnhancedLogger.isLevelEnabled('error')) {
185
+ return this._logger.error(message, ...optionalParams);
186
+ }
187
+ }
188
+ }
189
+
190
+ export class ConsoleLogger implements Logger {
191
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
192
+ private buildPrefix(level: LoggerLevel, message: any, ...optionalParams: any[]): Array<string> {
193
+ const date = new Date();
194
+ const {key, message: msg, optionalParams: params} = buildOutput(message, ...optionalParams);
195
+ return [
196
+ `%c[${date.toLocaleDateString()} ${date.toLocaleTimeString()}] %c[${key ?? 'UNKNOWN CATEGORY'}] %c[${level.toUpperCase()}]`,
197
+ 'color: #871094', 'color: #0033B3', 'color: #9E880D',
198
+ msg, ...params
199
+ ];
200
+ }
201
+
202
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
203
+ debug(message: any, ...optionalParams: any[]): any {
204
+ return console.debug(...this.buildPrefix('debug', message, ...optionalParams));
205
+ }
206
+
207
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
208
+ verbose(message: any, ...optionalParams: any[]): any {
209
+ return console.trace(...this.buildPrefix('verbose', message, ...optionalParams));
210
+ }
211
+
212
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+ log(message: any, ...optionalParams: any[]): any {
214
+ return console.log(...this.buildPrefix('log', message, ...optionalParams));
215
+ }
216
+
217
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
218
+ warn(message: any, ...optionalParams: any[]): any {
219
+ return console.warn(...this.buildPrefix('warn', message, ...optionalParams));
220
+ }
221
+
222
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
223
+ error(message: any, ...optionalParams: any[]): any {
224
+ return console.error(...this.buildPrefix('error', message, ...optionalParams));
225
+ }
226
+ }
227
+
228
+ export const createLogger = (logger?: Logger): EnhancedLogger => {
229
+ return new EnhancedLogger(logger ?? new ConsoleLogger());
230
+ };
231
+
232
+ export class LoggerPerformanceSaver {
233
+ public constructor(private readonly message: () => string) {
234
+ }
235
+
236
+ get [Symbol.toStringTag]() {
237
+ return this.message();
238
+ }
239
+ }
240
+
241
+ export const saveLoggerPerformance = (message: () => string) => {
242
+ return new LoggerPerformanceSaver(message);
243
+ };
244
+
245
+ export class LoggerUtils {
246
+ private constructor() {
247
+ // avoid extend
248
+ }
249
+
250
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
251
+ public static stringifyObject(given: any): string {
252
+ if (given instanceof Buffer) {
253
+ return '...Buffer (content ignored)';
254
+ } else if (typeof given === 'object' && given.type === 'Buffer' && given.data != null && Array.isArray(given.data)) {
255
+ return '...Buffer (content ignored)';
256
+ }
257
+ return JSON.stringify(given, (_key, value) => {
258
+ if (value == null) {
259
+ return (void 0);
260
+ } else if (value instanceof Buffer) {
261
+ return '...Buffer (content ignored)';
262
+ } else if (typeof value === 'object' && value.type === 'Buffer' && value.data != null && Array.isArray(value.data)) {
263
+ return '...Buffer (content ignored)';
264
+ } else {
265
+ return value;
266
+ }
267
+ });
268
+ }
269
+
270
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
271
+ public static normalizeObject(given: any): any {
272
+ if (given instanceof Buffer) {
273
+ return '...Buffer (content ignored)';
274
+ } else if (typeof given === 'object' && given.type === 'Buffer' && given.data != null && Array.isArray(given.data)) {
275
+ return '...Buffer (content ignored)';
276
+ }
277
+ return Object.keys(given).reduce((normalized, key) => {
278
+ const value = given[key];
279
+ if (value == null) {
280
+ return (void 0);
281
+ } else if (Array.isArray(value)) {
282
+ return value.map(LoggerUtils.normalizeObject);
283
+ } else if (value instanceof Buffer) {
284
+ return '...Buffer (content ignored)';
285
+ } else if (typeof value === 'object' && value.type === 'Buffer' && value.data != null && Array.isArray(value.data)) {
286
+ return '...Buffer (content ignored)';
287
+ } else {
288
+ return value;
289
+ }
290
+ }, {});
291
+ }
292
+ }
@@ -0,0 +1,11 @@
1
+ export type Nullable<T> = T | null | undefined;
2
+ export type Undefinable<T> = T | undefined;
3
+ export type DateTime = string;
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
6
+ export interface Type<T = any> extends Function {
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ new(...args: any[]): T;
9
+ }
10
+
11
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
package/tsconfig.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "outDir": "./dist",
5
+ "declarationDir": "./lib",
6
+ "module": "ES2015",
7
+ "target": "ESNext",
8
+ "moduleResolution": "node",
9
+ "sourceMap": true,
10
+ // create d.ts file
11
+ "declaration": true,
12
+ "removeComments": true,
13
+ "noImplicitAny": false,
14
+ "allowSyntheticDefaultImports": true,
15
+ "allowUnreachableCode": true,
16
+ "allowUnusedLabels": false,
17
+ "alwaysStrict": true,
18
+ "allowJs": true,
19
+ "experimentalDecorators": true,
20
+ "lib": [
21
+ "es5",
22
+ "es2015",
23
+ "es2016",
24
+ "es2017",
25
+ "es2018",
26
+ "dom"
27
+ ]
28
+ },
29
+ "include": [
30
+ "src/**/*"
31
+ ],
32
+ "exclude": [
33
+ "node_modules",
34
+ "dist"
35
+ ]
36
+ }