@aws/nx-plugin 0.18.3 → 0.19.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.
Files changed (33) hide show
  1. package/README.md +2 -0
  2. package/generators.json +13 -1
  3. package/package.json +1 -1
  4. package/src/ts/lib/ts-project-utils.js +0 -1
  5. package/src/ts/lib/ts-project-utils.js.map +1 -1
  6. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +330 -0
  7. package/src/ts/mcp-server/files/README.md.template +108 -0
  8. package/src/ts/mcp-server/files/src/global.d.ts.template +4 -0
  9. package/src/ts/mcp-server/files/src/index.ts.template +6 -0
  10. package/src/ts/mcp-server/files/src/resources/example-context.md +3 -0
  11. package/src/ts/mcp-server/files/src/server.ts.template +28 -0
  12. package/src/ts/mcp-server/generator.d.ts +10 -0
  13. package/src/ts/mcp-server/generator.js +61 -0
  14. package/src/ts/mcp-server/generator.js.map +1 -0
  15. package/src/ts/mcp-server/schema.d.ts +11 -0
  16. package/src/ts/mcp-server/schema.json +27 -0
  17. package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +263 -0
  18. package/src/ts/nx-generator/files/common/schema.d.ts.template +8 -0
  19. package/src/ts/nx-generator/files/common/schema.json.template +16 -0
  20. package/src/ts/nx-generator/files/local/files/hello.ts.template.template +4 -0
  21. package/src/ts/nx-generator/files/local/generator.spec.ts.template +17 -0
  22. package/src/ts/nx-generator/files/local/generator.ts.template +9 -0
  23. package/src/ts/nx-generator/files/nx-plugin-for-aws/docs/__nameKebabCase__.mdx.template +41 -0
  24. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.spec.ts.template +27 -0
  25. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +22 -0
  26. package/src/ts/nx-generator/generator.d.ts +9 -0
  27. package/src/ts/nx-generator/generator.js +137 -0
  28. package/src/ts/nx-generator/generator.js.map +1 -0
  29. package/src/ts/nx-generator/schema.d.ts +11 -0
  30. package/src/ts/nx-generator/schema.json +38 -0
  31. package/src/utils/versions.d.ts +3 -1
  32. package/src/utils/versions.js +2 -0
  33. package/src/utils/versions.js.map +1 -1
@@ -0,0 +1,263 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`nx-generator generator > within @aws/nx-plugin > should add guide page to docs > guide-page.mdx 1`] = `
4
+ "---
5
+ title: foo#bar
6
+ description: Some description
7
+ ---
8
+
9
+ import { FileTree } from '@astrojs/starlight/components';
10
+ import RunGenerator from '@components/run-generator.astro';
11
+ import GeneratorParameters from '@components/generator-parameters.astro';
12
+ import schema from '../../../../../../packages/nx-plugin/src/foo-bar/schema.json';
13
+
14
+ TODO: Add an overview of your generator here.
15
+
16
+ ## Usage
17
+
18
+ ### Generate a foo#bar
19
+
20
+ You can generate a foo#bar in two ways:
21
+
22
+ <RunGenerator generator="foo#bar" />
23
+
24
+ ### Options
25
+
26
+ <GeneratorParameters schema={schema} />
27
+
28
+ ## Generator Output
29
+
30
+ The generator will create the following project files:
31
+
32
+ <FileTree>
33
+ - todo.txt Update this section with what your generator generates!
34
+ </FileTree>
35
+
36
+ ## TODO: More Docs!
37
+
38
+ Add more documentation detailing things like:
39
+
40
+ - How to work with the project/code you've generated
41
+ - What new project.json targets have been added and how to run them (using the NxCommands component)
42
+ - Best practices when working with your generated project/code
43
+
44
+ See the existing guides for concrete examples.
45
+ "
46
+ `;
47
+
48
+ exports[`nx-generator generator > within @aws/nx-plugin > should generate an example schema, generator and test > generator.spec.ts 1`] = `
49
+ "import { Tree } from '@nx/devkit';
50
+ import { fooBarGenerator, FOO_BAR_GENERATOR_INFO } from './generator';
51
+ import { createTreeUsingTsSolutionSetup } from '../utils/test';
52
+ import { expectHasMetricTags } from '../utils/metrics.spec';
53
+ import { sharedConstructsGenerator } from '../utils/shared-constructs';
54
+
55
+ describe('foo#bar generator', () => {
56
+ let tree: Tree;
57
+
58
+ beforeEach(() => {
59
+ tree = createTreeUsingTsSolutionSetup();
60
+ });
61
+
62
+ it('should run successfully', async () => {
63
+ await fooBarGenerator(tree, { exampleOption: 'example' });
64
+
65
+ // TODO: check the tree is updated as expected
66
+ });
67
+
68
+ it('should add generator metric to app.ts', async () => {
69
+ await sharedConstructsGenerator(tree);
70
+
71
+ await fooBarGenerator(tree, { exampleOption: 'example' });
72
+
73
+ expectHasMetricTags(tree, FOO_BAR_GENERATOR_INFO.metric);
74
+ });
75
+ });
76
+ "
77
+ `;
78
+
79
+ exports[`nx-generator generator > within @aws/nx-plugin > should generate an example schema, generator and test > generator.ts 1`] = `
80
+ "import { GeneratorCallback, Tree, installPackagesTask } from '@nx/devkit';
81
+ import { FooBarGeneratorSchema } from './schema';
82
+ import { NxGeneratorInfo, getGeneratorInfo } from '../utils/nx';
83
+ import { addGeneratorMetricsIfApplicable } from '../utils/metrics';
84
+ import { formatFilesInSubtree } from '../utils/format';
85
+
86
+ export const FOO_BAR_GENERATOR_INFO: NxGeneratorInfo =
87
+ getGeneratorInfo(__filename);
88
+
89
+ export const fooBarGenerator = async (
90
+ tree: Tree,
91
+ options: FooBarGeneratorSchema,
92
+ ): Promise<GeneratorCallback> => {
93
+ // TODO: implement your generator here
94
+
95
+ await addGeneratorMetricsIfApplicable(tree, [FOO_BAR_GENERATOR_INFO]);
96
+
97
+ await formatFilesInSubtree(tree);
98
+ return () => {
99
+ installPackagesTask(tree);
100
+ };
101
+ };
102
+
103
+ export default fooBarGenerator;
104
+ "
105
+ `;
106
+
107
+ exports[`nx-generator generator > within @aws/nx-plugin > should generate an example schema, generator and test > schema.d.ts 1`] = `
108
+ "/**
109
+ * TypeScript types for options defined in schema.json
110
+ * Update this to match schema.json if you make changes.
111
+ */
112
+ export interface FooBarGeneratorSchema {
113
+ // Replace with your options
114
+ exampleOption: string;
115
+ }
116
+ "
117
+ `;
118
+
119
+ exports[`nx-generator generator > within @aws/nx-plugin > should generate an example schema, generator and test > schema.json 1`] = `
120
+ "{
121
+ "$schema": "https://json-schema.org/schema",
122
+ "$id": "foo#bar",
123
+ "title": "foo#bar",
124
+ "description": "<Describe your generator here!>",
125
+ "type": "object",
126
+ "properties": {
127
+ "exampleOption": {
128
+ "type": "string",
129
+ "description": "An example option. Refer to https://nx.dev/extending-nx/recipes/generator-options for more info",
130
+ "x-priority": "important",
131
+ "x-prompt": "This is an example option!"
132
+ }
133
+ },
134
+ "required": ["exampleOption"]
135
+ }
136
+ "
137
+ `;
138
+
139
+ exports[`nx-generator generator > within @aws/nx-plugin > should update generators.json > generators.json 1`] = `
140
+ "{
141
+ "generators": {
142
+ "existing": {
143
+ "factory": "./some/generator",
144
+ "schema": "./some/schema.json",
145
+ "description": "existing generator",
146
+ "metric": "g40"
147
+ },
148
+ "another": {
149
+ "factory": "./some/other/generator",
150
+ "schema": "./some/other/schema.json",
151
+ "description": "other existing generator",
152
+ "metric": "g41"
153
+ },
154
+ "foo#bar": {
155
+ "factory": "./src/foo-bar/generator",
156
+ "schema": "./src/foo-bar/schema.json",
157
+ "description": "Some description",
158
+ "metric": "g42"
159
+ }
160
+ }
161
+ }
162
+ "
163
+ `;
164
+
165
+ exports[`nx-generator generator > within another workspace > should generate an example schema, generator and test > local-generator.spec.ts 1`] = `
166
+ "import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
167
+ import { Tree } from '@nx/devkit';
168
+ import { fooBarGenerator } from './generator';
169
+
170
+ describe('foo#bar generator', () => {
171
+ let tree: Tree;
172
+
173
+ beforeEach(() => {
174
+ tree = createTreeWithEmptyWorkspace();
175
+ });
176
+
177
+ it('should run successfully', async () => {
178
+ await fooBarGenerator(tree, { exampleOption: 'example' });
179
+
180
+ // TODO: check the tree is updated as expected
181
+ });
182
+ });
183
+ "
184
+ `;
185
+
186
+ exports[`nx-generator generator > within another workspace > should generate an example schema, generator and test > local-generator.ts 1`] = `
187
+ "import {
188
+ GeneratorCallback,
189
+ Tree,
190
+ generateFiles,
191
+ joinPathFragments,
192
+ } from '@nx/devkit';
193
+ import { FooBarGeneratorSchema } from './schema';
194
+
195
+ export const fooBarGenerator = async (
196
+ tree: Tree,
197
+ options: FooBarGeneratorSchema,
198
+ ): Promise<GeneratorCallback | void> => {
199
+ // TODO: implement your generator here, for example:
200
+ generateFiles(
201
+ tree,
202
+ joinPathFragments(__dirname, 'files'),
203
+ 'target/dir',
204
+ options,
205
+ );
206
+ };
207
+
208
+ export default fooBarGenerator;
209
+ "
210
+ `;
211
+
212
+ exports[`nx-generator generator > within another workspace > should generate an example schema, generator and test > local-schema.d.ts 1`] = `
213
+ "/**
214
+ * TypeScript types for options defined in schema.json
215
+ * Update this to match schema.json if you make changes.
216
+ */
217
+ export interface FooBarGeneratorSchema {
218
+ // Replace with your options
219
+ exampleOption: string;
220
+ }
221
+ "
222
+ `;
223
+
224
+ exports[`nx-generator generator > within another workspace > should generate an example schema, generator and test > local-schema.json 1`] = `
225
+ "{
226
+ "$schema": "https://json-schema.org/schema",
227
+ "$id": "foo#bar",
228
+ "title": "foo#bar",
229
+ "description": "<Describe your generator here!>",
230
+ "type": "object",
231
+ "properties": {
232
+ "exampleOption": {
233
+ "type": "string",
234
+ "description": "An example option. Refer to https://nx.dev/extending-nx/recipes/generator-options for more info",
235
+ "x-priority": "important",
236
+ "x-prompt": "This is an example option!"
237
+ }
238
+ },
239
+ "required": ["exampleOption"]
240
+ }
241
+ "
242
+ `;
243
+
244
+ exports[`nx-generator generator > within another workspace > should generate an example template file > hello.ts.template 1`] = `
245
+ "
246
+ export const hello = () => {
247
+ return '<%- exampleOption %>';
248
+ };
249
+ "
250
+ `;
251
+
252
+ exports[`nx-generator generator > within another workspace > should update generators.json > local-generators.json 1`] = `
253
+ "{
254
+ "generators": {
255
+ "foo#bar": {
256
+ "factory": "./src/foo-bar/generator",
257
+ "schema": "./src/foo-bar/schema.json",
258
+ "description": "Some description"
259
+ }
260
+ }
261
+ }
262
+ "
263
+ `;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * TypeScript types for options defined in schema.json
3
+ * Update this to match schema.json if you make changes.
4
+ */
5
+ export interface <%- namePascalCase %>GeneratorSchema {
6
+ // Replace with your options
7
+ exampleOption: string;
8
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "<%- name %>",
4
+ "title": "<%- name %>",
5
+ "description": "<Describe your generator here!>",
6
+ "type": "object",
7
+ "properties": {
8
+ "exampleOption": {
9
+ "type": "string",
10
+ "description": "An example option. Refer to https://nx.dev/extending-nx/recipes/generator-options for more info",
11
+ "x-priority": "important",
12
+ "x-prompt": "This is an example option!"
13
+ }
14
+ },
15
+ "required": ["exampleOption"]
16
+ }
@@ -0,0 +1,4 @@
1
+
2
+ export const hello = () => {
3
+ return '<%%- exampleOption %>';
4
+ };
@@ -0,0 +1,17 @@
1
+ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2
+ import { Tree } from '@nx/devkit';
3
+ import { <%- nameCamelCase %>Generator } from './generator';
4
+
5
+ describe('<%- name %> generator', () => {
6
+ let tree: Tree;
7
+
8
+ beforeEach(() => {
9
+ tree = createTreeWithEmptyWorkspace();
10
+ });
11
+
12
+ it('should run successfully', async () => {
13
+ await <%- nameCamelCase %>Generator(tree, { exampleOption: 'example' });
14
+
15
+ // TODO: check the tree is updated as expected
16
+ });
17
+ });
@@ -0,0 +1,9 @@
1
+ import { GeneratorCallback, Tree, generateFiles, joinPathFragments } from "@nx/devkit";
2
+ import { <%- namePascalCase %>GeneratorSchema } from './schema';
3
+
4
+ export const <%- nameCamelCase %>Generator = async (tree: Tree, options: <%- namePascalCase %>GeneratorSchema): Promise<GeneratorCallback | void> => {
5
+ // TODO: implement your generator here, for example:
6
+ generateFiles(tree, joinPathFragments(__dirname, 'files'), 'target/dir', options);
7
+ };
8
+
9
+ export default <%- nameCamelCase %>Generator;
@@ -0,0 +1,41 @@
1
+ ---
2
+ title: <%- name %>
3
+ description: <%- description ?? 'TODO - A short description of your generator' %>
4
+ ---
5
+
6
+ import { FileTree } from '@astrojs/starlight/components';
7
+ import RunGenerator from '@components/run-generator.astro';
8
+ import GeneratorParameters from '@components/generator-parameters.astro';
9
+ import schema from '../../../../../../packages/nx-plugin/src/<%- generatorSubDir %>/schema.json';
10
+
11
+ TODO: Add an overview of your generator here.
12
+
13
+ ## Usage
14
+
15
+ ### Generate a <%- name %>
16
+
17
+ You can generate a <%- name %> in two ways:
18
+
19
+ <RunGenerator generator="<%- name %>" />
20
+
21
+ ### Options
22
+
23
+ <GeneratorParameters schema={schema} />
24
+
25
+ ## Generator Output
26
+
27
+ The generator will create the following project files:
28
+
29
+ <FileTree>
30
+ - todo.txt Update this section with what your generator generates!
31
+ </FileTree>
32
+
33
+ ## TODO: More Docs!
34
+
35
+ Add more documentation detailing things like:
36
+
37
+ - How to work with the project/code you've generated
38
+ - What new project.json targets have been added and how to run them (using the NxCommands component)
39
+ - Best practices when working with your generated project/code
40
+
41
+ See the existing guides for concrete examples.
@@ -0,0 +1,27 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { <%- nameCamelCase %>Generator, <%- nameUpperSnakeCase %>_GENERATOR_INFO } from './generator';
3
+ import { createTreeUsingTsSolutionSetup } from '<%- pathToProjectSourceRoot %>utils/test';
4
+ import { expectHasMetricTags } from '<%- pathToProjectSourceRoot %>utils/metrics.spec';
5
+ import { sharedConstructsGenerator } from '<%- pathToProjectSourceRoot %>utils/shared-constructs';
6
+
7
+ describe('<%- name %> generator', () => {
8
+ let tree: Tree;
9
+
10
+ beforeEach(() => {
11
+ tree = createTreeUsingTsSolutionSetup();
12
+ });
13
+
14
+ it('should run successfully', async () => {
15
+ await <%- nameCamelCase %>Generator(tree, { exampleOption: 'example' });
16
+
17
+ // TODO: check the tree is updated as expected
18
+ });
19
+
20
+ it('should add generator metric to app.ts', async () => {
21
+ await sharedConstructsGenerator(tree);
22
+
23
+ await <%- nameCamelCase %>Generator(tree, { exampleOption: 'example' });
24
+
25
+ expectHasMetricTags(tree, <%- nameUpperSnakeCase %>_GENERATOR_INFO.metric);
26
+ });
27
+ });
@@ -0,0 +1,22 @@
1
+ import { GeneratorCallback, Tree, installPackagesTask } from "@nx/devkit";
2
+ import { <%- namePascalCase %>GeneratorSchema } from './schema';
3
+ import { NxGeneratorInfo, getGeneratorInfo } from '<%- pathToProjectSourceRoot %>utils/nx';
4
+ import { addGeneratorMetricsIfApplicable } from '<%- pathToProjectSourceRoot %>utils/metrics';
5
+ import { formatFilesInSubtree } from '<%- pathToProjectSourceRoot %>utils/format';
6
+
7
+ export const <%- nameUpperSnakeCase %>_GENERATOR_INFO: NxGeneratorInfo =
8
+ getGeneratorInfo(__filename);
9
+
10
+ export const <%- nameCamelCase %>Generator = async (tree: Tree, options: <%- namePascalCase %>GeneratorSchema): Promise<GeneratorCallback> => {
11
+
12
+ // TODO: implement your generator here
13
+
14
+ await addGeneratorMetricsIfApplicable(tree, [<%- nameUpperSnakeCase %>_GENERATOR_INFO]);
15
+
16
+ await formatFilesInSubtree(tree);
17
+ return () => {
18
+ installPackagesTask(tree);
19
+ };
20
+ };
21
+
22
+ export default <%- nameCamelCase %>Generator;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { GeneratorCallback, Tree } from '@nx/devkit';
6
+ import { NxGeneratorGeneratorSchema } from './schema';
7
+ export declare const NX_GENERATOR_GENERATOR_INFO: import("../../utils/nx").NxGeneratorInfo;
8
+ export declare const nxGeneratorGenerator: (tree: Tree, options: NxGeneratorGeneratorSchema) => Promise<GeneratorCallback | void>;
9
+ export default nxGeneratorGenerator;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nxGeneratorGenerator = exports.NX_GENERATOR_GENERATOR_INFO = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /**
6
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
+ * SPDX-License-Identifier: Apache-2.0
8
+ */
9
+ const devkit_1 = require("@nx/devkit");
10
+ const lodash_kebabcase_1 = tslib_1.__importDefault(require("lodash.kebabcase"));
11
+ const names_1 = require("../../utils/names");
12
+ const lodash_camelcase_1 = tslib_1.__importDefault(require("lodash.camelcase"));
13
+ const paths_1 = require("../../utils/paths");
14
+ const lodash_snakecase_1 = tslib_1.__importDefault(require("lodash.snakecase"));
15
+ const ast_1 = require("../../utils/ast");
16
+ const typescript_1 = require("typescript");
17
+ const package_json_1 = tslib_1.__importDefault(require("../../../package.json"));
18
+ const nx_1 = require("../../utils/nx");
19
+ const metrics_1 = require("../../utils/metrics");
20
+ const versions_1 = require("../../utils/versions");
21
+ const format_1 = require("../../utils/format");
22
+ exports.NX_GENERATOR_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
23
+ const nxGeneratorGenerator = (tree, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
24
+ var _a, _b;
25
+ const { name, directory, pluginProject, description } = options;
26
+ const plugin = (0, devkit_1.readProjectConfiguration)(tree, pluginProject);
27
+ const sourceRoot = (_a = plugin.sourceRoot) !== null && _a !== void 0 ? _a : (0, devkit_1.joinPathFragments)(plugin.root, 'src');
28
+ const sourceRootParts = sourceRoot.split('/');
29
+ const srcDir = sourceRootParts[sourceRootParts.length - 1];
30
+ const generatorSubDir = directory !== null && directory !== void 0 ? directory : (0, lodash_kebabcase_1.default)(name);
31
+ const generatorDir = (0, devkit_1.joinPathFragments)(sourceRoot, generatorSubDir);
32
+ const rootPackageJson = tree.exists('package.json')
33
+ ? (0, devkit_1.readJson)(tree, 'package.json')
34
+ : undefined;
35
+ const isNxPluginForAws = (rootPackageJson === null || rootPackageJson === void 0 ? void 0 : rootPackageJson.name) === '@aws/nx-plugin-source';
36
+ const tsConfigPath = (0, devkit_1.joinPathFragments)(plugin.root, 'tsconfig.json');
37
+ if (!tree.exists(tsConfigPath)) {
38
+ throw new Error(`Selected plugin project ${pluginProject} is not a TypeScript project`);
39
+ }
40
+ // Generators must use commonjs as a limitation of nx
41
+ // https://github.com/nrwl/nx/issues/15682
42
+ (0, devkit_1.updateJson)(tree, tsConfigPath, (tsConfig) => {
43
+ var _a, _b;
44
+ var _c;
45
+ (_a = tsConfig.compilerOptions) !== null && _a !== void 0 ? _a : (tsConfig.compilerOptions = {});
46
+ (_b = (_c = tsConfig.compilerOptions).module) !== null && _b !== void 0 ? _b : (_c.module = 'commonjs');
47
+ return tsConfig;
48
+ });
49
+ const enhancedOptions = {
50
+ name,
51
+ description,
52
+ namePascalCase: (0, names_1.pascalCase)(name),
53
+ nameCamelCase: (0, lodash_camelcase_1.default)(name),
54
+ nameKebabCase: (0, lodash_kebabcase_1.default)(name),
55
+ nameUpperSnakeCase: (0, lodash_snakecase_1.default)(name).toUpperCase(),
56
+ isNxPluginForAws,
57
+ pathToProjectSourceRoot: (0, paths_1.getRelativePathToRootByDirectory)(generatorSubDir),
58
+ generatorDir,
59
+ generatorSubDir,
60
+ };
61
+ // Add the common files
62
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'common'), generatorDir, Object.assign({}, enhancedOptions));
63
+ // Add the files specific to this repo vs a local generator in another project
64
+ if (isNxPluginForAws) {
65
+ // Generators should be in the @aws/nx-plugin project
66
+ if (pluginProject !== package_json_1.default.name) {
67
+ throw new Error(`Generators should be added to the ${package_json_1.default.name} project.`);
68
+ }
69
+ // Add the generator
70
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'nx-plugin-for-aws', 'generator'), generatorDir, Object.assign({}, enhancedOptions));
71
+ // Generate guide page in docs
72
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'nx-plugin-for-aws', 'docs'), (0, devkit_1.joinPathFragments)('docs', 'src', 'content', 'docs', 'en', 'guides'), Object.assign({}, enhancedOptions));
73
+ // Update the docs config to add the page entry
74
+ (0, ast_1.replace)(tree, (0, devkit_1.joinPathFragments)('docs', 'astro.config.mjs'), 'PropertyAssignment:has(Identifier[name="integrations"]) PropertyAssignment:has(Identifier[name="sidebar"]) ObjectLiteralExpression:has(PropertyAssignment:has(StringLiteral[value="Guides"])) PropertyAssignment:has(Identifier[name="items"]) > ArrayLiteralExpression', (node) => {
75
+ return typescript_1.factory.createArrayLiteralExpression([
76
+ ...node.elements,
77
+ typescript_1.factory.createObjectLiteralExpression([
78
+ typescript_1.factory.createPropertyAssignment('label', typescript_1.factory.createStringLiteral(name, true)),
79
+ typescript_1.factory.createPropertyAssignment('link', typescript_1.factory.createStringLiteral(`/guides/${enhancedOptions.nameKebabCase}`, true)),
80
+ ]),
81
+ ]);
82
+ });
83
+ }
84
+ else {
85
+ // Local generator in a project other than nx-plugin-for-aws
86
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'local'), generatorDir, Object.assign({}, enhancedOptions));
87
+ const indexPath = (0, devkit_1.joinPathFragments)(sourceRoot, 'index.ts');
88
+ if (tree.exists(indexPath)) {
89
+ (0, ast_1.addStarExport)(tree, indexPath, `./${generatorSubDir}/generator`);
90
+ }
91
+ }
92
+ const factoryBasePath = `./${srcDir}/${generatorSubDir}`;
93
+ // Update generators.json
94
+ const generatorsJsonPath = (0, devkit_1.joinPathFragments)(plugin.root, 'generators.json');
95
+ const generatorsJson = tree.exists(generatorsJsonPath)
96
+ ? (0, devkit_1.readJson)(tree, generatorsJsonPath)
97
+ : { generators: {} };
98
+ const existingGenerators = Object.values((_b = generatorsJson === null || generatorsJson === void 0 ? void 0 : generatorsJson.generators) !== null && _b !== void 0 ? _b : {});
99
+ (0, devkit_1.writeJson)(tree, generatorsJsonPath, Object.assign(Object.assign({}, generatorsJson), { generators: Object.assign(Object.assign({}, generatorsJson === null || generatorsJson === void 0 ? void 0 : generatorsJson.generators), { [name]: Object.assign({ factory: `${factoryBasePath}/generator`, schema: `${factoryBasePath}/schema.json`, description: description !== null && description !== void 0 ? description : 'TODO: Add short description of the generator' }, (isNxPluginForAws
100
+ ? {
101
+ metric: existingGenerators.length > 0
102
+ ? incrementMetric(existingGenerators[existingGenerators.length - 1].metric)
103
+ : 'g1',
104
+ }
105
+ : {})) }) }));
106
+ // Add the "generators" and "main" entries to package.json
107
+ const pluginPackageJsonPath = (0, devkit_1.joinPathFragments)(plugin.root, 'package.json');
108
+ if (!tree.exists(pluginPackageJsonPath)) {
109
+ // Write a simple package.json to ensure the generator can be found by the Nx VSCode extension
110
+ (0, devkit_1.writeJson)(tree, pluginPackageJsonPath, {
111
+ name: plugin.name,
112
+ });
113
+ }
114
+ (0, devkit_1.updateJson)(tree, pluginPackageJsonPath, (pkg) => {
115
+ var _a, _b;
116
+ (_a = pkg.main) !== null && _a !== void 0 ? _a : (pkg.main = './src/index.js');
117
+ (_b = pkg.generators) !== null && _b !== void 0 ? _b : (pkg.generators = './generators.json');
118
+ return pkg;
119
+ });
120
+ if (!isNxPluginForAws) {
121
+ // Add the required dependencies to the root package.json, and project's package.json
122
+ const deps = (0, versions_1.withVersions)(['@nx/devkit']);
123
+ (0, devkit_1.addDependenciesToPackageJson)(tree, {}, deps);
124
+ (0, devkit_1.addDependenciesToPackageJson)(tree, deps, {}, pluginPackageJsonPath);
125
+ }
126
+ yield (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [exports.NX_GENERATOR_GENERATOR_INFO]);
127
+ yield (0, format_1.formatFilesInSubtree)(tree);
128
+ return () => {
129
+ (0, devkit_1.installPackagesTask)(tree);
130
+ };
131
+ });
132
+ exports.nxGeneratorGenerator = nxGeneratorGenerator;
133
+ const incrementMetric = (metric) => {
134
+ return `g${Number(metric.slice(1)) + 1}`;
135
+ };
136
+ exports.default = exports.nxGeneratorGenerator;
137
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/nx-generator/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAWoB;AAEpB,g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 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ export interface NxGeneratorGeneratorSchema {
7
+ pluginProject: string;
8
+ name: string;
9
+ directory?: string;
10
+ description?: string;
11
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "TsGenerator",
4
+ "title": "Create an Nx Generator",
5
+ "description": "Create a TypeScript Nx Generator",
6
+ "type": "object",
7
+ "properties": {
8
+ "pluginProject": {
9
+ "type": "string",
10
+ "description": "TypeScript project to add the generator to. We recommend creating a ts#project in a top-level 'tools' directory.",
11
+ "x-priority": "important",
12
+ "x-prompt": "Choose the TypeScript project to add the generator to",
13
+ "x-dropdown": "projects",
14
+ "$default": {
15
+ "$source": "argv",
16
+ "index": 0
17
+ }
18
+ },
19
+ "name": {
20
+ "type": "string",
21
+ "description": "Generator name",
22
+ "x-priority": "important",
23
+ "x-prompt": "Choose a name for your generator, eg (ts#cool-project)"
24
+ },
25
+ "description": {
26
+ "type": "string",
27
+ "description": "A description of your generator",
28
+ "x-prompt": "Describe your new generator",
29
+ "x-priority": "important"
30
+ },
31
+ "directory": {
32
+ "type": "string",
33
+ "description": "The directory within the plugin project's source folder to add the generator to (default: <name>)",
34
+ "x-prompt": "Choose the directory you would like to generate the generator in relative to the project's source folder (default: <name>)"
35
+ }
36
+ },
37
+ "required": ["pluginProject", "name"]
38
+ }
@@ -12,6 +12,8 @@ export declare const VERSIONS: {
12
12
  readonly '@aws-lambda-powertools/metrics': "^2.17.0";
13
13
  readonly '@aws-lambda-powertools/tracer': "^2.17.0";
14
14
  readonly '@nxlv/python': "^20.12.0";
15
+ readonly '@nx/devkit': "~20.6.4";
16
+ readonly '@modelcontextprotocol/sdk': "^1.10.2";
15
17
  readonly '@tanstack/react-router': "^1.114.27";
16
18
  readonly '@tanstack/router-plugin': "^1.114.27";
17
19
  readonly '@cloudscape-design/board-components': "^3.0.94";
@@ -44,5 +46,5 @@ export declare const VERSIONS: {
44
46
  * Add versions to the given dependencies
45
47
  */
46
48
  export declare const withVersions: (deps: (keyof typeof VERSIONS)[]) => {
47
- [k: string]: "^0.0.60" | "^2.185.0-alpha.0" | "^3.775.0" | "^2.17.0" | "^20.12.0" | "^1.114.27" | "^3.0.94" | "^3.0.928" | "^1.0.38" | "^5.74.3" | "11.0.0" | "^22.13.13" | "^8.10.148" | "^4.2.0" | "^1.0.20" | "^2.1006.0" | "^2.185.0" | "^3.10.3" | "^10.4.2" | "^0.25.1" | "^5.2.5" | "^2.4.0" | "^3.2.0" | "^3.5.3" | "^0.5.21" | "^4.19.3" | "^5.1.4" | "^3.24.2";
49
+ [k: string]: "^0.0.60" | "^2.185.0-alpha.0" | "^3.775.0" | "^2.17.0" | "^20.12.0" | "~20.6.4" | "^1.10.2" | "^1.114.27" | "^3.0.94" | "^3.0.928" | "^1.0.38" | "^5.74.3" | "11.0.0" | "^22.13.13" | "^8.10.148" | "^4.2.0" | "^1.0.20" | "^2.1006.0" | "^2.185.0" | "^3.10.3" | "^10.4.2" | "^0.25.1" | "^5.2.5" | "^2.4.0" | "^3.2.0" | "^3.5.3" | "^0.5.21" | "^4.19.3" | "^5.1.4" | "^3.24.2";
48
50
  };
@@ -15,6 +15,8 @@ exports.VERSIONS = {
15
15
  '@aws-lambda-powertools/metrics': '^2.17.0',
16
16
  '@aws-lambda-powertools/tracer': '^2.17.0',
17
17
  '@nxlv/python': '^20.12.0',
18
+ '@nx/devkit': '~20.6.4',
19
+ '@modelcontextprotocol/sdk': '^1.10.2',
18
20
  '@tanstack/react-router': '^1.114.27',
19
21
  '@tanstack/router-plugin': '^1.114.27',
20
22
  '@cloudscape-design/board-components': '^3.0.94',