task-script-support-cli 0.2.12 → 0.2.13
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/assets/yargs-template/task-runner/README.md +1 -1
- package/assets/yargs-template/task-runner/src/commands/help-command.ts +8 -0
- package/assets/yargs-template/task-runner/src/index.ts +8 -1
- package/assets/yargs-template/task-runner/src/tasks/show-help.ts +19 -0
- package/assets/yargs-template/task-runner/src/types/state.ts +3 -0
- package/assets/yargs-template/task-runner/tests/tasks/check-env.test.ts +56 -9
- package/dist/assets/yargs-template/task-runner/README.md +1 -1
- package/dist/assets/yargs-template/task-runner/src/commands/help-command.ts +8 -0
- package/dist/assets/yargs-template/task-runner/src/index.ts +8 -1
- package/dist/assets/yargs-template/task-runner/src/tasks/show-help.ts +19 -0
- package/dist/assets/yargs-template/task-runner/src/types/state.ts +3 -0
- package/dist/assets/yargs-template/task-runner/tests/tasks/check-env.test.ts +56 -9
- package/dist/package.json +1 -1
- package/dist/src/tasks/stdout/print-generated-results.js +1 -1
- package/package.json +1 -1
- package/src/tasks/stdout/print-generated-results.ts +1 -1
|
@@ -12,11 +12,18 @@ initializeInjectables();
|
|
|
12
12
|
|
|
13
13
|
import { UtilService } from "./services/util-service";
|
|
14
14
|
import { VerifyCommand } from "./commands/verify";
|
|
15
|
+
import { HelpCommand } from "./commands/help-command";
|
|
15
16
|
|
|
16
17
|
const name = UtilService.getAppName();
|
|
18
|
+
const yargsInstance = yargs(hideBin(process.argv));
|
|
19
|
+
container.registerInstance("yargs", yargsInstance);
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
yargsInstance
|
|
19
22
|
.usage(`${UtilService.titleizeAll(name)} CLI Client`)
|
|
23
|
+
.command({
|
|
24
|
+
command: "$0",
|
|
25
|
+
handler: container.resolve(HelpCommand).handler,
|
|
26
|
+
})
|
|
20
27
|
.command(
|
|
21
28
|
"verify",
|
|
22
29
|
"check the app is working",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AppTask } from "../wrappers/app-task";
|
|
2
|
+
import { autoInjectable, inject } from "tsyringe";
|
|
3
|
+
import type { Yargs } from "../types/state";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Show the yargs help menu
|
|
7
|
+
*/
|
|
8
|
+
@autoInjectable()
|
|
9
|
+
export default class ShowHelp extends AppTask {
|
|
10
|
+
loggerName = "ShowHelp";
|
|
11
|
+
|
|
12
|
+
constructor(@inject("yargs") private yargs: Yargs) {
|
|
13
|
+
super();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async run() {
|
|
17
|
+
this.yargs.showHelp();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AppState as State, TaskClass } from "task-script-support";
|
|
2
|
+
import yargs from "yargs";
|
|
2
3
|
|
|
3
4
|
// Add app data here as needed. Use readonly for immutable fields.
|
|
4
5
|
//
|
|
@@ -31,3 +32,5 @@ export const EnvironmentConfigKeys = {
|
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
export type AppTaskClass = TaskClass<AppStateData, CLIArgs>;
|
|
35
|
+
|
|
36
|
+
export type Yargs = typeof yargs;
|
|
@@ -1,30 +1,77 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
2
|
import CheckEnv from "../../src/tasks/check-env";
|
|
3
3
|
import { LogService } from "../../src/services/log-service";
|
|
4
4
|
import { CommandService } from "task-script-support";
|
|
5
5
|
import { AppStateData, CLIArgs } from "../../src/types/state";
|
|
6
|
+
import { container } from "tsyringe";
|
|
6
7
|
|
|
7
8
|
describe("CheckEnv", () => {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
let mockLogService = {} as LogService;
|
|
10
|
+
let mockCommandService = {} as CommandService<AppStateData, CLIArgs>;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
container.reset();
|
|
14
|
+
|
|
15
|
+
mockLogService = {
|
|
10
16
|
info: vi.fn(),
|
|
11
17
|
debug: vi.fn(),
|
|
18
|
+
error: vi.fn(),
|
|
12
19
|
} as unknown as LogService;
|
|
13
|
-
|
|
20
|
+
|
|
21
|
+
mockCommandService = {
|
|
14
22
|
setData: vi.fn((state, data) => ({
|
|
15
23
|
...state,
|
|
16
24
|
data: { ...state.data, ...data },
|
|
17
25
|
})),
|
|
18
26
|
} as unknown as CommandService<AppStateData, CLIArgs>;
|
|
19
27
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
container.registerInstance(LogService, mockLogService);
|
|
29
|
+
container.registerInstance(
|
|
30
|
+
CommandService<AppStateData, CLIArgs>,
|
|
31
|
+
mockCommandService,
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should set environmentValidated to true", async () => {
|
|
36
|
+
const checkEnv = container.resolve(CheckEnv);
|
|
37
|
+
|
|
24
38
|
await checkEnv.run();
|
|
25
|
-
expect(mockLogService.
|
|
39
|
+
expect(mockLogService.debug).toHaveBeenCalledWith(
|
|
26
40
|
"Running Check Environment",
|
|
27
41
|
);
|
|
28
42
|
expect(checkEnv.state.data.environmentValidated).toBe(true);
|
|
29
43
|
});
|
|
44
|
+
|
|
45
|
+
it("should call exit on missing required environment variable", async () => {
|
|
46
|
+
const testError = new Error("process.exit called");
|
|
47
|
+
const mockExit = vi.spyOn(process, "exit").mockImplementation(() => {
|
|
48
|
+
throw testError;
|
|
49
|
+
});
|
|
50
|
+
const checkEnv = container.resolve(CheckEnv);
|
|
51
|
+
checkEnv.requiredEnv = ["MISSING_ENV_VAR"];
|
|
52
|
+
try {
|
|
53
|
+
expect(await checkEnv.run()).toThrow(testError);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
expect(`${err}`).toContain("process.exit");
|
|
56
|
+
expect(err).toBe(testError);
|
|
57
|
+
}
|
|
58
|
+
expect(mockLogService.error).toHaveBeenCalled();
|
|
59
|
+
mockExit.mockRestore();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should group environment issues into single error log", async () => {
|
|
63
|
+
const testError = new Error("process.exit called");
|
|
64
|
+
const mockExit = vi.spyOn(process, "exit").mockImplementation(() => {
|
|
65
|
+
throw testError;
|
|
66
|
+
});
|
|
67
|
+
const checkEnv = container.resolve(CheckEnv);
|
|
68
|
+
checkEnv.requiredEnv = ["MISSING_ENV_1", "MISSING_ENV_2", "MISSING_ENV_3"];
|
|
69
|
+
try {
|
|
70
|
+
await checkEnv.run();
|
|
71
|
+
} catch (err) {
|
|
72
|
+
expect(err).toBe(testError);
|
|
73
|
+
}
|
|
74
|
+
expect(mockLogService.error).toHaveBeenCalledOnce();
|
|
75
|
+
mockExit.mockRestore();
|
|
76
|
+
});
|
|
30
77
|
});
|
|
@@ -12,11 +12,18 @@ initializeInjectables();
|
|
|
12
12
|
|
|
13
13
|
import { UtilService } from "./services/util-service";
|
|
14
14
|
import { VerifyCommand } from "./commands/verify";
|
|
15
|
+
import { HelpCommand } from "./commands/help-command";
|
|
15
16
|
|
|
16
17
|
const name = UtilService.getAppName();
|
|
18
|
+
const yargsInstance = yargs(hideBin(process.argv));
|
|
19
|
+
container.registerInstance("yargs", yargsInstance);
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
yargsInstance
|
|
19
22
|
.usage(`${UtilService.titleizeAll(name)} CLI Client`)
|
|
23
|
+
.command({
|
|
24
|
+
command: "$0",
|
|
25
|
+
handler: container.resolve(HelpCommand).handler,
|
|
26
|
+
})
|
|
20
27
|
.command(
|
|
21
28
|
"verify",
|
|
22
29
|
"check the app is working",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AppTask } from "../wrappers/app-task";
|
|
2
|
+
import { autoInjectable, inject } from "tsyringe";
|
|
3
|
+
import type { Yargs } from "../types/state";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Show the yargs help menu
|
|
7
|
+
*/
|
|
8
|
+
@autoInjectable()
|
|
9
|
+
export default class ShowHelp extends AppTask {
|
|
10
|
+
loggerName = "ShowHelp";
|
|
11
|
+
|
|
12
|
+
constructor(@inject("yargs") private yargs: Yargs) {
|
|
13
|
+
super();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async run() {
|
|
17
|
+
this.yargs.showHelp();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AppState as State, TaskClass } from "task-script-support";
|
|
2
|
+
import yargs from "yargs";
|
|
2
3
|
|
|
3
4
|
// Add app data here as needed. Use readonly for immutable fields.
|
|
4
5
|
//
|
|
@@ -31,3 +32,5 @@ export const EnvironmentConfigKeys = {
|
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
export type AppTaskClass = TaskClass<AppStateData, CLIArgs>;
|
|
35
|
+
|
|
36
|
+
export type Yargs = typeof yargs;
|
|
@@ -1,30 +1,77 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
2
|
import CheckEnv from "../../src/tasks/check-env";
|
|
3
3
|
import { LogService } from "../../src/services/log-service";
|
|
4
4
|
import { CommandService } from "task-script-support";
|
|
5
5
|
import { AppStateData, CLIArgs } from "../../src/types/state";
|
|
6
|
+
import { container } from "tsyringe";
|
|
6
7
|
|
|
7
8
|
describe("CheckEnv", () => {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
let mockLogService = {} as LogService;
|
|
10
|
+
let mockCommandService = {} as CommandService<AppStateData, CLIArgs>;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
container.reset();
|
|
14
|
+
|
|
15
|
+
mockLogService = {
|
|
10
16
|
info: vi.fn(),
|
|
11
17
|
debug: vi.fn(),
|
|
18
|
+
error: vi.fn(),
|
|
12
19
|
} as unknown as LogService;
|
|
13
|
-
|
|
20
|
+
|
|
21
|
+
mockCommandService = {
|
|
14
22
|
setData: vi.fn((state, data) => ({
|
|
15
23
|
...state,
|
|
16
24
|
data: { ...state.data, ...data },
|
|
17
25
|
})),
|
|
18
26
|
} as unknown as CommandService<AppStateData, CLIArgs>;
|
|
19
27
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
container.registerInstance(LogService, mockLogService);
|
|
29
|
+
container.registerInstance(
|
|
30
|
+
CommandService<AppStateData, CLIArgs>,
|
|
31
|
+
mockCommandService,
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should set environmentValidated to true", async () => {
|
|
36
|
+
const checkEnv = container.resolve(CheckEnv);
|
|
37
|
+
|
|
24
38
|
await checkEnv.run();
|
|
25
|
-
expect(mockLogService.
|
|
39
|
+
expect(mockLogService.debug).toHaveBeenCalledWith(
|
|
26
40
|
"Running Check Environment",
|
|
27
41
|
);
|
|
28
42
|
expect(checkEnv.state.data.environmentValidated).toBe(true);
|
|
29
43
|
});
|
|
44
|
+
|
|
45
|
+
it("should call exit on missing required environment variable", async () => {
|
|
46
|
+
const testError = new Error("process.exit called");
|
|
47
|
+
const mockExit = vi.spyOn(process, "exit").mockImplementation(() => {
|
|
48
|
+
throw testError;
|
|
49
|
+
});
|
|
50
|
+
const checkEnv = container.resolve(CheckEnv);
|
|
51
|
+
checkEnv.requiredEnv = ["MISSING_ENV_VAR"];
|
|
52
|
+
try {
|
|
53
|
+
expect(await checkEnv.run()).toThrow(testError);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
expect(`${err}`).toContain("process.exit");
|
|
56
|
+
expect(err).toBe(testError);
|
|
57
|
+
}
|
|
58
|
+
expect(mockLogService.error).toHaveBeenCalled();
|
|
59
|
+
mockExit.mockRestore();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should group environment issues into single error log", async () => {
|
|
63
|
+
const testError = new Error("process.exit called");
|
|
64
|
+
const mockExit = vi.spyOn(process, "exit").mockImplementation(() => {
|
|
65
|
+
throw testError;
|
|
66
|
+
});
|
|
67
|
+
const checkEnv = container.resolve(CheckEnv);
|
|
68
|
+
checkEnv.requiredEnv = ["MISSING_ENV_1", "MISSING_ENV_2", "MISSING_ENV_3"];
|
|
69
|
+
try {
|
|
70
|
+
await checkEnv.run();
|
|
71
|
+
} catch (err) {
|
|
72
|
+
expect(err).toBe(testError);
|
|
73
|
+
}
|
|
74
|
+
expect(mockLogService.error).toHaveBeenCalledOnce();
|
|
75
|
+
mockExit.mockRestore();
|
|
76
|
+
});
|
|
30
77
|
});
|
package/dist/package.json
CHANGED
|
@@ -19,7 +19,7 @@ const util_service_1 = require("../../services/util-service");
|
|
|
19
19
|
const file_service_1 = require("../../services/file-service");
|
|
20
20
|
const newProjectMessage = (dest) => `
|
|
21
21
|
Try:
|
|
22
|
-
cd ${dest} && npm i && npm start
|
|
22
|
+
cd ${dest} && npm i && npm start
|
|
23
23
|
`;
|
|
24
24
|
/**
|
|
25
25
|
* Prints the generated output results
|
package/package.json
CHANGED