@tsed/cli-core 7.0.0-alpha.1 → 7.0.0-alpha.10

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.
@@ -8,7 +8,6 @@ import { Command } from "commander";
8
8
  import semver from "semver";
9
9
  import updateNotifier from "update-notifier";
10
10
  import { CliError } from "./domains/CliError.js";
11
- import { CliConfiguration } from "./services/CliConfiguration.js";
12
11
  import { CliPackageJson } from "./services/CliPackageJson.js";
13
12
  import { CliService } from "./services/CliService.js";
14
13
  import { ProjectPackageJson } from "./services/ProjectPackageJson.js";
@@ -23,6 +22,19 @@ export class CliCore {
23
22
  this.injector = inject(InjectorService);
24
23
  this.cliService = inject(CliService);
25
24
  }
25
+ static checkPrecondition(settings) {
26
+ const { pkg } = settings;
27
+ this.checkPackage(pkg);
28
+ if (pkg?.engines?.node) {
29
+ this.checkNodeVersion(pkg.engines.node, pkg.name);
30
+ }
31
+ }
32
+ static checkPackage(pkg) {
33
+ if (!pkg) {
34
+ console.log(chalk.red(`settings.pkg is required. Require the package.json of your CLI when you bootstrap the CLI.`));
35
+ process.exit(1);
36
+ }
37
+ }
26
38
  static checkNodeVersion(wanted, id) {
27
39
  if (!semver.satisfies(process.version, wanted)) {
28
40
  console.log(chalk.red("You are using Node " +
@@ -45,11 +57,17 @@ export class CliCore {
45
57
  return inject(CliCore);
46
58
  }
47
59
  static async bootstrap(settings, module = CliCore) {
60
+ if (settings.checkPrecondition) {
61
+ this.checkPrecondition(settings);
62
+ }
63
+ if (settings.updateNotifier) {
64
+ await this.updateNotifier(settings.pkg);
65
+ }
48
66
  const cli = await this.create(settings, module);
49
67
  return cli.bootstrap();
50
68
  }
51
69
  static async loadInjector(injector, module = CliCore) {
52
- await injector.emit("$beforeInit");
70
+ await $asyncEmit("$beforeInit");
53
71
  injector.addProvider(CliCore, {
54
72
  useClass: module
55
73
  });
@@ -93,4 +111,4 @@ export class CliCore {
93
111
  return this;
94
112
  }
95
113
  }
96
- injectable(CliCore).imports([CliPackageJson, ProjectPackageJson, CliService, CliConfiguration]);
114
+ injectable(CliCore).imports([CliPackageJson, ProjectPackageJson, CliService]);
@@ -1,5 +1,5 @@
1
1
  import { classOf } from "@tsed/core";
2
- import { configuration, constant, destroyInjector, DIContext, getContext, inject, injectable, injector, logger, Provider, runInContext } from "@tsed/di";
2
+ import { configuration, constant, context, destroyInjector, DIContext, getContext, inject, injectable, injector, logger, Provider, runInContext } from "@tsed/di";
3
3
  import { $asyncAlter, $asyncEmit } from "@tsed/hooks";
4
4
  import { pascalCase } from "change-case";
5
5
  import { Argument, Command } from "commander";
@@ -134,7 +134,17 @@ export class CliService {
134
134
  ...(await instance.$exec(data)),
135
135
  ...(await this.hooks.emit(CommandStoreKeys.EXEC_HOOKS, cmdName, data)),
136
136
  ...(await $asyncAlter(`$alter${pascalCase(cmdName)}Tasks`, [], [data]))
137
- ];
137
+ ].map((opts) => {
138
+ return {
139
+ ...opts,
140
+ task: async (arg, task) => {
141
+ context().set("currentTask", task);
142
+ const result = await opts.task(arg, task);
143
+ context().delete("currentTask");
144
+ return result;
145
+ }
146
+ };
147
+ });
138
148
  }
139
149
  async getPostInstallTasks(cmdName, data) {
140
150
  const provider = this.commands.get(cmdName);
@@ -1,4 +1,3 @@
1
- export * from "./CliConfiguration.js";
2
1
  export * from "./CliDockerComposeYaml.js";
3
2
  export * from "./CliExeca.js";
4
3
  export * from "./CliFs.js";
@@ -1,47 +1,50 @@
1
1
  import "@tsed/logger-std";
2
2
  import "@tsed/logger-pattern-layout";
3
- import { inject, injector, InjectorService } from "@tsed/di";
3
+ import { injector } from "@tsed/di";
4
4
  import { Logger } from "@tsed/logger";
5
- import { CliConfiguration } from "../services/CliConfiguration.js";
6
5
  import { ProjectPackageJson } from "../services/ProjectPackageJson.js";
7
6
  let logger;
8
7
  export function getLogger() {
9
8
  return logger;
10
9
  }
11
- function createConfiguration(injector) {
12
- injector.addProvider(CliConfiguration);
13
- return inject(CliConfiguration);
14
- }
15
10
  export function createInjector(settings = {}) {
16
11
  const inj = injector();
17
- inj.settings = createConfiguration(inj);
18
12
  logger = inj.logger = new Logger(settings.name || "CLI");
19
13
  inj.addProvider(ProjectPackageJson);
20
- inj.settings.set(settings);
14
+ inj.settings.set({
15
+ ...settings,
16
+ project: {
17
+ root: process.cwd(),
18
+ srcDir: "src",
19
+ ...(settings.project || {})
20
+ }
21
+ });
21
22
  /* istanbul ignore next */
22
23
  if (inj.settings.env === "test") {
23
24
  inj.logger.stop();
24
25
  }
25
26
  else {
26
27
  /* istanbul ignore next */
27
- inj.logger.level = inj.settings.logger?.level || "warn";
28
- inj.logger.appenders
29
- .set("stdout", {
30
- type: "stdout",
31
- layout: {
32
- type: "pattern",
33
- pattern: "[%d{hh:mm:ss}] %m"
34
- },
35
- levels: ["info", "debug"]
36
- })
37
- .set("stderr", {
38
- type: "stderr",
39
- layout: {
40
- type: "pattern",
41
- pattern: "[%d{hh:mm:ss}][%p] %m"
42
- },
43
- levels: ["trace", "fatal", "error", "warn"]
44
- });
28
+ if (!settings.logger?.disableCliFormat) {
29
+ inj.logger.level = inj.settings.logger?.level || "warn";
30
+ inj.logger.appenders
31
+ .set("stdout", {
32
+ type: "stdout",
33
+ layout: {
34
+ type: "pattern",
35
+ pattern: "[%d{hh:mm:ss}] %m"
36
+ },
37
+ levels: ["info", "debug"]
38
+ })
39
+ .set("stderr", {
40
+ type: "stderr",
41
+ layout: {
42
+ type: "pattern",
43
+ pattern: "[%d{hh:mm:ss}][%p] %m"
44
+ },
45
+ levels: ["trace", "fatal", "error", "warn"]
46
+ });
47
+ }
45
48
  }
46
49
  return inj;
47
50
  }
@@ -5,6 +5,8 @@ import { CliService } from "./services/CliService.js";
5
5
  export declare class CliCore {
6
6
  readonly injector: InjectorService;
7
7
  readonly cliService: CliService;
8
+ static checkPrecondition(settings: any): void;
9
+ static checkPackage(pkg: any): void;
8
10
  static checkNodeVersion(wanted: string, id: string): typeof CliCore;
9
11
  static create<Cli extends CliCore = CliCore>(settings: Partial<TsED.Configuration>, module?: Type): Promise<Cli>;
10
12
  static bootstrap(settings: Partial<TsED.Configuration>, module?: Type): Promise<CliCore>;
@@ -33,7 +33,7 @@ declare global {
33
33
  */
34
34
  templateDir?: string;
35
35
  /**
36
- *
36
+ * A function that return default projet settings set in fresh project.
37
37
  * @param pkg
38
38
  */
39
39
  defaultProjectPreferences?: (pkg?: any) => Record<string, any>;
@@ -50,6 +50,14 @@ declare global {
50
50
  * Enable plugins loading
51
51
  */
52
52
  plugins: boolean;
53
+ /**
54
+ * Check version and node version before running a command
55
+ */
56
+ checkPrecondition?: boolean;
57
+ /**
58
+ * Display available update on terminal before running a command
59
+ */
60
+ updateNotifier?: boolean;
53
61
  }
54
62
  }
55
63
  }
@@ -1,4 +1,3 @@
1
- export * from "./CliConfiguration.js";
2
1
  export * from "./CliDockerComposeYaml.js";
3
2
  export * from "./CliExeca.js";
4
3
  export * from "./CliFs.js";
@@ -1,6 +1,15 @@
1
1
  import "@tsed/logger-std";
2
2
  import "@tsed/logger-pattern-layout";
3
- import { type DIConfigurationOptions, InjectorService } from "@tsed/di";
4
3
  import { Logger } from "@tsed/logger";
4
+ declare global {
5
+ namespace TsED {
6
+ interface Configuration {
7
+ logger?: LoggerConfiguration;
8
+ }
9
+ interface LoggerConfiguration {
10
+ disableCliFormat?: boolean;
11
+ }
12
+ }
13
+ }
5
14
  export declare function getLogger(): Logger;
6
- export declare function createInjector(settings?: Partial<DIConfigurationOptions>): InjectorService;
15
+ export declare function createInjector(settings?: Partial<TsED.Configuration>): import("@tsed/di").InjectorService;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsed/cli-core",
3
3
  "description": "Build your CLI with TypeScript and Decorators",
4
- "version": "7.0.0-alpha.1",
4
+ "version": "7.0.0-alpha.10",
5
5
  "type": "module",
6
6
  "main": "./lib/esm/index.js",
7
7
  "source": "./src/index.ts",
@@ -32,6 +32,7 @@
32
32
  "listr"
33
33
  ],
34
34
  "dependencies": {
35
+ "@ts-morph/common": "0.28.0",
35
36
  "@tsed/logger": ">=8.0.3",
36
37
  "@tsed/logger-pattern-layout": ">=8.0.3",
37
38
  "@tsed/logger-std": ">=8.0.3",
@@ -64,7 +65,7 @@
64
65
  "uuid": "^10.0.0"
65
66
  },
66
67
  "devDependencies": {
67
- "@tsed/typescript": "7.0.0-alpha.1",
68
+ "@tsed/typescript": "7.0.0-alpha.10",
68
69
  "@types/commander": "2.12.2",
69
70
  "@types/figures": "3.0.1",
70
71
  "@types/fs-extra": "^11.0.4",
@@ -1,12 +0,0 @@
1
- import { DIConfiguration, injectable } from "@tsed/di";
2
- export class CliConfiguration extends DIConfiguration {
3
- constructor() {
4
- super({
5
- project: {
6
- root: process.cwd(),
7
- srcDir: "src"
8
- }
9
- });
10
- }
11
- }
12
- injectable(CliConfiguration);
@@ -1,4 +0,0 @@
1
- import { DIConfiguration } from "@tsed/di";
2
- export declare class CliConfiguration extends DIConfiguration {
3
- constructor();
4
- }