task-script-support-cli 0.3.0 → 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 (83) 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 +1 -1
  20. package/dist/src/commands/gen.d.ts +3 -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/services/project-service.d.ts +21 -0
  25. package/dist/src/services/project-service.d.ts.map +1 -1
  26. package/dist/src/services/project-service.js +41 -0
  27. package/dist/src/services/project-service.js.map +1 -1
  28. package/dist/src/services/templater-service.d.ts +1 -0
  29. package/dist/src/services/templater-service.d.ts.map +1 -1
  30. package/dist/src/services/templater-service.js +9 -3
  31. package/dist/src/services/templater-service.js.map +1 -1
  32. package/dist/src/tasks/generate/generate-command.d.ts +10 -3
  33. package/dist/src/tasks/generate/generate-command.d.ts.map +1 -1
  34. package/dist/src/tasks/generate/generate-command.js +27 -11
  35. package/dist/src/tasks/generate/generate-command.js.map +1 -1
  36. package/dist/src/tasks/generate/generate-service.d.ts +10 -3
  37. package/dist/src/tasks/generate/generate-service.d.ts.map +1 -1
  38. package/dist/src/tasks/generate/generate-service.js +26 -12
  39. package/dist/src/tasks/generate/generate-service.js.map +1 -1
  40. package/dist/src/tasks/generate/generate-task.d.ts +10 -3
  41. package/dist/src/tasks/generate/generate-task.d.ts.map +1 -1
  42. package/dist/src/tasks/generate/generate-task.js +27 -13
  43. package/dist/src/tasks/generate/generate-task.js.map +1 -1
  44. package/dist/src/tasks/generate/project-context-guard.d.ts +1 -1
  45. package/dist/src/tasks/generate/project-context-guard.js +1 -1
  46. package/dist/src/tasks/generate/resolve-injectables.d.ts +56 -0
  47. package/dist/src/tasks/generate/resolve-injectables.d.ts.map +1 -0
  48. package/dist/src/tasks/generate/resolve-injectables.js +134 -0
  49. package/dist/src/tasks/generate/resolve-injectables.js.map +1 -0
  50. package/dist/src/tasks/generate/select-gen-target-name.js +4 -4
  51. package/dist/src/tasks/generate/select-gen-target-name.js.map +1 -1
  52. package/dist/src/tasks/generate/select-gen-target.d.ts +1 -1
  53. package/dist/src/tasks/generate/select-gen-target.js +2 -2
  54. package/dist/src/tasks/generate/select-gen-target.js.map +1 -1
  55. package/dist/src/tasks/stdout/print-generated-results.js +2 -2
  56. package/dist/src/tasks/stdout/print-generated-results.js.map +1 -1
  57. package/dist/src/tasks/sync-configuration.d.ts +1 -1
  58. package/dist/src/tasks/sync-configuration.js +6 -6
  59. package/dist/src/tasks/sync-configuration.js.map +1 -1
  60. package/dist/src/types/state.d.ts +7 -3
  61. package/dist/src/types/state.d.ts.map +1 -1
  62. package/dist/src/types/state.js.map +1 -1
  63. package/package.json +1 -1
  64. package/src/commands/gen.ts +2 -0
  65. package/src/services/project-service.ts +54 -0
  66. package/src/services/templater-service.ts +15 -3
  67. package/src/tasks/generate/generate-command.ts +21 -11
  68. package/src/tasks/generate/generate-service.ts +20 -11
  69. package/src/tasks/generate/generate-task.ts +21 -12
  70. package/src/tasks/generate/project-context-guard.ts +1 -1
  71. package/src/tasks/generate/resolve-injectables.ts +154 -0
  72. package/src/tasks/generate/select-gen-target-name.ts +4 -4
  73. package/src/tasks/generate/select-gen-target.ts +2 -2
  74. package/src/tasks/stdout/print-generated-results.ts +2 -2
  75. package/src/tasks/sync-configuration.ts +6 -6
  76. package/src/types/state.ts +9 -3
  77. package/assets/yargs-template/task-runner/src/tasks/print-banner.ts +0 -73
  78. package/dist/assets/yargs-template/task-runner/src/tasks/print-banner.ts +0 -73
  79. package/dist/src/wrappers/gen-app-task.d.ts +0 -50
  80. package/dist/src/wrappers/gen-app-task.d.ts.map +0 -1
  81. package/dist/src/wrappers/gen-app-task.js +0 -124
  82. package/dist/src/wrappers/gen-app-task.js.map +0 -1
  83. package/src/wrappers/gen-app-task.ts +0 -150
@@ -4,6 +4,7 @@ import { autoInjectable } from "tsyringe";
4
4
  import { SpawnService } from "./spawn-service";
5
5
  import { LogService } from "./log-service";
6
6
  import { dockerIgnoreTemplate } from "../templates/docker-ignore";
7
+ import chalk from "chalk";
7
8
 
8
9
  const gitignoreContent = `node_modules
9
10
  dist
@@ -78,11 +79,19 @@ export class TemplateService {
78
79
  }
79
80
  }
80
81
 
82
+ toLogPath(pathString: string) {
83
+ return path.relative(
84
+ process.cwd(),
85
+ pathString.replaceAll("task-runner", this.outputName),
86
+ );
87
+ }
88
+
81
89
  private async copyDirectories() {
82
90
  for (const folder of this.dirListToCopy) {
83
91
  const src = path.join(this.sourceDir, folder);
84
92
  const dest = path.join(this.destination, folder);
85
- this.logger.debug(`Running Copy: cp -R ${src} ${dest}`);
93
+ // this.logger.debug(`Running Copy: cp -R ${src} ${dest}`);;
94
+ this.logger.debug(`Generating folder ${chalk.dim(this.toLogPath(dest))}`);
86
95
  fs.cpSync(src, dest, { recursive: true });
87
96
  }
88
97
  }
@@ -91,7 +100,8 @@ export class TemplateService {
91
100
  for (const filename of this.fileListToCopy) {
92
101
  const src = path.join(this.sourceDir, filename);
93
102
  const dest = path.join(this.destination, filename);
94
- this.logger.debug(`Running Copy: cp ${src} ${dest}`);
103
+ // this.logger.debug(`Running Copy: cp ${src} ${dest}`);
104
+ this.logger.debug(`Generating file ${chalk.dim(this.toLogPath(dest))}`);
95
105
  fs.copyFileSync(src, dest);
96
106
  }
97
107
  }
@@ -135,7 +145,9 @@ export class TemplateService {
135
145
  const rename = (ext = "") => {
136
146
  const src = path.join(this.destination, `task-runner${ext}`);
137
147
  const dest = path.join(this.destination, `${this.outputName}${ext}`);
138
- this.logger.debug(`Renaming task-runner to ${this.outputName}${ext}`);
148
+ this.logger.debug(
149
+ `Fixing references ${chalk.dim(`(${this.outputName}${ext})`)}`,
150
+ );
139
151
  fs.renameSync(src, dest);
140
152
  };
141
153
  rename();
@@ -5,15 +5,25 @@ import { CaseType } from "../../types/format";
5
5
  import path from "path";
6
6
  import { getCommandTemplate } from "../../templates/command";
7
7
  import { ProjectService } from "../../services/project-service";
8
- import GenerateAppTask from "../../wrappers/gen-app-task";
8
+ import { AppTask } from "../../wrappers/app-task";
9
+ import { FileService } from "../../services/file-service";
10
+ import { UtilService } from "../../services/util-service";
9
11
 
10
12
  /**
11
13
  * Generates a new command class
12
14
  */
13
15
  @autoInjectable()
14
- export default class GenerateCommand extends GenerateAppTask {
16
+ export default class GenerateCommand extends AppTask {
15
17
  loggerName = "Generate Command";
16
18
 
19
+ constructor(
20
+ private fileService: FileService,
21
+ private projectService: ProjectService,
22
+ private utilService: UtilService,
23
+ ) {
24
+ super();
25
+ }
26
+
17
27
  /**
18
28
  * Generates a new command class file.
19
29
  *
@@ -22,12 +32,12 @@ export default class GenerateCommand extends GenerateAppTask {
22
32
  async run(): Promise<void | Partial<AppState>> {
23
33
  const { utilService, fileService, projectService } = this;
24
34
 
25
- if (this.state.data.genTargetType !== GenTargetType.Command) {
35
+ if (this.state.data.genData!.targetType !== GenTargetType.Command) {
26
36
  return; // no-op
27
37
  }
28
38
 
29
39
  this.logger.info(chalk.blueBright("Generating Command"));
30
- const targetName = this.state.data.genTargetName!;
40
+ const targetName = this.state.data.genData!.targetName!;
31
41
  const targetDirectory = this.state.data.project!.commandDestination!;
32
42
 
33
43
  // detect case between commands and task files
@@ -40,10 +50,10 @@ export default class GenerateCommand extends GenerateAppTask {
40
50
  );
41
51
  const filename = `${utilService.titleizedToCase(targetName, convention)}${ProjectService.defaults.extention}`;
42
52
 
43
- const injectableMappings = new Map<string, string>();
44
- await this.addTasksToMap(injectableMappings);
45
-
46
- const rendered = getCommandTemplate(className, injectableMappings);
53
+ const injectablesMap = this.projectService.getImportMap(
54
+ this.state.data.genData!,
55
+ );
56
+ const rendered = getCommandTemplate(className, injectablesMap);
47
57
  const destination = path.join(targetDirectory, filename);
48
58
 
49
59
  // write contents
@@ -53,13 +63,13 @@ export default class GenerateCommand extends GenerateAppTask {
53
63
 
54
64
  /**
55
65
  * Checks state for required fields. Executes prior to run method.
56
- * Skips validation if genTargetType is not set to command.
66
+ * Skips validation if genData.targetType is not set to command.
57
67
  */
58
68
  async preRun() {
59
- if (this.state.data.genTargetType !== GenTargetType.Command) {
69
+ if (this.state.data.genData!.targetType !== GenTargetType.Command) {
60
70
  return; // no validation on no-op flow
61
71
  }
62
- if (!this.state.data.genTargetName) {
72
+ if (!this.state.data.genData!.targetName) {
63
73
  throw new Error("Unable to determine targetName");
64
74
  }
65
75
  if (!this.state.data.project) {
@@ -5,29 +5,39 @@ import { ProjectService } from "../../services/project-service";
5
5
  import { CaseType } from "../../types/format";
6
6
  import path from "path";
7
7
  import { getServiceTemplate } from "../../templates/service";
8
- import GenerateAppTask from "../../wrappers/gen-app-task";
8
+ import { AppTask } from "../../wrappers/app-task";
9
+ import { FileService } from "../../services/file-service";
10
+ import { UtilService } from "../../services/util-service";
9
11
 
10
12
  /**
11
13
  * Generates a new service class
12
14
  */
13
15
  @autoInjectable()
14
- export default class GenerateService extends GenerateAppTask {
16
+ export default class GenerateService extends AppTask {
15
17
  loggerName = "Generate Service";
16
18
 
19
+ constructor(
20
+ private fileService: FileService,
21
+ private projectService: ProjectService,
22
+ private utilService: UtilService,
23
+ ) {
24
+ super();
25
+ }
26
+
17
27
  /**
18
28
  * Generates a new service class file.
19
29
  *
20
30
  * @returns updated state with outputDestination set to a generated result path.
21
31
  */
22
32
  async run() {
23
- if (this.state.data.genTargetType !== GenTargetType.Service) {
33
+ if (this.state.data.genData!.targetType !== GenTargetType.Service) {
24
34
  return;
25
35
  }
26
36
 
27
37
  this.logger.info(chalk.blueBright("Generating Service"));
28
38
  const { utilService, projectService } = this;
29
39
 
30
- const targetName = this.state.data.genTargetName!;
40
+ const targetName = this.state.data.genData!.targetName!;
31
41
  const targetDirectory = this.state.data.project!.serviceDestination!;
32
42
 
33
43
  // detect case
@@ -38,10 +48,9 @@ export default class GenerateService extends GenerateAppTask {
38
48
  CaseType.PASCAL_CASE,
39
49
  );
40
50
 
41
- const injectableMappings = new Map<string, string>();
42
- if (this.argService.hasFlag("inject")) {
43
- await this.addServicesToMap(injectableMappings, targetDirectory);
44
- }
51
+ const injectableMappings = this.projectService.getImportMap(
52
+ this.state.data.genData!,
53
+ );
45
54
  const rendered = getServiceTemplate(className, injectableMappings);
46
55
  const filename = `${utilService.titleizedToCase(targetName, convention)}${ProjectService.defaults.extention}`;
47
56
  const destination = path.join(targetDirectory, filename);
@@ -53,13 +62,13 @@ export default class GenerateService extends GenerateAppTask {
53
62
 
54
63
  /**
55
64
  * Checks state for required fields. Executes prior to run method.
56
- * Skips validation if genTargetType is not set to service.
65
+ * Skips validation if genData.targetType is not set to service.
57
66
  */
58
67
  async preRun() {
59
- if (this.state.data.genTargetType !== GenTargetType.Service) {
68
+ if (this.state.data.genData!.targetType !== GenTargetType.Service) {
60
69
  return; // no validation on no-op flow
61
70
  }
62
- if (!this.state.data.genTargetName) {
71
+ if (!this.state.data.genData!.targetName) {
63
72
  throw new Error("Unable to determine targetName");
64
73
  }
65
74
  if (!this.state.data.project) {
@@ -5,22 +5,32 @@ import { getTaskTemplate } from "../../templates/task";
5
5
  import { CaseType } from "../../types/format";
6
6
  import { ProjectService } from "../../services/project-service";
7
7
  import path from "path";
8
- import GenAppTask from "../../wrappers/gen-app-task";
8
+ import { AppTask } from "../../wrappers/app-task";
9
+ import { FileService } from "../../services/file-service";
10
+ import { UtilService } from "../../services/util-service";
9
11
 
10
12
  /**
11
13
  * Generates a new task class
12
14
  */
13
15
  @autoInjectable()
14
- export default class GenerateTask extends GenAppTask {
16
+ export default class GenerateTask extends AppTask {
15
17
  loggerName = "Generate Task";
16
18
 
19
+ constructor(
20
+ private fileService: FileService,
21
+ private projectService: ProjectService,
22
+ private utilService: UtilService,
23
+ ) {
24
+ super();
25
+ }
26
+
17
27
  /**
18
28
  * Generates a new task class file.
19
29
  *
20
30
  * @returns updated state with outputDestination set to a generated result path.
21
31
  */
22
32
  async run() {
23
- if (this.state.data.genTargetType !== GenTargetType.Task) {
33
+ if (this.state.data.genData!.targetType !== GenTargetType.Task) {
24
34
  return;
25
35
  }
26
36
 
@@ -28,7 +38,7 @@ export default class GenerateTask extends GenAppTask {
28
38
 
29
39
  this.logger.info(chalk.blueBright("Generating Task"));
30
40
 
31
- const targetName = this.state.data.genTargetName!;
41
+ const targetName = this.state.data.genData!.targetName!;
32
42
  const targetDirectory = this.state.data.project!.taskDestination!;
33
43
 
34
44
  // detect case
@@ -39,11 +49,10 @@ export default class GenerateTask extends GenAppTask {
39
49
  CaseType.PASCAL_CASE,
40
50
  );
41
51
 
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);
52
+ const injectablesMap = this.projectService.getImportMap(
53
+ this.state.data.genData!,
54
+ );
55
+ const rendered = getTaskTemplate(className, injectablesMap);
47
56
  const filename = `${utilService.titleizedToCase(targetName, convention)}${ProjectService.defaults.extention}`;
48
57
  const destination = path.join(targetDirectory, filename);
49
58
 
@@ -54,13 +63,13 @@ export default class GenerateTask extends GenAppTask {
54
63
 
55
64
  /**
56
65
  * Checks state for required fields. Executes prior to run method.
57
- * Skips validation if genTargetType is not set to task.
66
+ * Skips validation if genData.targetType is not set to task.
58
67
  */
59
68
  async preRun() {
60
- if (this.state.data.genTargetType !== GenTargetType.Task) {
69
+ if (this.state.data.genData!.targetType !== GenTargetType.Task) {
61
70
  return; // no validation on no-op flow
62
71
  }
63
- if (!this.state.data.genTargetName) {
72
+ if (!this.state.data.genData!.targetName) {
64
73
  throw new Error("Unable to determine targetName");
65
74
  }
66
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,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
- }