task-script-support-cli 0.1.1

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 (151) hide show
  1. package/.prettierignore +3 -0
  2. package/.prettierrc +1 -0
  3. package/.vscode/launch.json +34 -0
  4. package/README.md +3 -0
  5. package/dist/eslint.config.d.ts +3 -0
  6. package/dist/eslint.config.d.ts.map +1 -0
  7. package/dist/eslint.config.js +16 -0
  8. package/dist/eslint.config.js.map +1 -0
  9. package/dist/package.json +55 -0
  10. package/dist/src/commands/about.d.ts +7 -0
  11. package/dist/src/commands/about.d.ts.map +1 -0
  12. package/dist/src/commands/about.js +24 -0
  13. package/dist/src/commands/about.js.map +1 -0
  14. package/dist/src/commands/gen.d.ts +12 -0
  15. package/dist/src/commands/gen.d.ts.map +1 -0
  16. package/dist/src/commands/gen.js +35 -0
  17. package/dist/src/commands/gen.js.map +1 -0
  18. package/dist/src/index.d.ts +2 -0
  19. package/dist/src/index.d.ts.map +1 -0
  20. package/dist/src/index.js +34 -0
  21. package/dist/src/index.js.map +1 -0
  22. package/dist/src/services/arg-service.d.ts +10 -0
  23. package/dist/src/services/arg-service.d.ts.map +1 -0
  24. package/dist/src/services/arg-service.js +71 -0
  25. package/dist/src/services/arg-service.js.map +1 -0
  26. package/dist/src/services/banner-service.d.ts +8 -0
  27. package/dist/src/services/banner-service.d.ts.map +1 -0
  28. package/dist/src/services/banner-service.js +50 -0
  29. package/dist/src/services/banner-service.js.map +1 -0
  30. package/dist/src/services/file-service.d.ts +12 -0
  31. package/dist/src/services/file-service.d.ts.map +1 -0
  32. package/dist/src/services/file-service.js +82 -0
  33. package/dist/src/services/file-service.js.map +1 -0
  34. package/dist/src/services/log-service.d.ts +14 -0
  35. package/dist/src/services/log-service.d.ts.map +1 -0
  36. package/dist/src/services/log-service.js +61 -0
  37. package/dist/src/services/log-service.js.map +1 -0
  38. package/dist/src/services/project-service.d.ts +31 -0
  39. package/dist/src/services/project-service.d.ts.map +1 -0
  40. package/dist/src/services/project-service.js +86 -0
  41. package/dist/src/services/project-service.js.map +1 -0
  42. package/dist/src/services/spawn-service.d.ts +12 -0
  43. package/dist/src/services/spawn-service.d.ts.map +1 -0
  44. package/dist/src/services/spawn-service.js +111 -0
  45. package/dist/src/services/spawn-service.js.map +1 -0
  46. package/dist/src/services/updater-service.d.ts +7 -0
  47. package/dist/src/services/updater-service.d.ts.map +1 -0
  48. package/dist/src/services/updater-service.js +24 -0
  49. package/dist/src/services/updater-service.js.map +1 -0
  50. package/dist/src/services/util-service.d.ts +23 -0
  51. package/dist/src/services/util-service.d.ts.map +1 -0
  52. package/dist/src/services/util-service.js +89 -0
  53. package/dist/src/services/util-service.js.map +1 -0
  54. package/dist/src/tasks/check-env.d.ts +44 -0
  55. package/dist/src/tasks/check-env.d.ts.map +1 -0
  56. package/dist/src/tasks/check-env.js +126 -0
  57. package/dist/src/tasks/check-env.js.map +1 -0
  58. package/dist/src/tasks/generate-command.d.ts +23 -0
  59. package/dist/src/tasks/generate-command.d.ts.map +1 -0
  60. package/dist/src/tasks/generate-command.js +91 -0
  61. package/dist/src/tasks/generate-command.js.map +1 -0
  62. package/dist/src/tasks/generate-service.d.ts +26 -0
  63. package/dist/src/tasks/generate-service.d.ts.map +1 -0
  64. package/dist/src/tasks/generate-service.js +88 -0
  65. package/dist/src/tasks/generate-service.js.map +1 -0
  66. package/dist/src/tasks/generate-task.d.ts +26 -0
  67. package/dist/src/tasks/generate-task.d.ts.map +1 -0
  68. package/dist/src/tasks/generate-task.js +88 -0
  69. package/dist/src/tasks/generate-task.js.map +1 -0
  70. package/dist/src/tasks/print-about-information.d.ts +8 -0
  71. package/dist/src/tasks/print-about-information.d.ts.map +1 -0
  72. package/dist/src/tasks/print-about-information.js +30 -0
  73. package/dist/src/tasks/print-about-information.js.map +1 -0
  74. package/dist/src/tasks/print-banner.d.ts +12 -0
  75. package/dist/src/tasks/print-banner.d.ts.map +1 -0
  76. package/dist/src/tasks/print-banner.js +47 -0
  77. package/dist/src/tasks/print-banner.js.map +1 -0
  78. package/dist/src/tasks/print-generated-results.d.ts +12 -0
  79. package/dist/src/tasks/print-generated-results.d.ts.map +1 -0
  80. package/dist/src/tasks/print-generated-results.js +48 -0
  81. package/dist/src/tasks/print-generated-results.js.map +1 -0
  82. package/dist/src/tasks/select-gen-target.d.ts +9 -0
  83. package/dist/src/tasks/select-gen-target.d.ts.map +1 -0
  84. package/dist/src/tasks/select-gen-target.js +44 -0
  85. package/dist/src/tasks/select-gen-target.js.map +1 -0
  86. package/dist/src/templates/command.d.ts +2 -0
  87. package/dist/src/templates/command.d.ts.map +1 -0
  88. package/dist/src/templates/command.js +19 -0
  89. package/dist/src/templates/command.js.map +1 -0
  90. package/dist/src/templates/service.d.ts +2 -0
  91. package/dist/src/templates/service.d.ts.map +1 -0
  92. package/dist/src/templates/service.js +16 -0
  93. package/dist/src/templates/service.js.map +1 -0
  94. package/dist/src/templates/task.d.ts +2 -0
  95. package/dist/src/templates/task.d.ts.map +1 -0
  96. package/dist/src/templates/task.js +20 -0
  97. package/dist/src/templates/task.js.map +1 -0
  98. package/dist/src/types/format.d.ts +7 -0
  99. package/dist/src/types/format.d.ts.map +1 -0
  100. package/dist/src/types/format.js +11 -0
  101. package/dist/src/types/format.js.map +1 -0
  102. package/dist/src/types/process.d.ts +16 -0
  103. package/dist/src/types/process.d.ts.map +1 -0
  104. package/dist/src/types/process.js +12 -0
  105. package/dist/src/types/process.js.map +1 -0
  106. package/dist/src/types/state.d.ts +26 -0
  107. package/dist/src/types/state.d.ts.map +1 -0
  108. package/dist/src/types/state.js +17 -0
  109. package/dist/src/types/state.js.map +1 -0
  110. package/dist/src/wrappers/app-task.d.ts +19 -0
  111. package/dist/src/wrappers/app-task.d.ts.map +1 -0
  112. package/dist/src/wrappers/app-task.js +61 -0
  113. package/dist/src/wrappers/app-task.js.map +1 -0
  114. package/dist/src/wrappers/command.d.ts +11 -0
  115. package/dist/src/wrappers/command.d.ts.map +1 -0
  116. package/dist/src/wrappers/command.js +36 -0
  117. package/dist/src/wrappers/command.js.map +1 -0
  118. package/dist/tssc +3 -0
  119. package/eslint.config.ts +11 -0
  120. package/install-link.sh +21 -0
  121. package/package.json +55 -0
  122. package/setup.md +37 -0
  123. package/src/commands/about.ts +9 -0
  124. package/src/commands/gen.ts +20 -0
  125. package/src/index.ts +38 -0
  126. package/src/services/arg-service.ts +52 -0
  127. package/src/services/banner-service.ts +42 -0
  128. package/src/services/file-service.ts +78 -0
  129. package/src/services/log-service.ts +43 -0
  130. package/src/services/project-service.ts +72 -0
  131. package/src/services/spawn-service.ts +73 -0
  132. package/src/services/updater-service.ts +9 -0
  133. package/src/services/util-service.ts +87 -0
  134. package/src/tasks/check-env.ts +125 -0
  135. package/src/tasks/generate-command.ts +87 -0
  136. package/src/tasks/generate-service.ts +82 -0
  137. package/src/tasks/generate-task.ts +83 -0
  138. package/src/tasks/print-about-information.ts +16 -0
  139. package/src/tasks/print-banner.ts +37 -0
  140. package/src/tasks/print-generated-results.ts +36 -0
  141. package/src/tasks/select-gen-target.ts +29 -0
  142. package/src/templates/command.ts +18 -0
  143. package/src/templates/service.ts +12 -0
  144. package/src/templates/task.ts +16 -0
  145. package/src/types/format.ts +6 -0
  146. package/src/types/process.ts +18 -0
  147. package/src/types/state.ts +29 -0
  148. package/src/wrappers/app-task.ts +48 -0
  149. package/src/wrappers/command.ts +21 -0
  150. package/tsconfig.json +27 -0
  151. package/tssc +3 -0
@@ -0,0 +1,83 @@
1
+ import chalk from "chalk";
2
+ import { AppTask } from "../wrappers/app-task";
3
+ import { autoInjectable } from "tsyringe";
4
+ import { GenTargetType } from "../types/state";
5
+ import { getTaskTemplate } from "../templates/task";
6
+ import { CaseType } from "../types/format";
7
+ import { UtilService } from "../services/util-service";
8
+ import FileService from "../services/file-service";
9
+ import ProjectService from "../services/project-service";
10
+ import path from "path";
11
+
12
+ /**
13
+ * Generates a new task class
14
+ */
15
+ @autoInjectable()
16
+ export default class GenerateTask extends AppTask {
17
+ loggerName = "Generate Task";
18
+
19
+ constructor(
20
+ private utilService: UtilService,
21
+ private fileService: FileService,
22
+ private projectService: ProjectService,
23
+ ) {
24
+ super();
25
+ }
26
+
27
+ async run() {
28
+ if (this.state.data.genTargetType !== GenTargetType.Task) {
29
+ return;
30
+ }
31
+
32
+ const { utilService, argService } = this;
33
+
34
+ this.logger.info(chalk.blueBright("Generating Task"));
35
+
36
+ let targetName = argService.getTargetName();
37
+ if (!targetName) {
38
+ // TODO: Prompt for target name?
39
+ targetName = argService.cleanTargetName(
40
+ ProjectService.defaults.targetName,
41
+ );
42
+ }
43
+
44
+ const targetDirectory = this.getTargetDirectory();
45
+ if (!targetDirectory) {
46
+ throw new Error("Unable to determine target Directory");
47
+ }
48
+
49
+ // detect case
50
+ const convention = this.projectService.getConvention();
51
+ this.logger.debug(`Using convention: ${chalk.magentaBright(convention)}`);
52
+ const className = utilService.titleizedToCase(
53
+ targetName,
54
+ CaseType.PASCAL_CASE,
55
+ );
56
+
57
+ const rendered = getTaskTemplate(className);
58
+ const filename = `${utilService.titleizedToCase(targetName, convention)}${ProjectService.defaults.extention}`;
59
+ const destination = path.join(targetDirectory, filename);
60
+
61
+ // write contents
62
+ this.fileService.writeFile(destination, rendered);
63
+ return { data: { outputDestination: destination } };
64
+ }
65
+
66
+ /**
67
+ * Get the target directory to save the generated file.
68
+ *
69
+ * @returns the destination path of the parent folder to save the new file in.
70
+ */
71
+ getTargetDirectory() {
72
+ const runnerRoot = this.fileService.getRunnerRootDir();
73
+ const tasksFolders = this.fileService.getTaskDirs(runnerRoot);
74
+
75
+ if (tasksFolders.length === 1) {
76
+ return tasksFolders[0];
77
+ }
78
+
79
+ // TODO: prompt to select destination from available tasksFolders
80
+ this.logger.warn(`Multiple task folders detected. Using first found.`);
81
+ return tasksFolders[0];
82
+ }
83
+ }
@@ -0,0 +1,16 @@
1
+ import chalk from "chalk";
2
+ import { UtilService } from "../services/util-service";
3
+ import { AppTask } from "../wrappers/app-task";
4
+ import { autoInjectable } from "tsyringe";
5
+
6
+ /**
7
+ * Prints general information about the app
8
+ */
9
+ @autoInjectable()
10
+ export default class PrintAboutInformation extends AppTask {
11
+ async run() {
12
+ console.log(`Name: ${chalk.green("Task Script Support CLI")}`);
13
+ console.log(`Version: ${chalk.green(UtilService.getAppVersion())}`);
14
+ console.log(`About: ${chalk.dim(UtilService.getAppDescription())}`);
15
+ }
16
+ }
@@ -0,0 +1,37 @@
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
+ @autoInjectable()
9
+ export default class PrintBanner extends AppTask {
10
+ loggerName = "Print Banner";
11
+
12
+ constructor(
13
+ private bannnerSvc: BannerService,
14
+ private utilSvc: UtilService,
15
+ ) {
16
+ super();
17
+ }
18
+
19
+ async run(): Promise<Partial<AppState> | void> {
20
+ let font = "";
21
+
22
+ if (this.argService.hasFlag("randomFont")) {
23
+ font = await this.bannnerSvc.getRandomFont();
24
+ console.log(`Using random font ${font}`);
25
+ }
26
+
27
+ console.log(
28
+ chalk.blueBright(
29
+ await this.bannnerSvc.toBanner(this.utilSvc.getAppName(), font),
30
+ ),
31
+ );
32
+
33
+ this.setData({
34
+ banner: { font: font || this.bannnerSvc.defaultFontFamily },
35
+ });
36
+ }
37
+ }
@@ -0,0 +1,36 @@
1
+ import chalk from "chalk";
2
+ import { AppTask } from "../wrappers/app-task";
3
+ import { autoInjectable } from "tsyringe";
4
+ import { GenTargetType } from "../types/state";
5
+ import { UtilService } from "../services/util-service";
6
+
7
+ /**
8
+ * Prints the generated output results
9
+ */
10
+ @autoInjectable()
11
+ export default class PrintGeneratedResults extends AppTask {
12
+ loggerName = "Print Results";
13
+
14
+ constructor(private utilService: UtilService) {
15
+ super();
16
+ }
17
+
18
+ async run() {
19
+ const target: GenTargetType = this.state.data.genTargetType!;
20
+ this.logger.info(
21
+ chalk.blueBright(
22
+ `Generated Results for ${this.utilService.titleize(target)}`,
23
+ ),
24
+ );
25
+
26
+ setTimeout(() => {
27
+ console.log(`
28
+
29
+ Generated new file:
30
+
31
+ ${this.state.data.outputDestination || "<None>"}
32
+
33
+ `);
34
+ }, 1000);
35
+ }
36
+ }
@@ -0,0 +1,29 @@
1
+ import chalk from "chalk";
2
+ import { AppTask } from "../wrappers/app-task";
3
+ import { autoInjectable } from "tsyringe";
4
+ import { GenTargetType } from "../types/state";
5
+
6
+ /**
7
+ * Sets the genTargetType based on input
8
+ */
9
+ @autoInjectable()
10
+ export default class SelectGenTarget extends AppTask {
11
+ loggerName = "Select Target";
12
+ async run() {
13
+ let target: GenTargetType = GenTargetType.Command;
14
+ this.logger.info(chalk.blueBright("Checking Target"));
15
+
16
+ if (this.argService.hasFlag("service")) {
17
+ target = GenTargetType.Service;
18
+ } else if (this.argService.hasFlag("task")) {
19
+ target = GenTargetType.Task;
20
+ } else if (this.argService.hasFlag("command")) {
21
+ target = GenTargetType.Command;
22
+ } else {
23
+ this.logger.warn(`Using default target: ${target}`);
24
+ }
25
+
26
+ this.logger.debug(`Target selected: ${chalk.magentaBright(target)}`);
27
+ this.setData({ genTargetType: target });
28
+ }
29
+ }
@@ -0,0 +1,18 @@
1
+ export const getCommandTemplate = (
2
+ className: string,
3
+ tasks: Map<string, string> = new Map(),
4
+ ) =>
5
+ `import { singleton } from "tsyringe";
6
+ import { Command } from "../wrappers/command";
7
+ ${tasks
8
+ .keys()
9
+ .toArray()
10
+ .map((k) => `import { ${k} } from "${tasks.get(k)}";`)
11
+ .join("\n")}
12
+
13
+ @singleton()
14
+ export class ${className} extends Command {
15
+ tasks = [${tasks.keys().toArray().join(",")}];
16
+ }
17
+
18
+ `;
@@ -0,0 +1,12 @@
1
+ export const getServiceTemplate = (className: string) =>
2
+ `import { singleton } from "tsyringe";
3
+
4
+ /**
5
+ * ${className}
6
+ */
7
+ @singleton()
8
+ export default class ${className} {
9
+ constructor() {}
10
+ }
11
+
12
+ `;
@@ -0,0 +1,16 @@
1
+ export const getTaskTemplate = (className: string) =>
2
+ `import { AppTask } from "../wrappers/app-task";
3
+ import { autoInjectable } from "tsyringe";
4
+
5
+ /**
6
+ * ${className}
7
+ */
8
+ @autoInjectable()
9
+ export default class ${className} extends AppTask {
10
+ loggerName = "${className}";
11
+ async run() {
12
+ // TODO: implement task
13
+ }
14
+ }
15
+
16
+ `;
@@ -0,0 +1,6 @@
1
+ export enum CaseType {
2
+ KEBAB_CASE = "kebab-case",
3
+ SNAKE_CASE = "snake_case",
4
+ CAMEL_CASE = "camelCase",
5
+ PASCAL_CASE = "pascalCase",
6
+ }
@@ -0,0 +1,18 @@
1
+ export interface ProcessStatus {
2
+ readonly pid: number;
3
+ readonly status: "running" | "completed" | "unknown";
4
+ }
5
+
6
+ export interface ArgObject {
7
+ readonly [name: string]: string | boolean | number;
8
+ }
9
+
10
+ export type CLIArg = string | string[] | ArgObject;
11
+
12
+ export enum CLIOptions {
13
+ randomFont = "randomFont",
14
+ service = "service",
15
+ command = "command",
16
+ task = "task",
17
+ targetName = "targetName",
18
+ }
@@ -0,0 +1,29 @@
1
+ import { CLIArg } from "./process";
2
+ import { AppState as State, TaskClass } from "task-script-support";
3
+
4
+ export enum GenTargetType {
5
+ Command = "command",
6
+ Service = "service",
7
+ Task = "task",
8
+ }
9
+
10
+ export interface AppStateData {
11
+ readonly errorMessages?: string[];
12
+ readonly banner?: {
13
+ readonly font?: string;
14
+ };
15
+ readonly genTargetType?: GenTargetType;
16
+ readonly environmentValidated?: boolean;
17
+ readonly outputDestination?: string;
18
+ }
19
+
20
+ export const EnvironmentConfigKeys = {
21
+ PINO_LOG_DIR_PATH: "PINO_LOG_DIR_PATH",
22
+ PINO_LOG_LEVEL: "PINO_LOG_LEVEL",
23
+ NODE_ENV: "NODE_ENV",
24
+ PINO_LOG_FILENAME: "PINO_LOG_FILENAME",
25
+ PINO_LOG_TARGET: "PINO_LOG_TARGET",
26
+ };
27
+
28
+ export type AppState = State<AppStateData, CLIArg[]>;
29
+ export type AppTaskClass = TaskClass<AppStateData, CLIArg[]>;
@@ -0,0 +1,48 @@
1
+ import { autoInjectable } from "tsyringe";
2
+ import { CommandService, Task } from "task-script-support";
3
+ import { LogService } from "../services/log-service";
4
+ import { ArgService } from "../services/arg-service";
5
+ import type { AppState, AppStateData } from "../types/state";
6
+ import type { CLIArg } from "../types/process";
7
+
8
+ @autoInjectable()
9
+ export class AppTask extends Task<AppStateData, CLIArg[]> {
10
+ state: AppState = {
11
+ id: "uninitialized",
12
+ args: [],
13
+ data: {},
14
+ };
15
+ loggerName: string = "";
16
+
17
+ get argService() {
18
+ return this._argService!;
19
+ }
20
+ get logger(): LogService {
21
+ return this._logService!;
22
+ }
23
+
24
+ constructor(
25
+ public _logService?: LogService,
26
+ public _argService?: ArgService,
27
+ public _commandService?: CommandService<AppStateData, CLIArg[]>,
28
+ ) {
29
+ super();
30
+ }
31
+
32
+ //@override
33
+ async initialize() {
34
+ if (this.loggerName) {
35
+ this.logger!.setPrefix(`${this.loggerName} :: `);
36
+ }
37
+ }
38
+
39
+ //@override
40
+ async run(state: AppState): Promise<Partial<AppState> | void> {
41
+ throw new Error(`run not implemented (${state.id})`);
42
+ }
43
+
44
+ setData(data: Partial<AppStateData>) {
45
+ this.state = this._commandService!.setData(this.state, data);
46
+ return this.state;
47
+ }
48
+ }
@@ -0,0 +1,21 @@
1
+ import { CommandService } from "task-script-support";
2
+ import { inject } from "tsyringe";
3
+ import { AppStateData, AppTaskClass } from "../types/state";
4
+ import { CLIArg } from "../types/process";
5
+
6
+ export class Command {
7
+ tasks: (AppTaskClass | AppTaskClass[])[] = [];
8
+
9
+ constructor(
10
+ @inject(CommandService<AppStateData, CLIArg[]>)
11
+ private commandService: CommandService<AppStateData, CLIArg[]>,
12
+ ) {}
13
+
14
+ get handler(): (cliArgs: unknown[]) => Promise<void> {
15
+ return this.commandService.fromTasks(this.getTasks());
16
+ }
17
+
18
+ getTasks(): (AppTaskClass | AppTaskClass[])[] {
19
+ return this.tasks;
20
+ }
21
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": ".",
4
+ "sourceRoot": "./src",
5
+ "outDir": "./dist",
6
+ "module": "node16",
7
+ "target": "esnext",
8
+ "lib": ["esnext"],
9
+ "types": ["node", "vitest"],
10
+ "sourceMap": true,
11
+ "declaration": true,
12
+ "declarationMap": true,
13
+ "noUncheckedIndexedAccess": true,
14
+ "exactOptionalPropertyTypes": true,
15
+ "strict": true,
16
+ "jsx": "react-jsx",
17
+ "resolveJsonModule": true,
18
+ "esModuleInterop": true,
19
+ "isolatedModules": true,
20
+ "noUncheckedSideEffectImports": true,
21
+ "experimentalDecorators": true,
22
+ "emitDecoratorMetadata": true,
23
+ "moduleDetection": "force",
24
+ "skipLibCheck": true
25
+ },
26
+ "exclude": ["node_modules", "dist", "tests"]
27
+ }
package/tssc ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require("./src/index.js");