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.
- package/dist/package.json +2 -2
- package/dist/src/commands/gen.d.ts +1 -2
- package/dist/src/commands/gen.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/services/file-service.d.ts.map +1 -1
- package/dist/src/services/file-service.js +2 -1
- package/dist/src/services/file-service.js.map +1 -1
- package/dist/src/tasks/generate/generate-command.d.ts +3 -18
- package/dist/src/tasks/generate/generate-command.d.ts.map +1 -1
- package/dist/src/tasks/generate/generate-command.js +7 -60
- package/dist/src/tasks/generate/generate-command.js.map +1 -1
- package/dist/src/tasks/generate/generate-service.d.ts +3 -10
- package/dist/src/tasks/generate/generate-service.d.ts.map +1 -1
- package/dist/src/tasks/generate/generate-service.js +9 -22
- package/dist/src/tasks/generate/generate-service.js.map +1 -1
- package/dist/src/tasks/generate/generate-task.d.ts +3 -10
- package/dist/src/tasks/generate/generate-task.d.ts.map +1 -1
- package/dist/src/tasks/generate/generate-task.js +9 -22
- package/dist/src/tasks/generate/generate-task.js.map +1 -1
- package/dist/src/templates/command.d.ts.map +1 -1
- package/dist/src/templates/command.js +8 -2
- package/dist/src/templates/command.js.map +1 -1
- package/dist/src/templates/service.d.ts +1 -1
- package/dist/src/templates/service.d.ts.map +1 -1
- package/dist/src/templates/service.js +29 -1
- package/dist/src/templates/service.js.map +1 -1
- package/dist/src/templates/task.d.ts +1 -1
- package/dist/src/templates/task.d.ts.map +1 -1
- package/dist/src/templates/task.js +37 -1
- package/dist/src/templates/task.js.map +1 -1
- package/dist/src/types/project.d.ts +4 -0
- package/dist/src/types/project.d.ts.map +1 -1
- package/dist/src/wrappers/gen-app-task.d.ts +50 -0
- package/dist/src/wrappers/gen-app-task.d.ts.map +1 -0
- package/dist/src/wrappers/gen-app-task.js +124 -0
- package/dist/src/wrappers/gen-app-task.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/services/file-service.ts +2 -1
- package/src/tasks/generate/generate-command.ts +7 -70
- package/src/tasks/generate/generate-service.ts +8 -14
- package/src/tasks/generate/generate-task.ts +8 -14
- package/src/templates/command.ts +10 -2
- package/src/templates/service.ts +34 -2
- package/src/templates/task.ts +42 -2
- package/src/types/project.ts +5 -0
- package/src/wrappers/gen-app-task.ts +150 -0
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
}
|