@aws/nx-plugin 0.18.2 → 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.
- package/README.md +2 -0
- package/generators.json +13 -1
- package/package.json +1 -1
- package/src/open-api/ts-hooks/__snapshots__/generator.spec.tsx.snap +14 -18
- package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +1 -1
- package/src/ts/lib/ts-project-utils.js +0 -1
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +330 -0
- package/src/ts/mcp-server/files/README.md.template +108 -0
- package/src/ts/mcp-server/files/src/global.d.ts.template +4 -0
- package/src/ts/mcp-server/files/src/index.ts.template +6 -0
- package/src/ts/mcp-server/files/src/resources/example-context.md +3 -0
- package/src/ts/mcp-server/files/src/server.ts.template +28 -0
- package/src/ts/mcp-server/generator.d.ts +10 -0
- package/src/ts/mcp-server/generator.js +61 -0
- package/src/ts/mcp-server/generator.js.map +1 -0
- package/src/ts/mcp-server/schema.d.ts +11 -0
- package/src/ts/mcp-server/schema.json +27 -0
- package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +263 -0
- package/src/ts/nx-generator/files/common/schema.d.ts.template +8 -0
- package/src/ts/nx-generator/files/common/schema.json.template +16 -0
- package/src/ts/nx-generator/files/local/files/hello.ts.template.template +4 -0
- package/src/ts/nx-generator/files/local/generator.spec.ts.template +17 -0
- package/src/ts/nx-generator/files/local/generator.ts.template +9 -0
- package/src/ts/nx-generator/files/nx-plugin-for-aws/docs/__nameKebabCase__.mdx.template +41 -0
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.spec.ts.template +27 -0
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +22 -0
- package/src/ts/nx-generator/generator.d.ts +9 -0
- package/src/ts/nx-generator/generator.js +137 -0
- package/src/ts/nx-generator/generator.js.map +1 -0
- package/src/ts/nx-generator/schema.d.ts +11 -0
- package/src/ts/nx-generator/schema.json +38 -0
- package/src/utils/__snapshots__/shared-constructs.spec.ts.snap +1 -1
- package/src/utils/files/common/constructs/src/core/app.ts.template +1 -1
- package/src/utils/versions.d.ts +4 -2
- package/src/utils/versions.js +3 -1
- package/src/utils/versions.js.map +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsMcpServerGenerator = exports.TS_MCP_SERVER_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 nx_1 = require("../../utils/nx");
|
|
11
|
+
const metrics_1 = require("../../utils/metrics");
|
|
12
|
+
const format_1 = require("../../utils/format");
|
|
13
|
+
const generator_1 = tslib_1.__importStar(require("../lib/generator"));
|
|
14
|
+
const versions_1 = require("../../utils/versions");
|
|
15
|
+
exports.TS_MCP_SERVER_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
16
|
+
const tsMcpServerGenerator = (tree, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
|
+
// Generate a TypeScript library
|
|
19
|
+
yield (0, generator_1.default)(tree, options);
|
|
20
|
+
const { fullyQualifiedName } = (0, generator_1.getTsLibDetails)(tree, options);
|
|
21
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, fullyQualifiedName);
|
|
22
|
+
// Add dependencies
|
|
23
|
+
const deps = (0, versions_1.withVersions)(['@modelcontextprotocol/sdk', 'zod']);
|
|
24
|
+
const devDeps = (0, versions_1.withVersions)(['tsx', 'esbuild']);
|
|
25
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, deps, devDeps);
|
|
26
|
+
// Generate example server
|
|
27
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), project.root, {
|
|
28
|
+
name: options.name,
|
|
29
|
+
dir: project.root,
|
|
30
|
+
}, { overwriteStrategy: devkit_1.OverwriteStrategy.Overwrite });
|
|
31
|
+
// Add build targets
|
|
32
|
+
(0, devkit_1.updateProjectConfiguration)(tree, fullyQualifiedName, Object.assign(Object.assign({}, project), { targets: Object.assign(Object.assign({}, project === null || project === void 0 ? void 0 : project.targets), {
|
|
33
|
+
// Bundle with esbuild
|
|
34
|
+
bundle: {
|
|
35
|
+
executor: 'nx:run-commands',
|
|
36
|
+
options: {
|
|
37
|
+
commands: [
|
|
38
|
+
`esbuild "${(0, devkit_1.joinPathFragments)(project.sourceRoot, 'index.ts')}" --bundle --platform=node --format=esm --loader:.md=text --outfile=${(0, devkit_1.joinPathFragments)('dist', project.root, 'bundle', 'index.js')}`,
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
// Dev task for bundling whenever changes are made
|
|
43
|
+
dev: {
|
|
44
|
+
executor: 'nx:run-commands',
|
|
45
|
+
options: {
|
|
46
|
+
commands: [
|
|
47
|
+
`nx watch --projects=${fullyQualifiedName} --includeDependentProjects -- nx run ${fullyQualifiedName}:bundle`,
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
// Ensure bundle runs as part of build
|
|
52
|
+
build: Object.assign(Object.assign({}, (_a = project === null || project === void 0 ? void 0 : project.targets) === null || _a === void 0 ? void 0 : _a.build), { dependsOn: [...((_d = (_c = (_b = project === null || project === void 0 ? void 0 : project.targets) === null || _b === void 0 ? void 0 : _b.build) === null || _c === void 0 ? void 0 : _c.dependsOn) !== null && _d !== void 0 ? _d : []), 'bundle'] }) }) }));
|
|
53
|
+
yield (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [exports.TS_MCP_SERVER_GENERATOR_INFO]);
|
|
54
|
+
yield (0, format_1.formatFilesInSubtree)(tree);
|
|
55
|
+
return () => {
|
|
56
|
+
(0, devkit_1.installPackagesTask)(tree);
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
exports.tsMcpServerGenerator = tsMcpServerGenerator;
|
|
60
|
+
exports.default = exports.tsMcpServerGenerator;
|
|
61
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAUoB;AAEpB,uCAAmE;AACnE,iDAAsE;AACtE,+CAA0D;AAC1D,sEAAmE;AACnE,mDAAoD;AAEvC,QAAA,4BAA4B,GACvC,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,oBAAoB,GAAG,CAClC,IAAU,EACV,OAAmC,EACP,EAAE;;IAC9B,gCAAgC;IAChC,MAAM,IAAA,mBAAc,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEpC,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAAA,2BAAe,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9D,MAAM,OAAO,GAAG,IAAA,iCAAwB,EAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IAEnE,mBAAmB;IACnB,MAAM,IAAI,GAAG,IAAA,uBAAY,EAAC,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,IAAA,uBAAY,EAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;IACjD,IAAA,qCAA4B,EAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAElD,0BAA0B;IAC1B,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EAAC,SAAS,EAAE,OAAO,CAAC,EACrC,OAAO,CAAC,IAAI,EACZ;QACE,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,GAAG,EAAE,OAAO,CAAC,IAAI;KAClB,EACD,EAAE,iBAAiB,EAAE,0BAAiB,CAAC,SAAS,EAAE,CACnD,CAAC;IAEF,oBAAoB;IACpB,IAAA,mCAA0B,EAAC,IAAI,EAAE,kBAAkB,kCAC9C,OAAO,KACV,OAAO,kCACF,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO;YACnB,sBAAsB;YACtB,MAAM,EAAE;gBACN,QAAQ,EAAE,iBAAiB;gBAC3B,OAAO,EAAE;oBACP,QAAQ,EAAE;wBACR,YAAY,IAAA,0BAAiB,EAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,uEAAuE,IAAA,0BAAiB,EAAC,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE;qBACpM;iBACF;aACF;YACD,kDAAkD;YAClD,GAAG,EAAE;gBACH,QAAQ,EAAE,iBAAiB;gBAC3B,OAAO,EAAE;oBACP,QAAQ,EAAE;wBACR,uBAAuB,kBAAkB,yCAAyC,kBAAkB,SAAS;qBAC9G;iBACF;aACF;YACD,sCAAsC;YACtC,KAAK,kCACA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,KAAK,KAC1B,SAAS,EAAE,CAAC,GAAG,CAAC,MAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,KAAK,0CAAE,SAAS,mCAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,UAGxE,CAAC;IAEH,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE,CAAC,oCAA4B,CAAC,CAAC,CAAC;IAE5E,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE;QACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC,CAAA,CAAC;AAhEW,QAAA,oBAAoB,wBAgE/B;AAEF,kBAAe,4BAAoB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { TsLibGeneratorSchema } from '../lib/schema';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TypeScript types for options defined in schema.json
|
|
9
|
+
* Update this to match schema.json if you make changes.
|
|
10
|
+
*/
|
|
11
|
+
export type TsMcpServerGeneratorSchema = TsLibGeneratorSchema;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#mcp-server",
|
|
4
|
+
"title": "ts#mcp-server",
|
|
5
|
+
"description": "Generate a TypeScript Model Context Protocol (MCP) server for providing context to Large Language Models",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "MCP server project name.",
|
|
11
|
+
"x-priority": "important"
|
|
12
|
+
},
|
|
13
|
+
"directory": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Parent directory where the MCP server is placed.",
|
|
16
|
+
"default": "packages",
|
|
17
|
+
"x-prompt": "Which directory do you want to create the MCP server in?",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
},
|
|
20
|
+
"subDirectory": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "The sub directory the MCP server is placed in. By default this is the MCP server project name.",
|
|
23
|
+
"x-prompt": "Which sub directory do you want to create the MCP server in? (By default this is the MCP server project name)"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"required": ["name"]
|
|
27
|
+
}
|
|
@@ -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,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,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;
|