task-script-support-cli 0.2.20 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/assets/yargs-template/task-runner/src/commands/verify.ts +3 -2
  2. package/assets/yargs-template/task-runner/src/services/banner-service.ts +13 -9
  3. package/assets/yargs-template/task-runner/src/tasks/banner/print-banner.ts +38 -0
  4. package/assets/yargs-template/task-runner/src/tasks/banner/resolve-banner-font.ts +70 -0
  5. package/assets/yargs-template/task-runner/src/types/state.ts +4 -0
  6. package/{dist/assets/yargs-template/task-runner/src/wrappers → assets/yargs-template/task-runner/src/wrappers/electives}/concurrent-task-group.ts +4 -4
  7. package/assets/yargs-template/task-runner/src/wrappers/electives/resolver-task.ts +87 -0
  8. package/assets/yargs-template/task-runner/src/wrappers/{sequential-task-group.ts → electives/sequential-task-group.ts} +4 -4
  9. package/assets/yargs-template/task-runner/tests/commands/verify.test.ts +14 -21
  10. package/dist/assets/yargs-template/task-runner/src/commands/verify.ts +3 -2
  11. package/dist/assets/yargs-template/task-runner/src/services/banner-service.ts +13 -9
  12. package/dist/assets/yargs-template/task-runner/src/tasks/banner/print-banner.ts +38 -0
  13. package/dist/assets/yargs-template/task-runner/src/tasks/banner/resolve-banner-font.ts +70 -0
  14. package/dist/assets/yargs-template/task-runner/src/types/state.ts +4 -0
  15. package/{assets/yargs-template/task-runner/src/wrappers → dist/assets/yargs-template/task-runner/src/wrappers/electives}/concurrent-task-group.ts +4 -4
  16. package/dist/assets/yargs-template/task-runner/src/wrappers/electives/resolver-task.ts +87 -0
  17. package/dist/assets/yargs-template/task-runner/src/wrappers/{sequential-task-group.ts → electives/sequential-task-group.ts} +4 -4
  18. package/dist/assets/yargs-template/task-runner/tests/commands/verify.test.ts +14 -21
  19. package/dist/package.json +2 -2
  20. package/dist/src/commands/gen.d.ts +2 -1
  21. package/dist/src/commands/gen.d.ts.map +1 -1
  22. package/dist/src/commands/gen.js +2 -0
  23. package/dist/src/commands/gen.js.map +1 -1
  24. package/dist/src/index.js +1 -0
  25. package/dist/src/index.js.map +1 -1
  26. package/dist/src/services/file-service.d.ts.map +1 -1
  27. package/dist/src/services/file-service.js +2 -1
  28. package/dist/src/services/file-service.js.map +1 -1
  29. package/dist/src/services/project-service.d.ts +21 -0
  30. package/dist/src/services/project-service.d.ts.map +1 -1
  31. package/dist/src/services/project-service.js +41 -0
  32. package/dist/src/services/project-service.js.map +1 -1
  33. package/dist/src/services/templater-service.d.ts +1 -0
  34. package/dist/src/services/templater-service.d.ts.map +1 -1
  35. package/dist/src/services/templater-service.js +9 -3
  36. package/dist/src/services/templater-service.js.map +1 -1
  37. package/dist/src/tasks/generate/generate-command.d.ts +6 -14
  38. package/dist/src/tasks/generate/generate-command.d.ts.map +1 -1
  39. package/dist/src/tasks/generate/generate-command.js +15 -52
  40. package/dist/src/tasks/generate/generate-command.js.map +1 -1
  41. package/dist/src/tasks/generate/generate-service.d.ts +6 -6
  42. package/dist/src/tasks/generate/generate-service.d.ts.map +1 -1
  43. package/dist/src/tasks/generate/generate-service.js +17 -16
  44. package/dist/src/tasks/generate/generate-service.js.map +1 -1
  45. package/dist/src/tasks/generate/generate-task.d.ts +6 -6
  46. package/dist/src/tasks/generate/generate-task.d.ts.map +1 -1
  47. package/dist/src/tasks/generate/generate-task.js +17 -16
  48. package/dist/src/tasks/generate/generate-task.js.map +1 -1
  49. package/dist/src/tasks/generate/project-context-guard.d.ts +1 -1
  50. package/dist/src/tasks/generate/project-context-guard.js +1 -1
  51. package/dist/src/tasks/generate/resolve-injectables.d.ts +56 -0
  52. package/dist/src/tasks/generate/resolve-injectables.d.ts.map +1 -0
  53. package/dist/src/tasks/generate/resolve-injectables.js +134 -0
  54. package/dist/src/tasks/generate/resolve-injectables.js.map +1 -0
  55. package/dist/src/tasks/generate/select-gen-target-name.js +4 -4
  56. package/dist/src/tasks/generate/select-gen-target-name.js.map +1 -1
  57. package/dist/src/tasks/generate/select-gen-target.d.ts +1 -1
  58. package/dist/src/tasks/generate/select-gen-target.js +2 -2
  59. package/dist/src/tasks/generate/select-gen-target.js.map +1 -1
  60. package/dist/src/tasks/stdout/print-generated-results.js +2 -2
  61. package/dist/src/tasks/stdout/print-generated-results.js.map +1 -1
  62. package/dist/src/tasks/sync-configuration.d.ts +1 -1
  63. package/dist/src/tasks/sync-configuration.js +6 -6
  64. package/dist/src/tasks/sync-configuration.js.map +1 -1
  65. package/dist/src/templates/command.d.ts.map +1 -1
  66. package/dist/src/templates/command.js +8 -2
  67. package/dist/src/templates/command.js.map +1 -1
  68. package/dist/src/templates/service.d.ts +1 -1
  69. package/dist/src/templates/service.d.ts.map +1 -1
  70. package/dist/src/templates/service.js +29 -1
  71. package/dist/src/templates/service.js.map +1 -1
  72. package/dist/src/templates/task.d.ts +1 -1
  73. package/dist/src/templates/task.d.ts.map +1 -1
  74. package/dist/src/templates/task.js +37 -1
  75. package/dist/src/templates/task.js.map +1 -1
  76. package/dist/src/types/project.d.ts +4 -0
  77. package/dist/src/types/project.d.ts.map +1 -1
  78. package/dist/src/types/state.d.ts +7 -3
  79. package/dist/src/types/state.d.ts.map +1 -1
  80. package/dist/src/types/state.js.map +1 -1
  81. package/package.json +2 -2
  82. package/src/commands/gen.ts +2 -0
  83. package/src/index.ts +1 -0
  84. package/src/services/file-service.ts +2 -1
  85. package/src/services/project-service.ts +54 -0
  86. package/src/services/templater-service.ts +15 -3
  87. package/src/tasks/generate/generate-command.ts +14 -67
  88. package/src/tasks/generate/generate-service.ts +14 -11
  89. package/src/tasks/generate/generate-task.ts +14 -11
  90. package/src/tasks/generate/project-context-guard.ts +1 -1
  91. package/src/tasks/generate/resolve-injectables.ts +154 -0
  92. package/src/tasks/generate/select-gen-target-name.ts +4 -4
  93. package/src/tasks/generate/select-gen-target.ts +2 -2
  94. package/src/tasks/stdout/print-generated-results.ts +2 -2
  95. package/src/tasks/sync-configuration.ts +6 -6
  96. package/src/templates/command.ts +10 -2
  97. package/src/templates/service.ts +34 -2
  98. package/src/templates/task.ts +42 -2
  99. package/src/types/project.ts +5 -0
  100. package/src/types/state.ts +9 -3
  101. package/assets/yargs-template/task-runner/src/tasks/print-banner.ts +0 -73
  102. package/dist/assets/yargs-template/task-runner/src/tasks/print-banner.ts +0 -73
@@ -1,13 +1,13 @@
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 { AppTask } from "../../wrappers/app-task";
9
+ import { FileService } from "../../services/file-service";
10
+ import { UtilService } from "../../services/util-service";
11
11
 
12
12
  /**
13
13
  * Generates a new task class
@@ -17,9 +17,9 @@ export default class GenerateTask extends AppTask {
17
17
  loggerName = "Generate Task";
18
18
 
19
19
  constructor(
20
- private utilService: UtilService,
21
20
  private fileService: FileService,
22
21
  private projectService: ProjectService,
22
+ private utilService: UtilService,
23
23
  ) {
24
24
  super();
25
25
  }
@@ -27,10 +27,10 @@ export default class GenerateTask extends AppTask {
27
27
  /**
28
28
  * Generates a new task class file.
29
29
  *
30
- * @returns updated state with outputDestination set to generated result path.
30
+ * @returns updated state with outputDestination set to a generated result path.
31
31
  */
32
32
  async run() {
33
- if (this.state.data.genTargetType !== GenTargetType.Task) {
33
+ if (this.state.data.genData!.targetType !== GenTargetType.Task) {
34
34
  return;
35
35
  }
36
36
 
@@ -38,7 +38,7 @@ export default class GenerateTask extends AppTask {
38
38
 
39
39
  this.logger.info(chalk.blueBright("Generating Task"));
40
40
 
41
- const targetName = this.state.data.genTargetName!;
41
+ const targetName = this.state.data.genData!.targetName!;
42
42
  const targetDirectory = this.state.data.project!.taskDestination!;
43
43
 
44
44
  // detect case
@@ -49,7 +49,10 @@ export default class GenerateTask extends AppTask {
49
49
  CaseType.PASCAL_CASE,
50
50
  );
51
51
 
52
- const rendered = getTaskTemplate(className);
52
+ const injectablesMap = this.projectService.getImportMap(
53
+ this.state.data.genData!,
54
+ );
55
+ const rendered = getTaskTemplate(className, injectablesMap);
53
56
  const filename = `${utilService.titleizedToCase(targetName, convention)}${ProjectService.defaults.extention}`;
54
57
  const destination = path.join(targetDirectory, filename);
55
58
 
@@ -60,13 +63,13 @@ export default class GenerateTask extends AppTask {
60
63
 
61
64
  /**
62
65
  * Checks state for required fields. Executes prior to run method.
63
- * Skips validation if genTargetType is not set to task.
66
+ * Skips validation if genData.targetType is not set to task.
64
67
  */
65
68
  async preRun() {
66
- if (this.state.data.genTargetType !== GenTargetType.Task) {
69
+ if (this.state.data.genData!.targetType !== GenTargetType.Task) {
67
70
  return; // no validation on no-op flow
68
71
  }
69
- if (!this.state.data.genTargetName) {
72
+ if (!this.state.data.genData!.targetName) {
70
73
  throw new Error("Unable to determine targetName");
71
74
  }
72
75
  if (!this.state.data.project) {
@@ -4,7 +4,7 @@ import { AppTask } from "../../wrappers/app-task";
4
4
  import { autoInjectable } from "tsyringe";
5
5
 
6
6
  /**
7
- * Checks so see if we are in the context of a task-script-support
7
+ * Checks to see if we are in the context of a task-script-support
8
8
  * project or not and fails the process with a friendly error message.
9
9
  */
10
10
  @autoInjectable()
@@ -0,0 +1,154 @@
1
+ import { AppTask } from "../../wrappers/app-task";
2
+ import { autoInjectable } from "tsyringe";
3
+ import { FileService } from "../../services/file-service";
4
+ import { ProjectService } from "../../services/project-service";
5
+ import { PromptService } from "../../services/prompt-service";
6
+ import { UtilService } from "../../services/util-service";
7
+ import { ProjectImport } from "../../types/project";
8
+ import { CaseType } from "../../types/format";
9
+ import { AppState, GenTargetType } from "../../types/state";
10
+
11
+ /**
12
+ * ResolveInjectables
13
+ */
14
+ @autoInjectable()
15
+ export default class ResolveInjectables extends AppTask {
16
+ loggerName = "ResolveInjectables";
17
+
18
+ constructor(
19
+ private fileService: FileService,
20
+ private projectService: ProjectService,
21
+ private promptService: PromptService,
22
+ private utilService: UtilService,
23
+ ) {
24
+ super();
25
+ }
26
+
27
+ /**
28
+ * Prompts to select tasks or services to import into the file being generated.
29
+ *
30
+ * @param state the current state of the application. Expects genData to be
31
+ * populated with targetType. Expects the project to be populated with
32
+ * serviceDestination, taskDestination, and commandDestination.
33
+ * @returns updated state with genData imports field set.
34
+ */
35
+ async run(state: AppState): Promise<Partial<AppState>> {
36
+ if (this.shouldSkip()) return { data: { genData: { imports: [] } } };
37
+
38
+ const { genData, project } = state.data;
39
+
40
+ // determine the directory we would need to import into
41
+ const sourceDirectory =
42
+ genData!.targetType === GenTargetType.Service
43
+ ? project!.serviceDestination!
44
+ : project!.taskDestination!;
45
+
46
+ let injectableImports: ProjectImport[];
47
+ switch (genData!.targetType) {
48
+ case GenTargetType.Command:
49
+ injectableImports = await this.getTaskImports();
50
+ break;
51
+ case GenTargetType.Service:
52
+ case GenTargetType.Task:
53
+ injectableImports = await this.getServiceImports(sourceDirectory);
54
+ break;
55
+ default:
56
+ injectableImports = [];
57
+ }
58
+
59
+ return { data: { genData: { imports: injectableImports } } };
60
+ }
61
+
62
+ /**
63
+ * Prompt to select tasks to use in the command being generated.
64
+ *
65
+ * @returns the selected task imports
66
+ */
67
+ async getTaskImports(): Promise<ProjectImport[]> {
68
+ if (!this.state.data.project?.taskDestination) {
69
+ throw new Error("Unable to resolve task destination");
70
+ }
71
+
72
+ const taskFiles = this.fileService.getFilesInDir(
73
+ this.state.data.project.taskDestination,
74
+ );
75
+
76
+ this.logger.debug(`Found ${taskFiles.length} task files`);
77
+ const pickedTasks = await this.promptForImports("Include Tasks", taskFiles);
78
+
79
+ this.logger.debug(`Selected ${pickedTasks.length} tasks`);
80
+ // add them to the map
81
+ return !pickedTasks.length
82
+ ? []
83
+ : this.projectService.formalizeImports(
84
+ pickedTasks,
85
+ this.state.data.project!.commandDestination!,
86
+ );
87
+ }
88
+
89
+ /**
90
+ * Prompt to select services to use in the command being generated.
91
+ *
92
+ * @param sourcePath the path to the parent directory of the source file being
93
+ * generated to resolve relative paths for imports
94
+ * @returns the selected service imports
95
+ */
96
+ async getServiceImports(sourcePath: string): Promise<ProjectImport[]> {
97
+ if (!this.state.data.project?.serviceDestination) {
98
+ throw new Error("Unable to resolve service destination");
99
+ }
100
+
101
+ const serviceFiles = this.fileService.getFilesInDir(
102
+ this.state.data.project.serviceDestination,
103
+ );
104
+
105
+ this.logger.debug(`Found ${serviceFiles.length} service files`);
106
+ const pickedServices = await this.promptForImports(
107
+ "Include Services",
108
+ serviceFiles,
109
+ );
110
+
111
+ this.logger.debug(`Selected ${pickedServices.length} services`);
112
+
113
+ return !pickedServices.length
114
+ ? []
115
+ : this.projectService.formalizeImports(pickedServices, sourcePath);
116
+ }
117
+
118
+ /**
119
+ * Prompt to select imports to use in the class being generated.
120
+ *
121
+ * @param messagePrompt the prompt message to display
122
+ * @param filePaths the file paths to select from
123
+ * @returns the selected file paths
124
+ */
125
+ private async promptForImports(
126
+ messagePrompt: string,
127
+ filePaths: string[],
128
+ ): Promise<string[]> {
129
+ return await this.promptService.pickMultiple(
130
+ messagePrompt,
131
+ filePaths.map((filePath: string) => ({
132
+ name: this.utilService.titleizedToCase(
133
+ this.utilService.titleizeAll(
134
+ this.fileService.getFilenameNoExt(filePath),
135
+ ),
136
+ CaseType.PASCAL_CASE,
137
+ ),
138
+ value: filePath,
139
+ })),
140
+ );
141
+ }
142
+
143
+ /**
144
+ * Determines if the task should skip the prompt for injectables.
145
+ *
146
+ * @returns true if the task should be skipped.
147
+ */
148
+ private shouldSkip(): boolean {
149
+ return (
150
+ !this.argService.hasFlag("inject") &&
151
+ this.state.data.genData?.targetType !== GenTargetType.Command
152
+ );
153
+ }
154
+ }
@@ -25,7 +25,7 @@ export default class SelectGenTargetName extends AppTask {
25
25
  if (!targetName) {
26
26
  targetName =
27
27
  (await this.promptService.getInput(
28
- `Enter Name for ${chalk.blueBright(this.utilService.titleize(this.state.data.genTargetType!))}`,
28
+ `Enter Name for ${chalk.blueBright(this.utilService.titleize(this.state.data.genData!.targetType!))}`,
29
29
  )) || ProjectService.defaults.targetName;
30
30
  }
31
31
  if (!targetName) {
@@ -33,12 +33,12 @@ export default class SelectGenTargetName extends AppTask {
33
33
  }
34
34
  this.logger.debug(`Name selected: ${chalk.magentaBright(targetName)}`);
35
35
  targetName = this.utilService.titleizeAll(targetName);
36
- this.setData({ genTargetName: targetName });
36
+ this.setData({ genData: { targetName: targetName } });
37
37
  }
38
38
 
39
39
  async preRun() {
40
- if (!this.state.data.genTargetType) {
41
- throw new Error("Unable to determine genTargetType");
40
+ if (!this.state.data.genData?.targetType) {
41
+ throw new Error("Unable to determine genData.targetType");
42
42
  }
43
43
  }
44
44
  }
@@ -6,7 +6,7 @@ import { PromptService } from "../../services/prompt-service";
6
6
  import { CLIOptions } from "../../types/process";
7
7
 
8
8
  /**
9
- * Sets the genTargetType based on input
9
+ * Sets the genData.targetType based on input
10
10
  */
11
11
  @autoInjectable()
12
12
  export default class SelectGenTargetType extends AppTask {
@@ -31,7 +31,7 @@ export default class SelectGenTargetType extends AppTask {
31
31
  }
32
32
 
33
33
  this.logger.debug(`Target selected: ${chalk.magentaBright(target)}`);
34
- this.setData({ genTargetType: target });
34
+ this.setData({ genData: { targetType: target } });
35
35
  }
36
36
 
37
37
  async getGenTargetInput() {
@@ -24,8 +24,8 @@ export default class PrintGeneratedResults extends AppTask {
24
24
  }
25
25
 
26
26
  async run() {
27
- const genType: string = this.state.data.genTargetType
28
- ? this.utilService.titleize(this.state.data.genTargetType)
27
+ const genType: string = this.state.data.genData?.targetType
28
+ ? this.utilService.titleize(this.state.data.genData.targetType)
29
29
  : "Project";
30
30
 
31
31
  this.logger.info(`Generated Results for ${chalk.blueBright(genType)}`);
@@ -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,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
+ };
@@ -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
- }