@runium/cli 0.0.1 → 0.0.2
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/{lib/commands → commands}/index.js +0 -0
- package/{lib/commands → commands}/project/project-start.js +1 -1
- package/{lib/constants → constants}/index.js +0 -0
- package/{lib/macros → macros}/index.js +0 -0
- package/package.json +7 -30
- package/{lib/services → services}/index.js +0 -0
- package/services/plugin-context.js +1 -0
- package/services/shutdown.js +1 -0
- package/{lib/utils → utils}/index.js +0 -0
- package/.eslintrc.json +0 -31
- package/.prettierrc.json +0 -10
- package/README.md +0 -3
- package/build.js +0 -104
- package/lib/package.json +0 -21
- package/lib/services/plugin-context.js +0 -1
- package/lib/services/shutdown.js +0 -1
- package/src/app.ts +0 -175
- package/src/commands/index.ts +0 -2
- package/src/commands/plugin/plugin-add.ts +0 -48
- package/src/commands/plugin/plugin-command.ts +0 -36
- package/src/commands/plugin/plugin-disable.ts +0 -46
- package/src/commands/plugin/plugin-enable.ts +0 -50
- package/src/commands/plugin/plugin-list.ts +0 -61
- package/src/commands/plugin/plugin-remove.ts +0 -42
- package/src/commands/plugin/plugin.ts +0 -41
- package/src/commands/project/project-add.ts +0 -46
- package/src/commands/project/project-command.ts +0 -36
- package/src/commands/project/project-list.ts +0 -32
- package/src/commands/project/project-remove.ts +0 -41
- package/src/commands/project/project-start.ts +0 -152
- package/src/commands/project/project-state-command.ts +0 -68
- package/src/commands/project/project-status.ts +0 -103
- package/src/commands/project/project-stop.ts +0 -55
- package/src/commands/project/project-validate.ts +0 -43
- package/src/commands/project/project.ts +0 -45
- package/src/commands/runium-command.ts +0 -50
- package/src/constants/error-code.ts +0 -15
- package/src/constants/index.ts +0 -1
- package/src/index.ts +0 -21
- package/src/macros/conditional.ts +0 -31
- package/src/macros/empty.ts +0 -6
- package/src/macros/env.ts +0 -8
- package/src/macros/index.ts +0 -12
- package/src/macros/path.ts +0 -9
- package/src/services/config.ts +0 -76
- package/src/services/index.ts +0 -7
- package/src/services/output.ts +0 -201
- package/src/services/plugin-context.ts +0 -81
- package/src/services/plugin.ts +0 -144
- package/src/services/profile.ts +0 -211
- package/src/services/project.ts +0 -114
- package/src/services/shutdown.ts +0 -130
- package/src/utils/convert-path-to-valid-file-name.ts +0 -39
- package/src/utils/debounce.ts +0 -23
- package/src/utils/format-timestamp.ts +0 -17
- package/src/utils/index.ts +0 -3
- package/tsconfig.json +0 -40
- /package/{lib/app.js → app.js} +0 -0
- /package/{lib/commands → commands}/plugin/plugin-add.js +0 -0
- /package/{lib/commands → commands}/plugin/plugin-command.js +0 -0
- /package/{lib/commands → commands}/plugin/plugin-disable.js +0 -0
- /package/{lib/commands → commands}/plugin/plugin-enable.js +0 -0
- /package/{lib/commands → commands}/plugin/plugin-list.js +0 -0
- /package/{lib/commands → commands}/plugin/plugin-remove.js +0 -0
- /package/{lib/commands → commands}/plugin/plugin.js +0 -0
- /package/{lib/commands → commands}/project/project-add.js +0 -0
- /package/{lib/commands → commands}/project/project-command.js +0 -0
- /package/{lib/commands → commands}/project/project-list.js +0 -0
- /package/{lib/commands → commands}/project/project-remove.js +0 -0
- /package/{lib/commands → commands}/project/project-state-command.js +0 -0
- /package/{lib/commands → commands}/project/project-status.js +0 -0
- /package/{lib/commands → commands}/project/project-stop.js +0 -0
- /package/{lib/commands → commands}/project/project-validate.js +0 -0
- /package/{lib/commands → commands}/project/project.js +0 -0
- /package/{lib/commands → commands}/runium-command.js +0 -0
- /package/{lib/constants → constants}/error-code.js +0 -0
- /package/{lib/index.js → index.js} +0 -0
- /package/{lib/macros → macros}/conditional.js +0 -0
- /package/{lib/macros → macros}/empty.js +0 -0
- /package/{lib/macros → macros}/env.js +0 -0
- /package/{lib/macros → macros}/path.js +0 -0
- /package/{lib/services → services}/config.js +0 -0
- /package/{lib/services → services}/output.js +0 -0
- /package/{lib/services → services}/plugin.js +0 -0
- /package/{lib/services → services}/profile.js +0 -0
- /package/{lib/services → services}/project.js +0 -0
- /package/{lib/utils → utils}/convert-path-to-valid-file-name.js +0 -0
- /package/{lib/utils → utils}/debounce.js +0 -0
- /package/{lib/utils → utils}/format-timestamp.js +0 -0
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { ProjectCommand } from './project-command.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Project validate command
|
|
5
|
-
*/
|
|
6
|
-
export class ProjectValidateCommand extends ProjectCommand {
|
|
7
|
-
/**
|
|
8
|
-
* Config command
|
|
9
|
-
*/
|
|
10
|
-
protected config(): void {
|
|
11
|
-
this.command
|
|
12
|
-
.name('validate')
|
|
13
|
-
.description('validate project')
|
|
14
|
-
.option('-f, --file', 'use file path instead of project name')
|
|
15
|
-
.argument('<project>', 'project name or file path');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Handle command
|
|
20
|
-
* @param project
|
|
21
|
-
* @param file
|
|
22
|
-
*/
|
|
23
|
-
protected async handle(
|
|
24
|
-
project: string,
|
|
25
|
-
{ file }: { file: boolean }
|
|
26
|
-
): Promise<void> {
|
|
27
|
-
const path = file
|
|
28
|
-
? this.projectService.resolvePath(project)
|
|
29
|
-
: this.ensureProfileProject(project).path;
|
|
30
|
-
const projectInstance = await this.projectService.initProject(path);
|
|
31
|
-
try {
|
|
32
|
-
await projectInstance.validate();
|
|
33
|
-
this.outputService.success(`Project "%s" is valid`, project);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
// TODO stringify validation errors
|
|
36
|
-
this.outputService.error(
|
|
37
|
-
`Project "%s" validation failed`,
|
|
38
|
-
project,
|
|
39
|
-
error
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { RuniumCommand } from '@commands/runium-command.js';
|
|
2
|
-
import { ProjectAddCommand } from './project-add.js';
|
|
3
|
-
import { ProjectListCommand } from './project-list.js';
|
|
4
|
-
import { ProjectRemoveCommand } from './project-remove.js';
|
|
5
|
-
import { ProjectStartCommand } from './project-start.js';
|
|
6
|
-
import { ProjectStopCommand } from './project-stop.js';
|
|
7
|
-
import { ProjectStatusCommand } from './project-status.js';
|
|
8
|
-
import { ProjectValidateCommand } from './project-validate.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Project group command
|
|
12
|
-
*/
|
|
13
|
-
export class ProjectCommand extends RuniumCommand {
|
|
14
|
-
/**
|
|
15
|
-
* Config command
|
|
16
|
-
*/
|
|
17
|
-
protected config(): void {
|
|
18
|
-
this.command.name('project').description('manage projects');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Handle command
|
|
23
|
-
*/
|
|
24
|
-
protected async handle(): Promise<void> {
|
|
25
|
-
this.command.help();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Add subcommands
|
|
30
|
-
*/
|
|
31
|
-
protected addSubcommands(): void {
|
|
32
|
-
const constructors = [
|
|
33
|
-
ProjectListCommand,
|
|
34
|
-
ProjectAddCommand,
|
|
35
|
-
ProjectRemoveCommand,
|
|
36
|
-
ProjectStartCommand,
|
|
37
|
-
ProjectStopCommand,
|
|
38
|
-
ProjectStatusCommand,
|
|
39
|
-
ProjectValidateCommand,
|
|
40
|
-
];
|
|
41
|
-
for (const CommandConstructor of constructors) {
|
|
42
|
-
this.subcommands.push(new CommandConstructor(this.command));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { Container } from 'typedi';
|
|
3
|
-
import { OutputService } from '@services';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Base runium command
|
|
7
|
-
*/
|
|
8
|
-
export abstract class RuniumCommand {
|
|
9
|
-
protected outputService: OutputService;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Parent command
|
|
13
|
-
*/
|
|
14
|
-
protected parent: Command;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Current command
|
|
18
|
-
*/
|
|
19
|
-
protected command: Command;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Subcommands
|
|
23
|
-
*/
|
|
24
|
-
protected subcommands: RuniumCommand[] = [];
|
|
25
|
-
|
|
26
|
-
constructor(parent: Command) {
|
|
27
|
-
this.outputService = Container.get(OutputService);
|
|
28
|
-
this.parent = parent;
|
|
29
|
-
this.command = new Command();
|
|
30
|
-
this.config();
|
|
31
|
-
this.command.action(this.handle.bind(this));
|
|
32
|
-
this.addSubcommands();
|
|
33
|
-
this.parent.addCommand(this.command);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Add subcommands
|
|
38
|
-
*/
|
|
39
|
-
protected addSubcommands(): void {}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Config command
|
|
43
|
-
*/
|
|
44
|
-
protected abstract config(): void;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Handle command
|
|
48
|
-
*/
|
|
49
|
-
protected abstract handle(...args: unknown[]): Promise<void>;
|
|
50
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export enum ErrorCode {
|
|
2
|
-
PLUGIN_NOT_FOUND = 'plugin-not-found',
|
|
3
|
-
PLUGIN_FILE_NOT_FOUND = 'plugin-file-not-found',
|
|
4
|
-
PLUGIN_INCORRECT_MODULE = 'plugin-incorrect-module',
|
|
5
|
-
PLUGIN_INCORRECT_PLUGIN = 'plugin-incorrect-plugin',
|
|
6
|
-
PLUGIN_PATH_RESOLVE_ERROR = 'plugin-path-resolve-error',
|
|
7
|
-
PROJECT_ALREADY_STARTED = 'project-already-started',
|
|
8
|
-
PROJECT_NOT_STARTED = 'project-not-started',
|
|
9
|
-
PROJECT_STOP_ERROR = 'project-stop-error',
|
|
10
|
-
PROJECT_NOT_FOUND = 'project-not-found',
|
|
11
|
-
PROJECT_FILE_NOT_FOUND = 'project-file-not-found',
|
|
12
|
-
PROJECT_FILE_CAN_NOT_READ = 'project-file-can-not-read',
|
|
13
|
-
PROJECT_JSON_PARSE_ERROR = 'project-json-parse-error',
|
|
14
|
-
PROFILE_JSON_WRITE_ERROR = 'profile-json-write-error',
|
|
15
|
-
}
|
package/src/constants/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './error-code.js';
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import 'reflect-metadata';
|
|
4
|
-
import { Container } from 'typedi';
|
|
5
|
-
import { RuniumCliApp } from './app.js';
|
|
6
|
-
import { OutputService } from '@services';
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
const app = new RuniumCliApp();
|
|
10
|
-
await app.start();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
main().catch(error => {
|
|
14
|
-
const outputService = Container.get(OutputService);
|
|
15
|
-
outputService.error('Error: %s', error.message);
|
|
16
|
-
outputService.debug('Error details:', {
|
|
17
|
-
code: error.code,
|
|
18
|
-
payload: error.payload,
|
|
19
|
-
});
|
|
20
|
-
process.exit(1);
|
|
21
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Equal
|
|
3
|
-
* @param value1
|
|
4
|
-
* @param value2
|
|
5
|
-
* @param trueValue
|
|
6
|
-
* @param falseValue
|
|
7
|
-
*/
|
|
8
|
-
export function eqMacro(
|
|
9
|
-
value1: string,
|
|
10
|
-
value2: string,
|
|
11
|
-
trueValue?: string,
|
|
12
|
-
falseValue?: string
|
|
13
|
-
): string {
|
|
14
|
-
return value1 === value2 ? (trueValue ?? '') : (falseValue ?? '');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Not equal
|
|
19
|
-
* @param value1
|
|
20
|
-
* @param value2
|
|
21
|
-
* @param trueValue
|
|
22
|
-
* @param falseValue
|
|
23
|
-
*/
|
|
24
|
-
export function neMacro(
|
|
25
|
-
value1: string,
|
|
26
|
-
value2: string,
|
|
27
|
-
trueValue?: string,
|
|
28
|
-
falseValue?: string
|
|
29
|
-
): string {
|
|
30
|
-
return value1 !== value2 ? (trueValue ?? '') : (falseValue ?? '');
|
|
31
|
-
}
|
package/src/macros/empty.ts
DELETED
package/src/macros/env.ts
DELETED
package/src/macros/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { eqMacro, neMacro } from './conditional.js';
|
|
2
|
-
import { emptyMacro } from './empty.js';
|
|
3
|
-
import { envMacro } from './env.js';
|
|
4
|
-
import { pathMacro } from './path.js';
|
|
5
|
-
|
|
6
|
-
export const macros = {
|
|
7
|
-
env: envMacro,
|
|
8
|
-
empty: emptyMacro,
|
|
9
|
-
eq: eqMacro,
|
|
10
|
-
ne: neMacro,
|
|
11
|
-
path: pathMacro,
|
|
12
|
-
};
|
package/src/macros/path.ts
DELETED
package/src/services/config.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { join, resolve } from 'node:path';
|
|
4
|
-
import { Service } from 'typedi';
|
|
5
|
-
import { readJsonFile } from '@runium/core';
|
|
6
|
-
|
|
7
|
-
interface ConfigEnv {
|
|
8
|
-
path: string[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface ConfigOutput {
|
|
12
|
-
debug: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface ConfigProfile {
|
|
16
|
-
path: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface ConfigData {
|
|
20
|
-
env: ConfigEnv;
|
|
21
|
-
output: ConfigOutput;
|
|
22
|
-
profile: ConfigProfile;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const CONFIG_FILE_NAME = '.runiumrc.json';
|
|
26
|
-
const CONFIG_FILE_PATH = join(process.cwd(), CONFIG_FILE_NAME);
|
|
27
|
-
const PROFILE_DIR_NAME = '.runium';
|
|
28
|
-
const HOME_PROFILE_PATH = join(homedir(), PROFILE_DIR_NAME);
|
|
29
|
-
const CWD_PROFILE_PATH = join(process.cwd(), PROFILE_DIR_NAME);
|
|
30
|
-
|
|
31
|
-
@Service()
|
|
32
|
-
export class ConfigService {
|
|
33
|
-
private data: ConfigData = {
|
|
34
|
-
profile: { path: HOME_PROFILE_PATH },
|
|
35
|
-
output: { debug: false },
|
|
36
|
-
env: { path: [] },
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Initialize the config service
|
|
41
|
-
*/
|
|
42
|
-
async init(): Promise<void> {
|
|
43
|
-
if (existsSync(CWD_PROFILE_PATH)) {
|
|
44
|
-
this.data.profile.path = CWD_PROFILE_PATH;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (existsSync(CONFIG_FILE_PATH)) {
|
|
48
|
-
// TODO validate config file
|
|
49
|
-
const configData: ConfigData =
|
|
50
|
-
await readJsonFile<ConfigData>(CONFIG_FILE_PATH);
|
|
51
|
-
if (configData) {
|
|
52
|
-
const data = {
|
|
53
|
-
env: Object.assign({}, this.data.env, configData.env ?? {}),
|
|
54
|
-
output: Object.assign({}, this.data.output, configData.output ?? {}),
|
|
55
|
-
profile: Object.assign(
|
|
56
|
-
{},
|
|
57
|
-
this.data.profile,
|
|
58
|
-
configData.profile ?? {}
|
|
59
|
-
),
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
data.env.path = data.env.path.map(envPath => resolve(envPath));
|
|
63
|
-
data.profile.path = resolve(data.profile.path);
|
|
64
|
-
this.data = data;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get a configuration value
|
|
71
|
-
* @param key
|
|
72
|
-
*/
|
|
73
|
-
get<T extends keyof ConfigData>(key: T): ConfigData[T] {
|
|
74
|
-
return this.data[key];
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/services/index.ts
DELETED
package/src/services/output.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { Console } from 'node:console';
|
|
2
|
-
import { Transform } from 'node:stream';
|
|
3
|
-
|
|
4
|
-
import { Service } from 'typedi';
|
|
5
|
-
|
|
6
|
-
export enum OutputLevel {
|
|
7
|
-
TRACE = 0,
|
|
8
|
-
DEBUG = 1,
|
|
9
|
-
INFO = 2,
|
|
10
|
-
WARN = 3,
|
|
11
|
-
ERROR = 4,
|
|
12
|
-
SILENT = 5,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Console dumper
|
|
17
|
-
* wrapper around node console with a transform stream
|
|
18
|
-
*/
|
|
19
|
-
class ConsoleDumper extends Console {
|
|
20
|
-
private readonly transform: Transform;
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
const transform = new Transform({
|
|
24
|
-
transform: (chunk, _, cb) => cb(null, chunk),
|
|
25
|
-
});
|
|
26
|
-
super({
|
|
27
|
-
stdout: transform,
|
|
28
|
-
stderr: transform,
|
|
29
|
-
colorMode: false,
|
|
30
|
-
});
|
|
31
|
-
this.transform = transform;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get a table output with index column removed
|
|
36
|
-
* @param data
|
|
37
|
-
* @param columns
|
|
38
|
-
*/
|
|
39
|
-
getPatchedTable(data: unknown[], columns?: string[]): string {
|
|
40
|
-
this.table(data, columns);
|
|
41
|
-
|
|
42
|
-
const original = (this.transform.read() || '').toString();
|
|
43
|
-
|
|
44
|
-
// Tables should all start with roughly:
|
|
45
|
-
// ┌─────────┬──────
|
|
46
|
-
// │ (index) │
|
|
47
|
-
// ├─────────┼
|
|
48
|
-
const columnWidth = original.indexOf('┬') + 1;
|
|
49
|
-
|
|
50
|
-
return original
|
|
51
|
-
.split('\n')
|
|
52
|
-
.map((line: string) => line.charAt(0) + line.slice(columnWidth))
|
|
53
|
-
.join('\n');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const dumper = new ConsoleDumper();
|
|
58
|
-
|
|
59
|
-
@Service()
|
|
60
|
-
export class OutputService {
|
|
61
|
-
private outputLevel: OutputLevel = OutputLevel.INFO;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Set output level
|
|
65
|
-
* @param level
|
|
66
|
-
*/
|
|
67
|
-
setLevel(level: OutputLevel): void {
|
|
68
|
-
this.outputLevel = level;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get output level
|
|
73
|
-
*/
|
|
74
|
-
getLevel(): OutputLevel {
|
|
75
|
-
return this.outputLevel;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Log a trace message
|
|
80
|
-
* @param message
|
|
81
|
-
* @param args
|
|
82
|
-
*/
|
|
83
|
-
trace(message: string, ...args: unknown[]): void {
|
|
84
|
-
if (this.outputLevel <= OutputLevel.TRACE) {
|
|
85
|
-
// eslint-disable-next-line no-console
|
|
86
|
-
console.log(message, ...args);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Log a debug message
|
|
92
|
-
* @param message
|
|
93
|
-
* @param args
|
|
94
|
-
*/
|
|
95
|
-
debug(message: string, ...args: unknown[]): void {
|
|
96
|
-
if (this.outputLevel <= OutputLevel.DEBUG) {
|
|
97
|
-
// eslint-disable-next-line no-console
|
|
98
|
-
console.log(message, ...args);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Log an info message
|
|
104
|
-
* @param message
|
|
105
|
-
* @param args
|
|
106
|
-
*/
|
|
107
|
-
info(message: string, ...args: unknown[]): void {
|
|
108
|
-
if (this.outputLevel <= OutputLevel.INFO) {
|
|
109
|
-
// eslint-disable-next-line no-console
|
|
110
|
-
console.log(message, ...args);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Log a success message
|
|
116
|
-
* @param message
|
|
117
|
-
* @param args
|
|
118
|
-
*/
|
|
119
|
-
success(message: string, ...args: unknown[]): void {
|
|
120
|
-
if (this.outputLevel <= OutputLevel.INFO) {
|
|
121
|
-
// eslint-disable-next-line no-console
|
|
122
|
-
console.log(message, ...args);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Log a warning message
|
|
128
|
-
* @param message
|
|
129
|
-
* @param args
|
|
130
|
-
*/
|
|
131
|
-
warn(message: string, ...args: unknown[]): void {
|
|
132
|
-
if (this.outputLevel <= OutputLevel.WARN) {
|
|
133
|
-
// eslint-disable-next-line no-console
|
|
134
|
-
console.warn(message, ...args);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Log an error message
|
|
140
|
-
* @param message
|
|
141
|
-
* @param args
|
|
142
|
-
*/
|
|
143
|
-
error(message: string, ...args: unknown[]): void {
|
|
144
|
-
if (this.outputLevel <= OutputLevel.ERROR) {
|
|
145
|
-
// eslint-disable-next-line no-console
|
|
146
|
-
console.error(message, ...args);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Log a message without level
|
|
152
|
-
* @param message
|
|
153
|
-
* @param args
|
|
154
|
-
*/
|
|
155
|
-
log(message: string, ...args: unknown[]): void {
|
|
156
|
-
if (this.outputLevel < OutputLevel.SILENT) {
|
|
157
|
-
// eslint-disable-next-line no-console
|
|
158
|
-
console.log(message, ...args);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Output a table
|
|
164
|
-
* @param data
|
|
165
|
-
* @param columns
|
|
166
|
-
*/
|
|
167
|
-
table(data: unknown[], columns?: string[]): void {
|
|
168
|
-
if (this.outputLevel < OutputLevel.SILENT) {
|
|
169
|
-
const patchedData = data.map((item, index) => ({
|
|
170
|
-
...(item as object),
|
|
171
|
-
'#': index + 1,
|
|
172
|
-
}));
|
|
173
|
-
const patchedOutput = dumper.getPatchedTable(
|
|
174
|
-
patchedData,
|
|
175
|
-
columns ? ['#', ...columns] : undefined
|
|
176
|
-
);
|
|
177
|
-
// eslint-disable-next-line no-console
|
|
178
|
-
console.log(patchedOutput);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Output a blank line
|
|
184
|
-
*/
|
|
185
|
-
newLine(): void {
|
|
186
|
-
if (this.outputLevel < OutputLevel.SILENT) {
|
|
187
|
-
// eslint-disable-next-line no-console
|
|
188
|
-
console.log('');
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Clear output
|
|
194
|
-
*/
|
|
195
|
-
clear(): void {
|
|
196
|
-
if (this.outputLevel < OutputLevel.SILENT) {
|
|
197
|
-
// eslint-disable-next-line no-console
|
|
198
|
-
console.clear();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Inject, Service } from 'typedi';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
RuniumError,
|
|
5
|
-
isRuniumError,
|
|
6
|
-
RuniumTask,
|
|
7
|
-
RuniumTrigger,
|
|
8
|
-
readJsonFile,
|
|
9
|
-
writeJsonFile,
|
|
10
|
-
applyMacros,
|
|
11
|
-
TaskStatus,
|
|
12
|
-
ProjectEvent,
|
|
13
|
-
ProjectStatus,
|
|
14
|
-
} from '@runium/core';
|
|
15
|
-
import { RuniumCommand } from '@commands/runium-command.js';
|
|
16
|
-
import { OutputLevel, OutputService, ShutdownService } from '@services';
|
|
17
|
-
|
|
18
|
-
// @ts-expect-error global object access
|
|
19
|
-
global.runium = null;
|
|
20
|
-
|
|
21
|
-
@Service()
|
|
22
|
-
export class PluginContextService {
|
|
23
|
-
constructor(
|
|
24
|
-
@Inject() private outputService: OutputService,
|
|
25
|
-
@Inject() private shutdownService: ShutdownService
|
|
26
|
-
) {}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Initialize the plugin context service
|
|
30
|
-
*/
|
|
31
|
-
async init(): Promise<void> {
|
|
32
|
-
const output = this.outputService;
|
|
33
|
-
const shutdown = this.shutdownService;
|
|
34
|
-
|
|
35
|
-
const runium = {
|
|
36
|
-
class: {
|
|
37
|
-
RuniumCommand,
|
|
38
|
-
RuniumError,
|
|
39
|
-
RuniumTask,
|
|
40
|
-
RuniumTrigger,
|
|
41
|
-
},
|
|
42
|
-
enum: {
|
|
43
|
-
OutputLevel: Object.keys(OutputLevel)
|
|
44
|
-
.filter(key => isNaN(Number(key)))
|
|
45
|
-
.reduce(
|
|
46
|
-
(acc, key) => {
|
|
47
|
-
acc[key] = OutputLevel[key as keyof typeof OutputLevel];
|
|
48
|
-
return acc;
|
|
49
|
-
},
|
|
50
|
-
{} as Record<string, number>
|
|
51
|
-
),
|
|
52
|
-
ProjectEvent,
|
|
53
|
-
ProjectStatus,
|
|
54
|
-
TaskStatus,
|
|
55
|
-
},
|
|
56
|
-
utils: {
|
|
57
|
-
applyMacros,
|
|
58
|
-
isRuniumError,
|
|
59
|
-
readJsonFile,
|
|
60
|
-
writeJsonFile,
|
|
61
|
-
},
|
|
62
|
-
output: {
|
|
63
|
-
getLevel: output.getLevel.bind(output),
|
|
64
|
-
setLevel: output.setLevel.bind(output),
|
|
65
|
-
trace: output.trace.bind(output),
|
|
66
|
-
debug: output.debug.bind(output),
|
|
67
|
-
info: output.info.bind(output),
|
|
68
|
-
warn: output.warn.bind(output),
|
|
69
|
-
error: output.error.bind(output),
|
|
70
|
-
table: output.table.bind(output),
|
|
71
|
-
log: output.log.bind(output),
|
|
72
|
-
},
|
|
73
|
-
shutdown: {
|
|
74
|
-
addBlocker: shutdown.addBlocker.bind(shutdown),
|
|
75
|
-
removeBlocker: shutdown.removeBlocker.bind(shutdown),
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
// @ts-expect-error global object access
|
|
79
|
-
global.runium = Object.freeze(runium);
|
|
80
|
-
}
|
|
81
|
-
}
|