@aws/nx-plugin 0.5.0 → 0.6.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/LICENSE-THIRD-PARTY +104 -0
- package/generators.json +10 -0
- package/package.json +3 -1
- package/src/cloudscape-website/app/__snapshots__/generator.spec.ts.snap +4 -2
- package/src/cloudscape-website/app/files/common/constructs/src/app/static-websites/__websiteNameKebabCase__.ts.template +1 -1
- package/src/cloudscape-website/app/generator.js +25 -10
- package/src/cloudscape-website/app/generator.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +24 -41
- package/src/infra/app/generator.js +2 -1
- package/src/infra/app/generator.js.map +1 -1
- package/src/py/fast-api/files/app/__name__/main.py.template +9 -0
- package/src/py/fast-api/files/app/tests/test_main.py +7 -0
- package/src/py/fast-api/files/common/constructs/src/app/http-apis/__apiNameKebabCase__.ts.template +22 -0
- package/src/py/fast-api/generator.d.ts +11 -0
- package/src/py/fast-api/generator.js +116 -0
- package/src/py/fast-api/generator.js.map +1 -0
- package/src/py/fast-api/schema.d.ts +9 -0
- package/src/py/fast-api/schema.json +22 -0
- package/src/py/project/generator.d.ts +31 -0
- package/src/py/project/generator.js +103 -0
- package/src/py/project/generator.js.map +1 -0
- package/src/py/project/schema.d.ts +11 -0
- package/src/py/project/schema.json +32 -0
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +50 -44
- package/src/trpc/backend/files/backend/README.md.template +4 -0
- package/src/trpc/backend/files/common/constructs/src/app/{trpc-apis → http-apis}/__apiNameKebabCase__.ts.template +7 -3
- package/src/trpc/backend/generator.js +29 -23
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +0 -2
- package/src/trpc/backend/schema.json +0 -13
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/trpc/react/files/src/hooks/useSigV4.tsx.template +1 -1
- package/src/trpc/react/generator.js +1 -40
- package/src/trpc/react/generator.js.map +1 -1
- package/src/ts/lib/__snapshots__/generator.spec.ts.snap +12 -33
- package/src/ts/lib/eslint.js +28 -0
- package/src/ts/lib/eslint.js.map +1 -1
- package/src/ts/lib/generator.js +20 -12
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.js +2 -2
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/{trpc/backend/files/common/constructs/src/core/trpc-api.ts.template → utils/files/http-api/common/constructs/src/core/http-api.ts.template} +20 -18
- package/src/utils/http-api.d.ts +6 -0
- package/src/utils/http-api.js +61 -0
- package/src/utils/http-api.js.map +1 -0
- package/src/utils/names.d.ts +1 -0
- package/src/utils/names.js +4 -1
- package/src/utils/names.js.map +1 -1
- package/src/utils/npm-scope.js +2 -2
- package/src/utils/npm-scope.js.map +1 -1
- package/src/utils/nx.d.ts +8 -0
- package/src/utils/nx.js +11 -0
- package/src/utils/nx.js.map +1 -0
- package/src/utils/shared-constructs.js +1 -1
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/versions.d.ts +5 -2
- package/src/utils/versions.js +4 -1
- package/src/utils/versions.js.map +1 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fastApiProjectGenerator = 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 provider_1 = require("@nxlv/python/src/provider/uv/provider");
|
|
11
|
+
const logger_1 = require("@nxlv/python/src/executors/utils/logger");
|
|
12
|
+
const generator_1 = tslib_1.__importStar(require("../project/generator"));
|
|
13
|
+
const toml_1 = require("@iarna/toml");
|
|
14
|
+
const shared_constructs_1 = require("../../utils/shared-constructs");
|
|
15
|
+
const names_1 = require("../../utils/names");
|
|
16
|
+
const ast_1 = require("../../utils/ast");
|
|
17
|
+
const format_1 = require("../../utils/format");
|
|
18
|
+
const http_api_1 = require("../../utils/http-api");
|
|
19
|
+
const nx_1 = require("../../utils/nx");
|
|
20
|
+
/**
|
|
21
|
+
* Generates a Python FastAPI project
|
|
22
|
+
*/
|
|
23
|
+
const fastApiProjectGenerator = (tree, schema) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
yield (0, shared_constructs_1.sharedConstructsGenerator)(tree);
|
|
26
|
+
const { dir, normalizedName, normalizedModuleName, fullyQualifiedName } = (0, generator_1.getPyProjectDetails)(tree, {
|
|
27
|
+
name: schema.name,
|
|
28
|
+
directory: schema.directory,
|
|
29
|
+
});
|
|
30
|
+
const apiNameSnakeCase = (0, names_1.toSnakeCase)(schema.name);
|
|
31
|
+
const apiNameKebabCase = (0, names_1.toKebabCase)(schema.name);
|
|
32
|
+
const apiNameClassName = (0, names_1.toClassName)(schema.name);
|
|
33
|
+
const enhancedOptions = Object.assign(Object.assign({}, schema), { dir,
|
|
34
|
+
apiNameClassName,
|
|
35
|
+
apiNameKebabCase,
|
|
36
|
+
apiNameSnakeCase });
|
|
37
|
+
yield (0, generator_1.default)(tree, {
|
|
38
|
+
name: normalizedName,
|
|
39
|
+
directory: schema.directory,
|
|
40
|
+
moduleName: normalizedModuleName,
|
|
41
|
+
projectType: 'application',
|
|
42
|
+
});
|
|
43
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, fullyQualifiedName);
|
|
44
|
+
projectConfig.targets.bundle = {
|
|
45
|
+
cache: true,
|
|
46
|
+
executor: 'nx:run-commands',
|
|
47
|
+
outputs: [`{workspaceRoot}/dist/${dir}/bundle`],
|
|
48
|
+
options: {
|
|
49
|
+
commands: [
|
|
50
|
+
`uv export --frozen --no-dev --no-editable --project ${normalizedName} -o dist/${dir}/bundle/requirements.txt`,
|
|
51
|
+
`uv pip install --no-installer-metadata --no-compile-bytecode --python-platform x86_64-manylinux2014 --python \`uv python pin\` --target dist/${dir}/bundle -r dist/${dir}/bundle/requirements.txt`
|
|
52
|
+
],
|
|
53
|
+
parallel: false,
|
|
54
|
+
},
|
|
55
|
+
dependsOn: ['compile'],
|
|
56
|
+
};
|
|
57
|
+
projectConfig.targets.build.dependsOn = [
|
|
58
|
+
...((_a = projectConfig.targets.build.dependsOn) !== null && _a !== void 0 ? _a : []),
|
|
59
|
+
'bundle',
|
|
60
|
+
];
|
|
61
|
+
projectConfig.targets.serve = {
|
|
62
|
+
executor: '@nxlv/python:run-commands',
|
|
63
|
+
options: {
|
|
64
|
+
command: `uv run fastapi dev ${normalizedName}/main.py`,
|
|
65
|
+
cwd: dir,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
projectConfig.targets = (0, nx_1.sortProjectTargets)(projectConfig.targets);
|
|
69
|
+
(0, devkit_1.updateProjectConfiguration)(tree, normalizedName, projectConfig);
|
|
70
|
+
[
|
|
71
|
+
(0, devkit_1.joinPathFragments)(dir, normalizedModuleName !== null && normalizedModuleName !== void 0 ? normalizedModuleName : normalizedName, 'hello.py'),
|
|
72
|
+
(0, devkit_1.joinPathFragments)(dir, 'tests', 'test_hello.py'),
|
|
73
|
+
].forEach((f) => tree.delete(f));
|
|
74
|
+
(0, devkit_1.generateFiles)(tree, // the virtual file system
|
|
75
|
+
(0, devkit_1.joinPathFragments)(__dirname, 'files', 'app'), // path to the file templates
|
|
76
|
+
dir, // destination path of the files
|
|
77
|
+
{
|
|
78
|
+
name: normalizedName,
|
|
79
|
+
}, {
|
|
80
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.Overwrite,
|
|
81
|
+
});
|
|
82
|
+
if (!tree.exists((0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'http-apis', `${apiNameKebabCase}.ts`))) {
|
|
83
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), enhancedOptions, {
|
|
84
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
85
|
+
});
|
|
86
|
+
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'index.ts'), './http-apis/index.js');
|
|
87
|
+
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'http-apis', 'index.ts'), `./${apiNameKebabCase}.js`);
|
|
88
|
+
}
|
|
89
|
+
(0, http_api_1.addHttpApi)(tree, apiNameClassName);
|
|
90
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'project.json'), (config) => {
|
|
91
|
+
var _a;
|
|
92
|
+
if (!config.targets) {
|
|
93
|
+
config.targets = {};
|
|
94
|
+
}
|
|
95
|
+
if (!config.targets.build) {
|
|
96
|
+
config.targets.build = {};
|
|
97
|
+
}
|
|
98
|
+
config.targets.build.dependsOn = [
|
|
99
|
+
...((_a = config.targets.build.dependsOn) !== null && _a !== void 0 ? _a : []),
|
|
100
|
+
`${fullyQualifiedName}:build`,
|
|
101
|
+
];
|
|
102
|
+
return config;
|
|
103
|
+
});
|
|
104
|
+
const projectToml = (0, toml_1.parse)(tree.read((0, devkit_1.joinPathFragments)(dir, 'pyproject.toml'), 'utf8'));
|
|
105
|
+
projectToml.project.dependencies = ['fastapi', 'mangum'].concat(((_b = projectToml.project) === null || _b === void 0 ? void 0 : _b.dependencies) || []);
|
|
106
|
+
projectToml['dependency-groups'] = { dev: ['fastapi[standard]>=0.115'] };
|
|
107
|
+
tree.write((0, devkit_1.joinPathFragments)(dir, 'pyproject.toml'), (0, toml_1.stringify)(projectToml));
|
|
108
|
+
yield (0, format_1.formatFilesInSubtree)(tree);
|
|
109
|
+
return () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
yield new provider_1.UVProvider(tree.root, new logger_1.Logger(), tree).install();
|
|
111
|
+
(0, devkit_1.installPackagesTask)(tree);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
exports.fastApiProjectGenerator = fastApiProjectGenerator;
|
|
115
|
+
exports.default = exports.fastApiProjectGenerator;
|
|
116
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/py/fast-api/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAWoB;AAEpB,oEAAmE;AACnE,oEAAiE;AACjE,0EAA+E;AAC/E,sCAA+C;AAE/C,qEAIuC;AACvC,6CAA0E;AAC1E,yCAAgD;AAChD,+CAA0D;AAC1D,mDAAkD;AAClD,uCAAoD;AAEpD;;GAEG;AACI,MAAM,uBAAuB,GAAG,CACrC,IAAU,EACV,MAAqC,EACT,EAAE;;IAC9B,MAAM,IAAA,6CAAyB,EAAC,IAAI,CAAC,CAAC;IAEtC,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,GAAG,IAAA,+BAAmB,EAC3F,IAAI,EACJ;QACE,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CACF,CAAC;IACF,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAAC,MA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AAC,CAAC,CAAC;IAE7E,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;IAEjC,OAAO,GAAS,EAAE;QAChB,MAAM,IAAI,qBAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,eAAM,EAAE,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAC9D,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAA,CAAC;AACJ,CAAC,CAAA,CAAC;AAtKW,QAAA,uBAAuB,2BAsKlC;AACF,kBAAe,+BAAuB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "TsLib",
|
|
4
|
+
"title": "Create a Python FastAPI project",
|
|
5
|
+
"description": "Create a Python FastAPI project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "project name.",
|
|
11
|
+
"x-priority": "important"
|
|
12
|
+
},
|
|
13
|
+
"directory": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Parent directory where the project is placed.",
|
|
16
|
+
"default": "packages",
|
|
17
|
+
"x-prompt": "Which directory do you want to create the project in?",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["name"]
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 { PyProjectGeneratorSchema } from './schema';
|
|
7
|
+
export interface PyProjectDetails {
|
|
8
|
+
readonly normalizedName: string;
|
|
9
|
+
/**
|
|
10
|
+
* Full package name including scope (eg foo.bar)
|
|
11
|
+
*/
|
|
12
|
+
readonly fullyQualifiedName: string;
|
|
13
|
+
/**
|
|
14
|
+
* Directory of the library relative to the root
|
|
15
|
+
*/
|
|
16
|
+
readonly dir: string;
|
|
17
|
+
readonly normalizedModuleName?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns details about the Python project to be created
|
|
21
|
+
*/
|
|
22
|
+
export declare const getPyProjectDetails: (tree: Tree, schema: {
|
|
23
|
+
name: string;
|
|
24
|
+
directory?: string;
|
|
25
|
+
moduleName?: string;
|
|
26
|
+
}) => PyProjectDetails;
|
|
27
|
+
/**
|
|
28
|
+
* Generates a Python project
|
|
29
|
+
*/
|
|
30
|
+
export declare const pyProjectGenerator: (tree: Tree, schema: PyProjectGeneratorSchema) => Promise<GeneratorCallback>;
|
|
31
|
+
export default pyProjectGenerator;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pyProjectGenerator = exports.getPyProjectDetails = 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 generator_1 = tslib_1.__importDefault(require("@nxlv/python/src/generators/migrate-to-shared-venv/generator"));
|
|
11
|
+
const generator_2 = tslib_1.__importDefault(require("@nxlv/python/src/generators/uv-project/generator"));
|
|
12
|
+
const provider_1 = require("@nxlv/python/src/provider/uv/provider");
|
|
13
|
+
const logger_1 = require("@nxlv/python/src/executors/utils/logger");
|
|
14
|
+
const versions_1 = require("../../utils/versions");
|
|
15
|
+
const npm_scope_1 = require("../../utils/npm-scope");
|
|
16
|
+
const names_1 = require("../../utils/names");
|
|
17
|
+
const nx_1 = require("../../utils/nx");
|
|
18
|
+
/**
|
|
19
|
+
* Returns details about the Python project to be created
|
|
20
|
+
*/
|
|
21
|
+
const getPyProjectDetails = (tree, schema) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const scope = (0, names_1.toSnakeCase)((0, npm_scope_1.getNpmScope)(tree));
|
|
24
|
+
const normalizedName = (0, names_1.toSnakeCase)(schema.name);
|
|
25
|
+
const normalizedModuleName = (0, names_1.toSnakeCase)(schema.moduleName);
|
|
26
|
+
const fullyQualifiedName = `${scope}.${normalizedName}`;
|
|
27
|
+
const dir = (0, devkit_1.joinPathFragments)((_a = (0, names_1.toSnakeCase)(schema.directory)) !== null && _a !== void 0 ? _a : '.', normalizedName);
|
|
28
|
+
return { dir, fullyQualifiedName, normalizedName, normalizedModuleName };
|
|
29
|
+
};
|
|
30
|
+
exports.getPyProjectDetails = getPyProjectDetails;
|
|
31
|
+
/**
|
|
32
|
+
* Generates a Python project
|
|
33
|
+
*/
|
|
34
|
+
const pyProjectGenerator = (tree, schema) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
const { dir, normalizedName, normalizedModuleName, fullyQualifiedName } = (0, exports.getPyProjectDetails)(tree, schema);
|
|
37
|
+
const pythonPlugin = (0, versions_1.withVersions)(['@nxlv/python']);
|
|
38
|
+
Object.entries(pythonPlugin).forEach(([name, version]) => (0, devkit_1.ensurePackage)(name, version));
|
|
39
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
40
|
+
if (!((_a = nxJson.plugins) === null || _a === void 0 ? void 0 : _a.find((p) => typeof p === 'string'
|
|
41
|
+
? p === '@nxlv/python'
|
|
42
|
+
: p.plugin === '@nxlv/python'))) {
|
|
43
|
+
nxJson.plugins = [
|
|
44
|
+
...((_b = nxJson.plugins) !== null && _b !== void 0 ? _b : []),
|
|
45
|
+
{
|
|
46
|
+
plugin: '@nxlv/python',
|
|
47
|
+
options: {
|
|
48
|
+
packageManager: 'uv',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
53
|
+
}
|
|
54
|
+
if (!tree.exists('uv.lock')) {
|
|
55
|
+
yield (0, generator_1.default)(tree, {
|
|
56
|
+
autoActivate: true,
|
|
57
|
+
packageManager: 'uv',
|
|
58
|
+
moveDevDependencies: false,
|
|
59
|
+
pyenvPythonVersion: '3.12.0',
|
|
60
|
+
pyprojectPythonDependency: '>=3.12',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
yield (0, generator_2.default)(tree, {
|
|
64
|
+
name: normalizedName,
|
|
65
|
+
publishable: false,
|
|
66
|
+
buildLockedVersions: true,
|
|
67
|
+
buildBundleLocalDependencies: true,
|
|
68
|
+
linter: 'ruff',
|
|
69
|
+
rootPyprojectDependencyGroup: 'main',
|
|
70
|
+
pyenvPythonVersion: '3.12.0',
|
|
71
|
+
pyprojectPythonDependency: '>=3.12',
|
|
72
|
+
projectType: schema.projectType,
|
|
73
|
+
projectNameAndRootFormat: 'as-provided',
|
|
74
|
+
moduleName: normalizedModuleName,
|
|
75
|
+
directory: dir,
|
|
76
|
+
unitTestRunner: 'pytest',
|
|
77
|
+
codeCoverage: true,
|
|
78
|
+
codeCoverageHtmlReport: true,
|
|
79
|
+
codeCoverageXmlReport: true,
|
|
80
|
+
unitTestHtmlReport: true,
|
|
81
|
+
unitTestJUnitReport: true,
|
|
82
|
+
});
|
|
83
|
+
const outputPath = `{workspaceRoot}/dist/${dir}`;
|
|
84
|
+
const buildOutputPath = (0, devkit_1.joinPathFragments)(outputPath, 'build');
|
|
85
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, normalizedName);
|
|
86
|
+
projectConfiguration.name = fullyQualifiedName;
|
|
87
|
+
const buildTarget = projectConfiguration.targets.build;
|
|
88
|
+
projectConfiguration.targets.compile = Object.assign(Object.assign({}, buildTarget), { outputs: [buildOutputPath], options: Object.assign(Object.assign({}, buildTarget.options), { outputPath: buildOutputPath }) });
|
|
89
|
+
projectConfiguration.targets.build = {
|
|
90
|
+
dependsOn: ['lint', 'compile', 'test', ...((_c = buildTarget.dependsOn) !== null && _c !== void 0 ? _c : [])],
|
|
91
|
+
options: {
|
|
92
|
+
outputPath,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
projectConfiguration.targets = (0, nx_1.sortProjectTargets)(projectConfiguration.targets);
|
|
96
|
+
(0, devkit_1.updateProjectConfiguration)(tree, normalizedName, projectConfiguration);
|
|
97
|
+
return () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
yield new provider_1.UVProvider(tree.root, new logger_1.Logger(), tree).install();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
exports.pyProjectGenerator = pyProjectGenerator;
|
|
102
|
+
exports.default = exports.pyProjectGenerator;
|
|
103
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/py/project/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCASoB;AAEpB,qHAAwG;AACxG,yGAAkF;AAClF,oEAAmE;AACnE,oEAAiE;AACjE,mDAAoD;AACpD,qDAAoD;AACpD,6CAAgD;AAChD,uCAAoD;AAgBpD;;GAEG;AACI,MAAM,mBAAmB,GAAG,CACjC,IAAU,EACV,MAAiE,EAC/C,EAAE;;IACpB,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,IAAA,uBAAW,EAAC,IAAI,CAAC,CAAC,CAAC;IAC7C,MAAM,cAAc,GAAG,IAAA,mBAAW,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,oBAAoB,GAAG,IAAA,mBAAW,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC5D,MAAM,kBAAkB,GAAG,GAAG,KAAK,IAAI,cAAc,EAAE,CAAC;IACxD,MAAM,GAAG,GAAG,IAAA,0BAAiB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tB,UAAU,EAAE,eAAe,MAE9B,CAAC;IACF,oBAAoB,CAAC,OAAO,CAAC,KAAK,GAAG;QACnC,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,MAAA,WAAW,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC;QACxE,OAAO,EAAE;YACP,UAAU;SACX;KACF,CAAC;IACF,oBAAoB,CAAC,OAAO,GAAG,IAAA,uBAAkB,EAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAChF,IAAA,mCAA0B,EAAC,IAAI,EAAE,cAAc,EAAE,oBAAoB,CAAC,CAAC;IAEvE,OAAO,GAAS,EAAE;QAChB,MAAM,IAAI,qBAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,eAAM,EAAE,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IAChE,CAAC,CAAA,CAAC;AACJ,CAAC,CAAA,CAAC;AA3FW,QAAA,kBAAkB,sBA2F7B;AACF,kBAAe,0BAAkB,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
|
+
|
|
6
|
+
export interface PyProjectGeneratorSchema {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly projectType: 'application' | 'library';
|
|
9
|
+
readonly directory?: string;
|
|
10
|
+
readonly moduleName?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "TsLib",
|
|
4
|
+
"title": "Create a Python project",
|
|
5
|
+
"description": "Create a Python project.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Project name.",
|
|
11
|
+
"x-priority": "important"
|
|
12
|
+
},
|
|
13
|
+
"directory": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Parent directory where the project is placed.",
|
|
16
|
+
"default": "packages",
|
|
17
|
+
"x-prompt": "Which directory do you want to create the project in?",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
},
|
|
20
|
+
"projectType": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Project type",
|
|
23
|
+
"default": "application",
|
|
24
|
+
"enum": ["application", "library"]
|
|
25
|
+
},
|
|
26
|
+
"moduleName": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "Python module name"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"required": ["name", "projectType"]
|
|
32
|
+
}
|
|
@@ -327,71 +327,46 @@ export type IEchoOutput = z.TypeOf<typeof EchoOutputSchema>;
|
|
|
327
327
|
"
|
|
328
328
|
`;
|
|
329
329
|
|
|
330
|
-
exports[`trpc backend generator > should set up shared constructs >
|
|
331
|
-
"export * from './test-api.js';
|
|
332
|
-
"
|
|
333
|
-
`;
|
|
334
|
-
|
|
335
|
-
exports[`trpc backend generator > should set up shared constructs > test-api.ts 1`] = `
|
|
336
|
-
"import { Construct } from 'constructs';
|
|
337
|
-
import * as url from 'url';
|
|
338
|
-
import { TrpcApi } from '../../core/trpc-api.js';
|
|
339
|
-
import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
340
|
-
|
|
341
|
-
export class TestApi extends TrpcApi {
|
|
342
|
-
constructor(scope: Construct, id: string) {
|
|
343
|
-
super(scope, id, {
|
|
344
|
-
defaultAuthorizer: new HttpIamAuthorizer(),
|
|
345
|
-
handlerFilePath: url.fileURLToPath(
|
|
346
|
-
new URL(
|
|
347
|
-
'../../../../../../apps/test-api/backend/src/router.ts',
|
|
348
|
-
import.meta.url,
|
|
349
|
-
),
|
|
350
|
-
),
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
"
|
|
355
|
-
`;
|
|
356
|
-
|
|
357
|
-
exports[`trpc backend generator > should set up shared constructs > trpc-api.ts 1`] = `
|
|
330
|
+
exports[`trpc backend generator > should set up shared constructs > http-api.ts 1`] = `
|
|
358
331
|
"import { Construct } from 'constructs';
|
|
359
|
-
import { Runtime, RuntimeFamily } from 'aws-cdk-lib/aws-lambda';
|
|
360
332
|
import { CfnOutput, Duration } from 'aws-cdk-lib';
|
|
361
333
|
import {
|
|
362
334
|
CorsHttpMethod,
|
|
363
|
-
HttpApi,
|
|
335
|
+
HttpApi as _HttpApi,
|
|
364
336
|
HttpMethod,
|
|
365
337
|
IHttpRouteAuthorizer,
|
|
366
338
|
} from 'aws-cdk-lib/aws-apigatewayv2';
|
|
367
339
|
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
368
|
-
import {
|
|
340
|
+
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
369
341
|
import { Effect, IRole, PolicyStatement } from 'aws-cdk-lib/aws-iam';
|
|
370
342
|
import { RuntimeConfig } from './runtime-config.js';
|
|
371
343
|
|
|
372
|
-
export interface
|
|
344
|
+
export interface HttpApiProps {
|
|
345
|
+
readonly apiName: string;
|
|
346
|
+
readonly handler: string;
|
|
373
347
|
readonly handlerFilePath: string;
|
|
348
|
+
readonly runtime: Runtime;
|
|
374
349
|
readonly defaultAuthorizer: IHttpRouteAuthorizer;
|
|
375
350
|
readonly allowedOrigins?: string[];
|
|
376
351
|
}
|
|
377
352
|
|
|
378
|
-
export class
|
|
379
|
-
public readonly api:
|
|
353
|
+
export class HttpApi extends Construct {
|
|
354
|
+
public readonly api: _HttpApi;
|
|
380
355
|
|
|
381
|
-
constructor(scope: Construct, id: string, props:
|
|
356
|
+
constructor(scope: Construct, id: string, props: HttpApiProps) {
|
|
382
357
|
super(scope, id);
|
|
383
358
|
|
|
384
|
-
const routerFunction = new
|
|
359
|
+
const routerFunction = new Function(this, \`\${id}Handler\`, {
|
|
385
360
|
timeout: Duration.seconds(30),
|
|
386
|
-
runtime:
|
|
387
|
-
handler:
|
|
388
|
-
|
|
361
|
+
runtime: props.runtime,
|
|
362
|
+
handler: props.handler,
|
|
363
|
+
code: Code.fromAsset(props.handlerFilePath),
|
|
389
364
|
environment: {
|
|
390
365
|
AWS_CONNECTION_REUSE_ENABLED: '1',
|
|
391
366
|
},
|
|
392
367
|
});
|
|
393
368
|
|
|
394
|
-
this.api = new
|
|
369
|
+
this.api = new _HttpApi(this, id, {
|
|
395
370
|
corsPreflight: {
|
|
396
371
|
allowOrigins: props.allowedOrigins ?? ['*'],
|
|
397
372
|
allowMethods: [CorsHttpMethod.ANY],
|
|
@@ -422,11 +397,11 @@ export class TrpcApi extends Construct {
|
|
|
422
397
|
),
|
|
423
398
|
});
|
|
424
399
|
|
|
425
|
-
new CfnOutput(this, \`\${
|
|
400
|
+
new CfnOutput(this, \`\${props.apiName}Url\`, { value: this.api.url! });
|
|
426
401
|
|
|
427
|
-
RuntimeConfig.ensure(this).config.
|
|
428
|
-
...RuntimeConfig.ensure(this).config.
|
|
429
|
-
[
|
|
402
|
+
RuntimeConfig.ensure(this).config.httpApis = {
|
|
403
|
+
...RuntimeConfig.ensure(this).config.httpApis!,
|
|
404
|
+
[props.apiName]: this.api.url!,
|
|
430
405
|
};
|
|
431
406
|
}
|
|
432
407
|
|
|
@@ -442,3 +417,34 @@ export class TrpcApi extends Construct {
|
|
|
442
417
|
}
|
|
443
418
|
"
|
|
444
419
|
`;
|
|
420
|
+
|
|
421
|
+
exports[`trpc backend generator > should set up shared constructs > index.ts 1`] = `
|
|
422
|
+
"export * from './test-api.js';
|
|
423
|
+
"
|
|
424
|
+
`;
|
|
425
|
+
|
|
426
|
+
exports[`trpc backend generator > should set up shared constructs > test-api.ts 1`] = `
|
|
427
|
+
"import { Construct } from 'constructs';
|
|
428
|
+
import * as url from 'url';
|
|
429
|
+
import { HttpApi } from '../../core/http-api.js';
|
|
430
|
+
import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
431
|
+
import { Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
432
|
+
|
|
433
|
+
export class TestApi extends HttpApi {
|
|
434
|
+
constructor(scope: Construct, id: string) {
|
|
435
|
+
super(scope, id, {
|
|
436
|
+
defaultAuthorizer: new HttpIamAuthorizer(),
|
|
437
|
+
apiName: 'TestApi',
|
|
438
|
+
runtime: Runtime.NODEJS_LATEST,
|
|
439
|
+
handler: 'index.handler',
|
|
440
|
+
handlerFilePath: url.fileURLToPath(
|
|
441
|
+
new URL(
|
|
442
|
+
'../../../../../../dist/apps/test-api/backend/bundle',
|
|
443
|
+
import.meta.url,
|
|
444
|
+
),
|
|
445
|
+
),
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
"
|
|
450
|
+
`;
|
|
@@ -6,6 +6,10 @@ This library was generated with [@aws/nx-plugin](https://github.com/awslabs/nx-p
|
|
|
6
6
|
|
|
7
7
|
Run `<%= pkgMgrCmd %> nx build <%= backendProjectName %> [--skip-nx-cache]` to build the application.
|
|
8
8
|
|
|
9
|
+
## Running local server
|
|
10
|
+
|
|
11
|
+
Run `<%= pkgMgrCmd %> nx serve <%= backendProjectName %>` to start a local server
|
|
12
|
+
|
|
9
13
|
## Running unit tests
|
|
10
14
|
|
|
11
15
|
Run `<%= pkgMgrCmd %> nx test <%= backendProjectName %>` to execute the unit tests via Vitest.
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import * as url from 'url';
|
|
3
|
-
import {
|
|
3
|
+
import { HttpApi } from '../../core/http-api.js';
|
|
4
4
|
import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
5
|
+
import { Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
5
6
|
|
|
6
|
-
export class <%= apiNameClassName %> extends
|
|
7
|
+
export class <%= apiNameClassName %> extends HttpApi {
|
|
7
8
|
constructor(scope: Construct, id: string) {
|
|
8
9
|
super(scope, id, {
|
|
9
10
|
defaultAuthorizer: new HttpIamAuthorizer(),
|
|
11
|
+
apiName: '<%= apiNameClassName %>',
|
|
12
|
+
runtime: Runtime.NODEJS_LATEST,
|
|
13
|
+
handler: 'index.handler',
|
|
10
14
|
handlerFilePath: url.fileURLToPath(
|
|
11
15
|
new URL(
|
|
12
|
-
'
|
|
16
|
+
'../../../../../../dist/<%= backendRoot %>/bundle',
|
|
13
17
|
import.meta.url
|
|
14
18
|
)
|
|
15
19
|
)
|
|
@@ -12,10 +12,11 @@ const shared_constructs_1 = require("../../utils/shared-constructs");
|
|
|
12
12
|
const generator_1 = tslib_1.__importDefault(require("../../ts/lib/generator"));
|
|
13
13
|
const npm_scope_1 = require("../../utils/npm-scope");
|
|
14
14
|
const versions_1 = require("../../utils/versions");
|
|
15
|
-
const paths_1 = require("../../utils/paths");
|
|
16
15
|
const names_1 = require("../../utils/names");
|
|
17
16
|
const ast_1 = require("../../utils/ast");
|
|
18
17
|
const format_1 = require("../../utils/format");
|
|
18
|
+
const http_api_1 = require("../../utils/http-api");
|
|
19
|
+
const nx_1 = require("../../utils/nx");
|
|
19
20
|
function trpcBackendGenerator(tree, options) {
|
|
20
21
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
22
|
var _a;
|
|
@@ -24,7 +25,6 @@ function trpcBackendGenerator(tree, options) {
|
|
|
24
25
|
const apiNameKebabCase = (0, lodash_kebabcase_1.default)(options.apiName);
|
|
25
26
|
const apiNameClassName = (0, names_1.toClassName)(options.apiName);
|
|
26
27
|
const projectRoot = (0, devkit_1.joinPathFragments)((_a = options.directory) !== null && _a !== void 0 ? _a : '.', apiNameKebabCase);
|
|
27
|
-
const relativePathToProjectRoot = `${(0, devkit_1.joinPathFragments)((0, paths_1.getRelativePathToRoot)(tree, `${(0, npm_scope_1.getNpmScopePrefix)(tree)}common-constructs`), projectRoot)}`;
|
|
28
28
|
const schemaRoot = (0, devkit_1.joinPathFragments)(projectRoot, 'schema');
|
|
29
29
|
const backendRoot = (0, devkit_1.joinPathFragments)(projectRoot, 'backend');
|
|
30
30
|
const backendName = `${apiNameKebabCase}-backend`;
|
|
@@ -33,7 +33,7 @@ function trpcBackendGenerator(tree, options) {
|
|
|
33
33
|
const schemaProjectName = `${apiNamespace}${schemaName}`;
|
|
34
34
|
const enhancedOptions = Object.assign({ backendProjectName, backendProjectAlias: (0, npm_scope_1.toScopeAlias)(backendProjectName), schemaProjectName, schemaProjectAlias: (0, npm_scope_1.toScopeAlias)(schemaProjectName), apiNameKebabCase,
|
|
35
35
|
apiNameClassName,
|
|
36
|
-
|
|
36
|
+
backendRoot, pkgMgrCmd: (0, devkit_1.getPackageManagerCommand)().exec }, options);
|
|
37
37
|
yield (0, generator_1.default)(tree, {
|
|
38
38
|
name: backendName,
|
|
39
39
|
directory: projectRoot,
|
|
@@ -44,33 +44,39 @@ function trpcBackendGenerator(tree, options) {
|
|
|
44
44
|
directory: projectRoot,
|
|
45
45
|
subDirectory: 'schema',
|
|
46
46
|
});
|
|
47
|
-
if (!tree.exists((0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', '
|
|
47
|
+
if (!tree.exists((0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'http-apis', `${apiNameKebabCase}.ts`))) {
|
|
48
48
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), enhancedOptions, {
|
|
49
49
|
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
50
50
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'core'), (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'core'), enhancedOptions, {
|
|
54
|
-
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'index.ts'), './trpc-apis/index.js');
|
|
58
|
-
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'trpc-apis', 'index.ts'), `./${apiNameKebabCase}.js`);
|
|
59
|
-
if (shouldGenerateCoreTrpcApiConstruct) {
|
|
60
|
-
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'core', 'index.ts'), './trpc-api.js');
|
|
61
|
-
}
|
|
51
|
+
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'index.ts'), './http-apis/index.js');
|
|
52
|
+
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'http-apis', 'index.ts'), `./${apiNameKebabCase}.js`);
|
|
62
53
|
}
|
|
54
|
+
(0, http_api_1.addHttpApi)(tree, apiNameClassName);
|
|
63
55
|
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(backendRoot, 'project.json'), (config) => {
|
|
56
|
+
var _a;
|
|
64
57
|
config.metadata = {
|
|
65
58
|
apiName: options.apiName,
|
|
66
59
|
};
|
|
67
|
-
config.targets =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
config.targets.serve = {
|
|
61
|
+
executor: 'nx:run-commands',
|
|
62
|
+
options: {
|
|
63
|
+
commands: ['tsx src/local-server.ts'],
|
|
64
|
+
cwd: backendRoot,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
config.targets.bundle = {
|
|
68
|
+
cache: true,
|
|
69
|
+
executor: 'nx:run-commands',
|
|
70
|
+
outputs: [`{workspaceRoot}/dist/${backendRoot}/bundle`],
|
|
71
|
+
options: {
|
|
72
|
+
command: `esbuild ${backendRoot}/src/index.ts --bundle --outfile=dist/${backendRoot}/bundle/index.js --platform=node --format=cjs`
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
config.targets.build.dependsOn = [
|
|
76
|
+
...((_a = config.targets.build.dependsOn) !== null && _a !== void 0 ? _a : []),
|
|
77
|
+
'bundle',
|
|
78
|
+
];
|
|
79
|
+
config.targets = (0, nx_1.sortProjectTargets)(config.targets);
|
|
74
80
|
return config;
|
|
75
81
|
});
|
|
76
82
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'backend'), backendRoot, enhancedOptions, {
|
|
@@ -90,7 +96,7 @@ function trpcBackendGenerator(tree, options) {
|
|
|
90
96
|
'@trpc/server',
|
|
91
97
|
'aws4fetch',
|
|
92
98
|
'@aws-sdk/credential-providers',
|
|
93
|
-
]), (0, versions_1.withVersions)(['@types/aws-lambda', 'tsx']));
|
|
99
|
+
]), (0, versions_1.withVersions)(['@types/aws-lambda', 'esbuild', 'tsx']));
|
|
94
100
|
tree.delete((0, devkit_1.joinPathFragments)(backendRoot, 'package.json'));
|
|
95
101
|
tree.delete((0, devkit_1.joinPathFragments)(schemaRoot, 'package.json'));
|
|
96
102
|
yield (0, format_1.formatFilesInSubtree)(tree);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;AA8BA,oDAyKC;;AAvMD;;;GAGG;AACH,uCAUoB;AAEpB,gFAAyC;AACzC,qEAIuC;AACvC,+EAAoD;AACpD,qDAAwE;AACxE,mDAAoD;AACpD,6CAAgD;AAChD,yCAAgD;AAChD,+CAA0D;AAC1D,mDAAkD;AAClD,uCAAoD;AACpD,SAAsB,oBAAoB,CACxC,IAAU,EACV,OAAmC;;;QAEnC,MAAM,IAAA,6CAAyB,EAAC,IAAI,CAAC,CAAC;QACtC,MAAM,YAAY,GAAG,IAAA,6BAAiB,EAAC,IAAI,CAAC,CAAC;QAC7C,MAAM,gBAAgB,GAAG,IAAA,0BAAS,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACpD,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,MAAM,WAAW,GAAG,IAAA,0BAAiB,EACnC,MAAA,OAAO,CAAC,SAAS,mCAAI,GAAG,EACxB,gBAAgB,CACjB,CAAC;QAEF,MAAM,UAAU,GAAG,IAAA,0BAAiB,EAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAC5D,MAAM,WAAW,GAAG,IAAA,0BAAiB,EAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAC9D,MAAM,WAAW,GAAG,GAAG,gBAAgB,UAAU,CAAC;QAClD,MAAM,UAAU,GAAG,GAAG,gBAAgB,SAAS,CAAC;QAChD,MAAM,kBAAkB,GAAG,GAAG,YAAY,GAAG,WAAW,EAAE,CAAC;QAC3D,MAA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