@storm-software/workspace-tools 1.19.3 → 1.20.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storm-software/workspace-tools",
3
- "version": "1.19.3",
3
+ "version": "1.20.1",
4
4
  "private": false,
5
5
  "description": "⚡ A Nx plugin package that contains various executors and generators used in a Storm workspaces.",
6
6
  "keywords": [
package/src/base/index.js CHANGED
@@ -6755,26 +6755,39 @@ var getWorkspaceRoot2 = () => {
6755
6755
  };
6756
6756
 
6757
6757
  // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
6758
- var applyWorkspaceTokens = (option, config) => {
6758
+ var applyWorkspaceExecutorTokens = (option, tokenizerOptions) => {
6759
+ console.log("applyWorkspaceExecutorTokens", option);
6759
6760
  let result = option;
6760
6761
  if (!result) {
6761
6762
  return result;
6762
6763
  }
6763
- const workspaceRoot = getWorkspaceRoot2();
6764
6764
  let projectName;
6765
6765
  let projectRoot;
6766
6766
  let sourceRoot;
6767
- if (config?.projectsConfigurations?.projects && config?.projectName) {
6768
- const context = config;
6767
+ if (tokenizerOptions?.projectName) {
6768
+ const context = tokenizerOptions;
6769
6769
  projectName = context.projectName;
6770
- projectRoot = context.projectsConfigurations.projects[projectName].root;
6771
- sourceRoot = context.projectsConfigurations.projects[projectName].sourceRoot;
6770
+ projectRoot = context.root;
6771
+ sourceRoot = context.sourceRoot;
6772
6772
  } else {
6773
- const projectConfig = config;
6773
+ const projectConfig = tokenizerOptions;
6774
6774
  projectName = projectConfig.name;
6775
6775
  projectRoot = projectConfig.root;
6776
6776
  sourceRoot = projectConfig.sourceRoot;
6777
6777
  }
6778
+ if (tokenizerOptions.config) {
6779
+ const configKeys = Object.keys(tokenizerOptions.config);
6780
+ if (configKeys.some((configKey) => result.includes(`{${configKey}}`))) {
6781
+ configKeys.forEach((configKey) => {
6782
+ if (result.includes(`{${configKey}}`)) {
6783
+ result = result.replaceAll(
6784
+ `{${configKey}}`,
6785
+ tokenizerOptions.config[configKey]
6786
+ );
6787
+ }
6788
+ });
6789
+ }
6790
+ }
6778
6791
  if (result.includes("{projectName}")) {
6779
6792
  result = result.replaceAll("{projectName}", projectName);
6780
6793
  }
@@ -6785,28 +6798,69 @@ var applyWorkspaceTokens = (option, config) => {
6785
6798
  result = result.replaceAll("{sourceRoot}", sourceRoot);
6786
6799
  }
6787
6800
  if (result.includes("{workspaceRoot}")) {
6788
- result = result.replaceAll("{workspaceRoot}", workspaceRoot);
6801
+ result = result.replaceAll(
6802
+ "{workspaceRoot}",
6803
+ tokenizerOptions.workspaceRoot ?? getWorkspaceRoot2()
6804
+ );
6805
+ }
6806
+ return result;
6807
+ };
6808
+ var applyWorkspaceGeneratorTokens = (option, tokenizerOptions) => {
6809
+ let result = option;
6810
+ if (!result) {
6811
+ return result;
6812
+ }
6813
+ if (result.includes("{workspaceRoot}")) {
6814
+ result = result.replaceAll(
6815
+ "{workspaceRoot}",
6816
+ tokenizerOptions.workspaceRoot ?? tokenizerOptions.config.workspaceRoot ?? getWorkspaceRoot2()
6817
+ );
6789
6818
  }
6790
6819
  return result;
6791
6820
  };
6821
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
6822
+ let result = options;
6823
+ if (!result) {
6824
+ return {};
6825
+ }
6826
+ return Object.keys(options).reduce(
6827
+ (ret, option) => {
6828
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
6829
+ ret[option] = tokenizerFn(option, config);
6830
+ } else if (Array.isArray(options[option])) {
6831
+ ret[option] = options[option].map(
6832
+ (item) => tokenizerFn(item, config)
6833
+ );
6834
+ } else if (typeof options[option] === "object") {
6835
+ ret[option] = tokenizerFn(options[option], config);
6836
+ }
6837
+ return ret;
6838
+ },
6839
+ {}
6840
+ );
6841
+ };
6792
6842
 
6793
6843
  // packages/workspace-tools/src/base/base-executor.ts
6794
- var withRunExecutor = (name, executorFn, executorOptions = { skipReadingConfig: false }) => async (options, context) => {
6844
+ var withRunExecutor = (name, executorFn, executorOptions = {
6845
+ skipReadingConfig: false
6846
+ }) => async (options, context) => {
6795
6847
  const startTime = Date.now();
6796
6848
  try {
6797
6849
  console.info(`\u26A1 Running the ${name} executor...`);
6798
- console.debug(`\u2699\uFE0F Executor schema options:
6850
+ if (executorOptions?.applyDefaultFn) {
6851
+ options = executorOptions.applyDefaultFn(options);
6852
+ }
6853
+ console.debug(`\u2699\uFE0F Executor schema options:
6799
6854
  `, options);
6800
- const tokenized = Object.keys(options).reduce(
6801
- (ret, key) => {
6802
- ret[key] = applyWorkspaceTokens(
6803
- options[key],
6804
- context
6805
- );
6806
- return ret;
6807
- },
6808
- options
6809
- );
6855
+ if (!context.projectsConfigurations?.projects || !context.projectName || !context.projectsConfigurations.projects[context.projectName]) {
6856
+ throw new Error(
6857
+ "The Build process failed because the context is not valid. Please run this command from a workspace."
6858
+ );
6859
+ }
6860
+ const workspaceRoot = getWorkspaceRoot2();
6861
+ const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
6862
+ const sourceRoot = context.projectsConfigurations.projects[context.projectName].sourceRoot;
6863
+ const projectName = context.projectsConfigurations.projects[context.projectName].name;
6810
6864
  let config;
6811
6865
  if (!executorOptions.skipReadingConfig) {
6812
6866
  const configFile = await getConfigFile();
@@ -6817,8 +6871,21 @@ var withRunExecutor = (name, executorFn, executorOptions = { skipReadingConfig:
6817
6871
  });
6818
6872
  setConfigEnv(config);
6819
6873
  console.debug(`Loaded Storm config into env:
6820
- ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
6821
- }
6874
+ ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
6875
+ }
6876
+ const tokenized = applyWorkspaceTokens(
6877
+ options,
6878
+ {
6879
+ config,
6880
+ workspaceRoot,
6881
+ projectRoot,
6882
+ sourceRoot,
6883
+ projectName,
6884
+ ...context.projectsConfigurations.projects[context.projectName],
6885
+ ...executorOptions
6886
+ },
6887
+ applyWorkspaceExecutorTokens
6888
+ );
6822
6889
  const result = await Promise.resolve(
6823
6890
  executorFn(tokenized, context, config)
6824
6891
  );
@@ -6843,11 +6910,16 @@ ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\
6843
6910
  };
6844
6911
 
6845
6912
  // packages/workspace-tools/src/base/base-generator.ts
6846
- var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, options) => {
6913
+ var withRunGenerator = (name, generatorFn, generatorOptions = {
6914
+ skipReadingConfig: false
6915
+ }) => async (tree, options) => {
6847
6916
  const startTime = Date.now();
6848
6917
  try {
6849
6918
  console.info(`\u26A1 Running the ${name} generator...`);
6850
- console.debug("\u2699\uFE0F Generator schema options: \n", options);
6919
+ if (generatorOptions?.applyDefaultFn) {
6920
+ options = generatorOptions.applyDefaultFn(options);
6921
+ }
6922
+ console.debug("\u2699\uFE0F Generator schema options: \n", options);
6851
6923
  let config;
6852
6924
  if (!generatorOptions.skipReadingConfig) {
6853
6925
  const configFile = await getConfigFile();
@@ -6860,7 +6932,14 @@ var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfi
6860
6932
  console.debug(`Loaded Storm config into env:
6861
6933
  ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
6862
6934
  }
6863
- const result = await Promise.resolve(generatorFn(tree, options, config));
6935
+ const tokenized = applyWorkspaceTokens(
6936
+ options,
6937
+ { workspaceRoot: tree.root, config },
6938
+ applyWorkspaceGeneratorTokens
6939
+ );
6940
+ const result = await Promise.resolve(
6941
+ generatorFn(tree, tokenized, config)
6942
+ );
6864
6943
  if (result && (!result.success || result.error && result?.error?.message && typeof result?.error?.message === "string" && result?.error?.name && typeof result?.error?.name === "string")) {
6865
6944
  throw new Error(`The ${name} generator failed to run`, {
6866
6945
  cause: result.error