task-script-support-cli 0.2.7 ā 0.2.8
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/dist/src/commands/configure.d.ts +2 -1
- package/dist/src/commands/configure.d.ts.map +1 -1
- package/dist/src/commands/configure.js +2 -1
- package/dist/src/commands/configure.js.map +1 -1
- package/dist/src/commands/gen.d.ts +2 -1
- package/dist/src/commands/gen.d.ts.map +1 -1
- package/dist/src/commands/gen.js +2 -0
- package/dist/src/commands/gen.js.map +1 -1
- package/dist/src/tasks/check-env.d.ts +0 -17
- package/dist/src/tasks/check-env.d.ts.map +1 -1
- package/dist/src/tasks/check-env.js +0 -53
- package/dist/src/tasks/check-env.js.map +1 -1
- package/dist/src/tasks/generate/project-context-guard.d.ts +42 -0
- package/dist/src/tasks/generate/project-context-guard.d.ts.map +1 -0
- package/dist/src/tasks/generate/project-context-guard.js +119 -0
- package/dist/src/tasks/generate/project-context-guard.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/configure.ts +2 -1
- package/src/commands/gen.ts +2 -0
- package/src/tasks/check-env.ts +0 -55
- package/src/tasks/generate/project-context-guard.ts +116 -0
|
@@ -2,7 +2,8 @@ import { Command } from "../wrappers/command";
|
|
|
2
2
|
import CheckEnv from "../tasks/check-env";
|
|
3
3
|
import ConfigureCache from "../tasks/configure";
|
|
4
4
|
import PrintBanner from "../tasks/stdout/print-banner";
|
|
5
|
+
import ProjectContextGuard from "../tasks/generate/project-context-guard";
|
|
5
6
|
export declare class ConfigureCommand extends Command {
|
|
6
|
-
tasks: (typeof PrintBanner | typeof CheckEnv | typeof ConfigureCache)[];
|
|
7
|
+
tasks: (typeof PrintBanner | typeof CheckEnv | typeof ProjectContextGuard | typeof ConfigureCache)[];
|
|
7
8
|
}
|
|
8
9
|
//# sourceMappingURL=configure.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure.d.ts","sourceRoot":"./src/","sources":["src/commands/configure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,cAAc,MAAM,oBAAoB,CAAC;AAChD,OAAO,WAAW,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"configure.d.ts","sourceRoot":"./src/","sources":["src/commands/configure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,cAAc,MAAM,oBAAoB,CAAC;AAChD,OAAO,WAAW,MAAM,8BAA8B,CAAC;AACvD,OAAO,mBAAmB,MAAM,yCAAyC,CAAC;AAE1E,qBACa,gBAAiB,SAAQ,OAAO;IAC3C,KAAK,gGAAgE;CACtE"}
|
|
@@ -15,8 +15,9 @@ const command_1 = require("../wrappers/command");
|
|
|
15
15
|
const check_env_1 = __importDefault(require("../tasks/check-env"));
|
|
16
16
|
const configure_1 = __importDefault(require("../tasks/configure"));
|
|
17
17
|
const print_banner_1 = __importDefault(require("../tasks/stdout/print-banner"));
|
|
18
|
+
const project_context_guard_1 = __importDefault(require("../tasks/generate/project-context-guard"));
|
|
18
19
|
let ConfigureCommand = class ConfigureCommand extends command_1.Command {
|
|
19
|
-
tasks = [print_banner_1.default, check_env_1.default, configure_1.default];
|
|
20
|
+
tasks = [print_banner_1.default, check_env_1.default, project_context_guard_1.default, configure_1.default];
|
|
20
21
|
};
|
|
21
22
|
exports.ConfigureCommand = ConfigureCommand;
|
|
22
23
|
exports.ConfigureCommand = ConfigureCommand = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure.js","sourceRoot":"./src/","sources":["src/commands/configure.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAqC;AACrC,iDAA8C;AAC9C,mEAA0C;AAC1C,mEAAgD;AAChD,gFAAuD;
|
|
1
|
+
{"version":3,"file":"configure.js","sourceRoot":"./src/","sources":["src/commands/configure.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAqC;AACrC,iDAA8C;AAC9C,mEAA0C;AAC1C,mEAAgD;AAChD,gFAAuD;AACvD,oGAA0E;AAGnE,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,iBAAO;IAC3C,KAAK,GAAG,CAAC,sBAAW,EAAE,mBAAQ,EAAE,+BAAmB,EAAE,mBAAc,CAAC,CAAC;CACtE,CAAA;AAFY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,oBAAS,GAAE;GACC,gBAAgB,CAE5B"}
|
|
@@ -8,7 +8,8 @@ import GenerateTask from "../tasks/generate/generate-task";
|
|
|
8
8
|
import PrintGeneratedResults from "../tasks/stdout/print-generated-results";
|
|
9
9
|
import SyncConfiguration from "../tasks/sync-configuration";
|
|
10
10
|
import SelectGenTargetName from "../tasks/generate/select-gen-target-name";
|
|
11
|
+
import ProjectContextGuard from "../tasks/generate/project-context-guard";
|
|
11
12
|
export declare class GenCommand extends Command {
|
|
12
|
-
tasks: (typeof PrintBanner | typeof CheckEnvironment | typeof SelectGenTarget | typeof PrintGeneratedResults | typeof SyncConfiguration | typeof SelectGenTargetName | (typeof GenerateService | typeof GenerateCommand | typeof GenerateTask)[])[];
|
|
13
|
+
tasks: (typeof PrintBanner | typeof CheckEnvironment | typeof SelectGenTarget | typeof PrintGeneratedResults | typeof SyncConfiguration | typeof SelectGenTargetName | typeof ProjectContextGuard | (typeof GenerateService | typeof GenerateCommand | typeof GenerateTask)[])[];
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=gen.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gen.d.ts","sourceRoot":"./src/","sources":["src/commands/gen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,WAAW,MAAM,8BAA8B,CAAC;AACvD,OAAO,eAAe,MAAM,qCAAqC,CAAC;AAClE,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,YAAY,MAAM,iCAAiC,CAAC;AAC3D,OAAO,qBAAqB,MAAM,yCAAyC,CAAC;AAC5E,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAC5D,OAAO,mBAAmB,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"gen.d.ts","sourceRoot":"./src/","sources":["src/commands/gen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,WAAW,MAAM,8BAA8B,CAAC;AACvD,OAAO,eAAe,MAAM,qCAAqC,CAAC;AAClE,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,YAAY,MAAM,iCAAiC,CAAC;AAC3D,OAAO,qBAAqB,MAAM,yCAAyC,CAAC;AAC5E,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAC5D,OAAO,mBAAmB,MAAM,0CAA0C,CAAC;AAC3E,OAAO,mBAAmB,MAAM,yCAAyC,CAAC;AAE1E,qBACa,UAAW,SAAQ,OAAO;IACrC,KAAK,4QASH;CACH"}
|
package/dist/src/commands/gen.js
CHANGED
|
@@ -21,10 +21,12 @@ const generate_task_1 = __importDefault(require("../tasks/generate/generate-task
|
|
|
21
21
|
const print_generated_results_1 = __importDefault(require("../tasks/stdout/print-generated-results"));
|
|
22
22
|
const sync_configuration_1 = __importDefault(require("../tasks/sync-configuration"));
|
|
23
23
|
const select_gen_target_name_1 = __importDefault(require("../tasks/generate/select-gen-target-name"));
|
|
24
|
+
const project_context_guard_1 = __importDefault(require("../tasks/generate/project-context-guard"));
|
|
24
25
|
let GenCommand = class GenCommand extends command_1.Command {
|
|
25
26
|
tasks = [
|
|
26
27
|
print_banner_1.default,
|
|
27
28
|
check_env_1.default,
|
|
29
|
+
project_context_guard_1.default,
|
|
28
30
|
select_gen_target_1.default,
|
|
29
31
|
sync_configuration_1.default,
|
|
30
32
|
select_gen_target_name_1.default,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gen.js","sourceRoot":"./src/","sources":["src/commands/gen.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAqC;AACrC,iDAA8C;AAC9C,mEAAkD;AAClD,gFAAuD;AACvD,4FAAkE;AAClE,0FAAiE;AACjE,0FAAiE;AACjE,oFAA2D;AAC3D,sGAA4E;AAC5E,qFAA4D;AAC5D,sGAA2E;
|
|
1
|
+
{"version":3,"file":"gen.js","sourceRoot":"./src/","sources":["src/commands/gen.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAqC;AACrC,iDAA8C;AAC9C,mEAAkD;AAClD,gFAAuD;AACvD,4FAAkE;AAClE,0FAAiE;AACjE,0FAAiE;AACjE,oFAA2D;AAC3D,sGAA4E;AAC5E,qFAA4D;AAC5D,sGAA2E;AAC3E,oGAA0E;AAGnE,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,iBAAO;IACrC,KAAK,GAAG;QACN,sBAAW;QACX,mBAAgB;QAChB,+BAAmB;QACnB,2BAAe;QACf,4BAAiB;QACjB,gCAAmB;QACnB,CAAC,0BAAe,EAAE,0BAAe,EAAE,uBAAY,CAAC;QAChD,iCAAqB;KACtB,CAAC;CACH,CAAA;AAXY,gCAAU;qBAAV,UAAU;IADtB,IAAA,oBAAS,GAAE;GACC,UAAU,CAWtB"}
|
|
@@ -10,23 +10,6 @@ export default class CheckEnvironment extends AppTask {
|
|
|
10
10
|
optionalEnvVars: string[];
|
|
11
11
|
constructor(fileService: FileService);
|
|
12
12
|
run(): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Check for the folders we need to generate files in. Add errors
|
|
15
|
-
* when no target directories can be found. Saves project data to
|
|
16
|
-
* state so we don't have to refetch it later.
|
|
17
|
-
*
|
|
18
|
-
* @param projectDir the target project root directory path
|
|
19
|
-
* @param errors string array error messages are added to
|
|
20
|
-
*/
|
|
21
|
-
checkProjectDirectories(projectDir: string, errors: string[]): void;
|
|
22
|
-
/**
|
|
23
|
-
* Check that the project has the right dependencies installed. Adds
|
|
24
|
-
* to the errors array when they can't be found.
|
|
25
|
-
*
|
|
26
|
-
* @param projectDir the target project root directory path
|
|
27
|
-
* @param errors string array error messages are added to
|
|
28
|
-
*/
|
|
29
|
-
checkProjectDependencies(projectDir: string, errors: string[]): void;
|
|
30
13
|
/**
|
|
31
14
|
* Log and exit program if errors are present.
|
|
32
15
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-env.d.ts","sourceRoot":"./src/","sources":["src/tasks/check-env.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"check-env.d.ts","sourceRoot":"./src/","sources":["src/tasks/check-env.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,OAAO;IAcvC,OAAO,CAAC,WAAW;IAb/B,UAAU,SAAuB;IAEjC,eAAe,EAAE,MAAM,EAAE,CAAM;IAE/B,eAAe,WAOb;gBAEkB,WAAW,EAAE,WAAW;IAItC,GAAG;IAYT;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAOnB;;;;OAIG;IACH,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,eAAe,CAKjB;IAEN,OAAO,CAAC,gBAAgB,CAGsC;CAC/D"}
|
|
@@ -17,7 +17,6 @@ const app_task_1 = require("../wrappers/app-task");
|
|
|
17
17
|
const tsyringe_1 = require("tsyringe");
|
|
18
18
|
const state_1 = require("../types/state");
|
|
19
19
|
const file_service_1 = require("../services/file-service");
|
|
20
|
-
const path_1 = __importDefault(require("path"));
|
|
21
20
|
/**
|
|
22
21
|
* Checks the environment configuration
|
|
23
22
|
*/
|
|
@@ -43,61 +42,9 @@ let CheckEnvironment = class CheckEnvironment extends app_task_1.AppTask {
|
|
|
43
42
|
this.getReadMessages(envVars).forEach((m) => this.logger.debug(m));
|
|
44
43
|
const errors = this.getErrorMessages(this.requiredEnvVars);
|
|
45
44
|
this.checkToExit(errors);
|
|
46
|
-
try {
|
|
47
|
-
const projectDir = this.fileService.getRunnerRootDir();
|
|
48
|
-
this.checkProjectDependencies(projectDir, errors);
|
|
49
|
-
this.checkProjectDirectories(projectDir, errors);
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
errors.push(`Unexpected error checking project: ${err}`);
|
|
53
|
-
}
|
|
54
45
|
this.checkToExit(errors);
|
|
55
46
|
this.setData({ environmentValidated: true });
|
|
56
47
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Check for the folders we need to generate files in. Add errors
|
|
59
|
-
* when no target directories can be found. Saves project data to
|
|
60
|
-
* state so we don't have to refetch it later.
|
|
61
|
-
*
|
|
62
|
-
* @param projectDir the target project root directory path
|
|
63
|
-
* @param errors string array error messages are added to
|
|
64
|
-
*/
|
|
65
|
-
checkProjectDirectories(projectDir, errors) {
|
|
66
|
-
const directories = {
|
|
67
|
-
taskFolders: this.fileService.getTaskDirs(projectDir),
|
|
68
|
-
serviceFolders: this.fileService.getServiceDirs(projectDir),
|
|
69
|
-
commandFolders: this.fileService.getCommandDirs(projectDir),
|
|
70
|
-
};
|
|
71
|
-
Object.keys(directories).forEach((k) => {
|
|
72
|
-
const key = k;
|
|
73
|
-
if (!directories[key] || !directories[key].length) {
|
|
74
|
-
errors.push(`Unable to find any ${k} in project`);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
this.setData({
|
|
78
|
-
project: {
|
|
79
|
-
rootDir: projectDir,
|
|
80
|
-
...directories,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Check that the project has the right dependencies installed. Adds
|
|
86
|
-
* to the errors array when they can't be found.
|
|
87
|
-
*
|
|
88
|
-
* @param projectDir the target project root directory path
|
|
89
|
-
* @param errors string array error messages are added to
|
|
90
|
-
*/
|
|
91
|
-
checkProjectDependencies(projectDir, errors) {
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
93
|
-
const packagePath = require(path_1.default.join(projectDir, "package.json"));
|
|
94
|
-
const requireDeps = ["task-script-support", "tsyringe"];
|
|
95
|
-
requireDeps.forEach((d) => {
|
|
96
|
-
if (!Object.keys(packagePath.dependencies || {}).includes(d)) {
|
|
97
|
-
errors.push(`Missing required dependencies in project: '${d}'`);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
48
|
/**
|
|
102
49
|
* Log and exit program if errors are present.
|
|
103
50
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-env.js","sourceRoot":"./src/","sources":["src/tasks/check-env.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,mDAA+C;AAC/C,uCAA0C;AAC1C,0CAAuD;AACvD,2DAAuD;
|
|
1
|
+
{"version":3,"file":"check-env.js","sourceRoot":"./src/","sources":["src/tasks/check-env.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,mDAA+C;AAC/C,uCAA0C;AAC1C,0CAAuD;AACvD,2DAAuD;AAEvD;;GAEG;AAEY,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,kBAAO;IAc/B;IAbpB,UAAU,GAAG,mBAAmB,CAAC;IAEjC,eAAe,GAAa,E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M,CAAC,KAAK,CACf,IAAI,KAAK,CAAC,2BAA2B,CAAC,EACtC,eAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAC7B,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,eAAe,GAAG,CAAC,UAAoB,EAAE,EAAE,CACjD,UAAU;SACP,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SAC/B,GAAG,CACF,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,eAAK,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CACrE,CAAC;IAEE,gBAAgB,GAAG,CAAC,UAAoB,EAAE,EAAE,CAClD,UAAU;SACP,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,yCAAyC,CAAC,EAAE,CAAC,CAAC;CAC/D,CAAA;AAnEoB,gBAAgB;IADpC,IAAA,yBAAc,GAAE;qCAekB,0BAAW;GAdzB,gBAAgB,CAmEpC;kBAnEoB,gBAAgB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FileService } from "../../services/file-service";
|
|
2
|
+
import { AppTask } from "../../wrappers/app-task";
|
|
3
|
+
/**
|
|
4
|
+
* Checks so see if we are in the context of a task-script-support
|
|
5
|
+
* project or not and fails the process with a friendly error message.
|
|
6
|
+
*/
|
|
7
|
+
export default class ProjectContextGuard extends AppTask {
|
|
8
|
+
private fileService;
|
|
9
|
+
loggerName: string;
|
|
10
|
+
constructor(fileService: FileService);
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Check for the folders we need to generate files in. Add errors
|
|
14
|
+
* when no target directories can be found. Saves project data to
|
|
15
|
+
* state so we don't have to refetch it later.
|
|
16
|
+
*
|
|
17
|
+
* @param projectDir the target project root directory path
|
|
18
|
+
* @param errors string array error messages are added to
|
|
19
|
+
*/
|
|
20
|
+
checkProjectDirectories(projectDir: string, errors: string[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Check that the project has the right dependencies installed. Adds
|
|
23
|
+
* to the errors array when they can't be found.
|
|
24
|
+
*
|
|
25
|
+
* @param projectDir the target project root directory path
|
|
26
|
+
* @param errors string array error messages are added to
|
|
27
|
+
*/
|
|
28
|
+
checkProjectDependencies(projectDir: string, errors: string[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Log and exit program if errors are present.
|
|
31
|
+
*
|
|
32
|
+
* @param errors the error messages array to check
|
|
33
|
+
*/
|
|
34
|
+
private checkToExit;
|
|
35
|
+
/**
|
|
36
|
+
* Logs any error messages in the provided array.
|
|
37
|
+
*
|
|
38
|
+
* @param errors the error messages array to log
|
|
39
|
+
*/
|
|
40
|
+
private logEnvErrors;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=project-context-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-context-guard.d.ts","sourceRoot":"./src/","sources":["src/tasks/generate/project-context-guard.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD;;;GAGG;AAEH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,OAAO;IAG1C,OAAO,CAAC,WAAW;IAF/B,UAAU,SAA2B;gBAEjB,WAAW,EAAE,WAAW;IAItC,GAAG;IAwBT;;;;;;;OAOG;IACH,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;IAoB5D;;;;;;OAMG;IACH,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;IAa7D;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAOnB;;;;OAIG;IACH,OAAO,CAAC,YAAY;CAQrB"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
16
|
+
const file_service_1 = require("../../services/file-service");
|
|
17
|
+
const app_task_1 = require("../../wrappers/app-task");
|
|
18
|
+
const tsyringe_1 = require("tsyringe");
|
|
19
|
+
/**
|
|
20
|
+
* Checks so see if we are in the context of a task-script-support
|
|
21
|
+
* project or not and fails the process with a friendly error message.
|
|
22
|
+
*/
|
|
23
|
+
let ProjectContextGuard = class ProjectContextGuard extends app_task_1.AppTask {
|
|
24
|
+
fileService;
|
|
25
|
+
loggerName = "Project Context Check";
|
|
26
|
+
constructor(fileService) {
|
|
27
|
+
super();
|
|
28
|
+
this.fileService = fileService;
|
|
29
|
+
}
|
|
30
|
+
async run() {
|
|
31
|
+
this.logger.info(chalk_1.default.blueBright("Running Project Check"));
|
|
32
|
+
const errors = [];
|
|
33
|
+
try {
|
|
34
|
+
const projectDir = this.fileService.getRunnerRootDir();
|
|
35
|
+
this.checkProjectDependencies(projectDir, errors);
|
|
36
|
+
this.checkProjectDirectories(projectDir, errors);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
errors.push(`Unexpected error checking project: ${err}`);
|
|
40
|
+
}
|
|
41
|
+
if (errors.length) {
|
|
42
|
+
this.logger.error(`\n\nš§ ${chalk_1.default.yellowBright("Note")}: This command requires execution from a ${chalk_1.default.blueBright("task-script-support")} project (folder)` +
|
|
43
|
+
`\n - Try running the ${chalk_1.default.blueBright("tssc " + chalk_1.default.bold("new"))} command to create a new project \n`, "Error Note");
|
|
44
|
+
}
|
|
45
|
+
this.checkToExit(errors);
|
|
46
|
+
this.setData({ environmentValidated: true });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check for the folders we need to generate files in. Add errors
|
|
50
|
+
* when no target directories can be found. Saves project data to
|
|
51
|
+
* state so we don't have to refetch it later.
|
|
52
|
+
*
|
|
53
|
+
* @param projectDir the target project root directory path
|
|
54
|
+
* @param errors string array error messages are added to
|
|
55
|
+
*/
|
|
56
|
+
checkProjectDirectories(projectDir, errors) {
|
|
57
|
+
const directories = {
|
|
58
|
+
taskFolders: this.fileService.getTaskDirs(projectDir),
|
|
59
|
+
serviceFolders: this.fileService.getServiceDirs(projectDir),
|
|
60
|
+
commandFolders: this.fileService.getCommandDirs(projectDir),
|
|
61
|
+
};
|
|
62
|
+
Object.keys(directories).forEach((k) => {
|
|
63
|
+
const key = k;
|
|
64
|
+
if (!directories[key] || !directories[key].length) {
|
|
65
|
+
errors.push(`Unable to find any ${k} in project`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
this.setData({
|
|
69
|
+
project: {
|
|
70
|
+
rootDir: projectDir,
|
|
71
|
+
...directories,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check that the project has the right dependencies installed. Adds
|
|
77
|
+
* to the errors array when they can't be found.
|
|
78
|
+
*
|
|
79
|
+
* @param projectDir the target project root directory path
|
|
80
|
+
* @param errors string array error messages are added to
|
|
81
|
+
*/
|
|
82
|
+
checkProjectDependencies(projectDir, errors) {
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
84
|
+
const packagePath = require(this.fileService.join(projectDir, "package.json"));
|
|
85
|
+
const requireDeps = ["task-script-support", "tsyringe"];
|
|
86
|
+
requireDeps.forEach((d) => {
|
|
87
|
+
if (!Object.keys(packagePath.dependencies || {}).includes(d)) {
|
|
88
|
+
errors.push(`Missing required dependencies in project: '${d}'`);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Log and exit program if errors are present.
|
|
94
|
+
*
|
|
95
|
+
* @param errors the error messages array to check
|
|
96
|
+
*/
|
|
97
|
+
checkToExit(errors) {
|
|
98
|
+
if (errors.length) {
|
|
99
|
+
this.logEnvErrors(errors);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Logs any error messages in the provided array.
|
|
105
|
+
*
|
|
106
|
+
* @param errors the error messages array to log
|
|
107
|
+
*/
|
|
108
|
+
logEnvErrors(errors) {
|
|
109
|
+
if (errors.length) {
|
|
110
|
+
this.logger.error(new Error("Misconfigured Environment"), `Errors: \n${chalk_1.default.red(errors.join("\n"))}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
ProjectContextGuard = __decorate([
|
|
115
|
+
(0, tsyringe_1.autoInjectable)(),
|
|
116
|
+
__metadata("design:paramtypes", [file_service_1.FileService])
|
|
117
|
+
], ProjectContextGuard);
|
|
118
|
+
exports.default = ProjectContextGuard;
|
|
119
|
+
//# sourceMappingURL=project-context-guard.js.map
|
|
@@ -0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AE,CAAC;gBAC7D,MAAM,CAAC,IAAI,CAAC,8CAA8C,CAAC,GAAG,CAAC,CAAC;YAClE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACK,WAAW,CAAC,MAAgB;QAClC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACK,YAAY,CAAC,MAAgB;QACnC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,IAAI,KAAK,CAAC,2BAA2B,CAAC,EACtC,aAAa,eAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAC5C,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AAxGoB,mBAAmB;IADvC,IAAA,yBAAc,GAAE;qCAIkB,0BAAW;GAHzB,mBAAmB,CAwGvC;kBAxGoB,mBAAmB"}
|
package/package.json
CHANGED
|
@@ -3,8 +3,9 @@ import { Command } from "../wrappers/command";
|
|
|
3
3
|
import CheckEnv from "../tasks/check-env";
|
|
4
4
|
import ConfigureCache from "../tasks/configure";
|
|
5
5
|
import PrintBanner from "../tasks/stdout/print-banner";
|
|
6
|
+
import ProjectContextGuard from "../tasks/generate/project-context-guard";
|
|
6
7
|
|
|
7
8
|
@singleton()
|
|
8
9
|
export class ConfigureCommand extends Command {
|
|
9
|
-
tasks = [PrintBanner, CheckEnv, ConfigureCache];
|
|
10
|
+
tasks = [PrintBanner, CheckEnv, ProjectContextGuard, ConfigureCache];
|
|
10
11
|
}
|
package/src/commands/gen.ts
CHANGED
|
@@ -9,12 +9,14 @@ import GenerateTask from "../tasks/generate/generate-task";
|
|
|
9
9
|
import PrintGeneratedResults from "../tasks/stdout/print-generated-results";
|
|
10
10
|
import SyncConfiguration from "../tasks/sync-configuration";
|
|
11
11
|
import SelectGenTargetName from "../tasks/generate/select-gen-target-name";
|
|
12
|
+
import ProjectContextGuard from "../tasks/generate/project-context-guard";
|
|
12
13
|
|
|
13
14
|
@singleton()
|
|
14
15
|
export class GenCommand extends Command {
|
|
15
16
|
tasks = [
|
|
16
17
|
PrintBanner,
|
|
17
18
|
CheckEnvironment,
|
|
19
|
+
ProjectContextGuard,
|
|
18
20
|
SelectGenTarget,
|
|
19
21
|
SyncConfiguration,
|
|
20
22
|
SelectGenTargetName,
|
package/src/tasks/check-env.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { AppTask } from "../wrappers/app-task";
|
|
|
3
3
|
import { autoInjectable } from "tsyringe";
|
|
4
4
|
import { EnvironmentConfigKeys } from "../types/state";
|
|
5
5
|
import { FileService } from "../services/file-service";
|
|
6
|
-
import path from "path";
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Checks the environment configuration
|
|
@@ -35,64 +34,10 @@ export default class CheckEnvironment extends AppTask {
|
|
|
35
34
|
const errors: string[] = this.getErrorMessages(this.requiredEnvVars);
|
|
36
35
|
this.checkToExit(errors);
|
|
37
36
|
|
|
38
|
-
try {
|
|
39
|
-
const projectDir = this.fileService.getRunnerRootDir();
|
|
40
|
-
this.checkProjectDependencies(projectDir, errors);
|
|
41
|
-
this.checkProjectDirectories(projectDir, errors);
|
|
42
|
-
} catch (err) {
|
|
43
|
-
errors.push(`Unexpected error checking project: ${err}`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
37
|
this.checkToExit(errors);
|
|
47
38
|
this.setData({ environmentValidated: true });
|
|
48
39
|
}
|
|
49
40
|
|
|
50
|
-
/**
|
|
51
|
-
* Check for the folders we need to generate files in. Add errors
|
|
52
|
-
* when no target directories can be found. Saves project data to
|
|
53
|
-
* state so we don't have to refetch it later.
|
|
54
|
-
*
|
|
55
|
-
* @param projectDir the target project root directory path
|
|
56
|
-
* @param errors string array error messages are added to
|
|
57
|
-
*/
|
|
58
|
-
checkProjectDirectories(projectDir: string, errors: string[]) {
|
|
59
|
-
const directories = {
|
|
60
|
-
taskFolders: this.fileService.getTaskDirs(projectDir),
|
|
61
|
-
serviceFolders: this.fileService.getServiceDirs(projectDir),
|
|
62
|
-
commandFolders: this.fileService.getCommandDirs(projectDir),
|
|
63
|
-
};
|
|
64
|
-
Object.keys(directories).forEach((k: string) => {
|
|
65
|
-
const key: keyof typeof directories = k as keyof typeof directories;
|
|
66
|
-
if (!directories[key] || !directories[key].length) {
|
|
67
|
-
errors.push(`Unable to find any ${k} in project`);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
this.setData({
|
|
71
|
-
project: {
|
|
72
|
-
rootDir: projectDir,
|
|
73
|
-
...directories,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Check that the project has the right dependencies installed. Adds
|
|
80
|
-
* to the errors array when they can't be found.
|
|
81
|
-
*
|
|
82
|
-
* @param projectDir the target project root directory path
|
|
83
|
-
* @param errors string array error messages are added to
|
|
84
|
-
*/
|
|
85
|
-
checkProjectDependencies(projectDir: string, errors: string[]) {
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
87
|
-
const packagePath = require(path.join(projectDir, "package.json"));
|
|
88
|
-
const requireDeps = ["task-script-support", "tsyringe"];
|
|
89
|
-
requireDeps.forEach((d) => {
|
|
90
|
-
if (!Object.keys(packagePath.dependencies || {}).includes(d)) {
|
|
91
|
-
errors.push(`Missing required dependencies in project: '${d}'`);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
41
|
/**
|
|
97
42
|
* Log and exit program if errors are present.
|
|
98
43
|
*
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { FileService } from "../../services/file-service";
|
|
3
|
+
import { AppTask } from "../../wrappers/app-task";
|
|
4
|
+
import { autoInjectable } from "tsyringe";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Checks so see if we are in the context of a task-script-support
|
|
8
|
+
* project or not and fails the process with a friendly error message.
|
|
9
|
+
*/
|
|
10
|
+
@autoInjectable()
|
|
11
|
+
export default class ProjectContextGuard extends AppTask {
|
|
12
|
+
loggerName = "Project Context Check";
|
|
13
|
+
|
|
14
|
+
constructor(private fileService: FileService) {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async run() {
|
|
19
|
+
this.logger.info(chalk.blueBright("Running Project Check"));
|
|
20
|
+
|
|
21
|
+
const errors: string[] = [];
|
|
22
|
+
try {
|
|
23
|
+
const projectDir = this.fileService.getRunnerRootDir();
|
|
24
|
+
this.checkProjectDependencies(projectDir, errors);
|
|
25
|
+
this.checkProjectDirectories(projectDir, errors);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
errors.push(`Unexpected error checking project: ${err}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (errors.length) {
|
|
31
|
+
// give jimmy a message
|
|
32
|
+
this.logger.error(
|
|
33
|
+
`\n\nš§ ${chalk.yellowBright("Note")}: This command requires execution from a ${chalk.blueBright("task-script-support")} project (folder)` +
|
|
34
|
+
`\n - Try running the ${chalk.blueBright("tssc " + chalk.bold("new"))} command to create a new project \n`,
|
|
35
|
+
"Error Note",
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.checkToExit(errors);
|
|
40
|
+
this.setData({ environmentValidated: true });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check for the folders we need to generate files in. Add errors
|
|
45
|
+
* when no target directories can be found. Saves project data to
|
|
46
|
+
* state so we don't have to refetch it later.
|
|
47
|
+
*
|
|
48
|
+
* @param projectDir the target project root directory path
|
|
49
|
+
* @param errors string array error messages are added to
|
|
50
|
+
*/
|
|
51
|
+
checkProjectDirectories(projectDir: string, errors: string[]) {
|
|
52
|
+
const directories = {
|
|
53
|
+
taskFolders: this.fileService.getTaskDirs(projectDir),
|
|
54
|
+
serviceFolders: this.fileService.getServiceDirs(projectDir),
|
|
55
|
+
commandFolders: this.fileService.getCommandDirs(projectDir),
|
|
56
|
+
};
|
|
57
|
+
Object.keys(directories).forEach((k: string) => {
|
|
58
|
+
const key: keyof typeof directories = k as keyof typeof directories;
|
|
59
|
+
if (!directories[key] || !directories[key].length) {
|
|
60
|
+
errors.push(`Unable to find any ${k} in project`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
this.setData({
|
|
64
|
+
project: {
|
|
65
|
+
rootDir: projectDir,
|
|
66
|
+
...directories,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Check that the project has the right dependencies installed. Adds
|
|
73
|
+
* to the errors array when they can't be found.
|
|
74
|
+
*
|
|
75
|
+
* @param projectDir the target project root directory path
|
|
76
|
+
* @param errors string array error messages are added to
|
|
77
|
+
*/
|
|
78
|
+
checkProjectDependencies(projectDir: string, errors: string[]) {
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
80
|
+
const packagePath = require(
|
|
81
|
+
this.fileService.join(projectDir, "package.json"),
|
|
82
|
+
);
|
|
83
|
+
const requireDeps = ["task-script-support", "tsyringe"];
|
|
84
|
+
requireDeps.forEach((d) => {
|
|
85
|
+
if (!Object.keys(packagePath.dependencies || {}).includes(d)) {
|
|
86
|
+
errors.push(`Missing required dependencies in project: '${d}'`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Log and exit program if errors are present.
|
|
93
|
+
*
|
|
94
|
+
* @param errors the error messages array to check
|
|
95
|
+
*/
|
|
96
|
+
private checkToExit(errors: string[]) {
|
|
97
|
+
if (errors.length) {
|
|
98
|
+
this.logEnvErrors(errors);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Logs any error messages in the provided array.
|
|
105
|
+
*
|
|
106
|
+
* @param errors the error messages array to log
|
|
107
|
+
*/
|
|
108
|
+
private logEnvErrors(errors: string[]): void {
|
|
109
|
+
if (errors.length) {
|
|
110
|
+
this.logger.error(
|
|
111
|
+
new Error("Misconfigured Environment"),
|
|
112
|
+
`Errors: \n${chalk.red(errors.join("\n"))}`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|