@aws/nx-plugin 1.0.0-rc.52 → 1.0.0-rc.53

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 CHANGED
@@ -171,6 +171,7 @@ pnpm nx g @aws/nx-plugin:ts#infra
171
171
  | `ts#mcp-server` | MCP server (TypeScript) |
172
172
  | `ts#agent` | [Strands Agent](https://strandsagents.com/) (TypeScript) |
173
173
  | `ts#nx-generator` | Nx generator scaffold |
174
+ | `smithy#project` | Smithy model project — a service model, or a shape library shared between Smithy projects |
174
175
  | `py#project` | Python project (uv) |
175
176
  | `py#api` | Python API (FastAPI) with API Gateway + Lambda + [Powertools](https://github.com/aws-powertools/powertools-lambda-python) |
176
177
  | `py#lambda-function` | Python Lambda with type-safe event sources |
package/generators.json CHANGED
@@ -165,9 +165,9 @@
165
165
  "smithy#project": {
166
166
  "factory": "./src/smithy/project/generator",
167
167
  "schema": "./src/smithy/project/schema.json",
168
- "description": "Generate a Smithy model project",
168
+ "description": "Generate a Smithy model project, either defining a service or a library of reusable shapes",
169
169
  "metric": "g27",
170
- "hidden": true
170
+ "guidePages": ["smithy-project"]
171
171
  },
172
172
  "smithy#react-connection": {
173
173
  "factory": "./src/smithy/react-connection/generator",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws/nx-plugin",
3
- "version": "1.0.0-rc.52",
3
+ "version": "1.0.0-rc.53",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/awslabs/nx-plugin-for-aws.git",
@@ -108,6 +108,8 @@ The following list of generators are what is currently available in the \`@aws/n
108
108
 
109
109
  - **py#agent**: Add an AI Agent to a Python project
110
110
 
111
+ - **smithy#project**: Generate a Smithy model project, either defining a service or a library of reusable shapes
112
+
111
113
  - **terraform#project**: Generates a Terraform project
112
114
 
113
115
  - **ts#docs**: Generates a documentation site
@@ -1,5 +1,102 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
+ exports[`smithyProjectGenerator > shape libraries > should generate a shape library without a service > shapes-build.Dockerfile 1`] = `
4
+ "FROM public.ecr.aws/docker/library/node:24 AS builder
5
+ ENV CI=true
6
+
7
+ # Output directory
8
+ RUN mkdir /out
9
+
10
+ # Install Smithy CLI
11
+ # https://smithy.io/2.0/guides/smithy-cli/cli_installation.html
12
+ WORKDIR /smithy
13
+ ARG TARGETPLATFORM
14
+ RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then ARCH="aarch64"; else ARCH="x86_64"; fi && \\
15
+ mkdir -p smithy-install/smithy && \\
16
+ curl -L https://github.com/smithy-lang/smithy/releases/download/1.61.0/smithy-cli-linux-$ARCH.zip -o smithy-install/smithy-cli-linux-$ARCH.zip && \\
17
+ unzip -qo smithy-install/smithy-cli-linux-$ARCH.zip -d smithy-install && \\
18
+ mv smithy-install/smithy-cli-linux-$ARCH/* smithy-install/smithy
19
+ RUN smithy-install/smithy/install
20
+
21
+ # Copy project files
22
+ WORKDIR /project
23
+ COPY smithy-build.json .
24
+ COPY src src
25
+
26
+ # Validate the model and assemble it into a single JSON model file
27
+ RUN --mount=type=cache,target=/root/.m2/repository,id=maven-cache \\
28
+ smithy build
29
+
30
+ # Copy the assembled model to the output location
31
+ RUN mkdir -p /out/model
32
+ RUN cp /project/build/smithy/source/model/model.json /out/model/model.json
33
+
34
+ # Export the /out directory
35
+ FROM scratch AS export
36
+ COPY --from=builder /out /
37
+ "
38
+ `;
39
+
40
+ exports[`smithyProjectGenerator > shape libraries > should generate a shape library without a service > shapes-main.smithy 1`] = `
41
+ "$version: "2.0"
42
+
43
+ namespace proj
44
+
45
+ /// TODO: define the shapes you would like to share between your Smithy projects
46
+ structure ExampleShape {
47
+ @required
48
+ id: String
49
+
50
+ description: String
51
+ }
52
+ "
53
+ `;
54
+
55
+ exports[`smithyProjectGenerator > shape libraries > should generate a shape library without a service > shapes-project.json 1`] = `
56
+ "{
57
+ "name": "@proj/test-shapes",
58
+ "$schema": "../node_modules/nx/schemas/project-schema.json",
59
+ "sourceRoot": "test-shapes/src",
60
+ "projectType": "library",
61
+ "metadata": {
62
+ "generator": "smithy#project",
63
+ "smithyType": "shapes",
64
+ "namespace": "proj"
65
+ },
66
+ "targets": {
67
+ "build": {
68
+ "dependsOn": ["compile"]
69
+ },
70
+ "compile": {
71
+ "cache": true,
72
+ "outputs": ["{workspaceRoot}/dist/{projectRoot}/build"],
73
+ "executor": "nx:run-commands",
74
+ "options": {
75
+ "commands": [
76
+ "rimraf dist/{projectRoot}/build",
77
+ "make-dir dist/{projectRoot}/build",
78
+ "docker build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
79
+ ],
80
+ "parallel": false,
81
+ "cwd": "{workspaceRoot}"
82
+ }
83
+ }
84
+ }
85
+ }
86
+ "
87
+ `;
88
+
89
+ exports[`smithyProjectGenerator > shape libraries > should generate a shape library without a service > shapes-smithy-build.json 1`] = `
90
+ "{
91
+ "version": "1.0",
92
+ "sources": ["src/"],
93
+ "maven": {
94
+ "dependencies": ["software.amazon.smithy:smithy-model:1.61.0"]
95
+ }
96
+ }
97
+ "
98
+ `;
99
+
3
100
  exports[`smithyProjectGenerator > should generate smithy project with all custom options > all-custom-main.smithy 1`] = `
4
101
  "$version: "2.0"
5
102
 
@@ -31,6 +128,8 @@ exports[`smithyProjectGenerator > should generate smithy project with all custom
31
128
  "projectType": "library",
32
129
  "metadata": {
33
130
  "generator": "smithy#project",
131
+ "smithyType": "service",
132
+ "namespace": "com.mycompany.api",
34
133
  "apiName": "test-api"
35
134
  },
36
135
  "targets": {
@@ -45,7 +144,7 @@ exports[`smithyProjectGenerator > should generate smithy project with all custom
45
144
  "commands": [
46
145
  "rimraf dist/{projectRoot}/build",
47
146
  "make-dir dist/{projectRoot}/build",
48
- "docker build -f {projectRoot}/build.Dockerfile --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
147
+ "docker build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
49
148
  ],
50
149
  "parallel": false,
51
150
  "cwd": "{workspaceRoot}"
@@ -64,6 +163,8 @@ exports[`smithyProjectGenerator > should generate smithy project with custom dir
64
163
  "projectType": "library",
65
164
  "metadata": {
66
165
  "generator": "smithy#project",
166
+ "smithyType": "service",
167
+ "namespace": "proj",
67
168
  "apiName": "test-api"
68
169
  },
69
170
  "targets": {
@@ -78,7 +179,7 @@ exports[`smithyProjectGenerator > should generate smithy project with custom dir
78
179
  "commands": [
79
180
  "rimraf dist/{projectRoot}/build",
80
181
  "make-dir dist/{projectRoot}/build",
81
- "docker build -f {projectRoot}/build.Dockerfile --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
182
+ "docker build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
82
183
  ],
83
184
  "parallel": false,
84
185
  "cwd": "{workspaceRoot}"
@@ -288,6 +389,8 @@ exports[`smithyProjectGenerator > should generate smithy project with default op
288
389
  "projectType": "library",
289
390
  "metadata": {
290
391
  "generator": "smithy#project",
392
+ "smithyType": "service",
393
+ "namespace": "proj",
291
394
  "apiName": "test-api"
292
395
  },
293
396
  "targets": {
@@ -302,7 +405,7 @@ exports[`smithyProjectGenerator > should generate smithy project with default op
302
405
  "commands": [
303
406
  "rimraf dist/{projectRoot}/build",
304
407
  "make-dir dist/{projectRoot}/build",
305
- "docker build -f {projectRoot}/build.Dockerfile --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
408
+ "docker build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
306
409
  ],
307
410
  "parallel": false,
308
411
  "cwd": "{workspaceRoot}"
@@ -350,6 +453,8 @@ exports[`smithyProjectGenerator > should generate smithy project with subdirecto
350
453
  "projectType": "library",
351
454
  "metadata": {
352
455
  "generator": "smithy#project",
456
+ "smithyType": "service",
457
+ "namespace": "proj",
353
458
  "apiName": "test-api"
354
459
  },
355
460
  "targets": {
@@ -364,7 +469,7 @@ exports[`smithyProjectGenerator > should generate smithy project with subdirecto
364
469
  "commands": [
365
470
  "rimraf dist/{projectRoot}/build",
366
471
  "make-dir dist/{projectRoot}/build",
367
- "docker build -f {projectRoot}/build.Dockerfile --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
472
+ "docker build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
368
473
  ],
369
474
  "parallel": false,
370
475
  "cwd": "{workspaceRoot}"
@@ -0,0 +1,33 @@
1
+ FROM public.ecr.aws/docker/library/node:24 AS builder
2
+ ENV CI=true
3
+
4
+ # Output directory
5
+ RUN mkdir /out
6
+
7
+ # Install Smithy CLI
8
+ # https://smithy.io/2.0/guides/smithy-cli/cli_installation.html
9
+ WORKDIR /smithy
10
+ ARG TARGETPLATFORM
11
+ RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then ARCH="aarch64"; else ARCH="x86_64"; fi && \
12
+ mkdir -p smithy-install/smithy && \
13
+ curl -L https://github.com/smithy-lang/smithy/releases/download/1.61.0/smithy-cli-linux-$ARCH.zip -o smithy-install/smithy-cli-linux-$ARCH.zip && \
14
+ unzip -qo smithy-install/smithy-cli-linux-$ARCH.zip -d smithy-install && \
15
+ mv smithy-install/smithy-cli-linux-$ARCH/* smithy-install/smithy
16
+ RUN smithy-install/smithy/install
17
+
18
+ # Copy project files
19
+ WORKDIR /project
20
+ COPY smithy-build.json .
21
+ COPY src src
22
+
23
+ # Validate the model and assemble it into a single JSON model file
24
+ RUN --mount=type=cache,target=/root/.m2/repository,id=maven-cache \
25
+ smithy build
26
+
27
+ # Copy the assembled model to the output location
28
+ RUN mkdir -p /out/model
29
+ RUN cp /project/build/smithy/source/model/model.json /out/model/model.json
30
+
31
+ # Export the /out directory
32
+ FROM scratch AS export
33
+ COPY --from=builder /out /
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": "1.0",
3
+ "sources": ["src/"],
4
+ "maven": {
5
+ "dependencies": ["software.amazon.smithy:smithy-model:1.61.0"]
6
+ }
7
+ }
@@ -0,0 +1,11 @@
1
+ $version: "2.0"
2
+
3
+ namespace <%- namespace %>
4
+
5
+ /// TODO: define the shapes you would like to share between your Smithy projects
6
+ structure ExampleShape {
7
+ @required
8
+ id: String
9
+
10
+ description: String
11
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
- */ import { addProjectConfiguration, generateFiles, joinPathFragments } from "@nx/devkit";
4
+ */ import { addProjectConfiguration, generateFiles, joinPathFragments, OverwriteStrategy } from "@nx/devkit";
5
5
  import { getTsLibDetails } from "../../ts/lib/generator.js";
6
6
  import { resolveContainers } from "../../utils/containers.js";
7
7
  import { formatFilesInSubtree } from "../../utils/format.js";
@@ -15,6 +15,7 @@ export const SMITHY_PROJECT_GENERATOR_INFO = getGeneratorInfo(import.meta.filena
15
15
  export const smithyProjectGenerator = async (tree, options)=>{
16
16
  const cmd = new FsCommands(tree);
17
17
  const containers = await resolveContainers(tree, 'inherit');
18
+ const type = options.type ?? 'service';
18
19
  // Create project.json
19
20
  const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);
20
21
  if (!projectExists(tree, fullyQualifiedName)) {
@@ -39,7 +40,10 @@ export const smithyProjectGenerator = async (tree, options)=>{
39
40
  commands: [
40
41
  cmd.rm('dist/{projectRoot}/build'),
41
42
  cmd.mkdir('dist/{projectRoot}/build'),
42
- `${containers} build -f {projectRoot}/build.Dockerfile --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}`
43
+ // The workspace build context lets a project's Dockerfile copy in
44
+ // the built models of shape libraries it depends on. Commands run
45
+ // from the workspace root, so it is the current directory.
46
+ `${containers} build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}`
43
47
  ],
44
48
  parallel: false,
45
49
  cwd: '{workspaceRoot}'
@@ -53,14 +57,21 @@ export const smithyProjectGenerator = async (tree, options)=>{
53
57
  const serviceNameKebabCase = toKebabCase(serviceName);
54
58
  const scope = getNpmScope(tree);
55
59
  const namespace = options.namespace ?? toKebabCase(scope).replace(/-/g, '.');
56
- generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), dir, {
60
+ generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', type), dir, {
57
61
  namespace,
58
62
  serviceNameClassName,
59
63
  serviceNameKebabCase,
60
64
  scope
65
+ }, {
66
+ // Smithy models are user-owned — a re-run must not discard edits
67
+ overwriteStrategy: OverwriteStrategy.KeepExisting
61
68
  });
62
69
  addGeneratorMetadata(tree, fullyQualifiedName, SMITHY_PROJECT_GENERATOR_INFO, {
63
- apiName: options.name
70
+ smithyType: type,
71
+ namespace,
72
+ ...type === 'service' ? {
73
+ apiName: options.name
74
+ } : {}
64
75
  });
65
76
  await addGeneratorMetricsIfApplicable(tree, [
66
77
  SMITHY_PROJECT_GENERATOR_INFO
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/smithy/project/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n type Tree,\n} from '@nx/devkit';\nimport { getTsLibDetails } from '../../ts/lib/generator';\nimport { resolveContainers } from '../../utils/containers';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { toClassName, toKebabCase } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport type { SmithyProjectGeneratorSchema } from './schema';\n\nexport const SMITHY_PROJECT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const smithyProjectGenerator = async (\n tree: Tree,\n options: SmithyProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const cmd = new FsCommands(tree);\n const containers = await resolveContainers(tree, 'inherit');\n\n // Create project.json\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);\n\n if (!projectExists(tree, fullyQualifiedName)) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'library',\n targets: {\n build: {\n dependsOn: ['compile'],\n },\n compile: {\n cache: true,\n outputs: ['{workspaceRoot}/dist/{projectRoot}/build'],\n executor: 'nx:run-commands',\n options: {\n commands: [\n cmd.rm('dist/{projectRoot}/build'),\n cmd.mkdir('dist/{projectRoot}/build'),\n `${containers} build -f {projectRoot}/build.Dockerfile --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}`,\n ],\n parallel: false,\n cwd: '{workspaceRoot}',\n },\n },\n },\n });\n }\n\n const serviceName = options.serviceName ?? options.name;\n const serviceNameClassName = toClassName(serviceName);\n const serviceNameKebabCase = toKebabCase(serviceName);\n const scope = getNpmScope(tree);\n const namespace = options.namespace ?? toKebabCase(scope).replace(/-/g, '.');\n\n generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), dir, {\n namespace,\n serviceNameClassName,\n serviceNameKebabCase,\n scope,\n });\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n SMITHY_PROJECT_GENERATOR_INFO,\n {\n apiName: options.name,\n },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [SMITHY_PROJECT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default smithyProjectGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","getTsLibDetails","resolveContainers","formatFilesInSubtree","FsCommands","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toKebabCase","getNpmScope","addGeneratorMetadata","getGeneratorInfo","projectExists","SMITHY_PROJECT_GENERATOR_INFO","filename","smithyProjectGenerator","tree","options","cmd","containers","fullyQualifiedName","dir","name","root","sourceRoot","projectType","targets","build","dependsOn","compile","cache","outputs","executor","commands","rm","mkdir","parallel","cwd","serviceName","serviceNameClassName","serviceNameKebabCase","scope","namespace","replace","dirname","apiName","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,QAEZ,aAAa;AACpB,SAASC,eAAe,QAAQ,4BAAyB;AACzD,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,oBAAiB;AAC5C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,WAAW,EAAEC,WAAW,QAAQ,uBAAoB;AAC7D,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAiB;AAGxB,OAAO,MAAMC,gCAAiDF,iBAC5D,YAAYG,QAAQ,EACpB;AAEF,OAAO,MAAMC,yBAAyB,OACpCC,MACAC;IAEA,MAAMC,MAAM,IAAId,WAAWY;IAC3B,MAAMG,aAAa,MAAMjB,kBAAkBc,MAAM;IAEjD,sBAAsB;IACtB,MAAM,EAAEI,kBAAkB,EAAEC,GAAG,EAAE,GAAGpB,gBAAgBe,MAAMC;IAE1D,IAAI,CAACL,cAAcI,MAAMI,qBAAqB;QAC5CtB,wBAAwBkB,MAAMI,oBAAoB;YAChDE,MAAMF;YACNG,MAAMF;YACNG,YAAYxB,kBAAkBqB,KAAK;YACnCI,aAAa;YACbC,SAAS;gBACPC,OAAO;oBACLC,WAAW;wBAAC;qBAAU;gBACxB;gBACAC,SAAS;oBACPC,OAAO;oBACPC,SAAS;wBAAC;qBAA2C;oBACrDC,UAAU;oBACVf,SAAS;wBACPgB,UAAU;4BACRf,IAAIgB,EAAE,CAAC;4BACPhB,IAAIiB,KAAK,CAAC;4BACV,GAAGhB,WAAW,wHAAwH,CAAC;yBACxI;wBACDiB,UAAU;wBACVC,KAAK;oBACP;gBACF;YACF;QACF;IACF;IAEA,MAAMC,cAAcrB,QAAQqB,WAAW,IAAIrB,QAAQK,IAAI;IACvD,MAAMiB,uBAAuBhC,YAAY+B;IACzC,MAAME,uBAAuBhC,YAAY8B;IACzC,MAAMG,QAAQhC,YAAYO;IAC1B,MAAM0B,YAAYzB,QAAQyB,SAAS,IAAIlC,YAAYiC,OAAOE,OAAO,CAAC,MAAM;IAExE5C,cAAciB,MAAMhB,kBAAkB,YAAY4C,OAAO,EAAE,UAAUvB,KAAK;QACxEqB;QACAH;QACAC;QACAC;IACF;IAEA/B,qBACEM,MACAI,oBACAP,+BACA;QACEgC,SAAS5B,QAAQK,IAAI;IACvB;IAGF,MAAMhB,gCAAgCU,MAAM;QAACH;KAA8B;IAE3E,MAAMV,qBAAqBa;IAC3B,OAAO,IACLX,oBAAoBW,MAAMC,QAAQ6B,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAehC,uBAAuB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/smithy/project/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n} from '@nx/devkit';\nimport { getTsLibDetails } from '../../ts/lib/generator';\nimport { resolveContainers } from '../../utils/containers';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { toClassName, toKebabCase } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport type { SmithyProjectGeneratorSchema } from './schema';\n\nexport const SMITHY_PROJECT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const smithyProjectGenerator = async (\n tree: Tree,\n options: SmithyProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const cmd = new FsCommands(tree);\n const containers = await resolveContainers(tree, 'inherit');\n const type = options.type ?? 'service';\n\n // Create project.json\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);\n\n if (!projectExists(tree, fullyQualifiedName)) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'library',\n targets: {\n build: {\n dependsOn: ['compile'],\n },\n compile: {\n cache: true,\n outputs: ['{workspaceRoot}/dist/{projectRoot}/build'],\n executor: 'nx:run-commands',\n options: {\n commands: [\n cmd.rm('dist/{projectRoot}/build'),\n cmd.mkdir('dist/{projectRoot}/build'),\n // The workspace build context lets a project's Dockerfile copy in\n // the built models of shape libraries it depends on. Commands run\n // from the workspace root, so it is the current directory.\n `${containers} build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}`,\n ],\n parallel: false,\n cwd: '{workspaceRoot}',\n },\n },\n },\n });\n }\n\n const serviceName = options.serviceName ?? options.name;\n const serviceNameClassName = toClassName(serviceName);\n const serviceNameKebabCase = toKebabCase(serviceName);\n const scope = getNpmScope(tree);\n const namespace = options.namespace ?? toKebabCase(scope).replace(/-/g, '.');\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', type),\n dir,\n {\n namespace,\n serviceNameClassName,\n serviceNameKebabCase,\n scope,\n },\n {\n // Smithy models are user-owned — a re-run must not discard edits\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n SMITHY_PROJECT_GENERATOR_INFO,\n {\n smithyType: type,\n namespace,\n ...(type === 'service' ? { apiName: options.name } : {}),\n },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [SMITHY_PROJECT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default smithyProjectGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","getTsLibDetails","resolveContainers","formatFilesInSubtree","FsCommands","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toKebabCase","getNpmScope","addGeneratorMetadata","getGeneratorInfo","projectExists","SMITHY_PROJECT_GENERATOR_INFO","filename","smithyProjectGenerator","tree","options","cmd","containers","type","fullyQualifiedName","dir","name","root","sourceRoot","projectType","targets","build","dependsOn","compile","cache","outputs","executor","commands","rm","mkdir","parallel","cwd","serviceName","serviceNameClassName","serviceNameKebabCase","scope","namespace","replace","dirname","overwriteStrategy","KeepExisting","smithyType","apiName","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAEZ,aAAa;AACpB,SAASC,eAAe,QAAQ,4BAAyB;AACzD,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,oBAAiB;AAC5C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,WAAW,EAAEC,WAAW,QAAQ,uBAAoB;AAC7D,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAiB;AAGxB,OAAO,MAAMC,gCAAiDF,iBAC5D,YAAYG,QAAQ,EACpB;AAEF,OAAO,MAAMC,yBAAyB,OACpCC,MACAC;IAEA,MAAMC,MAAM,IAAId,WAAWY;IAC3B,MAAMG,aAAa,MAAMjB,kBAAkBc,MAAM;IACjD,MAAMI,OAAOH,QAAQG,IAAI,IAAI;IAE7B,sBAAsB;IACtB,MAAM,EAAEC,kBAAkB,EAAEC,GAAG,EAAE,GAAGrB,gBAAgBe,MAAMC;IAE1D,IAAI,CAACL,cAAcI,MAAMK,qBAAqB;QAC5CxB,wBAAwBmB,MAAMK,oBAAoB;YAChDE,MAAMF;YACNG,MAAMF;YACNG,YAAY1B,kBAAkBuB,KAAK;YACnCI,aAAa;YACbC,SAAS;gBACPC,OAAO;oBACLC,WAAW;wBAAC;qBAAU;gBACxB;gBACAC,SAAS;oBACPC,OAAO;oBACPC,SAAS;wBAAC;qBAA2C;oBACrDC,UAAU;oBACVhB,SAAS;wBACPiB,UAAU;4BACRhB,IAAIiB,EAAE,CAAC;4BACPjB,IAAIkB,KAAK,CAAC;4BACV,kEAAkE;4BAClE,kEAAkE;4BAClE,2DAA2D;4BAC3D,GAAGjB,WAAW,oJAAoJ,CAAC;yBACpK;wBACDkB,UAAU;wBACVC,KAAK;oBACP;gBACF;YACF;QACF;IACF;IAEA,MAAMC,cAActB,QAAQsB,WAAW,IAAItB,QAAQM,IAAI;IACvD,MAAMiB,uBAAuBjC,YAAYgC;IACzC,MAAME,uBAAuBjC,YAAY+B;IACzC,MAAMG,QAAQjC,YAAYO;IAC1B,MAAM2B,YAAY1B,QAAQ0B,SAAS,IAAInC,YAAYkC,OAAOE,OAAO,CAAC,MAAM;IAExE9C,cACEkB,MACAjB,kBAAkB,YAAY8C,OAAO,EAAE,SAASzB,OAChDE,KACA;QACEqB;QACAH;QACAC;QACAC;IACF,GACA;QACE,iEAAiE;QACjEI,mBAAmB9C,kBAAkB+C,YAAY;IACnD;IAGFrC,qBACEM,MACAK,oBACAR,+BACA;QACEmC,YAAY5B;QACZuB;QACA,GAAIvB,SAAS,YAAY;YAAE6B,SAAShC,QAAQM,IAAI;QAAC,IAAI,CAAC,CAAC;IACzD;IAGF,MAAMjB,gCAAgCU,MAAM;QAACH;KAA8B;IAE3E,MAAMV,qBAAqBa;IAC3B,OAAO,IACLX,oBAAoBW,MAAMC,QAAQiC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAepC,uBAAuB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/smithy/project/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nexport interface SmithyProjectGeneratorSchema {\n name: string;\n serviceName?: string;\n namespace?: string;\n directory?: string;\n subDirectory?: string;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GACD,WAOC"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/smithy/project/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nexport interface SmithyProjectGeneratorSchema {\n name: string;\n type?: 'service' | 'shapes';\n serviceName?: string;\n namespace?: string;\n directory?: string;\n subDirectory?: string;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GACD,WAQC"}
@@ -4,6 +4,7 @@
4
4
  */
5
5
  export interface SmithyProjectGeneratorSchema {
6
6
  name: string;
7
+ type?: 'service' | 'shapes';
7
8
  serviceName?: string;
8
9
  namespace?: string;
9
10
  directory?: string;
@@ -15,9 +15,31 @@
15
15
  "x-priority": "important",
16
16
  "x-prompt": "What would you like to call your Smithy project?"
17
17
  },
18
+ "type": {
19
+ "type": "string",
20
+ "description": "The type of Smithy project to create. Choose between service (a model with a service shape, ready for an implementation) and shapes (a shape library of reusable shapes, shared between multiple Smithy projects).",
21
+ "default": "service",
22
+ "enum": ["service", "shapes"],
23
+ "x-priority": "important",
24
+ "x-prompt": {
25
+ "message": "What type of Smithy project would you like to create?",
26
+ "type": "list",
27
+ "items": [
28
+ {
29
+ "value": "service",
30
+ "label": "service (a model which defines a service and its operations)"
31
+ },
32
+ {
33
+ "value": "shapes",
34
+ "label": "shapes (a library of reusable shapes, shared between Smithy projects)"
35
+ }
36
+ ],
37
+ "default": "service"
38
+ }
39
+ },
18
40
  "serviceName": {
19
41
  "type": "string",
20
- "description": "The name of your Smithy service. Uses the supplied name by default.",
42
+ "description": "The name of your Smithy service. Uses the supplied name by default. Not applicable to shape libraries.",
21
43
  "x-prompt": "What name would you like your Smithy Service to have? i.e: MyService"
22
44
  },
23
45
  "namespace": {
@@ -1743,6 +1743,8 @@ exports[`tsSmithyApiGenerator > should generate smithy ts api with default optio
1743
1743
  "projectType": "library",
1744
1744
  "metadata": {
1745
1745
  "generator": "smithy#project",
1746
+ "smithyType": "service",
1747
+ "namespace": "proj",
1746
1748
  "apiName": "test-api-model",
1747
1749
  "backendProject": "@proj/test-api"
1748
1750
  },
@@ -1758,7 +1760,7 @@ exports[`tsSmithyApiGenerator > should generate smithy ts api with default optio
1758
1760
  "commands": [
1759
1761
  "rimraf dist/{projectRoot}/build",
1760
1762
  "make-dir dist/{projectRoot}/build",
1761
- "docker build -f {projectRoot}/build.Dockerfile --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
1763
+ "docker build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}"
1762
1764
  ],
1763
1765
  "parallel": false,
1764
1766
  "cwd": "{workspaceRoot}"