task-script-support-cli 0.3.0 → 0.3.3

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 (85) hide show
  1. package/assets/yargs-template/task-runner/package-lock.json +128 -110
  2. package/assets/yargs-template/task-runner/src/commands/verify.ts +3 -2
  3. package/assets/yargs-template/task-runner/src/services/banner-service.ts +13 -9
  4. package/assets/yargs-template/task-runner/src/tasks/banner/print-banner.ts +38 -0
  5. package/assets/yargs-template/task-runner/src/tasks/banner/resolve-banner-font.ts +70 -0
  6. package/assets/yargs-template/task-runner/src/types/state.ts +4 -0
  7. package/{dist/assets/yargs-template/task-runner/src/wrappers → assets/yargs-template/task-runner/src/wrappers/electives}/concurrent-task-group.ts +4 -4
  8. package/assets/yargs-template/task-runner/src/wrappers/electives/resolver-task.ts +87 -0
  9. package/assets/yargs-template/task-runner/src/wrappers/{sequential-task-group.ts → electives/sequential-task-group.ts} +4 -4
  10. package/assets/yargs-template/task-runner/tests/commands/verify.test.ts +14 -21
  11. package/dist/assets/yargs-template/task-runner/package-lock.json +128 -110
  12. package/dist/assets/yargs-template/task-runner/src/commands/verify.ts +3 -2
  13. package/dist/assets/yargs-template/task-runner/src/services/banner-service.ts +13 -9
  14. package/dist/assets/yargs-template/task-runner/src/tasks/banner/print-banner.ts +38 -0
  15. package/dist/assets/yargs-template/task-runner/src/tasks/banner/resolve-banner-font.ts +70 -0
  16. package/dist/assets/yargs-template/task-runner/src/types/state.ts +4 -0
  17. package/{assets/yargs-template/task-runner/src/wrappers → dist/assets/yargs-template/task-runner/src/wrappers/electives}/concurrent-task-group.ts +4 -4
  18. package/dist/assets/yargs-template/task-runner/src/wrappers/electives/resolver-task.ts +87 -0
  19. package/dist/assets/yargs-template/task-runner/src/wrappers/{sequential-task-group.ts → electives/sequential-task-group.ts} +4 -4
  20. package/dist/assets/yargs-template/task-runner/tests/commands/verify.test.ts +14 -21
  21. package/dist/package.json +1 -1
  22. package/dist/src/commands/gen.d.ts +3 -1
  23. package/dist/src/commands/gen.d.ts.map +1 -1
  24. package/dist/src/commands/gen.js +2 -0
  25. package/dist/src/commands/gen.js.map +1 -1
  26. package/dist/src/services/project-service.d.ts +21 -0
  27. package/dist/src/services/project-service.d.ts.map +1 -1
  28. package/dist/src/services/project-service.js +41 -0
  29. package/dist/src/services/project-service.js.map +1 -1
  30. package/dist/src/services/templater-service.d.ts +1 -0
  31. package/dist/src/services/templater-service.d.ts.map +1 -1
  32. package/dist/src/services/templater-service.js +9 -3
  33. package/dist/src/services/templater-service.js.map +1 -1
  34. package/dist/src/tasks/generate/generate-command.d.ts +10 -3
  35. package/dist/src/tasks/generate/generate-command.d.ts.map +1 -1
  36. package/dist/src/tasks/generate/generate-command.js +27 -11
  37. package/dist/src/tasks/generate/generate-command.js.map +1 -1
  38. package/dist/src/tasks/generate/generate-service.d.ts +10 -3
  39. package/dist/src/tasks/generate/generate-service.d.ts.map +1 -1
  40. package/dist/src/tasks/generate/generate-service.js +26 -12
  41. package/dist/src/tasks/generate/generate-service.js.map +1 -1
  42. package/dist/src/tasks/generate/generate-task.d.ts +10 -3
  43. package/dist/src/tasks/generate/generate-task.d.ts.map +1 -1
  44. package/dist/src/tasks/generate/generate-task.js +27 -13
  45. package/dist/src/tasks/generate/generate-task.js.map +1 -1
  46. package/dist/src/tasks/generate/project-context-guard.d.ts +1 -1
  47. package/dist/src/tasks/generate/project-context-guard.js +1 -1
  48. package/dist/src/tasks/generate/resolve-injectables.d.ts +56 -0
  49. package/dist/src/tasks/generate/resolve-injectables.d.ts.map +1 -0
  50. package/dist/src/tasks/generate/resolve-injectables.js +134 -0
  51. package/dist/src/tasks/generate/resolve-injectables.js.map +1 -0
  52. package/dist/src/tasks/generate/select-gen-target-name.js +4 -4
  53. package/dist/src/tasks/generate/select-gen-target-name.js.map +1 -1
  54. package/dist/src/tasks/generate/select-gen-target.d.ts +1 -1
  55. package/dist/src/tasks/generate/select-gen-target.js +2 -2
  56. package/dist/src/tasks/generate/select-gen-target.js.map +1 -1
  57. package/dist/src/tasks/stdout/print-generated-results.js +2 -2
  58. package/dist/src/tasks/stdout/print-generated-results.js.map +1 -1
  59. package/dist/src/tasks/sync-configuration.d.ts +1 -1
  60. package/dist/src/tasks/sync-configuration.js +6 -6
  61. package/dist/src/tasks/sync-configuration.js.map +1 -1
  62. package/dist/src/types/state.d.ts +7 -3
  63. package/dist/src/types/state.d.ts.map +1 -1
  64. package/dist/src/types/state.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/commands/gen.ts +2 -0
  67. package/src/services/project-service.ts +54 -0
  68. package/src/services/templater-service.ts +15 -3
  69. package/src/tasks/generate/generate-command.ts +21 -11
  70. package/src/tasks/generate/generate-service.ts +20 -11
  71. package/src/tasks/generate/generate-task.ts +21 -12
  72. package/src/tasks/generate/project-context-guard.ts +1 -1
  73. package/src/tasks/generate/resolve-injectables.ts +154 -0
  74. package/src/tasks/generate/select-gen-target-name.ts +4 -4
  75. package/src/tasks/generate/select-gen-target.ts +2 -2
  76. package/src/tasks/stdout/print-generated-results.ts +2 -2
  77. package/src/tasks/sync-configuration.ts +6 -6
  78. package/src/types/state.ts +9 -3
  79. package/assets/yargs-template/task-runner/src/tasks/print-banner.ts +0 -73
  80. package/dist/assets/yargs-template/task-runner/src/tasks/print-banner.ts +0 -73
  81. package/dist/src/wrappers/gen-app-task.d.ts +0 -50
  82. package/dist/src/wrappers/gen-app-task.d.ts.map +0 -1
  83. package/dist/src/wrappers/gen-app-task.js +0 -124
  84. package/dist/src/wrappers/gen-app-task.js.map +0 -1
  85. package/src/wrappers/gen-app-task.ts +0 -150
@@ -39,15 +39,15 @@ export default class SyncConfiguration extends AppTask {
39
39
  }
40
40
 
41
41
  // get target destination if not cached yet
42
- if (this.state.data.genTargetType) {
43
- const targetType = this.state.data.genTargetType;
42
+ if (this.state.data.genData?.targetType) {
43
+ const targetType = this.state.data.genData.targetType;
44
44
  const destinationKey: keyof typeof project = `${targetType}Destination`;
45
45
  project[destinationKey] =
46
46
  project[destinationKey] || (await this.getDestination(targetType));
47
47
  this.logDestination(project[destinationKey]);
48
48
  }
49
49
 
50
- // attempt to determine others config without prompting
50
+ // attempt to determine other config dirs without prompting
51
51
  const isPassive: boolean = true;
52
52
  project.commandDestination =
53
53
  project.commandDestination ||
@@ -75,7 +75,7 @@ export default class SyncConfiguration extends AppTask {
75
75
 
76
76
  /**
77
77
  * Gets the destination path for generating resources by resource type.
78
- * If only one resource destination folder was found it is returned
78
+ * If only one resource destination folder was found, it is returned,
79
79
  * otherwise the user is prompted to select one from the found folders.
80
80
  *
81
81
  * @param keyType the type of destination to resolve
@@ -121,9 +121,9 @@ export default class SyncConfiguration extends AppTask {
121
121
  );
122
122
  }
123
123
 
124
- if (!this.state.data.genTargetType) {
124
+ if (!this.state.data.genData?.targetType) {
125
125
  throw new Error(
126
- `Missing genTargetType! SyncConfiguration requires the SelectGenTarget task to be ran first.`,
126
+ `Missing genData.targetType! SyncConfiguration requires the SelectGenTarget task to be ran first.`,
127
127
  );
128
128
  }
129
129
  }
@@ -1,6 +1,6 @@
1
1
  import { CLIArg } from "./process";
2
2
  import { AppState as State, TaskClass } from "task-script-support";
3
- import { ProjectConfig, ProjectData } from "./project";
3
+ import { ProjectConfig, ProjectData, ProjectImport } from "./project";
4
4
 
5
5
  export enum GenTargetType {
6
6
  Command = "command",
@@ -8,12 +8,18 @@ export enum GenTargetType {
8
8
  Task = "task",
9
9
  }
10
10
 
11
+ export interface GenData {
12
+ readonly targetType?: GenTargetType;
13
+ readonly targetName?: string;
14
+ readonly imports?: ProjectImport[];
15
+ }
16
+
11
17
  export interface AppStateData {
12
18
  readonly banner?: {
13
19
  readonly font?: string;
14
20
  };
15
- readonly genTargetType?: GenTargetType;
16
- readonly genTargetName?: string;
21
+
22
+ readonly genData?: GenData;
17
23
 
18
24
  readonly environmentValidated?: boolean;
19
25
  readonly project?: ProjectConfig & ProjectData;
@@ -1,73 +0,0 @@
1
- import { autoInjectable } from "tsyringe";
2
- import { AppState } from "../types/state";
3
- import { AppTask } from "../wrappers/app-task";
4
- import { BannerService } from "../services/banner-service";
5
- import { UtilService } from "../services/util-service";
6
- import chalk from "chalk";
7
-
8
- /**
9
- * Prints an app banner to the console
10
- */
11
- @autoInjectable()
12
- export default class PrintBanner extends AppTask {
13
- loggerName = "Print Banner";
14
-
15
- constructor(
16
- private bannnerSvc: BannerService,
17
- private utilService: UtilService,
18
- ) {
19
- super();
20
- }
21
-
22
- async preRun() {
23
- await this.validateFont();
24
- }
25
-
26
- async run({ args }: AppState): Promise<Partial<AppState> | void> {
27
- let font = "";
28
-
29
- try {
30
- if (args.randomFont) {
31
- font = await this.bannnerSvc.getRandomFont();
32
- console.log(`Using random font ${font}`);
33
- }
34
-
35
- // allow banner-font as user input
36
- if (args.bannerFont) {
37
- font = args.bannerFont;
38
- }
39
-
40
- console.log(
41
- chalk.blueBright(
42
- await this.bannnerSvc.toBanner(this.utilService.getAppName(), font),
43
- ),
44
- );
45
-
46
- // mutate state
47
- this.setData({
48
- banner: { font: font || this.bannnerSvc.defaultFontFamily },
49
- });
50
-
51
- // return updated state instead of calling setData
52
- return { data: { banner: { status: "success" } } } as const;
53
- } catch (err) {
54
- this.setData({ banner: { status: "failed" }, errorMessages: [`${err}`] });
55
- }
56
- }
57
-
58
- /*
59
- Helper for ensuring font is supported if provided as input
60
- */
61
- async validateFont() {
62
- const { args } = this.state;
63
- if (!args.bannerFont) {
64
- return;
65
- }
66
-
67
- const fontName = args.bannerFont;
68
- const availableFonts = await this.bannnerSvc.getSupportedFonts();
69
- if (!availableFonts.includes(fontName)) {
70
- throw new Error(`Unsupported font provided: ${chalk.red(fontName)}`);
71
- }
72
- }
73
- }
@@ -1,73 +0,0 @@
1
- import { autoInjectable } from "tsyringe";
2
- import { AppState } from "../types/state";
3
- import { AppTask } from "../wrappers/app-task";
4
- import { BannerService } from "../services/banner-service";
5
- import { UtilService } from "../services/util-service";
6
- import chalk from "chalk";
7
-
8
- /**
9
- * Prints an app banner to the console
10
- */
11
- @autoInjectable()
12
- export default class PrintBanner extends AppTask {
13
- loggerName = "Print Banner";
14
-
15
- constructor(
16
- private bannnerSvc: BannerService,
17
- private utilService: UtilService,
18
- ) {
19
- super();
20
- }
21
-
22
- async preRun() {
23
- await this.validateFont();
24
- }
25
-
26
- async run({ args }: AppState): Promise<Partial<AppState> | void> {
27
- let font = "";
28
-
29
- try {
30
- if (args.randomFont) {
31
- font = await this.bannnerSvc.getRandomFont();
32
- console.log(`Using random font ${font}`);
33
- }
34
-
35
- // allow banner-font as user input
36
- if (args.bannerFont) {
37
- font = args.bannerFont;
38
- }
39
-
40
- console.log(
41
- chalk.blueBright(
42
- await this.bannnerSvc.toBanner(this.utilService.getAppName(), font),
43
- ),
44
- );
45
-
46
- // mutate state
47
- this.setData({
48
- banner: { font: font || this.bannnerSvc.defaultFontFamily },
49
- });
50
-
51
- // return updated state instead of calling setData
52
- return { data: { banner: { status: "success" } } } as const;
53
- } catch (err) {
54
- this.setData({ banner: { status: "failed" }, errorMessages: [`${err}`] });
55
- }
56
- }
57
-
58
- /*
59
- Helper for ensuring font is supported if provided as input
60
- */
61
- async validateFont() {
62
- const { args } = this.state;
63
- if (!args.bannerFont) {
64
- return;
65
- }
66
-
67
- const fontName = args.bannerFont;
68
- const availableFonts = await this.bannnerSvc.getSupportedFonts();
69
- if (!availableFonts.includes(fontName)) {
70
- throw new Error(`Unsupported font provided: ${chalk.red(fontName)}`);
71
- }
72
- }
73
- }
@@ -1,50 +0,0 @@
1
- import { AppTask } from "./app-task";
2
- import { UtilService } from "../services/util-service";
3
- import { FileService } from "../services/file-service";
4
- import { ProjectService } from "../services/project-service";
5
- import { PromptService } from "../services/prompt-service";
6
- /**
7
- * Generation Task Type
8
- */
9
- export default class GenAppTask extends AppTask {
10
- protected utilService: UtilService;
11
- protected fileService: FileService;
12
- protected projectService: ProjectService;
13
- protected promptService: PromptService;
14
- constructor(utilService: UtilService, fileService: FileService, projectService: ProjectService, promptService: PromptService);
15
- /**
16
- * Prompt to select tasks to use in the command being generated.
17
- *
18
- * @param taskMappings the map to add picked tasks to import for the command
19
- */
20
- addTasksToMap(taskMappings: Map<string, string>): Promise<void>;
21
- /**
22
- * Prompt to select services to use in the command being generated.
23
- *
24
- * @param serviceMappings the map to add picked services to import for the command
25
- * @param sourcePath the path to the parent directory of the source file being
26
- * generated to resolve relative paths for imports
27
- */
28
- addServicesToMap(serviceMappings: Map<string, string>, sourcePath: string): Promise<void>;
29
- /**
30
- * Formalize the selected imports into a format that can be used in the source code being generated.
31
- *
32
- * 1. Generate a PascalCased import name from the filename
33
- * 2. Convert to a relative path
34
- * 3. Remove the file extension for TypeScript import
35
- *
36
- * @param selectedPaths the selected file paths to formalize
37
- * @param relativeSource the path to the source file being generated to resolve relative paths
38
- * @returns the formalized ProjectImport array ({ importClassName, importPath })
39
- */
40
- private formalizeImports;
41
- /**
42
- * Prompt to select imports to use in the class being generated.
43
- *
44
- * @param messagePrompt the prompt message to display
45
- * @param filePaths the file paths to select from
46
- * @returns the selected file paths
47
- */
48
- private promptForImports;
49
- }
50
- //# sourceMappingURL=gen-app-task.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gen-app-task.d.ts","sourceRoot":"./src/","sources":["src/wrappers/gen-app-task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,OAAO;IAE3C,SAAS,CAAC,WAAW,EAAE,WAAW;IAClC,SAAS,CAAC,WAAW,EAAE,WAAW;IAClC,SAAS,CAAC,cAAc,EAAE,cAAc;IACxC,SAAS,CAAC,aAAa,EAAE,aAAa;gBAH5B,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa;IAKxC;;;;OAIG;IACG,aAAa,CAAC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAyBrD;;;;;;OAMG;IACG,gBAAgB,CACpB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,UAAU,EAAE,MAAM;IA2BpB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,gBAAgB;IAyBxB;;;;;;OAMG;YACW,gBAAgB;CAiB/B"}
@@ -1,124 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const app_task_1 = require("./app-task");
13
- const tsyringe_1 = require("tsyringe");
14
- const format_1 = require("../types/format");
15
- const util_service_1 = require("../services/util-service");
16
- const file_service_1 = require("../services/file-service");
17
- const project_service_1 = require("../services/project-service");
18
- const prompt_service_1 = require("../services/prompt-service");
19
- /**
20
- * Generation Task Type
21
- */
22
- let GenAppTask = class GenAppTask extends app_task_1.AppTask {
23
- utilService;
24
- fileService;
25
- projectService;
26
- promptService;
27
- constructor(utilService, fileService, projectService, promptService) {
28
- super();
29
- this.utilService = utilService;
30
- this.fileService = fileService;
31
- this.projectService = projectService;
32
- this.promptService = promptService;
33
- }
34
- /**
35
- * Prompt to select tasks to use in the command being generated.
36
- *
37
- * @param taskMappings the map to add picked tasks to import for the command
38
- */
39
- async addTasksToMap(taskMappings) {
40
- if (!this.state.data.project?.taskDestination) {
41
- return;
42
- }
43
- const taskFiles = this.fileService.getFilesInDir(this.state.data.project.taskDestination);
44
- this.logger.debug(`Found ${taskFiles.length} task files`);
45
- const pickedTasks = await this.promptForImports("Include Tasks", taskFiles);
46
- this.logger.debug(`Selected ${pickedTasks.length} tasks`);
47
- if (!pickedTasks.length) {
48
- return;
49
- }
50
- // add them to the map
51
- this.formalizeImports(pickedTasks, this.state.data.project.commandDestination).forEach((i) => taskMappings.set(i.importClassName, i.importPath));
52
- }
53
- /**
54
- * Prompt to select services to use in the command being generated.
55
- *
56
- * @param serviceMappings the map to add picked services to import for the command
57
- * @param sourcePath the path to the parent directory of the source file being
58
- * generated to resolve relative paths for imports
59
- */
60
- async addServicesToMap(serviceMappings, sourcePath) {
61
- if (!this.state.data.project?.serviceDestination) {
62
- return;
63
- }
64
- const serviceFiles = this.fileService.getFilesInDir(this.state.data.project.serviceDestination);
65
- this.logger.debug(`Found ${serviceFiles.length} service files`);
66
- const pickedServices = await this.promptForImports("Include Services", serviceFiles);
67
- this.logger.debug(`Selected ${pickedServices.length} services`);
68
- if (!pickedServices.length) {
69
- return;
70
- }
71
- // add them to the map
72
- this.formalizeImports(pickedServices, sourcePath).forEach((i) => serviceMappings.set(i.importClassName, i.importPath));
73
- }
74
- /**
75
- * Formalize the selected imports into a format that can be used in the source code being generated.
76
- *
77
- * 1. Generate a PascalCased import name from the filename
78
- * 2. Convert to a relative path
79
- * 3. Remove the file extension for TypeScript import
80
- *
81
- * @param selectedPaths the selected file paths to formalize
82
- * @param relativeSource the path to the source file being generated to resolve relative paths
83
- * @returns the formalized ProjectImport array ({ importClassName, importPath })
84
- */
85
- formalizeImports(selectedPaths, relativeSource) {
86
- if (!selectedPaths?.length) {
87
- return [];
88
- }
89
- const formalizedPaths = [];
90
- for (const fullPath of selectedPaths) {
91
- const filename = this.fileService.getFilenameNoExt(fullPath);
92
- const importClassName = this.utilService.titleizedToCase(this.utilService.titleizeAll(filename), format_1.CaseType.PASCAL_CASE);
93
- formalizedPaths.push({
94
- importClassName,
95
- importPath: this.fileService
96
- .toRelativePath(relativeSource, fullPath)
97
- .replace(project_service_1.ProjectService.defaults.extention, ""),
98
- });
99
- }
100
- return formalizedPaths;
101
- }
102
- /**
103
- * Prompt to select imports to use in the class being generated.
104
- *
105
- * @param messagePrompt the prompt message to display
106
- * @param filePaths the file paths to select from
107
- * @returns the selected file paths
108
- */
109
- async promptForImports(messagePrompt, filePaths) {
110
- return await this.promptService.pickMultiple(messagePrompt, filePaths.map((filePath) => ({
111
- name: this.utilService.titleizedToCase(this.utilService.titleizeAll(this.fileService.getFilenameNoExt(filePath)), format_1.CaseType.PASCAL_CASE),
112
- value: filePath,
113
- })));
114
- }
115
- };
116
- GenAppTask = __decorate([
117
- (0, tsyringe_1.autoInjectable)(),
118
- __metadata("design:paramtypes", [util_service_1.UtilService,
119
- file_service_1.FileService,
120
- project_service_1.ProjectService,
121
- prompt_service_1.PromptService])
122
- ], GenAppTask);
123
- exports.default = GenAppTask;
124
- //# sourceMappingURL=gen-app-task.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gen-app-task.js","sourceRoot":"./src/","sources":["src/wrappers/gen-app-task.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yCAAqC;AACrC,uCAA0C;AAC1C,4CAA2C;AAC3C,2DAAuD;AACvD,2DAAuD;AACvD,iEAA6D;AAC7D,+DAA2D;AAG3D;;GAEG;AAEY,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,kBAAO;IAEjC;IACA;IACA;IACA;IAJZ,YACY,WAAwB,EACxB,WAAwB,EACxB,cAA8B,EAC9B,aAA4B;QAEtC,KAAK,EAAE,CAAC;QALE,gBAAW,GAA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,CAAC,gCAAc,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC;aAClD,CAAC,CAAC;QACL,CAAC;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACK,KAAK,CAAC,gBAAgB,CAC5B,aAAqB,EACrB,SAAmB;QAEnB,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAC1C,aAAa,EACb,SAAS,CAAC,GAAG,CAAC,CAAC,QAAgB,EAAE,EAAE,CAAC,CAAC;YACnC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe,CACpC,IAAI,CAAC,WAAW,CAAC,WAAW,CAC1B,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAC5C,EACD,iBAAQ,CAAC,WAAW,CACrB;YACD,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC,CACJ,CAAC;IACJ,CAAC;CACF,CAAA;AAxIoB,UAAU;IAD9B,IAAA,yBAAc,GAAE;qCAGU,0BAAW;QACX,0BAAW;QACR,gCAAc;QACf,8BAAa;GALrB,UAAU,CAwI9B;kBAxIoB,UAAU"}
@@ -1,150 +0,0 @@
1
- import { AppTask } from "./app-task";
2
- import { autoInjectable } from "tsyringe";
3
- import { CaseType } from "../types/format";
4
- import { UtilService } from "../services/util-service";
5
- import { FileService } from "../services/file-service";
6
- import { ProjectService } from "../services/project-service";
7
- import { PromptService } from "../services/prompt-service";
8
- import { ProjectImport } from "../types/project";
9
-
10
- /**
11
- * Generation Task Type
12
- */
13
- @autoInjectable()
14
- export default class GenAppTask extends AppTask {
15
- constructor(
16
- protected utilService: UtilService,
17
- protected fileService: FileService,
18
- protected projectService: ProjectService,
19
- protected promptService: PromptService,
20
- ) {
21
- super();
22
- }
23
-
24
- /**
25
- * Prompt to select tasks to use in the command being generated.
26
- *
27
- * @param taskMappings the map to add picked tasks to import for the command
28
- */
29
- async addTasksToMap(taskMappings: Map<string, string>) {
30
- if (!this.state.data.project?.taskDestination) {
31
- return;
32
- }
33
-
34
- const taskFiles = this.fileService.getFilesInDir(
35
- this.state.data.project.taskDestination,
36
- );
37
-
38
- this.logger.debug(`Found ${taskFiles.length} task files`);
39
- const pickedTasks = await this.promptForImports("Include Tasks", taskFiles);
40
-
41
- this.logger.debug(`Selected ${pickedTasks.length} tasks`);
42
- if (!pickedTasks.length) {
43
- return;
44
- }
45
- // add them to the map
46
- this.formalizeImports(
47
- pickedTasks,
48
- this.state.data.project!.commandDestination!,
49
- ).forEach((i: ProjectImport) =>
50
- taskMappings.set(i.importClassName, i.importPath),
51
- );
52
- }
53
-
54
- /**
55
- * Prompt to select services to use in the command being generated.
56
- *
57
- * @param serviceMappings the map to add picked services to import for the command
58
- * @param sourcePath the path to the parent directory of the source file being
59
- * generated to resolve relative paths for imports
60
- */
61
- async addServicesToMap(
62
- serviceMappings: Map<string, string>,
63
- sourcePath: string,
64
- ) {
65
- if (!this.state.data.project?.serviceDestination) {
66
- return;
67
- }
68
-
69
- const serviceFiles = this.fileService.getFilesInDir(
70
- this.state.data.project.serviceDestination,
71
- );
72
-
73
- this.logger.debug(`Found ${serviceFiles.length} service files`);
74
- const pickedServices = await this.promptForImports(
75
- "Include Services",
76
- serviceFiles,
77
- );
78
-
79
- this.logger.debug(`Selected ${pickedServices.length} services`);
80
- if (!pickedServices.length) {
81
- return;
82
- }
83
- // add them to the map
84
- this.formalizeImports(pickedServices, sourcePath).forEach(
85
- (i: ProjectImport) =>
86
- serviceMappings.set(i.importClassName, i.importPath),
87
- );
88
- }
89
-
90
- /**
91
- * Formalize the selected imports into a format that can be used in the source code being generated.
92
- *
93
- * 1. Generate a PascalCased import name from the filename
94
- * 2. Convert to a relative path
95
- * 3. Remove the file extension for TypeScript import
96
- *
97
- * @param selectedPaths the selected file paths to formalize
98
- * @param relativeSource the path to the source file being generated to resolve relative paths
99
- * @returns the formalized ProjectImport array ({ importClassName, importPath })
100
- */
101
- private formalizeImports(
102
- selectedPaths: string[],
103
- relativeSource: string,
104
- ): ProjectImport[] {
105
- if (!selectedPaths?.length) {
106
- return [];
107
- }
108
- const formalizedPaths: ProjectImport[] = [];
109
- for (const fullPath of selectedPaths) {
110
- const filename = this.fileService.getFilenameNoExt(fullPath);
111
- const importClassName = this.utilService.titleizedToCase(
112
- this.utilService.titleizeAll(filename),
113
- CaseType.PASCAL_CASE,
114
- );
115
-
116
- formalizedPaths.push({
117
- importClassName,
118
- importPath: this.fileService
119
- .toRelativePath(relativeSource, fullPath)
120
- .replace(ProjectService.defaults.extention, ""),
121
- });
122
- }
123
- return formalizedPaths;
124
- }
125
-
126
- /**
127
- * Prompt to select imports to use in the class being generated.
128
- *
129
- * @param messagePrompt the prompt message to display
130
- * @param filePaths the file paths to select from
131
- * @returns the selected file paths
132
- */
133
- private async promptForImports(
134
- messagePrompt: string,
135
- filePaths: string[],
136
- ): Promise<string[]> {
137
- return await this.promptService.pickMultiple(
138
- messagePrompt,
139
- filePaths.map((filePath: string) => ({
140
- name: this.utilService.titleizedToCase(
141
- this.utilService.titleizeAll(
142
- this.fileService.getFilenameNoExt(filePath),
143
- ),
144
- CaseType.PASCAL_CASE,
145
- ),
146
- value: filePath,
147
- })),
148
- );
149
- }
150
- }