@otwld/nx-helm 0.0.3 → 0.0.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,38 @@
1
+ ## 0.0.5 (2026-08-12)
2
+
3
+ ### Breaking Changes
4
+
5
+ - Infer cache, outputs, and Helm-version runtime inputs directly on standalone
6
+ chart targets.
7
+ - Replace workspace `validateTarget`, `packageTarget`, and `registry` options
8
+ with `validate`, `package`, and `publish.registry`.
9
+ - Infer `nx-release-publish` only for configured OCI registries; project
10
+ `metadata.helm` can override registry and validation settings or disable
11
+ publishing.
12
+ - Stop injecting target defaults during plugin initialization and stop adding
13
+ organization-specific chart tags.
14
+
15
+ ## 0.0.4 (2026-08-12)
16
+
17
+ ### 🚀 Features
18
+
19
+ - **plugins:** add nx helm and argo plugins ([eb30b828](https://github.com/otwld/devops/commit/eb30b828))
20
+
21
+ ### ❤️ Thank You
22
+
23
+ - Tréhout Nathan
24
+
25
+ ## 0.0.3 (2026-08-12)
26
+
27
+ ### 🚀 Features
28
+
29
+ - **helm:** add inferred chart projects and nx add setup ([2061556](https://github.com/otwld/monorepo-starter/commit/2061556))
30
+ - create nx-helm plugin with validate as a the first executor ([b7784f3](https://github.com/otwld/monorepo-starter/commit/b7784f3))
31
+
32
+ ### ❤️ Thank You
33
+
34
+ - Tréhout Nathan
35
+
1
36
  ## 0.0.2 (2026-08-12)
2
37
 
3
38
  ### Features
package/README.md CHANGED
@@ -19,9 +19,8 @@ charts/service/
19
19
  └── project.json
20
20
  ```
21
21
 
22
- Generated projects use the `helm-<name>` project name and the
23
- `scope:workspace`, `layer:infra`, and `runtime:helm` tags. The `directory`,
24
- `projectName`, and `starter` options customize generation.
22
+ Generated projects use the `helm-<name>` project name. The `directory`,
23
+ `projectName`, `starter`, and `tags` options customize generation.
25
24
 
26
25
  ## Inferred Targets
27
26
 
@@ -29,7 +28,11 @@ Charts with sibling `Chart.yaml` and `project.json` files receive these targets:
29
28
 
30
29
  - `helm:validate` runs `helm lint` and `helm template`.
31
30
  - `helm:package` packages the chart into `dist/<project-root>/helm`.
32
- - `nx-release-publish` pushes the packaged chart to an OCI registry.
31
+ - `nx-release-publish` is inferred only when an OCI registry is configured.
32
+
33
+ Each inferred validate and package target is cacheable, declares its direct
34
+ output where applicable, and includes the installed Helm version as a runtime
35
+ input.
33
36
 
34
37
  ## Configuration
35
38
 
@@ -39,21 +42,41 @@ Charts with sibling `Chart.yaml` and `project.json` files receive these targets:
39
42
  {
40
43
  "plugin": "@otwld/nx-helm",
41
44
  "options": {
42
- "validateTarget": {
43
- "name": "helm:validate",
45
+ "validate": {
46
+ "target": "helm:validate",
44
47
  "kubeVersion": "1.32.0",
45
48
  "strict": false,
49
+ "validationValues": ["values-ci.yaml"],
50
+ },
51
+ "package": {
52
+ "target": "helm:package",
46
53
  },
47
- "packageTarget": {
48
- "name": "helm:package",
54
+ "publish": {
55
+ "registry": "oci://registry.company.test/charts",
49
56
  },
50
- "registry": "oci://registry.example.com/charts",
51
57
  },
52
58
  },
53
59
  ],
54
60
  }
55
61
  ```
56
62
 
63
+ Project-specific settings belong in `project.json` under `metadata.helm`.
64
+ `registry`, `publish`, `kubeVersion`, `strict`, `releaseName`, and
65
+ `validationValues` override workspace options; `publish: false` suppresses the
66
+ release target.
67
+
68
+ ```jsonc
69
+ {
70
+ "metadata": {
71
+ "helm": {
72
+ "registry": "oci://registry.company.test/team-charts",
73
+ "releaseName": "service",
74
+ "validationValues": ["values-ci.yaml"],
75
+ },
76
+ },
77
+ }
78
+ ```
79
+
57
80
  ## Helm Release
58
81
 
59
82
  ```shell
@@ -65,7 +88,7 @@ pnpm exec nx release publish --groups=helm --dry-run
65
88
  Authenticate with the OCI registry before publishing:
66
89
 
67
90
  ```shell
68
- helm registry login registry.example.com
91
+ helm registry login registry.company.test
69
92
  pnpm exec nx release --groups=helm --first-release
70
93
  ```
71
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@otwld/nx-helm",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -54,4 +54,3 @@ function parseChartDocument(content, filePath) {
54
54
  }
55
55
  return document;
56
56
  }
57
- //# sourceMappingURL=chart-manifest.js.map
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const node_fs_1 = require("node:fs");
5
4
  const node_path_1 = require("node:path");
6
5
  const chart_manifest_1 = require("../../chart-manifest");
@@ -12,7 +11,7 @@ const run_helm_1 = require("../run-helm");
12
11
  * @param context Nx's executor context.
13
12
  * @returns Whether the Helm package operation completed successfully.
14
13
  */
15
- const runExecutor = (options, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
14
+ const runExecutor = async (options, context) => {
16
15
  const projectDirectory = (0, project_directory_1.getProjectDirectory)(context, 'packaging');
17
16
  if (!projectDirectory) {
18
17
  return { success: false };
@@ -29,7 +28,7 @@ const runExecutor = (options, context) => tslib_1.__awaiter(void 0, void 0, void
29
28
  }
30
29
  (0, node_fs_1.mkdirSync)(outputDirectory, { recursive: true });
31
30
  console.log(`[nx-helm] Packaging chart ${projectDirectory}`);
32
- if (!(yield (0, run_helm_1.runHelm)(['package', '.', '--destination', outputDirectory], projectDirectory))) {
31
+ if (!(await (0, run_helm_1.runHelm)(['package', '.', '--destination', outputDirectory], projectDirectory))) {
33
32
  return { success: false };
34
33
  }
35
34
  }
@@ -38,14 +37,14 @@ const runExecutor = (options, context) => tslib_1.__awaiter(void 0, void 0, void
38
37
  return { success: false };
39
38
  }
40
39
  return { success: true };
41
- });
40
+ };
42
41
  /**
43
42
  * Checks the Nx dry-run environment and executor option.
44
43
  * @param optionDryRun Explicit executor dry-run option.
45
44
  * @returns Whether the operation must avoid filesystem changes.
46
45
  */
47
46
  function isDryRun(optionDryRun) {
48
- return optionDryRun === true || process.env.NX_DRY_RUN === 'true';
47
+ return optionDryRun === true || process.env['NX_DRY_RUN'] === 'true';
49
48
  }
50
49
  /**
51
50
  * Converts unknown caught values into useful command-line text.
@@ -56,4 +55,3 @@ function getErrorMessage(error) {
56
55
  return error instanceof Error ? error.message : String(error);
57
56
  }
58
57
  exports.default = runExecutor;
59
- //# sourceMappingURL=package.js.map
@@ -21,4 +21,3 @@ function getProjectDirectory(context, operation) {
21
21
  }
22
22
  return (0, node_path_1.resolve)(context.root, project.root);
23
23
  }
24
- //# sourceMappingURL=project-directory.js.map
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const node_fs_1 = require("node:fs");
5
4
  const node_path_1 = require("node:path");
6
5
  const chart_manifest_1 = require("../../chart-manifest");
@@ -12,7 +11,7 @@ const run_helm_1 = require("../run-helm");
12
11
  * @param context Nx's executor context.
13
12
  * @returns Whether the Helm chart was published successfully.
14
13
  */
15
- const runExecutor = (options, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
14
+ const runExecutor = async (options, context) => {
16
15
  const projectDirectory = (0, project_directory_1.getProjectDirectory)(context, 'publishing');
17
16
  if (!projectDirectory) {
18
17
  return { success: false };
@@ -20,23 +19,23 @@ const runExecutor = (options, context) => tslib_1.__awaiter(void 0, void 0, void
20
19
  const registry = normalizeRegistry(options.registry);
21
20
  if (!registry) {
22
21
  console.error('[nx-helm] Helm release publishing requires an OCI registry such as ' +
23
- 'oci://registry.example.com/charts.');
22
+ 'oci://registry.company.test/charts.');
24
23
  return { success: false };
25
24
  }
26
25
  const outputDirectory = (0, node_path_1.resolve)(context.root, options.outputPath);
27
26
  const dryRun = isDryRun(options.dryRun);
28
- if (!(yield publishChart(projectDirectory, outputDirectory, registry, dryRun))) {
27
+ if (!(await publishChart(projectDirectory, outputDirectory, registry, dryRun))) {
29
28
  return { success: false };
30
29
  }
31
30
  return { success: true };
32
- });
31
+ };
33
32
  /**
34
33
  * Normalizes and validates the Helm OCI repository reference.
35
34
  * @param registry Configured registry repository.
36
35
  * @returns A normalized OCI repository, or undefined when invalid.
37
36
  */
38
37
  function normalizeRegistry(registry) {
39
- let normalized = registry === null || registry === void 0 ? void 0 : registry.trim();
38
+ let normalized = registry?.trim();
40
39
  if (!normalized) {
41
40
  return undefined;
42
41
  }
@@ -53,38 +52,36 @@ function normalizeRegistry(registry) {
53
52
  * @param dryRun Whether to avoid package and push operations.
54
53
  * @returns Whether the chart publish operation succeeded.
55
54
  */
56
- function publishChart(projectDirectory, outputDirectory, registry, dryRun) {
57
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
58
- try {
59
- const chartFilePath = (0, node_path_1.join)(projectDirectory, 'Chart.yaml');
60
- const metadata = (0, chart_manifest_1.readChartMetadata)((0, node_fs_1.readFileSync)(chartFilePath, 'utf8'), chartFilePath);
61
- const archivePath = (0, node_path_1.join)(outputDirectory, `${metadata.name}-${metadata.version}.tgz`);
62
- if (dryRun) {
63
- if (!(0, node_fs_1.existsSync)(archivePath)) {
64
- console.log(`[nx-helm] Would package chart to ${archivePath}`);
65
- }
66
- console.log(`[nx-helm] Would push ${archivePath} to ${registry}`);
67
- return true;
68
- }
55
+ async function publishChart(projectDirectory, outputDirectory, registry, dryRun) {
56
+ try {
57
+ const chartFilePath = (0, node_path_1.join)(projectDirectory, 'Chart.yaml');
58
+ const metadata = (0, chart_manifest_1.readChartMetadata)((0, node_fs_1.readFileSync)(chartFilePath, 'utf8'), chartFilePath);
59
+ const archivePath = (0, node_path_1.join)(outputDirectory, `${metadata.name}-${metadata.version}.tgz`);
60
+ if (dryRun) {
69
61
  if (!(0, node_fs_1.existsSync)(archivePath)) {
70
- (0, node_fs_1.mkdirSync)(outputDirectory, { recursive: true });
71
- console.log(`[nx-helm] Packaging chart ${projectDirectory}`);
72
- if (!(yield (0, run_helm_1.runHelm)(['package', '.', '--destination', outputDirectory], projectDirectory))) {
73
- return false;
74
- }
62
+ console.log(`[nx-helm] Would package chart to ${archivePath}`);
75
63
  }
76
- if (!(0, node_fs_1.existsSync)(archivePath)) {
77
- console.error(`[nx-helm] Helm did not create ${archivePath}.`);
64
+ console.log(`[nx-helm] Would push ${archivePath} to ${registry}`);
65
+ return true;
66
+ }
67
+ if (!(0, node_fs_1.existsSync)(archivePath)) {
68
+ (0, node_fs_1.mkdirSync)(outputDirectory, { recursive: true });
69
+ console.log(`[nx-helm] Packaging chart ${projectDirectory}`);
70
+ if (!(await (0, run_helm_1.runHelm)(['package', '.', '--destination', outputDirectory], projectDirectory))) {
78
71
  return false;
79
72
  }
80
- console.log(`[nx-helm] Publishing chart ${metadata.name}:${metadata.version}`);
81
- return (0, run_helm_1.runHelm)(['push', archivePath, registry], projectDirectory);
82
73
  }
83
- catch (error) {
84
- console.error(`[nx-helm] Could not publish chart ${projectDirectory}: ${getErrorMessage(error)}`);
74
+ if (!(0, node_fs_1.existsSync)(archivePath)) {
75
+ console.error(`[nx-helm] Helm did not create ${archivePath}.`);
85
76
  return false;
86
77
  }
87
- });
78
+ console.log(`[nx-helm] Publishing chart ${metadata.name}:${metadata.version}`);
79
+ return (0, run_helm_1.runHelm)(['push', archivePath, registry], projectDirectory);
80
+ }
81
+ catch (error) {
82
+ console.error(`[nx-helm] Could not publish chart ${projectDirectory}: ${getErrorMessage(error)}`);
83
+ return false;
84
+ }
88
85
  }
89
86
  /**
90
87
  * Checks the Nx dry-run environment and executor option.
@@ -92,7 +89,7 @@ function publishChart(projectDirectory, outputDirectory, registry, dryRun) {
92
89
  * @returns Whether the operation must avoid publishing.
93
90
  */
94
91
  function isDryRun(optionDryRun) {
95
- return optionDryRun === true || process.env.NX_DRY_RUN === 'true';
92
+ return optionDryRun === true || process.env['NX_DRY_RUN'] === 'true';
96
93
  }
97
94
  /**
98
95
  * Converts unknown caught values into useful command-line text.
@@ -103,4 +100,3 @@ function getErrorMessage(error) {
103
100
  return error instanceof Error ? error.message : String(error);
104
101
  }
105
102
  exports.default = runExecutor;
106
- //# sourceMappingURL=release-publish.js.map
@@ -30,4 +30,3 @@ function runHelm(arguments_, cwd) {
30
30
  child.once('close', (code) => settle(code === 0));
31
31
  });
32
32
  }
33
- //# sourceMappingURL=run-helm.js.map
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createValuesArguments = createValuesArguments;
4
- const tslib_1 = require("tslib");
5
4
  const project_directory_1 = require("../project-directory");
6
5
  const run_helm_1 = require("../run-helm");
7
6
  const fallbackReleaseName = 'helm-validate';
@@ -11,13 +10,12 @@ const fallbackReleaseName = 'helm-validate';
11
10
  * @param context Nx's executor context.
12
11
  * @returns Whether every Helm command completed successfully.
13
12
  */
14
- const runExecutor = (options, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
15
- var _a, _b;
13
+ const runExecutor = async (options, context) => {
16
14
  const projectDirectory = (0, project_directory_1.getProjectDirectory)(context, 'validation');
17
15
  if (!projectDirectory) {
18
16
  return { success: false };
19
17
  }
20
- const releaseName = (_b = (_a = options.releaseName) !== null && _a !== void 0 ? _a : context.projectName) !== null && _b !== void 0 ? _b : fallbackReleaseName;
18
+ const releaseName = options.releaseName ?? context.projectName ?? fallbackReleaseName;
21
19
  const valuesArguments = createValuesArguments(options.valuesFiles);
22
20
  const lintArguments = [
23
21
  'lint',
@@ -33,14 +31,14 @@ const runExecutor = (options, context) => tslib_1.__awaiter(void 0, void 0, void
33
31
  ...valuesArguments,
34
32
  ];
35
33
  console.log(`[nx-helm] Validating chart ${projectDirectory}`);
36
- if (!(yield (0, run_helm_1.runHelm)(lintArguments, projectDirectory))) {
34
+ if (!(await (0, run_helm_1.runHelm)(lintArguments, projectDirectory))) {
37
35
  return { success: false };
38
36
  }
39
- if (!(yield (0, run_helm_1.runHelm)(templateArguments, projectDirectory))) {
37
+ if (!(await (0, run_helm_1.runHelm)(templateArguments, projectDirectory))) {
40
38
  return { success: false };
41
39
  }
42
40
  return { success: true };
43
- });
41
+ };
44
42
  /**
45
43
  * Builds repeated `--values` arguments without invoking a shell.
46
44
  * @param valuesFiles Values files to pass to Helm.
@@ -50,4 +48,3 @@ function createValuesArguments(valuesFiles = []) {
50
48
  return valuesFiles.flatMap((valuesFile) => ['--values', valuesFile]);
51
49
  }
52
50
  exports.default = runExecutor;
53
- //# sourceMappingURL=validate.js.map
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = chartGenerator;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const node_child_process_1 = require("node:child_process");
7
6
  const node_fs_1 = require("node:fs");
@@ -15,32 +14,29 @@ const defaultDirectory = 'charts';
15
14
  * @param options Generator options supplied by Nx.
16
15
  * @returns A promise that resolves after generated files are written.
17
16
  */
18
- function chartGenerator(tree, options) {
19
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
20
- var _a, _b;
21
- if (!options.name.trim()) {
22
- throw new Error('[nx-helm] A chart name is required.');
23
- }
24
- const chartDirectoryName = (0, devkit_1.names)(options.name).fileName;
25
- const projectRoot = (0, devkit_1.joinPathFragments)((_a = options.directory) !== null && _a !== void 0 ? _a : defaultDirectory, chartDirectoryName);
26
- const projectName = (_b = options.projectName) !== null && _b !== void 0 ? _b : `helm-${chartDirectoryName}`;
27
- if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'Chart.yaml'))) {
28
- throw new Error(`[nx-helm] A Helm chart already exists at ${projectRoot}.`);
29
- }
30
- const temporaryDirectory = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'nx-helm-'));
31
- const temporaryChartDirectory = (0, node_path_1.join)(temporaryDirectory, chartDirectoryName);
32
- try {
33
- runHelmCreate(temporaryChartDirectory, options.starter);
34
- copyGeneratedChartToTree(tree, temporaryChartDirectory, projectRoot);
35
- }
36
- finally {
37
- (0, node_fs_1.rmSync)(temporaryDirectory, { recursive: true, force: true });
38
- }
39
- (0, devkit_1.addProjectConfiguration)(tree, projectName, {
40
- root: projectRoot,
41
- projectType: 'application',
42
- tags: ['scope:workspace', 'layer:infra', 'runtime:helm'],
43
- });
17
+ async function chartGenerator(tree, options) {
18
+ if (!options.name.trim()) {
19
+ throw new Error('[nx-helm] A chart name is required.');
20
+ }
21
+ const chartDirectoryName = (0, devkit_1.names)(options.name).fileName;
22
+ const projectRoot = (0, devkit_1.joinPathFragments)(options.directory ?? defaultDirectory, chartDirectoryName);
23
+ const projectName = options.projectName ?? `helm-${chartDirectoryName}`;
24
+ if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'Chart.yaml'))) {
25
+ throw new Error(`[nx-helm] A Helm chart already exists at ${projectRoot}.`);
26
+ }
27
+ const temporaryDirectory = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'nx-helm-'));
28
+ const temporaryChartDirectory = (0, node_path_1.join)(temporaryDirectory, chartDirectoryName);
29
+ try {
30
+ runHelmCreate(temporaryChartDirectory, options.starter);
31
+ copyGeneratedChartToTree(tree, temporaryChartDirectory, projectRoot);
32
+ }
33
+ finally {
34
+ (0, node_fs_1.rmSync)(temporaryDirectory, { recursive: true, force: true });
35
+ }
36
+ (0, devkit_1.addProjectConfiguration)(tree, projectName, {
37
+ root: projectRoot,
38
+ projectType: 'application',
39
+ tags: options.tags,
44
40
  });
45
41
  }
46
42
  /**
@@ -50,7 +46,7 @@ function chartGenerator(tree, options) {
50
46
  */
51
47
  function runHelmCreate(chartDirectory, starter) {
52
48
  const arguments_ = ['create', chartDirectory];
53
- if (starter === null || starter === void 0 ? void 0 : starter.trim()) {
49
+ if (starter?.trim()) {
54
50
  arguments_.push('--starter', starter.trim());
55
51
  }
56
52
  try {
@@ -103,4 +99,3 @@ function getProcessErrorMessage(error) {
103
99
  }
104
100
  return error instanceof Error ? error.message : String(error);
105
101
  }
106
- //# sourceMappingURL=chart.js.map
@@ -8,4 +8,6 @@ export interface ChartGeneratorSchema {
8
8
  projectName?: string;
9
9
  /** Helm starter name or absolute starter path passed to helm create. */
10
10
  starter?: string;
11
+ /** Nx project tags assigned to the generated chart. */
12
+ tags?: string[];
11
13
  }
@@ -29,6 +29,13 @@
29
29
  "starter": {
30
30
  "type": "string",
31
31
  "description": "Helm starter name or absolute starter path passed to helm create."
32
+ },
33
+ "tags": {
34
+ "type": "array",
35
+ "description": "Nx project tags assigned to the generated chart.",
36
+ "items": {
37
+ "type": "string"
38
+ }
32
39
  }
33
40
  },
34
41
  "required": ["name"],
@@ -1,7 +1,7 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  import type { InitGeneratorSchema } from './schema';
3
3
  /**
4
- * Registers `@otwld/nx-helm` and fills missing shared target defaults.
4
+ * Registers `@otwld/nx-helm` without adding workspace target defaults.
5
5
  * @param tree Workspace tree to update.
6
6
  * @param options Init options supplied by Nx.
7
7
  * @returns A promise that resolves after optional formatting.
@@ -1,47 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = initGenerator;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const pluginName = '@otwld/nx-helm';
7
- const defaultValidateTargetName = 'helm:validate';
8
- const defaultPackageTargetName = 'helm:package';
9
- const defaultKubeVersion = '1.32.0';
10
- const defaultRegistry = 'oci://registry.example.com/charts';
11
6
  /**
12
- * Registers `@otwld/nx-helm` and fills missing shared target defaults.
7
+ * Registers `@otwld/nx-helm` without adding workspace target defaults.
13
8
  * @param tree Workspace tree to update.
14
9
  * @param options Init options supplied by Nx.
15
10
  * @returns A promise that resolves after optional formatting.
16
11
  */
17
- function initGenerator(tree, options) {
18
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
- var _a, _b;
20
- if (!tree.exists('nx.json')) {
21
- devkit_1.logger.warn('[nx-helm] nx.json was not found; plugin registration was skipped.');
22
- return;
23
- }
24
- const nxJson = (_a = (0, devkit_1.readNxJson)(tree)) !== null && _a !== void 0 ? _a : {};
25
- const existingPlugin = findPlugin(nxJson.plugins);
26
- const pluginOptions = existingPlugin
27
- ? readPluginOptions(existingPlugin)
28
- : createPluginOptions(options);
29
- if (!existingPlugin) {
30
- nxJson.plugins = [
31
- ...((_b = nxJson.plugins) !== null && _b !== void 0 ? _b : []),
32
- {
33
- plugin: pluginName,
34
- options: pluginOptions,
35
- },
36
- ];
37
- devkit_1.logger.info(`[nx-helm] Added ${pluginName} to nx.json.`);
38
- }
39
- addTargetDefaults(nxJson, pluginOptions);
40
- (0, devkit_1.updateNxJson)(tree, nxJson);
41
- if (!options.skipFormat) {
42
- yield (0, devkit_1.formatFiles)(tree);
43
- }
44
- });
12
+ async function initGenerator(tree, options) {
13
+ if (!tree.exists('nx.json')) {
14
+ devkit_1.logger.warn('[nx-helm] nx.json was not found; plugin registration was skipped.');
15
+ return;
16
+ }
17
+ const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
18
+ const existingPlugin = findPlugin(nxJson.plugins);
19
+ if (!existingPlugin) {
20
+ nxJson.plugins = [...(nxJson.plugins ?? []), pluginName];
21
+ devkit_1.logger.info(`[nx-helm] Added ${pluginName} to nx.json.`);
22
+ }
23
+ (0, devkit_1.updateNxJson)(tree, nxJson);
24
+ if (!options.skipFormat) {
25
+ await (0, devkit_1.formatFiles)(tree);
26
+ }
45
27
  }
46
28
  /**
47
29
  * Finds an existing string or object plugin registration.
@@ -49,88 +31,7 @@ function initGenerator(tree, options) {
49
31
  * @returns Existing Helm registration, or undefined.
50
32
  */
51
33
  function findPlugin(plugins) {
52
- return plugins === null || plugins === void 0 ? void 0 : plugins.find((plugin) => typeof plugin === 'string'
34
+ return plugins?.find((plugin) => typeof plugin === 'string'
53
35
  ? plugin === pluginName
54
- : (plugin === null || plugin === void 0 ? void 0 : plugin.plugin) === pluginName);
55
- }
56
- /**
57
- * Builds default plugin options for a new registration.
58
- * @param options Init generator options.
59
- * @returns Plugin options written to nx.json.
60
- */
61
- function createPluginOptions(options) {
62
- var _a, _b, _c, _d, _e;
63
- const validateTargetName = ((_a = options.validateTargetName) === null || _a === void 0 ? void 0 : _a.trim()) || defaultValidateTargetName;
64
- const packageTargetName = ((_b = options.packageTargetName) === null || _b === void 0 ? void 0 : _b.trim()) || defaultPackageTargetName;
65
- return {
66
- validateTarget: {
67
- name: validateTargetName,
68
- kubeVersion: ((_c = options.kubeVersion) === null || _c === void 0 ? void 0 : _c.trim()) || defaultKubeVersion,
69
- strict: (_d = options.strict) !== null && _d !== void 0 ? _d : false,
70
- },
71
- packageTarget: {
72
- name: packageTargetName,
73
- },
74
- registry: ((_e = options.registry) === null || _e === void 0 ? void 0 : _e.trim()) || defaultRegistry,
75
- };
76
- }
77
- /**
78
- * Reads target names from an existing object registration without changing it.
79
- * @param plugin Existing Helm registration.
80
- * @returns Existing plugin options or empty options for default resolution.
81
- */
82
- function readPluginOptions(plugin) {
83
- if (typeof plugin === 'string' || !isRecord(plugin.options)) {
84
- return {};
85
- }
86
- return plugin.options;
87
- }
88
- /**
89
- * Adds shared cache/input defaults only when a target has no existing default.
90
- * @param nxJson Nx workspace configuration.
91
- * @param pluginOptions Helm plugin options.
92
- */
93
- function addTargetDefaults(nxJson, pluginOptions) {
94
- var _a, _b, _c, _d, _e;
95
- var _f, _g;
96
- (_a = nxJson.targetDefaults) !== null && _a !== void 0 ? _a : (nxJson.targetDefaults = {});
97
- const validateTargetName = (_b = getNestedString(pluginOptions, 'validateTarget', 'name')) !== null && _b !== void 0 ? _b : defaultValidateTargetName;
98
- const packageTargetName = (_c = getNestedString(pluginOptions, 'packageTarget', 'name')) !== null && _c !== void 0 ? _c : defaultPackageTargetName;
99
- (_d = (_f = nxJson.targetDefaults)[validateTargetName]) !== null && _d !== void 0 ? _d : (_f[validateTargetName] = {
100
- cache: true,
101
- inputs: helmInputs,
102
- });
103
- (_e = (_g = nxJson.targetDefaults)[packageTargetName]) !== null && _e !== void 0 ? _e : (_g[packageTargetName] = {
104
- cache: true,
105
- dependsOn: [validateTargetName],
106
- inputs: helmInputs,
107
- });
108
- }
109
- const helmInputs = [
110
- '{projectRoot}/**/*',
111
- { runtime: "helm version --template '{{.Version}}'" },
112
- ];
113
- /**
114
- * Reads a nested string option from an unknown plugin options object.
115
- * @param options Plugin options.
116
- * @param parent Parent property name.
117
- * @param property Nested property name.
118
- * @returns Non-empty nested string, or undefined.
119
- */
120
- function getNestedString(options, parent, property) {
121
- const parentValue = options[parent];
122
- if (!isRecord(parentValue)) {
123
- return undefined;
124
- }
125
- const value = parentValue[property];
126
- return typeof value === 'string' && value.trim() ? value.trim() : undefined;
127
- }
128
- /**
129
- * Narrows unknown values to object records used by init configuration parsing.
130
- * @param value Value to inspect.
131
- * @returns Whether value is a non-null object record.
132
- */
133
- function isRecord(value) {
134
- return typeof value === 'object' && value !== null;
36
+ : plugin?.plugin === pluginName);
135
37
  }
136
- //# sourceMappingURL=init.js.map
@@ -1,15 +1,5 @@
1
1
  /** Options accepted by the `@otwld/nx-helm` init generator. */
2
2
  export interface InitGeneratorSchema {
3
- /** OCI repository used by inferred release publishing. */
4
- registry?: string;
5
- /** Kubernetes version passed to inferred helm template targets. */
6
- kubeVersion?: string;
7
- /** Whether inferred helm lint should fail on warnings. */
8
- strict?: boolean;
9
- /** Inferred Helm validation target name. */
10
- validateTargetName?: string;
11
- /** Inferred Helm packaging target name. */
12
- packageTargetName?: string;
13
3
  /** Skip Prettier formatting after nx.json is updated. */
14
4
  skipFormat?: boolean;
15
5
  }