@wolsok/nx-aws-cdk-v2 1.3.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/.babelrc +10 -0
- package/README.md +96 -0
- package/eslint.config.js +17 -0
- package/executors.json +20 -0
- package/generators.json +19 -0
- package/jest.config.ts +8 -0
- package/package.json +24 -0
- package/project.json +66 -0
- package/src/executors/bootstrap/bootstrap.spec.ts +57 -0
- package/src/executors/bootstrap/bootstrap.ts +45 -0
- package/src/executors/bootstrap/schema.d.ts +3 -0
- package/src/executors/bootstrap/schema.json +8 -0
- package/src/executors/deploy/deploy.spec.ts +106 -0
- package/src/executors/deploy/deploy.ts +43 -0
- package/src/executors/deploy/schema.d.ts +3 -0
- package/src/executors/deploy/schema.json +13 -0
- package/src/executors/destroy/destroy.spec.ts +56 -0
- package/src/executors/destroy/destroy.ts +45 -0
- package/src/executors/destroy/schema.d.ts +3 -0
- package/src/executors/destroy/schema.json +13 -0
- package/src/generators/application/application.spec.ts +30 -0
- package/src/generators/application/application.ts +125 -0
- package/src/generators/application/files/cdk.json__template__ +36 -0
- package/src/generators/application/files/src/main.ts__template__ +5 -0
- package/src/generators/application/files/src/stacks/app-stack.ts__template__ +9 -0
- package/src/generators/application/files/tsconfig.app.json__template__ +9 -0
- package/src/generators/application/files/tsconfig.json__template__ +15 -0
- package/src/generators/application/jest-files/src/main.test.ts__template__ +13 -0
- package/src/generators/application/schema.d.ts +8 -0
- package/src/generators/application/schema.json +44 -0
- package/src/generators/init/init.spec.ts +22 -0
- package/src/generators/init/init.ts +45 -0
- package/src/generators/init/schema.d.ts +4 -0
- package/src/generators/init/schema.json +20 -0
- package/src/index.ts +0 -0
- package/src/interfaces/parsed-executor.interface.ts +7 -0
- package/src/utils/cdk-shared.ts +2 -0
- package/src/utils/executor.util.ts +120 -0
- package/src/utils/testing.ts +28 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +11 -0
- package/tsconfig.spec.json +20 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
2
|
+
import { Tree, readProjectConfiguration } from '@nx/devkit';
|
|
3
|
+
|
|
4
|
+
import generator from './application';
|
|
5
|
+
import { ApplicationSchema } from './schema';
|
|
6
|
+
|
|
7
|
+
describe('aws-cdk generator', () => {
|
|
8
|
+
let appTree: Tree;
|
|
9
|
+
const options: ApplicationSchema = { name: 'test' };
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
appTree = createTreeWithEmptyWorkspace();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should run successfully', async () => {
|
|
16
|
+
await generator(appTree, options);
|
|
17
|
+
const config = readProjectConfiguration(appTree, 'test');
|
|
18
|
+
expect(config).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('directory option', async () => {
|
|
22
|
+
const directory = 'sub';
|
|
23
|
+
const directoryOptions = Object.assign({}, options);
|
|
24
|
+
directoryOptions.directory = directory;
|
|
25
|
+
|
|
26
|
+
await generator(appTree, directoryOptions);
|
|
27
|
+
const config = readProjectConfiguration(appTree, 'sub-test');
|
|
28
|
+
expect(config).toBeDefined();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import {
|
|
3
|
+
addProjectConfiguration,
|
|
4
|
+
convertNxGenerator,
|
|
5
|
+
formatFiles,
|
|
6
|
+
generateFiles,
|
|
7
|
+
GeneratorCallback,
|
|
8
|
+
getWorkspaceLayout,
|
|
9
|
+
names,
|
|
10
|
+
offsetFromRoot,
|
|
11
|
+
ProjectConfiguration,
|
|
12
|
+
readProjectConfiguration,
|
|
13
|
+
runTasksInSerial,
|
|
14
|
+
Tree,
|
|
15
|
+
updateProjectConfiguration,
|
|
16
|
+
} from '@nx/devkit';
|
|
17
|
+
import { configurationGenerator } from '@nx/jest';
|
|
18
|
+
|
|
19
|
+
import { ApplicationSchema } from './schema';
|
|
20
|
+
import { initGenerator } from '../init/init';
|
|
21
|
+
|
|
22
|
+
interface NormalizedSchema extends ApplicationSchema {
|
|
23
|
+
projectName: string;
|
|
24
|
+
projectRoot: string;
|
|
25
|
+
projectDirectory: string;
|
|
26
|
+
parsedTags: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function normalizeOptions(host: Tree, options: ApplicationSchema): NormalizedSchema {
|
|
30
|
+
const name = names(options.name).fileName;
|
|
31
|
+
const projectDirectory = options.directory ? `${names(options.directory).fileName}/${name}` : name;
|
|
32
|
+
const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
|
|
33
|
+
const projectRoot = `${getWorkspaceLayout(host).appsDir}/${projectDirectory}`;
|
|
34
|
+
const parsedTags = options.tags ? options.tags.split(',').map((s) => s.trim()) : [];
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...options,
|
|
38
|
+
projectName,
|
|
39
|
+
projectRoot,
|
|
40
|
+
projectDirectory,
|
|
41
|
+
parsedTags,
|
|
42
|
+
unitTestRunner: options.unitTestRunner ?? 'jest',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function addFiles(host: Tree, options: NormalizedSchema) {
|
|
47
|
+
const templateOptions = {
|
|
48
|
+
...options,
|
|
49
|
+
...names(options.projectName),
|
|
50
|
+
offsetFromRoot: offsetFromRoot(options.projectRoot),
|
|
51
|
+
template: '',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
generateFiles(host, path.join(__dirname, 'files'), options.projectRoot, templateOptions);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function addJestFiles(host: Tree, options: NormalizedSchema) {
|
|
58
|
+
const templateOptions = {
|
|
59
|
+
...options,
|
|
60
|
+
...names(options.projectName),
|
|
61
|
+
offsetFromRoot: offsetFromRoot(options.projectRoot),
|
|
62
|
+
template: '',
|
|
63
|
+
};
|
|
64
|
+
generateFiles(host, path.join(__dirname, 'jest-files'), options.projectRoot, templateOptions);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function applicationGenerator(host: Tree, options: ApplicationSchema) {
|
|
68
|
+
const tasks: GeneratorCallback[] = [];
|
|
69
|
+
const normalizedOptions = normalizeOptions(host, options);
|
|
70
|
+
const initTask = await initGenerator(host, {
|
|
71
|
+
...options,
|
|
72
|
+
skipFormat: true,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
tasks.push(initTask);
|
|
76
|
+
|
|
77
|
+
const project: ProjectConfiguration = {
|
|
78
|
+
root: normalizedOptions.projectRoot,
|
|
79
|
+
projectType: 'application',
|
|
80
|
+
sourceRoot: `${normalizedOptions.projectRoot}/src`,
|
|
81
|
+
targets: {
|
|
82
|
+
deploy: {
|
|
83
|
+
executor: '@ago-dev/nx-aws-cdk-v2:deploy',
|
|
84
|
+
options: {},
|
|
85
|
+
},
|
|
86
|
+
destroy: {
|
|
87
|
+
executor: '@ago-dev/nx-aws-cdk-v2:destroy',
|
|
88
|
+
options: {},
|
|
89
|
+
},
|
|
90
|
+
bootstrap: {
|
|
91
|
+
executor: '@ago-dev/nx-aws-cdk-v2:bootstrap',
|
|
92
|
+
options: {},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
tags: normalizedOptions.parsedTags,
|
|
96
|
+
};
|
|
97
|
+
addProjectConfiguration(host, normalizedOptions.projectName, project);
|
|
98
|
+
const workspace = readProjectConfiguration(host, normalizedOptions.projectName);
|
|
99
|
+
|
|
100
|
+
updateProjectConfiguration(host, normalizedOptions.projectName, workspace);
|
|
101
|
+
addFiles(host, normalizedOptions);
|
|
102
|
+
|
|
103
|
+
if (normalizedOptions.unitTestRunner === 'jest') {
|
|
104
|
+
const jestTask = await configurationGenerator(host, {
|
|
105
|
+
project: normalizedOptions.projectName,
|
|
106
|
+
setupFile: 'none',
|
|
107
|
+
skipSerializers: true,
|
|
108
|
+
supportTsx: false,
|
|
109
|
+
babelJest: false,
|
|
110
|
+
testEnvironment: 'node',
|
|
111
|
+
skipFormat: true,
|
|
112
|
+
});
|
|
113
|
+
tasks.push(jestTask);
|
|
114
|
+
addJestFiles(host, normalizedOptions);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!options.skipFormat) {
|
|
118
|
+
await formatFiles(host);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return runTasksInSerial(...tasks);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default applicationGenerator;
|
|
125
|
+
export const applicationSchematic = convertNxGenerator(applicationGenerator);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app": "npx ts-node src/main.ts",
|
|
3
|
+
"output": "<%= offsetFromRoot %>dist/apps/<%= projectName %>",
|
|
4
|
+
"requireApproval": "never",
|
|
5
|
+
"watch": {
|
|
6
|
+
"include": [
|
|
7
|
+
"**"
|
|
8
|
+
],
|
|
9
|
+
"exclude": [
|
|
10
|
+
"README.md",
|
|
11
|
+
"cdk*.json",
|
|
12
|
+
"**/*.d.ts",
|
|
13
|
+
"**/*.js",
|
|
14
|
+
"tsconfig.json",
|
|
15
|
+
"package*.json",
|
|
16
|
+
"yarn.lock",
|
|
17
|
+
"node_modules",
|
|
18
|
+
"test"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"context": {
|
|
22
|
+
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
|
|
23
|
+
"@aws-cdk/core:stackRelativeExports": true,
|
|
24
|
+
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
|
|
25
|
+
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
|
|
26
|
+
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
|
|
27
|
+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
|
|
28
|
+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
|
|
29
|
+
"@aws-cdk/core:checkSecretUsage": true,
|
|
30
|
+
"@aws-cdk/aws-iam:minimizePolicies": true,
|
|
31
|
+
"@aws-cdk/core:target-partitions": [
|
|
32
|
+
"aws",
|
|
33
|
+
"aws-cn"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "<%= offsetFromRoot %>tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
|
6
|
+
"types": ["node", "jest"]
|
|
7
|
+
},
|
|
8
|
+
"include": [],
|
|
9
|
+
"files": [],
|
|
10
|
+
"references": [
|
|
11
|
+
{
|
|
12
|
+
"path": "./tsconfig.app.json"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Stack, App } from 'aws-cdk-lib';
|
|
2
|
+
import { Template } from 'aws-cdk-lib/assertions';
|
|
3
|
+
import { AppStack } from './stacks/app-stack';
|
|
4
|
+
|
|
5
|
+
test('Empty Stack', () => {
|
|
6
|
+
const app = new App();
|
|
7
|
+
// WHEN
|
|
8
|
+
const stack = new AppStack(app, '<%= projectName %>TestStack');
|
|
9
|
+
// THEN
|
|
10
|
+
Template.fromStack(stack as Stack).templateMatches({
|
|
11
|
+
Resources: {}
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"id": "AwsCdk",
|
|
4
|
+
"title": "",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "argv",
|
|
12
|
+
"index": 0
|
|
13
|
+
},
|
|
14
|
+
"x-prompt": "What name would you like to use?"
|
|
15
|
+
},
|
|
16
|
+
"tags": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Add tags to the project (used for linting)",
|
|
19
|
+
"alias": "t"
|
|
20
|
+
},
|
|
21
|
+
"directory": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "A directory where the project is placed",
|
|
24
|
+
"alias": "d"
|
|
25
|
+
},
|
|
26
|
+
"skipFormat": {
|
|
27
|
+
"description": "Skip formatting files",
|
|
28
|
+
"type": "boolean",
|
|
29
|
+
"default": false
|
|
30
|
+
},
|
|
31
|
+
"unitTestRunner": {
|
|
32
|
+
"description": "Adds the specified unit test runner",
|
|
33
|
+
"type": "string",
|
|
34
|
+
"enum": ["jest", "none"],
|
|
35
|
+
"default": "jest"
|
|
36
|
+
},
|
|
37
|
+
"setParserOptionsProject": {
|
|
38
|
+
"type": "boolean",
|
|
39
|
+
"description": "Whether or not to configure the ESLint \"parserOptions.project\" option. We do not do this by default for lint performance reasons.",
|
|
40
|
+
"default": false
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"required": ["name"]
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readJson, Tree } from '@nx/devkit';
|
|
2
|
+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
3
|
+
|
|
4
|
+
import { initGenerator } from './init';
|
|
5
|
+
import { InitGeneratorSchema } from './schema';
|
|
6
|
+
|
|
7
|
+
describe('init', () => {
|
|
8
|
+
let tree: Tree;
|
|
9
|
+
const options: InitGeneratorSchema = {};
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
tree = createTreeWithEmptyWorkspace();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should add aws-cdk dependency', async () => {
|
|
16
|
+
await initGenerator(tree, options);
|
|
17
|
+
const packageJson = readJson(tree, 'package.json');
|
|
18
|
+
|
|
19
|
+
expect(packageJson.dependencies['aws-cdk-lib']).toBeDefined();
|
|
20
|
+
expect(packageJson.dependencies['aws-cdk']).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { addDependenciesToPackageJson, convertNxGenerator, formatFiles, GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { jestInitGenerator } from '@nx/jest';
|
|
3
|
+
|
|
4
|
+
import { InitGeneratorSchema } from './schema';
|
|
5
|
+
import { CDK_CONSTRUCTS_VERSION, CDK_VERSION } from '../../utils/cdk-shared';
|
|
6
|
+
|
|
7
|
+
function normalizeOptions(schema: InitGeneratorSchema) {
|
|
8
|
+
return {
|
|
9
|
+
...schema,
|
|
10
|
+
unitTestRunner: schema.unitTestRunner ?? 'jest',
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function initGenerator(host: Tree, options: InitGeneratorSchema) {
|
|
15
|
+
let jestInstall: GeneratorCallback;
|
|
16
|
+
const schema = normalizeOptions(options);
|
|
17
|
+
|
|
18
|
+
if (schema.unitTestRunner === 'jest') {
|
|
19
|
+
jestInstall = await jestInitGenerator(host, {});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const installTask = addDependenciesToPackageJson(
|
|
23
|
+
host,
|
|
24
|
+
{
|
|
25
|
+
'aws-cdk': CDK_VERSION,
|
|
26
|
+
'aws-cdk-lib': CDK_VERSION,
|
|
27
|
+
constructs: CDK_CONSTRUCTS_VERSION,
|
|
28
|
+
},
|
|
29
|
+
{}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (!schema.skipFormat) {
|
|
33
|
+
await formatFiles(host);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return async () => {
|
|
37
|
+
if (jestInstall) {
|
|
38
|
+
await jestInstall();
|
|
39
|
+
}
|
|
40
|
+
await installTask();
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default initGenerator;
|
|
45
|
+
export const initSchematic = convertNxGenerator(initGenerator);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"id": "AwsCdkInit",
|
|
4
|
+
"title": "Add AWS CDK Schematics",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"unitTestRunner": {
|
|
8
|
+
"description": "Adds the specified unit test runner",
|
|
9
|
+
"type": "string",
|
|
10
|
+
"enum": ["jest", "none"],
|
|
11
|
+
"default": "jest"
|
|
12
|
+
},
|
|
13
|
+
"skipFormat": {
|
|
14
|
+
"description": "Skip formatting files",
|
|
15
|
+
"type": "boolean",
|
|
16
|
+
"default": false
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"required": []
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
|
|
3
|
+
import { DeployExecutorSchema } from '../executors/deploy/schema';
|
|
4
|
+
import { ParsedExecutorInterface } from '../interfaces/parsed-executor.interface';
|
|
5
|
+
import { logger, detectPackageManager } from '@nx/devkit';
|
|
6
|
+
import { BootstrapExecutorSchema } from '../executors/bootstrap/schema';
|
|
7
|
+
import { getPackageJson } from '@nx/eslint-plugin/src/utils/package-json-utils';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
|
|
10
|
+
export const executorPropKeys = ['stacks'];
|
|
11
|
+
export const LARGE_BUFFER = 1024 * 1000000;
|
|
12
|
+
|
|
13
|
+
const NX_WORKSPACE_ROOT = process.env.NX_WORKSPACE_ROOT ?? '';
|
|
14
|
+
if (!NX_WORKSPACE_ROOT) {
|
|
15
|
+
throw new Error('CDK not Found');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function generateCommandString(command: string, appPath: string) {
|
|
19
|
+
const packageManager = detectPackageManager();
|
|
20
|
+
const packageManagerExecutor = packageManager === 'npm' ? 'npx' : packageManager;
|
|
21
|
+
|
|
22
|
+
const projectPath = path.join(NX_WORKSPACE_ROOT, appPath);
|
|
23
|
+
const moduleType = getModuleType(projectPath);
|
|
24
|
+
const tsNodePart = moduleType === 'module' ? '--loader ts-node/esm' : 'ts-node';
|
|
25
|
+
|
|
26
|
+
const generatePath = `"${packageManagerExecutor} ${tsNodePart} --require tsconfig-paths/register --project ${path.join(projectPath, 'tsconfig.app.json')} ${path.join(projectPath, '/src/main.ts')}"`;
|
|
27
|
+
return `node --require ts-node/register ${path.join(NX_WORKSPACE_ROOT, 'node_modules/aws-cdk/bin/cdk')} -a ${generatePath} ${command}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function parseArgs(options: DeployExecutorSchema | BootstrapExecutorSchema): Record<string, string | string[]> {
|
|
31
|
+
const keys = Object.keys(options);
|
|
32
|
+
return keys
|
|
33
|
+
.filter((prop) => executorPropKeys.indexOf(prop) < 0)
|
|
34
|
+
.reduce((acc, key) => {
|
|
35
|
+
acc[key] = options[key];
|
|
36
|
+
return acc;
|
|
37
|
+
}, {});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function createCommand(command: string, options: ParsedExecutorInterface): string {
|
|
41
|
+
console.log('OptionsParsedExecutorInterface', JSON.stringify(options));
|
|
42
|
+
|
|
43
|
+
const nodeCommandWithRelativePath = generateCommandString(command, options.root);
|
|
44
|
+
console.log('nodeCommandWithRelativePath', nodeCommandWithRelativePath);
|
|
45
|
+
const commands = [nodeCommandWithRelativePath];
|
|
46
|
+
|
|
47
|
+
if (typeof options.stacks === 'string') {
|
|
48
|
+
commands.push(options.stacks);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const arg in options.parseArgs) {
|
|
52
|
+
const parsedArg = options.parseArgs[arg];
|
|
53
|
+
if (Array.isArray(parsedArg)) {
|
|
54
|
+
parsedArg.forEach((value) => {
|
|
55
|
+
commands.push(`--${arg} ${value}`);
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
commands.push(`--${arg} ${parsedArg}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return commands.join(' ');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function runCommandProcess(command: string, cwd: string): Promise<boolean> {
|
|
66
|
+
return new Promise((resolve) => {
|
|
67
|
+
logger.debug(`Executing command: ${command}`);
|
|
68
|
+
|
|
69
|
+
const childProcess = exec(command, {
|
|
70
|
+
maxBuffer: LARGE_BUFFER,
|
|
71
|
+
env: process.env,
|
|
72
|
+
cwd: cwd,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Ensure the child process is killed when the parent exits
|
|
76
|
+
const processExitListener = () => childProcess.kill();
|
|
77
|
+
process.on('exit', processExitListener);
|
|
78
|
+
process.on('SIGTERM', processExitListener);
|
|
79
|
+
|
|
80
|
+
process.stdin.on('data', (data) => {
|
|
81
|
+
childProcess.stdin.write(data);
|
|
82
|
+
childProcess.stdin.end();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
childProcess.stdout.on('data', (data) => {
|
|
86
|
+
process.stdout.write(data);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
childProcess.stderr.on('data', (err) => {
|
|
90
|
+
process.stderr.write(err);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
childProcess.on('close', (code) => {
|
|
94
|
+
if (code === 0) {
|
|
95
|
+
resolve(true);
|
|
96
|
+
} else {
|
|
97
|
+
resolve(false);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
process.removeListener('exit', processExitListener);
|
|
101
|
+
|
|
102
|
+
if (process.stdin.isTTY) {
|
|
103
|
+
process.stdin.end();
|
|
104
|
+
}
|
|
105
|
+
process.stdin.removeListener('data', processExitListener);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getModuleType(projectPath: string) {
|
|
111
|
+
const packageJsonPath = path.join(NX_WORKSPACE_ROOT, projectPath, 'package.json');
|
|
112
|
+
const appPackageJson = getPackageJson(packageJsonPath);
|
|
113
|
+
if (appPackageJson?.type) {
|
|
114
|
+
console.log('App Package Json', appPackageJson.type);
|
|
115
|
+
return appPackageJson.type;
|
|
116
|
+
}
|
|
117
|
+
const globalPackageJson = getPackageJson(path.join(NX_WORKSPACE_ROOT, 'package.json'));
|
|
118
|
+
console.log('Global Package Json', globalPackageJson.type);
|
|
119
|
+
return globalPackageJson.type;
|
|
120
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
|
|
3
|
+
export function mockExecutorContext(executorName: string, workspaceVersion = 2): ExecutorContext {
|
|
4
|
+
return {
|
|
5
|
+
projectName: 'proj',
|
|
6
|
+
root: '/root',
|
|
7
|
+
cwd: '/root',
|
|
8
|
+
nxJsonConfiguration: {},
|
|
9
|
+
projectsConfigurations: {
|
|
10
|
+
version: workspaceVersion,
|
|
11
|
+
projects: {
|
|
12
|
+
proj: {
|
|
13
|
+
root: 'apps/proj',
|
|
14
|
+
targets: {
|
|
15
|
+
test: {
|
|
16
|
+
executor: `@wolsok/nx-aws-cdk-v2:${executorName}`,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
projectGraph: { nodes: {}, dependencies: {} },
|
|
23
|
+
target: {
|
|
24
|
+
executor: `@wolsok/nx-aws-cdk-v2:${executorName}`,
|
|
25
|
+
},
|
|
26
|
+
isVerbose: true,
|
|
27
|
+
};
|
|
28
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node"]
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"**/*.spec.ts",
|
|
10
|
+
"**/*.test.ts",
|
|
11
|
+
"**/*.spec.tsx",
|
|
12
|
+
"**/*.test.tsx",
|
|
13
|
+
"**/*.spec.js",
|
|
14
|
+
"**/*.test.js",
|
|
15
|
+
"**/*.spec.jsx",
|
|
16
|
+
"**/*.test.jsx",
|
|
17
|
+
"**/*.d.ts",
|
|
18
|
+
"jest.config.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|