@tsed/cli-core 3.14.1 → 3.17.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/lib/index.js CHANGED
@@ -731,24 +731,15 @@ function getLogger() {
731
731
  }
732
732
 
733
733
  function createConfiguration(injector) {
734
- const provider = di.GlobalProviders.get(exports.CliConfiguration).clone();
735
- provider.instance = injector.invoke(provider.useClass);
736
- injector.addProvider(exports.CliConfiguration, provider);
737
- return provider.instance;
738
- }
739
-
740
- function createProjectPackageJson(injector) {
741
- const provider = di.GlobalProviders.get(exports.ProjectPackageJson).clone();
742
- injector.addProvider(exports.ProjectPackageJson, provider);
743
- provider.instance = injector.invoke(provider);
744
- return provider.instance;
734
+ injector.addProvider(exports.CliConfiguration);
735
+ return injector.invoke(exports.CliConfiguration);
745
736
  }
746
737
 
747
738
  function createInjector(settings = {}) {
748
739
  const injector = new di.InjectorService();
749
740
  injector.settings = createConfiguration(injector);
750
741
  logger = injector.logger = new logger$1.Logger(settings.name || "CLI");
751
- createProjectPackageJson(injector);
742
+ injector.addProvider(exports.ProjectPackageJson);
752
743
  injector.settings.set(settings);
753
744
  /* istanbul ignore next */
754
745
 
@@ -1044,6 +1035,7 @@ exports.CliService = class CliService {
1044
1035
 
1045
1036
 
1046
1037
  async runLifecycle(cmdName, data = {}) {
1038
+ data = await this.beforePrompt(cmdName, data);
1047
1039
  data = await this.prompt(cmdName, data);
1048
1040
 
1049
1041
  try {
@@ -1079,6 +1071,25 @@ exports.CliService = class CliService {
1079
1071
  */
1080
1072
 
1081
1073
 
1074
+ async beforePrompt(cmdName, ctx = {}) {
1075
+ const provider = this.commands.get(cmdName);
1076
+ const instance = this.injector.get(provider.useClass);
1077
+ const verbose = ctx.verbose;
1078
+
1079
+ if (instance.$beforePrompt) {
1080
+ ctx = await instance.$beforePrompt(JSON.parse(JSON.stringify(ctx)));
1081
+ ctx.verbose = verbose;
1082
+ }
1083
+
1084
+ return ctx;
1085
+ }
1086
+ /**
1087
+ * Run prompt for a given command
1088
+ * @param cmdName
1089
+ * @param ctx Initial data
1090
+ */
1091
+
1092
+
1082
1093
  async prompt(cmdName, ctx = {}) {
1083
1094
  const provider = this.commands.get(cmdName);
1084
1095
  const instance = this.injector.get(provider.useClass);
@@ -1593,7 +1604,7 @@ async function loadPlugins(injector) {
1593
1604
  } = injector.settings;
1594
1605
  const projectPackageJson = injector.invoke(exports.ProjectPackageJson);
1595
1606
  const fs = injector.invoke(exports.CliFs);
1596
- const promises = Object.keys(projectPackageJson.allDependencies).filter(mod => mod.startsWith(`@${name}/cli-plugin`) || mod.startsWith(`${name}-cli-plugin`)).map(async mod => {
1607
+ const promises = Object.keys(projectPackageJson.allDependencies).filter(mod => mod.startsWith(`@${name}/cli-plugin`) || mod.includes(`${name}-cli-plugin`)).map(async mod => {
1597
1608
  const {
1598
1609
  default: plugin
1599
1610
  } = await fs.importModule(mod, rootDir);
@@ -1803,7 +1814,7 @@ exports.CliPlugins = class CliPlugins {
1803
1814
  }
1804
1815
 
1805
1816
  isPlugin(name) {
1806
- return name.startsWith(`@${this.name}/cli-plugin`) || name.startsWith(`${this.name}-cli-plugin`);
1817
+ return name.startsWith(`@${this.name}/cli-plugin`) || name.includes(`${this.name}-cli-plugin`);
1807
1818
  }
1808
1819
 
1809
1820
  };