@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.
@@ -29593,12 +29593,62 @@ var setConfigEnv = (config) => {
29593
29593
  });
29594
29594
  };
29595
29595
 
29596
+ // packages/workspace-tools/src/utils/get-workspace-root.ts
29597
+ var import_find_workspace_root2 = require("nx/src/utils/find-workspace-root.js");
29598
+ var getWorkspaceRoot2 = () => {
29599
+ const root = (0, import_find_workspace_root2.findWorkspaceRoot)(process.cwd());
29600
+ process.env.STORM_REPO_ROOT ??= root?.dir;
29601
+ process.env.NX_WORKSPACE_ROOT_PATH ??= root?.dir;
29602
+ return root?.dir;
29603
+ };
29604
+
29605
+ // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
29606
+ var applyWorkspaceGeneratorTokens = (option, tokenizerOptions) => {
29607
+ let result = option;
29608
+ if (!result) {
29609
+ return result;
29610
+ }
29611
+ if (result.includes("{workspaceRoot}")) {
29612
+ result = result.replaceAll(
29613
+ "{workspaceRoot}",
29614
+ tokenizerOptions.workspaceRoot ?? tokenizerOptions.config.workspaceRoot ?? getWorkspaceRoot2()
29615
+ );
29616
+ }
29617
+ return result;
29618
+ };
29619
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
29620
+ let result = options;
29621
+ if (!result) {
29622
+ return {};
29623
+ }
29624
+ return Object.keys(options).reduce(
29625
+ (ret, option) => {
29626
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
29627
+ ret[option] = tokenizerFn(option, config);
29628
+ } else if (Array.isArray(options[option])) {
29629
+ ret[option] = options[option].map(
29630
+ (item) => tokenizerFn(item, config)
29631
+ );
29632
+ } else if (typeof options[option] === "object") {
29633
+ ret[option] = tokenizerFn(options[option], config);
29634
+ }
29635
+ return ret;
29636
+ },
29637
+ {}
29638
+ );
29639
+ };
29640
+
29596
29641
  // packages/workspace-tools/src/base/base-generator.ts
29597
- var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, options) => {
29642
+ var withRunGenerator = (name, generatorFn, generatorOptions = {
29643
+ skipReadingConfig: false
29644
+ }) => async (tree, options) => {
29598
29645
  const startTime = Date.now();
29599
29646
  try {
29600
29647
  console.info(`\u26A1 Running the ${name} generator...`);
29601
- console.debug("\u2699\uFE0F Generator schema options: \n", options);
29648
+ if (generatorOptions?.applyDefaultFn) {
29649
+ options = generatorOptions.applyDefaultFn(options);
29650
+ }
29651
+ console.debug("\u2699\uFE0F Generator schema options: \n", options);
29602
29652
  let config;
29603
29653
  if (!generatorOptions.skipReadingConfig) {
29604
29654
  const configFile = await getConfigFile();
@@ -29611,7 +29661,14 @@ var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfi
29611
29661
  console.debug(`Loaded Storm config into env:
29612
29662
  ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
29613
29663
  }
29614
- const result = await Promise.resolve(generatorFn(tree, options, config));
29664
+ const tokenized = applyWorkspaceTokens(
29665
+ options,
29666
+ { workspaceRoot: tree.root, config },
29667
+ applyWorkspaceGeneratorTokens
29668
+ );
29669
+ const result = await Promise.resolve(
29670
+ generatorFn(tree, tokenized, config)
29671
+ );
29615
29672
  if (result && (!result.success || result.error && result?.error?.message && typeof result?.error?.message === "string" && result?.error?.name && typeof result?.error?.name === "string")) {
29616
29673
  throw new Error(`The ${name} generator failed to run`, {
29617
29674
  cause: result.error
@@ -29636,24 +29693,12 @@ ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\
29636
29693
 
29637
29694
  // packages/workspace-tools/src/utils/get-project-configurations.ts
29638
29695
  var import_retrieve_workspace_files = require("nx/src/project-graph/utils/retrieve-workspace-files");
29639
-
29640
- // packages/workspace-tools/src/utils/get-workspace-root.ts
29641
- var import_find_workspace_root2 = require("nx/src/utils/find-workspace-root.js");
29642
- var getWorkspaceRoot2 = () => {
29643
- const root = (0, import_find_workspace_root2.findWorkspaceRoot)(process.cwd());
29644
- process.env.STORM_REPO_ROOT ??= root?.dir;
29645
- process.env.NX_WORKSPACE_ROOT_PATH ??= root?.dir;
29646
- return root?.dir;
29647
- };
29648
-
29649
- // packages/workspace-tools/src/utils/get-project-configurations.ts
29650
29696
  var getProjectConfigurations = () => (0, import_retrieve_workspace_files.retrieveProjectConfigurationsWithoutPluginInference)(
29651
29697
  getWorkspaceRoot2()
29652
29698
  );
29653
29699
 
29654
29700
  // packages/workspace-tools/src/generators/config-schema/generator.ts
29655
29701
  async function configSchemaGeneratorFn(tree, options) {
29656
- const schema = {};
29657
29702
  const projectConfigurations = getProjectConfigurations();
29658
29703
  const workspaceRoot = getWorkspaceRoot2();
29659
29704
  const modules = await Promise.all(
@@ -43925,12 +43925,62 @@ var setConfigEnv = (config) => {
43925
43925
  });
43926
43926
  };
43927
43927
 
43928
+ // packages/workspace-tools/src/utils/get-workspace-root.ts
43929
+ var import_find_workspace_root2 = require("nx/src/utils/find-workspace-root.js");
43930
+ var getWorkspaceRoot2 = () => {
43931
+ const root = (0, import_find_workspace_root2.findWorkspaceRoot)(process.cwd());
43932
+ process.env.STORM_REPO_ROOT ??= root?.dir;
43933
+ process.env.NX_WORKSPACE_ROOT_PATH ??= root?.dir;
43934
+ return root?.dir;
43935
+ };
43936
+
43937
+ // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
43938
+ var applyWorkspaceGeneratorTokens = (option, tokenizerOptions) => {
43939
+ let result = option;
43940
+ if (!result) {
43941
+ return result;
43942
+ }
43943
+ if (result.includes("{workspaceRoot}")) {
43944
+ result = result.replaceAll(
43945
+ "{workspaceRoot}",
43946
+ tokenizerOptions.workspaceRoot ?? tokenizerOptions.config.workspaceRoot ?? getWorkspaceRoot2()
43947
+ );
43948
+ }
43949
+ return result;
43950
+ };
43951
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
43952
+ let result = options;
43953
+ if (!result) {
43954
+ return {};
43955
+ }
43956
+ return Object.keys(options).reduce(
43957
+ (ret, option) => {
43958
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
43959
+ ret[option] = tokenizerFn(option, config);
43960
+ } else if (Array.isArray(options[option])) {
43961
+ ret[option] = options[option].map(
43962
+ (item) => tokenizerFn(item, config)
43963
+ );
43964
+ } else if (typeof options[option] === "object") {
43965
+ ret[option] = tokenizerFn(options[option], config);
43966
+ }
43967
+ return ret;
43968
+ },
43969
+ {}
43970
+ );
43971
+ };
43972
+
43928
43973
  // packages/workspace-tools/src/base/base-generator.ts
43929
- var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, options) => {
43974
+ var withRunGenerator = (name, generatorFn, generatorOptions = {
43975
+ skipReadingConfig: false
43976
+ }) => async (tree, options) => {
43930
43977
  const startTime = Date.now();
43931
43978
  try {
43932
43979
  console.info(`\u26A1 Running the ${name} generator...`);
43933
- console.debug("\u2699\uFE0F Generator schema options: \n", options);
43980
+ if (generatorOptions?.applyDefaultFn) {
43981
+ options = generatorOptions.applyDefaultFn(options);
43982
+ }
43983
+ console.debug("\u2699\uFE0F Generator schema options: \n", options);
43934
43984
  let config;
43935
43985
  if (!generatorOptions.skipReadingConfig) {
43936
43986
  const configFile = await getConfigFile();
@@ -43943,7 +43993,14 @@ var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfi
43943
43993
  console.debug(`Loaded Storm config into env:
43944
43994
  ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
43945
43995
  }
43946
- const result = await Promise.resolve(generatorFn(tree, options, config));
43996
+ const tokenized = applyWorkspaceTokens(
43997
+ options,
43998
+ { workspaceRoot: tree.root, config },
43999
+ applyWorkspaceGeneratorTokens
44000
+ );
44001
+ const result = await Promise.resolve(
44002
+ generatorFn(tree, tokenized, config)
44003
+ );
43947
44004
  if (result && (!result.success || result.error && result?.error?.message && typeof result?.error?.message === "string" && result?.error?.name && typeof result?.error?.name === "string")) {
43948
44005
  throw new Error(`The ${name} generator failed to run`, {
43949
44006
  cause: result.error
@@ -24950,12 +24950,62 @@ var setConfigEnv = (config) => {
24950
24950
  });
24951
24951
  };
24952
24952
 
24953
+ // packages/workspace-tools/src/utils/get-workspace-root.ts
24954
+ var import_find_workspace_root2 = require("nx/src/utils/find-workspace-root.js");
24955
+ var getWorkspaceRoot2 = () => {
24956
+ const root = (0, import_find_workspace_root2.findWorkspaceRoot)(process.cwd());
24957
+ process.env.STORM_REPO_ROOT ??= root?.dir;
24958
+ process.env.NX_WORKSPACE_ROOT_PATH ??= root?.dir;
24959
+ return root?.dir;
24960
+ };
24961
+
24962
+ // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
24963
+ var applyWorkspaceGeneratorTokens = (option, tokenizerOptions) => {
24964
+ let result = option;
24965
+ if (!result) {
24966
+ return result;
24967
+ }
24968
+ if (result.includes("{workspaceRoot}")) {
24969
+ result = result.replaceAll(
24970
+ "{workspaceRoot}",
24971
+ tokenizerOptions.workspaceRoot ?? tokenizerOptions.config.workspaceRoot ?? getWorkspaceRoot2()
24972
+ );
24973
+ }
24974
+ return result;
24975
+ };
24976
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
24977
+ let result = options;
24978
+ if (!result) {
24979
+ return {};
24980
+ }
24981
+ return Object.keys(options).reduce(
24982
+ (ret, option) => {
24983
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
24984
+ ret[option] = tokenizerFn(option, config);
24985
+ } else if (Array.isArray(options[option])) {
24986
+ ret[option] = options[option].map(
24987
+ (item) => tokenizerFn(item, config)
24988
+ );
24989
+ } else if (typeof options[option] === "object") {
24990
+ ret[option] = tokenizerFn(options[option], config);
24991
+ }
24992
+ return ret;
24993
+ },
24994
+ {}
24995
+ );
24996
+ };
24997
+
24953
24998
  // packages/workspace-tools/src/base/base-generator.ts
24954
- var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, options) => {
24999
+ var withRunGenerator = (name, generatorFn, generatorOptions = {
25000
+ skipReadingConfig: false
25001
+ }) => async (tree, options) => {
24955
25002
  const startTime = Date.now();
24956
25003
  try {
24957
25004
  console.info(`\u26A1 Running the ${name} generator...`);
24958
- console.debug("\u2699\uFE0F Generator schema options: \n", options);
25005
+ if (generatorOptions?.applyDefaultFn) {
25006
+ options = generatorOptions.applyDefaultFn(options);
25007
+ }
25008
+ console.debug("\u2699\uFE0F Generator schema options: \n", options);
24959
25009
  let config;
24960
25010
  if (!generatorOptions.skipReadingConfig) {
24961
25011
  const configFile = await getConfigFile();
@@ -24968,7 +25018,14 @@ var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfi
24968
25018
  console.debug(`Loaded Storm config into env:
24969
25019
  ${Object.keys(process.env).map((key) => ` - ${key}=${process.env[key]}`).join("\n")}`);
24970
25020
  }
24971
- const result = await Promise.resolve(generatorFn(tree, options, config));
25021
+ const tokenized = applyWorkspaceTokens(
25022
+ options,
25023
+ { workspaceRoot: tree.root, config },
25024
+ applyWorkspaceGeneratorTokens
25025
+ );
25026
+ const result = await Promise.resolve(
25027
+ generatorFn(tree, tokenized, config)
25028
+ );
24972
25029
  if (result && (!result.success || result.error && result?.error?.message && typeof result?.error?.message === "string" && result?.error?.name && typeof result?.error?.name === "string")) {
24973
25030
  throw new Error(`The ${name} generator failed to run`, {
24974
25031
  cause: result.error
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var utils_exports = {};
21
21
  __export(utils_exports, {
22
22
  WorkspaceStorage: () => WorkspaceStorage,
23
+ applyWorkspaceExecutorTokens: () => applyWorkspaceExecutorTokens,
24
+ applyWorkspaceGeneratorTokens: () => applyWorkspaceGeneratorTokens,
23
25
  applyWorkspaceTokens: () => applyWorkspaceTokens,
24
26
  eslintVersion: () => eslintVersion,
25
27
  findCacheDirectory: () => findCacheDirectory,
@@ -58,26 +60,39 @@ var getWorkspaceRoot = () => {
58
60
  };
59
61
 
60
62
  // packages/workspace-tools/src/utils/apply-workspace-tokens.ts
61
- var applyWorkspaceTokens = (option, config) => {
63
+ var applyWorkspaceExecutorTokens = (option, tokenizerOptions) => {
64
+ console.log("applyWorkspaceExecutorTokens", option);
62
65
  let result = option;
63
66
  if (!result) {
64
67
  return result;
65
68
  }
66
- const workspaceRoot = getWorkspaceRoot();
67
69
  let projectName;
68
70
  let projectRoot;
69
71
  let sourceRoot;
70
- if (config?.projectsConfigurations?.projects && config?.projectName) {
71
- const context = config;
72
+ if (tokenizerOptions?.projectName) {
73
+ const context = tokenizerOptions;
72
74
  projectName = context.projectName;
73
- projectRoot = context.projectsConfigurations.projects[projectName].root;
74
- sourceRoot = context.projectsConfigurations.projects[projectName].sourceRoot;
75
+ projectRoot = context.root;
76
+ sourceRoot = context.sourceRoot;
75
77
  } else {
76
- const projectConfig = config;
78
+ const projectConfig = tokenizerOptions;
77
79
  projectName = projectConfig.name;
78
80
  projectRoot = projectConfig.root;
79
81
  sourceRoot = projectConfig.sourceRoot;
80
82
  }
83
+ if (tokenizerOptions.config) {
84
+ const configKeys = Object.keys(tokenizerOptions.config);
85
+ if (configKeys.some((configKey) => result.includes(`{${configKey}}`))) {
86
+ configKeys.forEach((configKey) => {
87
+ if (result.includes(`{${configKey}}`)) {
88
+ result = result.replaceAll(
89
+ `{${configKey}}`,
90
+ tokenizerOptions.config[configKey]
91
+ );
92
+ }
93
+ });
94
+ }
95
+ }
81
96
  if (result.includes("{projectName}")) {
82
97
  result = result.replaceAll("{projectName}", projectName);
83
98
  }
@@ -88,10 +103,47 @@ var applyWorkspaceTokens = (option, config) => {
88
103
  result = result.replaceAll("{sourceRoot}", sourceRoot);
89
104
  }
90
105
  if (result.includes("{workspaceRoot}")) {
91
- result = result.replaceAll("{workspaceRoot}", workspaceRoot);
106
+ result = result.replaceAll(
107
+ "{workspaceRoot}",
108
+ tokenizerOptions.workspaceRoot ?? getWorkspaceRoot()
109
+ );
110
+ }
111
+ return result;
112
+ };
113
+ var applyWorkspaceGeneratorTokens = (option, tokenizerOptions) => {
114
+ let result = option;
115
+ if (!result) {
116
+ return result;
117
+ }
118
+ if (result.includes("{workspaceRoot}")) {
119
+ result = result.replaceAll(
120
+ "{workspaceRoot}",
121
+ tokenizerOptions.workspaceRoot ?? tokenizerOptions.config.workspaceRoot ?? getWorkspaceRoot()
122
+ );
92
123
  }
93
124
  return result;
94
125
  };
126
+ var applyWorkspaceTokens = (options, config, tokenizerFn) => {
127
+ let result = options;
128
+ if (!result) {
129
+ return {};
130
+ }
131
+ return Object.keys(options).reduce(
132
+ (ret, option) => {
133
+ if (options[option] === void 0 || options[option] === null || typeof options[option] === "number" || typeof options[option] === "boolean" || typeof options[option] === "string") {
134
+ ret[option] = tokenizerFn(option, config);
135
+ } else if (Array.isArray(options[option])) {
136
+ ret[option] = options[option].map(
137
+ (item) => tokenizerFn(item, config)
138
+ );
139
+ } else if (typeof options[option] === "object") {
140
+ ret[option] = tokenizerFn(options[option], config);
141
+ }
142
+ return ret;
143
+ },
144
+ {}
145
+ );
146
+ };
95
147
 
96
148
  // packages/workspace-tools/src/utils/file-path-utils.ts
97
149
  var import_node_path = require("node:path");
@@ -283,6 +335,8 @@ var WorkspaceStorage = class {
283
335
  // Annotate the CommonJS export names for ESM import in node:
284
336
  0 && (module.exports = {
285
337
  WorkspaceStorage,
338
+ applyWorkspaceExecutorTokens,
339
+ applyWorkspaceGeneratorTokens,
286
340
  applyWorkspaceTokens,
287
341
  eslintVersion,
288
342
  findCacheDirectory,