task-script-support-cli 0.2.20 → 0.3.0

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 (48) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/commands/gen.d.ts +1 -2
  3. package/dist/src/commands/gen.d.ts.map +1 -1
  4. package/dist/src/index.js +1 -0
  5. package/dist/src/index.js.map +1 -1
  6. package/dist/src/services/file-service.d.ts.map +1 -1
  7. package/dist/src/services/file-service.js +2 -1
  8. package/dist/src/services/file-service.js.map +1 -1
  9. package/dist/src/tasks/generate/generate-command.d.ts +3 -18
  10. package/dist/src/tasks/generate/generate-command.d.ts.map +1 -1
  11. package/dist/src/tasks/generate/generate-command.js +7 -60
  12. package/dist/src/tasks/generate/generate-command.js.map +1 -1
  13. package/dist/src/tasks/generate/generate-service.d.ts +3 -10
  14. package/dist/src/tasks/generate/generate-service.d.ts.map +1 -1
  15. package/dist/src/tasks/generate/generate-service.js +9 -22
  16. package/dist/src/tasks/generate/generate-service.js.map +1 -1
  17. package/dist/src/tasks/generate/generate-task.d.ts +3 -10
  18. package/dist/src/tasks/generate/generate-task.d.ts.map +1 -1
  19. package/dist/src/tasks/generate/generate-task.js +9 -22
  20. package/dist/src/tasks/generate/generate-task.js.map +1 -1
  21. package/dist/src/templates/command.d.ts.map +1 -1
  22. package/dist/src/templates/command.js +8 -2
  23. package/dist/src/templates/command.js.map +1 -1
  24. package/dist/src/templates/service.d.ts +1 -1
  25. package/dist/src/templates/service.d.ts.map +1 -1
  26. package/dist/src/templates/service.js +29 -1
  27. package/dist/src/templates/service.js.map +1 -1
  28. package/dist/src/templates/task.d.ts +1 -1
  29. package/dist/src/templates/task.d.ts.map +1 -1
  30. package/dist/src/templates/task.js +37 -1
  31. package/dist/src/templates/task.js.map +1 -1
  32. package/dist/src/types/project.d.ts +4 -0
  33. package/dist/src/types/project.d.ts.map +1 -1
  34. package/dist/src/wrappers/gen-app-task.d.ts +50 -0
  35. package/dist/src/wrappers/gen-app-task.d.ts.map +1 -0
  36. package/dist/src/wrappers/gen-app-task.js +124 -0
  37. package/dist/src/wrappers/gen-app-task.js.map +1 -0
  38. package/package.json +2 -2
  39. package/src/index.ts +1 -0
  40. package/src/services/file-service.ts +2 -1
  41. package/src/tasks/generate/generate-command.ts +7 -70
  42. package/src/tasks/generate/generate-service.ts +8 -14
  43. package/src/tasks/generate/generate-task.ts +8 -14
  44. package/src/templates/command.ts +10 -2
  45. package/src/templates/service.ts +34 -2
  46. package/src/templates/task.ts +42 -2
  47. package/src/types/project.ts +5 -0
  48. package/src/wrappers/gen-app-task.ts +150 -0
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTaskTemplate = void 0;
4
- const getTaskTemplate = (className) => `import { AppTask } from "../wrappers/app-task";
4
+ const camelCase = (s) => s.charAt(0).toLowerCase() + s.slice(1);
5
+ const getTaskTemplate = (className, injections) => {
6
+ if (!injections || injections.size === 0) {
7
+ return `import { AppTask } from "../wrappers/app-task";
5
8
  import { autoInjectable } from "tsyringe";
6
9
 
7
10
  /**
@@ -16,5 +19,38 @@ export default class ${className} extends AppTask {
16
19
  }
17
20
 
18
21
  `;
22
+ }
23
+ return `import { AppTask } from "../wrappers/app-task";
24
+ import { autoInjectable } from "tsyringe";
25
+ ${injections
26
+ .keys()
27
+ .toArray()
28
+ .map((k) => `import { ${k} } from "${injections.get(k)}";`)
29
+ .join("\n")}
30
+
31
+ /**
32
+ * ${className}
33
+ */
34
+ @autoInjectable()
35
+ export default class ${className} extends AppTask {
36
+ loggerName = "${className}";
37
+
38
+ constructor(
39
+ ${injections
40
+ .keys()
41
+ .toArray()
42
+ .map((k) => `private ${camelCase(k)}: ${k}`)
43
+ .join(",\n ")}
44
+ ) {
45
+ super();
46
+ }
47
+
48
+ async run() {
49
+ // TODO: implement task
50
+ }
51
+ }
52
+
53
+ `;
54
+ };
19
55
  exports.getTaskTemplate = getTaskTemplate;
20
56
  //# sourceMappingURL=task.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"task.js","sourceRoot":"./src/","sources":["src/templates/task.ts"],"names":[],"mappings":";;;AAAO,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAE,EAAE,CACnD;;;;KAIG,SAAS;;;uBAGS,SAAS;kBACd,SAAS;;;;;;CAM1B,CAAC;AAfW,QAAA,eAAe,mBAe1B"}
1
+ {"version":3,"file":"task.js","sourceRoot":"./src/","sources":["src/templates/task.ts"],"names":[],"mappings":";;;AAAA,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEjE,MAAM,eAAe,GAAG,CAC7B,SAAiB,EACjB,UAA+B,EAC/B,EAAE;IACF,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACzC,OAAO;;;;KAIN,SAAS;;;uBAGS,SAAS;kBACd,SAAS;;;;;;CAM1B,CAAC;IACA,CAAC;IAED,OAAO;;EAEP,UAAU;SACT,IAAI,EAAE;SACN,OAAO,EAAE;SACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,YAAY,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;SAC1D,IAAI,CAAC,IAAI,CAAC;;;KAGR,SAAS;;;uBAGS,SAAS;kBACd,SAAS;;;MAGrB,UAAU;SACT,IAAI,EAAE;SACN,OAAO,EAAE;SACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;SAC3C,IAAI,CAAC,SAAS,CAAC;;;;;;;;;;CAUrB,CAAC;AACF,CAAC,CAAC;AArDW,QAAA,eAAe,mBAqD1B"}
@@ -9,4 +9,8 @@ export interface ProjectData {
9
9
  serviceFolders: string[];
10
10
  commandFolders: string[];
11
11
  }
12
+ export type ProjectImport = {
13
+ importClassName: string;
14
+ importPath: string;
15
+ };
12
16
  //# sourceMappingURL=project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"./src/","sources":["src/types/project.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B"}
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"./src/","sources":["src/types/project.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -0,0 +1,50 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,124 @@
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
@@ -0,0 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js",
6
6
  "preferGlobal": true,
@@ -17,7 +17,7 @@
17
17
  "format": "prettier --write ./",
18
18
  "format-check": "prettier --check .",
19
19
  "hooks-one-time-setup": "npx simple-git-hooks",
20
- "prettier-watch": "onchange \"**/*\" -- prettier --write --ignore-unknown {{changed}}",
20
+ "format-watch": "onchange \"**/*\" -- prettier --write --ignore-unknown {{changed}}",
21
21
  "build": "rm -rf ./dist && npx tsc && node dist/src/index.js -v && npm run cp-assets",
22
22
  "prepack": "npm run build",
23
23
  "test": "vitest run",
package/src/index.ts CHANGED
@@ -32,6 +32,7 @@ program
32
32
  program
33
33
  .command("gen [name]")
34
34
  .option("-n, --target-name <name>", "Name of Generated Target")
35
+ .option("-i, --inject", "Inject services")
35
36
  .option("-s, --service", "Generate a service")
36
37
  .option("-c, --command", "Generate a command")
37
38
  .option("-t, --task", "Generate a task")
@@ -20,7 +20,8 @@ export class FileService {
20
20
  }
21
21
 
22
22
  toRelativePath(fromPath: string, toPath: string) {
23
- return this.ensurePosix(path.relative(fromPath, toPath));
23
+ const p = this.ensurePosix(path.relative(fromPath, toPath));
24
+ return !p.includes("/") ? `./${p}` : p;
24
25
  }
25
26
 
26
27
  ensurePosix(possiblyWindowsPath: string) {
@@ -1,35 +1,23 @@
1
1
  import chalk from "chalk";
2
- import { AppTask } from "../../wrappers/app-task";
3
2
  import { autoInjectable } from "tsyringe";
4
3
  import { AppState, GenTargetType } from "../../types/state";
5
- import { FileService } from "../../services/file-service";
6
- import { UtilService } from "../../services/util-service";
7
4
  import { CaseType } from "../../types/format";
8
5
  import path from "path";
9
6
  import { getCommandTemplate } from "../../templates/command";
10
7
  import { ProjectService } from "../../services/project-service";
11
- import { PromptService } from "../../services/prompt-service";
8
+ import GenerateAppTask from "../../wrappers/gen-app-task";
12
9
 
13
10
  /**
14
11
  * Generates a new command class
15
12
  */
16
13
  @autoInjectable()
17
- export default class GenerateCommand extends AppTask {
14
+ export default class GenerateCommand extends GenerateAppTask {
18
15
  loggerName = "Generate Command";
19
16
 
20
- constructor(
21
- private fileService: FileService,
22
- private utilService: UtilService,
23
- private projectService: ProjectService,
24
- private promptService: PromptService,
25
- ) {
26
- super();
27
- }
28
-
29
17
  /**
30
18
  * Generates a new command class file.
31
19
  *
32
- * @returns updated state with outputDestination set to generated result path.
20
+ * @returns updated state with outputDestination set to a generated result path.
33
21
  */
34
22
  async run(): Promise<void | Partial<AppState>> {
35
23
  const { utilService, fileService, projectService } = this;
@@ -52,9 +40,10 @@ export default class GenerateCommand extends AppTask {
52
40
  );
53
41
  const filename = `${utilService.titleizedToCase(targetName, convention)}${ProjectService.defaults.extention}`;
54
42
 
55
- const taskMappings = new Map();
56
- await this.addTasksToMap(taskMappings);
57
- const rendered = getCommandTemplate(className, taskMappings);
43
+ const injectableMappings = new Map<string, string>();
44
+ await this.addTasksToMap(injectableMappings);
45
+
46
+ const rendered = getCommandTemplate(className, injectableMappings);
58
47
  const destination = path.join(targetDirectory, filename);
59
48
 
60
49
  // write contents
@@ -80,56 +69,4 @@ export default class GenerateCommand extends AppTask {
80
69
  throw new Error("Unable to determine targetDirectory");
81
70
  }
82
71
  }
83
-
84
- /**
85
- * Prompt to select tasks to use in the command being generated.
86
- *
87
- * @param taskMappings the map to add picked tasks to import for the command
88
- */
89
- async addTasksToMap(taskMappings: Map<string, string>) {
90
- if (!this.state.data.project?.taskDestination) {
91
- return;
92
- }
93
-
94
- const taskFiles = this.fileService.getFilesInDir(
95
- this.state.data.project.taskDestination,
96
- );
97
-
98
- this.logger.debug(`Found ${taskFiles.length} task files`);
99
-
100
- // prompt for tasks to use in the new command
101
- const pickedTasks = await this.promptService.pickMultiple(
102
- "Include Tasks",
103
- taskFiles.map((tf) => ({
104
- name: this.utilService.titleizedToCase(
105
- this.utilService.titleizeAll(this.fileService.getFilenameNoExt(tf)),
106
- CaseType.PASCAL_CASE,
107
- ),
108
- value: tf,
109
- })),
110
- );
111
-
112
- this.logger.debug(`Selected ${pickedTasks.length} tasks`);
113
- if (!pickedTasks.length) {
114
- return;
115
- }
116
-
117
- // add them to the map
118
- for (const picked of pickedTasks) {
119
- const filename = this.fileService.getFilenameNoExt(picked);
120
- const taskClassName = this.utilService.titleizedToCase(
121
- this.utilService.titleizeAll(filename),
122
- CaseType.PASCAL_CASE,
123
- );
124
- const relativeSource = this.state.data.project!.commandDestination!;
125
- const relativeDest = picked;
126
- taskMappings.set(
127
- taskClassName,
128
- this.fileService
129
- .toRelativePath(relativeSource, relativeDest)
130
- // remove extension for typescript import
131
- .replace(ProjectService.defaults.extention, ""),
132
- );
133
- }
134
- }
135
72
  }
@@ -1,33 +1,23 @@
1
1
  import chalk from "chalk";
2
- import { AppTask } from "../../wrappers/app-task";
3
2
  import { autoInjectable } from "tsyringe";
4
3
  import { GenTargetType } from "../../types/state";
5
4
  import { ProjectService } from "../../services/project-service";
6
- import { UtilService } from "../../services/util-service";
7
- import { FileService } from "../../services/file-service";
8
5
  import { CaseType } from "../../types/format";
9
6
  import path from "path";
10
7
  import { getServiceTemplate } from "../../templates/service";
8
+ import GenerateAppTask from "../../wrappers/gen-app-task";
11
9
 
12
10
  /**
13
11
  * Generates a new service class
14
12
  */
15
13
  @autoInjectable()
16
- export default class GenerateService extends AppTask {
14
+ export default class GenerateService extends GenerateAppTask {
17
15
  loggerName = "Generate Service";
18
16
 
19
- constructor(
20
- private projectService: ProjectService,
21
- private utilService: UtilService,
22
- private fileService: FileService,
23
- ) {
24
- super();
25
- }
26
-
27
17
  /**
28
18
  * Generates a new service class file.
29
19
  *
30
- * @returns updated state with outputDestination set to generated result path.
20
+ * @returns updated state with outputDestination set to a generated result path.
31
21
  */
32
22
  async run() {
33
23
  if (this.state.data.genTargetType !== GenTargetType.Service) {
@@ -48,7 +38,11 @@ export default class GenerateService extends AppTask {
48
38
  CaseType.PASCAL_CASE,
49
39
  );
50
40
 
51
- const rendered = getServiceTemplate(className);
41
+ const injectableMappings = new Map<string, string>();
42
+ if (this.argService.hasFlag("inject")) {
43
+ await this.addServicesToMap(injectableMappings, targetDirectory);
44
+ }
45
+ const rendered = getServiceTemplate(className, injectableMappings);
52
46
  const filename = `${utilService.titleizedToCase(targetName, convention)}${ProjectService.defaults.extention}`;
53
47
  const destination = path.join(targetDirectory, filename);
54
48
 
@@ -1,33 +1,23 @@
1
1
  import chalk from "chalk";
2
- import { AppTask } from "../../wrappers/app-task";
3
2
  import { autoInjectable } from "tsyringe";
4
3
  import { GenTargetType } from "../../types/state";
5
4
  import { getTaskTemplate } from "../../templates/task";
6
5
  import { CaseType } from "../../types/format";
7
- import { UtilService } from "../../services/util-service";
8
- import { FileService } from "../../services/file-service";
9
6
  import { ProjectService } from "../../services/project-service";
10
7
  import path from "path";
8
+ import GenAppTask from "../../wrappers/gen-app-task";
11
9
 
12
10
  /**
13
11
  * Generates a new task class
14
12
  */
15
13
  @autoInjectable()
16
- export default class GenerateTask extends AppTask {
14
+ export default class GenerateTask extends GenAppTask {
17
15
  loggerName = "Generate Task";
18
16
 
19
- constructor(
20
- private utilService: UtilService,
21
- private fileService: FileService,
22
- private projectService: ProjectService,
23
- ) {
24
- super();
25
- }
26
-
27
17
  /**
28
18
  * Generates a new task class file.
29
19
  *
30
- * @returns updated state with outputDestination set to generated result path.
20
+ * @returns updated state with outputDestination set to a generated result path.
31
21
  */
32
22
  async run() {
33
23
  if (this.state.data.genTargetType !== GenTargetType.Task) {
@@ -49,7 +39,11 @@ export default class GenerateTask extends AppTask {
49
39
  CaseType.PASCAL_CASE,
50
40
  );
51
41
 
52
- const rendered = getTaskTemplate(className);
42
+ const injectableMappings = new Map<string, string>();
43
+ if (this.argService.hasFlag("inject")) {
44
+ await this.addServicesToMap(injectableMappings, targetDirectory);
45
+ }
46
+ const rendered = getTaskTemplate(className, injectableMappings);
53
47
  const filename = `${utilService.titleizedToCase(targetName, convention)}${ProjectService.defaults.extention}`;
54
48
  const destination = path.join(targetDirectory, filename);
55
49
 
@@ -1,3 +1,7 @@
1
+ const nonClashingName = (name: string) => `${name}Task`;
2
+ const nameCheck = (name: string, className: string) =>
3
+ name === className ? nonClashingName(name) : name;
4
+
1
5
  export const getCommandTemplate = (
2
6
  className: string,
3
7
  tasks: Map<string, string> = new Map(),
@@ -7,12 +11,16 @@ import { Command } from "../wrappers/command";
7
11
  ${tasks
8
12
  .keys()
9
13
  .toArray()
10
- .map((k) => `import ${k} from "${tasks.get(k)}";`)
14
+ .map((k) => `import ${nameCheck(k, className)} from "${tasks.get(k)}";`)
11
15
  .join("\n")}
12
16
 
13
17
  @singleton()
14
18
  export class ${className} extends Command {
15
- tasks = [${tasks.keys().toArray().join(", ")}];
19
+ tasks = [${tasks
20
+ .keys()
21
+ .toArray()
22
+ .map((k) => nameCheck(k, className))
23
+ .join(", ")}];
16
24
  }
17
25
 
18
26
  `;
@@ -1,5 +1,11 @@
1
- export const getServiceTemplate = (className: string) =>
2
- `import { singleton } from "tsyringe";
1
+ const camelCase = (s: string) => s.charAt(0).toLowerCase() + s.slice(1);
2
+
3
+ export const getServiceTemplate = (
4
+ className: string,
5
+ injections: Map<string, string>,
6
+ ) => {
7
+ if (!injections || injections.size === 0) {
8
+ return `import { singleton } from "tsyringe";
3
9
 
4
10
  /**
5
11
  * ${className}
@@ -10,3 +16,29 @@ export class ${className} {
10
16
  }
11
17
 
12
18
  `;
19
+ }
20
+
21
+ return `import { singleton } from "tsyringe";
22
+ ${injections
23
+ .keys()
24
+ .toArray()
25
+ .map((k) => `import { ${k} } from "${injections.get(k)}";`)
26
+ .join("\n")}
27
+
28
+
29
+ /**
30
+ * ${className}
31
+ */
32
+ @singleton()
33
+ export class ${className} {
34
+ constructor(
35
+ ${injections
36
+ .keys()
37
+ .toArray()
38
+ .map((k) => `private ${camelCase(k)}: ${k}`)
39
+ .join(",\n ")}
40
+ ) {}
41
+ }
42
+
43
+ `;
44
+ };
@@ -1,6 +1,34 @@
1
- export const getTaskTemplate = (className: string) =>
2
- `import { AppTask } from "../wrappers/app-task";
1
+ const camelCase = (s: string) => s.charAt(0).toLowerCase() + s.slice(1);
2
+
3
+ export const getTaskTemplate = (
4
+ className: string,
5
+ injections: Map<string, string>,
6
+ ) => {
7
+ if (!injections || injections.size === 0) {
8
+ return `import { AppTask } from "../wrappers/app-task";
9
+ import { autoInjectable } from "tsyringe";
10
+
11
+ /**
12
+ * ${className}
13
+ */
14
+ @autoInjectable()
15
+ export default class ${className} extends AppTask {
16
+ loggerName = "${className}";
17
+ async run() {
18
+ // TODO: implement task
19
+ }
20
+ }
21
+
22
+ `;
23
+ }
24
+
25
+ return `import { AppTask } from "../wrappers/app-task";
3
26
  import { autoInjectable } from "tsyringe";
27
+ ${injections
28
+ .keys()
29
+ .toArray()
30
+ .map((k) => `import { ${k} } from "${injections.get(k)}";`)
31
+ .join("\n")}
4
32
 
5
33
  /**
6
34
  * ${className}
@@ -8,9 +36,21 @@ import { autoInjectable } from "tsyringe";
8
36
  @autoInjectable()
9
37
  export default class ${className} extends AppTask {
10
38
  loggerName = "${className}";
39
+
40
+ constructor(
41
+ ${injections
42
+ .keys()
43
+ .toArray()
44
+ .map((k) => `private ${camelCase(k)}: ${k}`)
45
+ .join(",\n ")}
46
+ ) {
47
+ super();
48
+ }
49
+
11
50
  async run() {
12
51
  // TODO: implement task
13
52
  }
14
53
  }
15
54
 
16
55
  `;
56
+ };
@@ -10,3 +10,8 @@ export interface ProjectData {
10
10
  serviceFolders: string[];
11
11
  commandFolders: string[];
12
12
  }
13
+
14
+ export type ProjectImport = {
15
+ importClassName: string;
16
+ importPath: string;
17
+ };