├── .commitlintrc.json
├── .editorconfig
├── .eslintignore
├── .eslintrc.json
├── .gitignore
├── .husky
├── commit-msg
└── pre-commit
├── .nvmrc
├── .prettierignore
├── .prettierrc
├── .verdaccio
└── config.yml
├── .vscode
└── extensions.json
├── CONTRIBUTING.md
├── PULL_REQUEST_TEMPLATE.md
├── README.md
├── e2e
├── nx-aws-cdk-e2e
│ ├── jest.config.js
│ ├── project.json
│ ├── tests
│ │ └── aws-cdk.spec.ts
│ ├── tsconfig.json
│ └── tsconfig.spec.json
└── nx-ncc-e2e
│ ├── .eslintrc.json
│ ├── jest.config.ts
│ ├── project.json
│ ├── src
│ └── nx-ncc.spec.ts
│ ├── tsconfig.json
│ └── tsconfig.spec.json
├── jest.config.ts
├── jest.preset.js
├── nx.json
├── package-lock.json
├── package.json
├── packages
├── nx-aws-cdk
│ ├── .babelrc
│ ├── .eslintrc.json
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── executors.json
│ ├── generators.json
│ ├── jest.config.ts
│ ├── package.json
│ ├── project.json
│ ├── src
│ │ ├── executors
│ │ │ ├── deploy
│ │ │ │ ├── deploy.spec.ts
│ │ │ │ ├── deploy.ts
│ │ │ │ ├── schema.d.ts
│ │ │ │ └── schema.json
│ │ │ └── destroy
│ │ │ │ ├── destroy.spec.ts
│ │ │ │ ├── destroy.ts
│ │ │ │ ├── schema.d.ts
│ │ │ │ └── schema.json
│ │ ├── generators
│ │ │ ├── application
│ │ │ │ ├── application.spec.ts
│ │ │ │ ├── application.ts
│ │ │ │ ├── files
│ │ │ │ │ ├── cdk.json__template__
│ │ │ │ │ ├── src
│ │ │ │ │ │ ├── main.ts__template__
│ │ │ │ │ │ └── stacks
│ │ │ │ │ │ │ └── app-stack.ts__template__
│ │ │ │ │ ├── tsconfig.app.json__template__
│ │ │ │ │ └── tsconfig.json__template__
│ │ │ │ ├── jest-files
│ │ │ │ │ └── src
│ │ │ │ │ │ └── main.test.ts__template__
│ │ │ │ ├── schema.d.ts
│ │ │ │ └── schema.json
│ │ │ └── init
│ │ │ │ ├── init.spec.ts
│ │ │ │ ├── init.ts
│ │ │ │ ├── schema.d.ts
│ │ │ │ └── schema.json
│ │ ├── index.ts
│ │ ├── interfaces
│ │ │ └── parsed-executor.interface.ts
│ │ └── utils
│ │ │ ├── cdk-shared.ts
│ │ │ ├── executor.util.ts
│ │ │ └── testing.ts
│ ├── tsconfig.json
│ ├── tsconfig.lib.json
│ └── tsconfig.spec.json
├── nx-ncc
│ ├── .eslintrc.json
│ ├── README.md
│ ├── executors.json
│ ├── generators.json
│ ├── jest.config.ts
│ ├── package.json
│ ├── project.json
│ ├── src
│ │ ├── executors
│ │ │ └── build
│ │ │ │ ├── executor.spec.ts
│ │ │ │ ├── executor.ts
│ │ │ │ ├── schema.d.ts
│ │ │ │ └── schema.json
│ │ ├── generators
│ │ │ └── init
│ │ │ │ ├── generator.spec.ts
│ │ │ │ ├── generator.ts
│ │ │ │ ├── schema.d.ts
│ │ │ │ └── schema.json
│ │ ├── index.ts
│ │ ├── interfaces
│ │ │ ├── base-executor-schema.interface.ts
│ │ │ └── normalized-executor-schema.interface.ts
│ │ └── utils
│ │ │ ├── create-ncc-command.ts
│ │ │ ├── index.ts
│ │ │ ├── normalize-arguments.ts
│ │ │ ├── normalize-options.ts
│ │ │ ├── should-watch.ts
│ │ │ └── testing.ts
│ ├── tsconfig.json
│ ├── tsconfig.lib.json
│ └── tsconfig.spec.json
└── utils
│ ├── .eslintrc.json
│ ├── README.md
│ ├── jest.config.ts
│ ├── project.json
│ ├── src
│ ├── index.ts
│ └── lib
│ │ └── run-command-process.ts
│ ├── tsconfig.json
│ ├── tsconfig.lib.json
│ └── tsconfig.spec.json
├── project.json
├── tools
├── scripts
│ ├── start-local-registry.ts
│ └── stop-local-registry.ts
└── tsconfig.tools.json
└── tsconfig.base.json
/.commitlintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["@commitlint/config-conventional"],
3 | "rules": {
4 | "subject-case": [2, "always", ["sentence-case", "start-case", "pascal-case", "upper-case", "lower-case"]],
5 | "type-enum": [
6 | 2,
7 | "always",
8 | ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test", "sample"]
9 | ]
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "ignorePatterns": ["**/*"],
4 | "plugins": ["@nx"],
5 | "extends": ["prettier"],
6 | "overrides": [
7 | {
8 | "files": "*.json",
9 | "parser": "jsonc-eslint-parser",
10 | "rules": {}
11 | },
12 | {
13 | "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
14 | "rules": {
15 | "@nx/enforce-module-boundaries": [
16 | "error",
17 | {
18 | "enforceBuildableLibDependency": true,
19 | "allow": [],
20 | "depConstraints": [
21 | {
22 | "sourceTag": "*",
23 | "onlyDependOnLibsWithTags": ["*"]
24 | }
25 | ]
26 | }
27 | ]
28 | }
29 | },
30 | {
31 | "files": ["*.ts", "*.tsx"],
32 | "extends": ["plugin:@nx/typescript"],
33 | "rules": {
34 | "@typescript-eslint/no-extra-semi": "error",
35 | "no-extra-semi": "off"
36 | }
37 | },
38 | {
39 | "files": ["*.js", "*.jsx"],
40 | "extends": ["plugin:@nx/javascript"],
41 | "rules": {
42 | "@typescript-eslint/no-extra-semi": "error",
43 | "no-extra-semi": "off"
44 | }
45 | }
46 | ]
47 | }
48 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | **/tmp
6 | /out-tsc
7 |
8 | # dependencies
9 | /node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | yarn-error.log
34 | testem.log
35 | /typings
36 |
37 | # System Files
38 | .DS_Store
39 | Thumbs.db
40 |
41 | .nx
42 |
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | npx --no-install commitlint --edit $1
5 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | npx lint-staged
5 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | v20.15.1
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | # Add files here to ignore them from prettier formatting
2 |
3 | /dist
4 | /coverage
5 |
6 | /.nx/cache
7 | /.nx/workspace-data
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "bracketSpacing": true,
4 | "useTabs": false,
5 | "tabWidth": 2,
6 | "trailingComma": "es5",
7 | "printWidth": 120
8 | }
9 |
--------------------------------------------------------------------------------
/.verdaccio/config.yml:
--------------------------------------------------------------------------------
1 | # path to a directory with all packages
2 | storage: ../tmp/local-registry/storage
3 |
4 | # a list of other known repositories we can talk to
5 | uplinks:
6 | npmjs:
7 | url: https://registry.npmjs.org/
8 | maxage: 60m
9 |
10 | packages:
11 | '**':
12 | # give all users (including non-authenticated users) full access
13 | # because it is a local registry
14 | access: $all
15 | publish: $all
16 | unpublish: $all
17 |
18 | # if package is not available locally, proxy requests to npm registry
19 | proxy: npmjs
20 |
21 | # log settings
22 | logs:
23 | type: stdout
24 | format: pretty
25 | level: warn
26 |
27 | publish:
28 | allow_offline: true # set offline to true to allow publish offline
29 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "nrwl.angular-console",
4 | "esbenp.prettier-vscode",
5 | "dbaeumer.vscode-eslint",
6 | "firsttris.vscode-jest-runner"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | PR's are are welcome and encouraged in this repository. Read this document to see how to contribute.
4 |
5 | ## Table of Contents
6 |
7 | - [Project Structure](#project-structure)
8 | - [Building a Plugin](#building-a-plugin)
9 | - [Running Unit Tests](#running-unit-tests)
10 | - [Running e2e Tests](#running-e2e-tests)
11 | - [Testing Locally](#testing-locally)
12 | - [Pull Requests](#pull-requests)
13 |
14 | ## Project Structure
15 |
16 | This project is built with Nx and follows the standard project structure. Visit the [Getting Started](https://nx.dev/react/getting-started/what-is-nx) guide to familiarize yourself with Nx workspaces.
17 |
18 | This workspace uses the Nx CLI with npm 6.x
19 |
20 | ## Building a Plugin
21 |
22 | After cloning the project, to install the dependencies, run:
23 |
24 | ```
25 | npm i
26 | ```
27 |
28 | To build a plugin, run:
29 |
30 | ```
31 | npm run build {plugin}
32 | ```
33 |
34 | ## Running Unit Tests
35 |
36 | To run unit tests for a plugin, run:
37 |
38 | ```
39 | npm run test {plugin}
40 | ```
41 |
42 | ## Running e2e Tests
43 |
44 | To run e2e tests for a plugin, run:
45 |
46 | ```
47 | npm run e2e {plugin}
48 | ```
49 |
50 | ## Testing Locally
51 |
52 | To test a plugin locally, build the plugin:
53 |
54 | ```
55 | npm run build {plugin}
56 | ```
57 |
58 | Next, navigate to the build output directory:
59 |
60 | ```
61 | cd dist/packages/{plugin}
62 | ```
63 |
64 | Next, if you want to test the plugin on a project that uses Yarn, run:
65 |
66 | ```
67 | yarn link
68 | ```
69 |
70 | If you want to test the plugin on a project that uses NPM, run:
71 |
72 | ```
73 | npm link
74 | ```
75 |
76 | Finally, in the project that you want to test, run:
77 |
78 | ```
79 | yarn link @codebrew/{plugin}
80 | ```
81 |
82 | Or:
83 |
84 | ```
85 | npm link @codebrew/{plugin}
86 | ```
87 |
88 | # Pull Requests
89 |
90 | Ensure that you have completed the PR checklist in the [pull request template](PULL_REQUEST_TEMPLATE.md) prior to opening a pull request.
91 |
--------------------------------------------------------------------------------
/PULL_REQUEST_TEMPLATE.md :
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | # PR Checklist
4 |
5 | - [ ] Migrations have been added if necessary
6 | - [ ] Unit tests have been added or updated if necessary
7 | - [ ] e2e tests have been added or updated if necessary
8 | - [ ] Changelog has been updated if necessary
9 | - [ ] Documentation has been updated if necessary
10 |
11 | # Issue
12 |
13 | Resolves #
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | [](https://github.com/RichardLitt/standard-readme)
3 |
4 |
5 |
6 | # Codebrew Nx Plugins
7 |
8 | A collection of third-party Nx plugins.
9 |
10 | ## Table of Contents
11 |
12 | - [Codebrew Nx Plugins](#codebrew-nx-plugins)
13 | - [Table of Contents](#table-of-contents)
14 | - [Plugins](#plugins)
15 | - [Maintainers](#maintainers)
16 | - [Contributing](#contributing)
17 | - [License](#license)
18 |
19 | ## Plugins
20 |
21 | | Plugin | Description |
22 | | --------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
23 | | [`@codebrew/nx-aws-cdk`](./packages/nx-aws-cdk/README.md) | An Nx plugin for developing [aws-cdk](https://docs.aws.amazon.com/cdk/latest/guide/home.html) |
24 | | [`@codebrew/nx-ncc`](./packages/nx-ncc/README.md) | nx plugin for [@vercel/ncc](https://github.com/vercel/ncc) |
25 |
26 | ## Maintainers
27 |
28 | [@tienne](https://github.com/tienne)
29 |
30 | ## Contributing
31 |
32 | See [the contributing file](CONTRIBUTING.md)!
33 |
34 | PRs accepted.
35 |
36 | If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
37 |
38 | ## License
39 |
40 | This project is MIT licensed 2021 David Kwon.
41 |
--------------------------------------------------------------------------------
/e2e/nx-aws-cdk-e2e/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | displayName: 'nx-aws-cdk-e2e',
3 | preset: '../../jest.preset.js',
4 | globals: {},
5 | transform: {
6 | '^.+\\.[tj]s$': [
7 | 'ts-jest',
8 | {
9 | tsconfig: '/tsconfig.spec.json',
10 | },
11 | ],
12 | },
13 | moduleFileExtensions: ['ts', 'js', 'html'],
14 | coverageDirectory: '../../coverage/e2e/nx-aws-cdk-e2e',
15 | };
16 |
--------------------------------------------------------------------------------
/e2e/nx-aws-cdk-e2e/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nx-aws-cdk-e2e",
3 | "$schema": "../../node_modules/nx/schemas/project-schema.json",
4 | "projectType": "application",
5 | "sourceRoot": "e2e/nx-aws-cdk-e2e/src",
6 | "targets": {
7 | "e2e": {
8 | "executor": "@nx/jest:jest",
9 | "options": {
10 | "npmPackageName": "@codebrew/nx-aws-cdk",
11 | "pluginOutputPath": "dist/packages/nx-aws-cdk",
12 | "jestConfig": "e2e/nx-aws-cdk-e2e/jest.config.js",
13 | "runInBand": true,
14 | "passWithNoTests": false
15 | },
16 | "dependsOn": ["nx-aws-cdk:build"]
17 | }
18 | },
19 | "tags": [],
20 | "implicitDependencies": ["nx-aws-cdk"]
21 | }
22 |
--------------------------------------------------------------------------------
/e2e/nx-aws-cdk-e2e/tests/aws-cdk.spec.ts:
--------------------------------------------------------------------------------
1 | import { checkFilesExist, ensureNxProject, readJson, runNxCommandAsync, uniq } from '@nx/plugin/testing';
2 |
3 | beforeAll(async () => {
4 | ensureNxProject('@codebrew/nx-aws-cdk', 'dist/packages/nx-aws-cdk');
5 | });
6 |
7 | describe('nx-aws-cdk e2e', () => {
8 | it('should create aws-cdk', async () => {
9 | const plugin = uniq('nx-aws-cdk');
10 |
11 | await runNxCommandAsync(`generate @codebrew/nx-aws-cdk:application ${plugin}`);
12 | }, 120000);
13 |
14 | describe('--directory', () => {
15 | it('should create src in the specified directory', async () => {
16 | const plugin = uniq('nx-aws-cdk');
17 |
18 | await runNxCommandAsync(`generate @codebrew/nx-aws-cdk:application ${plugin} --directory subdir`);
19 | expect(() => checkFilesExist(`subdir/${plugin}/src/main.ts`)).not.toThrow();
20 | }, 120000);
21 | });
22 |
23 | describe('--tags', () => {
24 | it('should add tags to nx.json', async () => {
25 | const plugin = uniq('nx-aws-cdk');
26 |
27 | await runNxCommandAsync(`generate @codebrew/nx-aws-cdk:application ${plugin} --tags e2etag,e2ePackage`);
28 | const projectJson = readJson(`${plugin}/project.json`);
29 | expect(projectJson.tags).toEqual(['e2etag', 'e2ePackage']);
30 | }, 120000);
31 | });
32 | });
33 |
--------------------------------------------------------------------------------
/e2e/nx-aws-cdk-e2e/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.base.json",
3 | "files": [],
4 | "include": [],
5 | "references": [
6 | {
7 | "path": "./tsconfig.e2e.json"
8 | },
9 | {
10 | "path": "./tsconfig.spec.json"
11 | }
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/e2e/nx-aws-cdk-e2e/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "module": "commonjs",
6 | "types": ["jest", "node"]
7 | },
8 | "include": ["**/*.spec.ts", "**/*.d.ts"]
9 | }
10 |
--------------------------------------------------------------------------------
/e2e/nx-ncc-e2e/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["../../.eslintrc.json"],
3 | "ignorePatterns": ["!**/*"],
4 | "overrides": [
5 | {
6 | "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7 | "rules": {}
8 | },
9 | {
10 | "files": ["*.ts", "*.tsx"],
11 | "rules": {}
12 | },
13 | {
14 | "files": ["*.js", "*.jsx"],
15 | "rules": {}
16 | }
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/e2e/nx-ncc-e2e/jest.config.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | export default {
3 | displayName: 'nx-ncc-e2e',
4 | preset: '../../jest.preset.js',
5 | transform: {
6 | '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }],
7 | },
8 | moduleFileExtensions: ['ts', 'js', 'html'],
9 | coverageDirectory: '../../coverage/e2e/nx-ncc-e2e',
10 | globalSetup: '../../tools/scripts/start-local-registry.ts',
11 | globalTeardown: '../../tools/scripts/stop-local-registry.ts',
12 | };
13 |
--------------------------------------------------------------------------------
/e2e/nx-ncc-e2e/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nx-ncc-e2e",
3 | "$schema": "../../node_modules/nx/schemas/project-schema.json",
4 | "projectType": "application",
5 | "sourceRoot": "e2e/nx-ncc-e2e/src",
6 | "implicitDependencies": ["nx-ncc"],
7 | "targets": {
8 | "e2e": {
9 | "executor": "@nx/jest:jest",
10 | "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
11 | "options": {
12 | "jestConfig": "e2e/nx-ncc-e2e/jest.config.ts",
13 | "runInBand": true
14 | },
15 | "dependsOn": ["^build"]
16 | },
17 | "lint": {
18 | "executor": "@nx/eslint:lint"
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/e2e/nx-ncc-e2e/src/nx-ncc.spec.ts:
--------------------------------------------------------------------------------
1 | import { checkFilesExist, ensureNxProject, readJson, runNxCommandAsync, uniq, updateFile } from '@nx/plugin/testing';
2 |
3 | describe('nx-ncc e2e', () => {
4 | beforeAll(async () => {
5 | ensureNxProject('@codebrew/nx-ncc', 'dist/packages/nx-ncc');
6 | });
7 |
8 | it('success build', async () => {
9 | const project = await createTestProject();
10 |
11 | await runNxCommandAsync(`build ${project}`);
12 | expect(() => checkFilesExist(`${project}/dist/index.js`)).not.toThrow();
13 | expect(() => checkFilesExist(`${project}/dist/README.md`)).not.toThrow();
14 | expect(() => checkFilesExist(`${project}/dist/project.json`)).not.toThrow();
15 | }, 120000);
16 | });
17 |
18 | async function createTestProject() {
19 | await runNxCommandAsync('g @codebrew/nx-ncc:init');
20 |
21 | const project = uniq('nx-ncc');
22 |
23 | try {
24 | await runNxCommandAsync(`generate @nx/node:library ${project}`);
25 | } catch (e) {
26 | console.log(e);
27 | }
28 |
29 | const projectJson = readJson(`${project}/project.json`, {
30 | expectComments: true,
31 | allowEmptyContent: false,
32 | });
33 |
34 | projectJson.targets = {
35 | build: {
36 | executor: '@codebrew/nx-ncc:build',
37 | options: {
38 | main: `${project}/src/index.ts`,
39 | outputPath: `${project}/dist`,
40 | assets: [
41 | `${project}/project.json`,
42 | {
43 | input: `${project}/`,
44 | output: '/',
45 | glob: 'README.MD',
46 | },
47 | ],
48 | },
49 | },
50 | serve: {
51 | executor: '@codebrew/nx-ncc:serve',
52 | options: {
53 | main: `${project}/src/index.ts`,
54 | },
55 | },
56 | };
57 |
58 | updateFile(`${project}/project.json`, JSON.stringify(projectJson));
59 |
60 | return project;
61 | }
62 |
--------------------------------------------------------------------------------
/e2e/nx-ncc-e2e/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.base.json",
3 | "files": [],
4 | "include": [],
5 | "references": [
6 | {
7 | "path": "./tsconfig.spec.json"
8 | }
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/e2e/nx-ncc-e2e/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "module": "commonjs",
6 | "types": ["jest", "node"]
7 | },
8 | "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
9 | }
10 |
--------------------------------------------------------------------------------
/jest.config.ts:
--------------------------------------------------------------------------------
1 | const { getJestProjects } = require('@nx/jest');
2 |
3 | export default { projects: [...getJestProjects(), '/e2e/nx-aws-cdk-e2e'] };
4 |
--------------------------------------------------------------------------------
/jest.preset.js:
--------------------------------------------------------------------------------
1 | const nxPreset = require('@nx/jest/preset').default;
2 |
3 | module.exports = {
4 | ...nxPreset,
5 | /* TODO: Update to latest Jest snapshotFormat
6 | * By default Nx has kept the older style of Jest Snapshot formats
7 | * to prevent breaking of any existing tests with snapshots.
8 | * It's recommend you update to the latest format.
9 | * You can do this by removing snapshotFormat property
10 | * and running tests with --update-snapshot flag.
11 | * Example: "nx affected --targets=test --update-snapshot"
12 | * More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
13 | */
14 | snapshotFormat: { escapeString: true, printBasicPrototype: true },
15 | };
16 |
--------------------------------------------------------------------------------
/nx.json:
--------------------------------------------------------------------------------
1 | {
2 | "workspaceLayout": {
3 | "appsDir": "e2e",
4 | "libsDir": "packages"
5 | },
6 | "$schema": "./node_modules/nx/schemas/nx-schema.json",
7 | "targetDefaults": {
8 | "build": {
9 | "dependsOn": ["^build"],
10 | "inputs": ["production", "^production"],
11 | "cache": true
12 | },
13 | "@nx/jest:jest": {
14 | "cache": true,
15 | "inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
16 | "options": {
17 | "passWithNoTests": true
18 | },
19 | "configurations": {
20 | "ci": {
21 | "ci": true,
22 | "codeCoverage": true
23 | }
24 | }
25 | },
26 | "@nx/eslint:lint": {
27 | "inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
28 | "cache": true
29 | },
30 | "@nx/js:tsc": {
31 | "cache": true,
32 | "dependsOn": ["^build"],
33 | "inputs": ["production", "^production"]
34 | }
35 | },
36 | "namedInputs": {
37 | "default": ["{projectRoot}/**/*", "sharedGlobals"],
38 | "sharedGlobals": [],
39 | "production": [
40 | "default",
41 | "!{projectRoot}/.eslintrc.json",
42 | "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
43 | "!{projectRoot}/tsconfig.spec.json",
44 | "!{projectRoot}/jest.config.[jt]s",
45 | "!{projectRoot}/src/test-setup.[jt]s"
46 | ]
47 | },
48 | "parallel": 1,
49 | "useInferencePlugins": false,
50 | "defaultBase": "master"
51 | }
52 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codebrew/sources",
3 | "description": "A collection of third-party Nx plugins",
4 | "author": {
5 | "name": "Devin Kwon",
6 | "email": "tienne89@gmail.com"
7 | },
8 | "license": "MIT",
9 | "homepage": "https://github.com/codebrewlab/nx-plugins",
10 | "repository": {
11 | "type": "git",
12 | "url": "git+https://github.com/codebrewlab/nx-plugins.git"
13 | },
14 | "scripts": {
15 | "nx": "nx",
16 | "ncc": "ncc",
17 | "lint-stage": "lint-staged",
18 | "commitlint": "commitlint",
19 | "is-ci": "is-ci",
20 | "test": "nx test",
21 | "lint": "nx workspace-lint && nx lint",
22 | "e2e": "nx e2e",
23 | "build:aws-cdk": "nx build nx-aws-cdk",
24 | "link:aws-cdk": "cd dist/packages/nx-aws-cdk && npm link",
25 | "prepare": "husky install"
26 | },
27 | "private": true,
28 | "dependencies": {
29 | "tslib": "^2.0.0"
30 | },
31 | "devDependencies": {
32 | "@commitlint/cli": "^13.2.1",
33 | "@commitlint/config-conventional": "^13.2.0",
34 | "@jscutlery/semver": "^5.3.1",
35 | "@nx/devkit": "19.6.3",
36 | "@nx/eslint": "19.6.3",
37 | "@nx/eslint-plugin": "19.6.3",
38 | "@nx/jest": "19.6.3",
39 | "@nx/js": "19.6.3",
40 | "@nx/node": "19.6.3",
41 | "@nx/plugin": "19.6.3",
42 | "@nx/workspace": "19.6.3",
43 | "@swc-node/register": "1.9.2",
44 | "@swc/cli": "~0.3.12",
45 | "@swc/core": "1.5.7",
46 | "@swc/helpers": "~0.5.11",
47 | "@types/jest": "29.5.12",
48 | "@types/node": "18.19.9",
49 | "@typescript-eslint/eslint-plugin": "7.18.0",
50 | "@typescript-eslint/parser": "7.18.0",
51 | "dotenv": "10.0.0",
52 | "eslint": "8.57.0",
53 | "eslint-config-prettier": "9.1.0",
54 | "husky": "^7.0.0",
55 | "is-ci": "^3.0.0",
56 | "jest": "29.7.0",
57 | "jest-environment-jsdom": "29.7.0",
58 | "jest-environment-node": "^29.7.0",
59 | "lint-staged": "^11.2.3",
60 | "nx": "19.6.3",
61 | "prettier": "2.8.8",
62 | "ts-jest": "29.1.5",
63 | "ts-node": "10.9.1",
64 | "tslib": "^2.3.0",
65 | "typescript": "5.5.4",
66 | "verdaccio": "^5.0.4"
67 | },
68 | "lint-staged": {
69 | "*.{js,json,css,scss,md,ts,html,graphql}": [
70 | "nx affected:lint --uncommitted --parallel --fix=true",
71 | "nx format:write --uncommitted"
72 | ]
73 | },
74 | "nx": {
75 | "includedScripts": []
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "@nx/js/babel",
5 | {
6 | "useBuiltIns": "usage"
7 | }
8 | ]
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["../../.eslintrc.json"],
3 | "ignorePatterns": ["!**/*"],
4 | "overrides": [
5 | {
6 | "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7 | "rules": {}
8 | },
9 | {
10 | "files": ["*.ts", "*.tsx"],
11 | "rules": {}
12 | },
13 | {
14 | "files": ["*.js", "*.jsx"],
15 | "rules": {}
16 | }
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4 |
5 | ## 2.0.0 (2024-08-27)
6 |
7 | ## 1.0.0 (2024-08-27)
8 |
9 | - chore: migrate 14.8.6 ([5ea5d38](https://github.com/codebrewlab/nx-plugins/commit/5ea5d38))
10 | - chore: nx migrate 13.10.6 ([08bf0e0](https://github.com/codebrewlab/nx-plugins/commit/08bf0e0))
11 | - chore: nx migrate 15.9.7 ([820fc52](https://github.com/codebrewlab/nx-plugins/commit/820fc52))
12 | - chore: nx migrate 16.10.0 ([5477ff8](https://github.com/codebrewlab/nx-plugins/commit/5477ff8))
13 | - chore: nx migrate 17.3.2 ([7925d6d](https://github.com/codebrewlab/nx-plugins/commit/7925d6d))
14 | - chore(aws-cdk): add license info ([6385c22](https://github.com/codebrewlab/nx-plugins/commit/6385c22))
15 | - chore(release): 0.1.0 ([6a560cd](https://github.com/codebrewlab/nx-plugins/commit/6a560cd))
16 | - chore(release): 0.1.1 ([dcecfb7](https://github.com/codebrewlab/nx-plugins/commit/dcecfb7))
17 | - chore(release): 1.0.0 ([98c9de1](https://github.com/codebrewlab/nx-plugins/commit/98c9de1))
18 | - chore(release): 1.0.1 ([a76cb78](https://github.com/codebrewlab/nx-plugins/commit/a76cb78))
19 | - chore(release): 1.0.2 ([7f8998d](https://github.com/codebrewlab/nx-plugins/commit/7f8998d))
20 | - chore(release): 1.0.3 ([e68a947](https://github.com/codebrewlab/nx-plugins/commit/e68a947))
21 | - fix(aws-cdk): executor stdin fix ([b5ef5c7](https://github.com/codebrewlab/nx-plugins/commit/b5ef5c7))
22 | - fix(aws-cdk): fix nx linter (#2) ([58673ae](https://github.com/codebrewlab/nx-plugins/commit/58673ae)), closes [#2](https://github.com/codebrewlab/nx-plugins/issues/2)
23 | - fix(aws-cdk): miss await in destroy executor ([23e1815](https://github.com/codebrewlab/nx-plugins/commit/23e1815))
24 | - fix(nx-aws-cdk): fix destroy executor (#4) ([2f48bc0](https://github.com/codebrewlab/nx-plugins/commit/2f48bc0)), closes [#4](https://github.com/codebrewlab/nx-plugins/issues/4)
25 | - test(aws-cdk): logger info to debug ([be3b4c7](https://github.com/codebrewlab/nx-plugins/commit/be3b4c7))
26 | - feat(aws-cdk): deploy, destroy executor add option ([b48e374](https://github.com/codebrewlab/nx-plugins/commit/b48e374))
27 | - feat(aws-cdk): generator, executor complete ([84dd16a](https://github.com/codebrewlab/nx-plugins/commit/84dd16a))
28 |
29 | ## 1.0.0 (2024-08-27)
30 |
31 | - chore: migrate 14.8.6 ([5ea5d38](https://github.com/codebrewlab/nx-plugins/commit/5ea5d38))
32 | - chore: nx migrate 13.10.6 ([08bf0e0](https://github.com/codebrewlab/nx-plugins/commit/08bf0e0))
33 | - chore: nx migrate 15.9.7 ([820fc52](https://github.com/codebrewlab/nx-plugins/commit/820fc52))
34 | - chore: nx migrate 16.10.0 ([5477ff8](https://github.com/codebrewlab/nx-plugins/commit/5477ff8))
35 | - chore: nx migrate 17.3.2 ([7925d6d](https://github.com/codebrewlab/nx-plugins/commit/7925d6d))
36 | - chore(aws-cdk): add license info ([6385c22](https://github.com/codebrewlab/nx-plugins/commit/6385c22))
37 | - chore(release): 0.1.0 ([6a560cd](https://github.com/codebrewlab/nx-plugins/commit/6a560cd))
38 | - chore(release): 0.1.1 ([dcecfb7](https://github.com/codebrewlab/nx-plugins/commit/dcecfb7))
39 | - chore(release): 1.0.0 ([98c9de1](https://github.com/codebrewlab/nx-plugins/commit/98c9de1))
40 | - chore(release): 1.0.1 ([a76cb78](https://github.com/codebrewlab/nx-plugins/commit/a76cb78))
41 | - chore(release): 1.0.2 ([7f8998d](https://github.com/codebrewlab/nx-plugins/commit/7f8998d))
42 | - chore(release): 1.0.3 ([e68a947](https://github.com/codebrewlab/nx-plugins/commit/e68a947))
43 | - fix(aws-cdk): executor stdin fix ([b5ef5c7](https://github.com/codebrewlab/nx-plugins/commit/b5ef5c7))
44 | - fix(aws-cdk): fix nx linter (#2) ([58673ae](https://github.com/codebrewlab/nx-plugins/commit/58673ae)), closes [#2](https://github.com/codebrewlab/nx-plugins/issues/2)
45 | - fix(aws-cdk): miss await in destroy executor ([23e1815](https://github.com/codebrewlab/nx-plugins/commit/23e1815))
46 | - fix(nx-aws-cdk): fix destroy executor (#4) ([2f48bc0](https://github.com/codebrewlab/nx-plugins/commit/2f48bc0)), closes [#4](https://github.com/codebrewlab/nx-plugins/issues/4)
47 | - test(aws-cdk): logger info to debug ([be3b4c7](https://github.com/codebrewlab/nx-plugins/commit/be3b4c7))
48 | - feat(aws-cdk): deploy, destroy executor add option ([b48e374](https://github.com/codebrewlab/nx-plugins/commit/b48e374))
49 | - feat(aws-cdk): generator, executor complete ([84dd16a](https://github.com/codebrewlab/nx-plugins/commit/84dd16a))
50 |
51 | ## [1.0.3](https://github.com/codebrewlab/nx-plugins/compare/v1.0.2...v1.0.3) (2022-01-28)
52 |
53 | ### Bug Fixes
54 |
55 | - **aws-cdk:** executor stdin fix ([b5ef5c7](https://github.com/codebrewlab/nx-plugins/commit/b5ef5c70283fc4652d86138b0470d40dba055ec9))
56 | - **aws-cdk:** miss await in destroy executor ([23e1815](https://github.com/codebrewlab/nx-plugins/commit/23e18151f5075ab32ef2c8f0a86712806f267ae1))
57 |
58 | ## [1.0.2](https://github.com/codebrewlab/nx-plugins/compare/v1.0.0...v1.0.1) (2021-11-22)
59 |
60 | ### Bug Fixes
61 |
62 | - **aws-cdk:** fix destroy executor ([#3](https://github.com/codebrewlab/nx-plugins/issues/3))
63 |
64 | ## [1.0.1](https://github.com/codebrewlab/nx-plugins/compare/v1.0.0...v1.0.1) (2021-11-22)
65 |
66 | ### Bug Fixes
67 |
68 | - **aws-cdk:** fix nx linter ([#2](https://github.com/codebrewlab/nx-plugins/issues/2)) ([58673ae](https://github.com/codebrewlab/nx-plugins/commit/58673aeb961d9745d8327b920884b3e1c649859b))
69 |
70 | # [1.0.0](https://github.com/codebrewlab/nx-plugins/compare/v0.1.1...v1.0.0) (2021-11-17)
71 |
72 | ### Features
73 |
74 | - **aws-cdk:** deploy, destroy executor add option ([b48e374](https://github.com/codebrewlab/nx-plugins/commit/b48e374daa68a7f69db54421e66d197dd2fc1fd3))
75 |
76 | ## [0.1.1](https://github.com/codebrewlab/nx-plugins/compare/v0.1.0...v0.1.1) (2021-10-16)
77 |
78 | # 0.1.0 (2021-10-16)
79 |
80 | ### Features
81 |
82 | - **aws-cdk:** generator, executor complete ([84dd16a](https://github.com/codebrewlab/nx-plugins/commit/84dd16abdf2bb7595ae6f38f9cd028b7b17c860e))
83 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/RichardLitt/standard-readme)
2 | [](https://github.com/codebrewlab/nx-plugins/tree/master/packages/nx-aws-cdk)
3 | [](https://www.typescriptlang.org/)
4 | [](https://www.npmjs.com/package/@codebrew/nx-aws-cdk)
5 | [](https://www.npmjs.com/package/@codebrew/nx-aws-cdk)
6 | [](https://www.npmjs.com/package/@codebrew/nx-aws-cdk)
7 |
8 |
9 |
10 | # @codebrew/nx-aws-cdk
11 |
12 | An Nx plugin for developing [aws-cdk](https://docs.aws.amazon.com/cdk/latest/guide/home.html)
13 |
14 | ## Table of Contents
15 |
16 | - [Install](#install)
17 | - [Usage](#usage)
18 | - [Generate Application](#generate-application)
19 | - [Targets](#targets)
20 | - [Maintainers](#maintainers)
21 | - [Contributing](#contributing)
22 | - [License](#license)
23 |
24 | ## Install
25 |
26 | ```shell
27 | # npm
28 | npm install --save-dev @codebrew/nx-aws-cdk
29 |
30 | # yarn
31 | yarn add --dev @codebrew/nx-aws-cdk
32 | ```
33 |
34 | ## Usage
35 |
36 | ### Generate Application
37 |
38 | Create Aws Cdk Application
39 |
40 | ```shell
41 | nx generate @codebrew/nx-aws-cdk:application myApp
42 | ```
43 |
44 | you can customize it further by passing these options:
45 |
46 | ```
47 | nx generate @codebrew/nx-aws-cdk:application [name] [options,...]
48 |
49 | Options:
50 | --name
51 | --tags Add tags to the project (used for linting)
52 | --directory A directory where the project is placed
53 | --skipFormat Skip formatting files
54 | --unitTestRunner Adds the specified unit test runner (default: jest)
55 | --linter The tool to use for running lint checks. (default: eslint)
56 | --setParserOptionsProject Whether or not to configure the ESLint "parserOptions.project" option. We do not do this by default for lint performance reasons.
57 | --dryRun Runs through and reports activity without writing to disk.
58 | --skip-nx-cache Skip the use of Nx cache.
59 | --help Show available options for project target.
60 | ```
61 |
62 | ### Targets
63 |
64 | Generated applications expose several functions to the CLI that allow users to deploy, destroy and so on.
65 |
66 | ```shell
67 | nx deploy {Project Name}
68 | nx destroy {Project Name}
69 | ```
70 |
71 | ## Maintainers
72 |
73 | [@tienne](https://github.com/tienne)
74 |
75 | ## Contributing
76 |
77 | See [the contributing file](../../contributing.md)!
78 |
79 | PRs accepted.
80 |
81 | If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
82 |
83 | ## License
84 |
85 | This project is MIT licensed 2021 David Kwon.
86 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/executors.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/schema",
3 | "executors": {
4 | "deploy": {
5 | "implementation": "./src/executors/deploy/deploy",
6 | "schema": "./src/executors/deploy/schema.json",
7 | "description": "build executor"
8 | },
9 | "destroy": {
10 | "implementation": "./src/executors/destroy/destroy",
11 | "schema": "./src/executors/destroy/schema.json",
12 | "description": "destroy executor"
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/generators.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/schema",
3 | "name": "nx-aws-cdk",
4 | "version": "0.0.1",
5 | "generators": {
6 | "init": {
7 | "factory": "./src/generators/init/init",
8 | "schema": "./src/generators/init/schema.json",
9 | "description": "init generator",
10 | "hidden": true
11 | },
12 | "application": {
13 | "factory": "./src/generators/application/application",
14 | "schema": "./src/generators/application/schema.json",
15 | "description": "create aws-cdk application"
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/jest.config.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | export default {
3 | displayName: 'nx-aws-cdk',
4 | preset: '../../jest.preset.js',
5 | globals: {},
6 | testEnvironment: 'node',
7 | transform: {
8 | '^.+\\.[tj]sx?$': [
9 | 'ts-jest',
10 | {
11 | tsconfig: '/tsconfig.spec.json',
12 | },
13 | ],
14 | },
15 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
16 | coverageDirectory: '../../coverage/packages/nx-aws-cdk',
17 | };
18 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codebrew/nx-aws-cdk",
3 | "version": "0.0.0-e2e",
4 | "main": "src/index.js",
5 | "generators": "./generators.json",
6 | "executors": "./executors.json",
7 | "keywords": [
8 | "nx",
9 | "aws-cdk",
10 | "monorepo",
11 | "aws cdk",
12 | "Node"
13 | ],
14 | "ng-update": {
15 | "requirements": {},
16 | "migrations": "./migrations.json"
17 | },
18 | "author": "David Kwon",
19 | "repository": {
20 | "type": "git",
21 | "url": "git@github.com:codebrewlab/nx-plugins.git"
22 | },
23 | "license": "MIT",
24 | "dependencies": {}
25 | }
26 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nx-aws-cdk",
3 | "$schema": "../../node_modules/nx/schemas/project-schema.json",
4 | "sourceRoot": "packages/nx-aws-cdk/src",
5 | "projectType": "library",
6 | "targets": {
7 | "lint": {
8 | "executor": "@nx/eslint:lint",
9 | "outputs": ["{options.outputFile}"]
10 | },
11 | "test": {
12 | "executor": "@nx/jest:jest",
13 | "outputs": ["{workspaceRoot}/coverage/packages/nx-aws-cdk"],
14 | "options": {
15 | "jestConfig": "packages/nx-aws-cdk/jest.config.ts"
16 | }
17 | },
18 | "build": {
19 | "executor": "@nx/js:tsc",
20 | "outputs": ["{options.outputPath}"],
21 | "options": {
22 | "outputPath": "dist/packages/nx-aws-cdk",
23 | "tsConfig": "packages/nx-aws-cdk/tsconfig.lib.json",
24 | "packageJson": "packages/nx-aws-cdk/package.json",
25 | "main": "packages/nx-aws-cdk/src/index.ts",
26 | "assets": [
27 | "packages/nx-aws-cdk/*.md",
28 | {
29 | "input": "./packages/nx-aws-cdk/src",
30 | "glob": "**/!(*.ts)",
31 | "output": "./src"
32 | },
33 | {
34 | "input": "./packages/nx-aws-cdk/src",
35 | "glob": "**/*.d.ts",
36 | "output": "./src"
37 | },
38 | {
39 | "input": "./packages/nx-aws-cdk",
40 | "glob": "generators.json",
41 | "output": "."
42 | },
43 | {
44 | "input": "./packages/nx-aws-cdk",
45 | "glob": "executors.json",
46 | "output": "."
47 | }
48 | ]
49 | }
50 | },
51 | "version": {
52 | "executor": "@jscutlery/semver:version",
53 | "options": {
54 | "postTargets": ["nx-aws-cdk:github"],
55 | "versionTagPrefix": "v"
56 | }
57 | },
58 | "github": {
59 | "executor": "@jscutlery/semver:github",
60 | "options": {
61 | "tag": "${tag}",
62 | "notesFile": "packages/nx-aws-cdk/CHANGELOG.md"
63 | }
64 | },
65 | "npm": {
66 | "executor": "ngx-deploy-npm:deploy",
67 | "options": {
68 | "access": "public",
69 | "distFolderPath": "dist/packages/nx-aws-cdk"
70 | }
71 | }
72 | },
73 | "tags": []
74 | }
75 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/executors/deploy/deploy.spec.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import * as childProcess from 'child_process';
3 | import { logger } from '@nx/devkit';
4 |
5 | import executor from './deploy';
6 | import { DeployExecutorSchema } from './schema';
7 | import { LARGE_BUFFER } from '../../utils/executor.util';
8 | import { mockExecutorContext } from '../../utils/testing';
9 |
10 | const options: DeployExecutorSchema = {};
11 |
12 | describe('nx-aws-cdk deploy Executor', () => {
13 | const context = mockExecutorContext('deploy');
14 |
15 | beforeEach(async () => {
16 | jest.spyOn(logger, 'debug');
17 | jest.spyOn(childProcess, 'exec');
18 | });
19 |
20 | afterEach(() => jest.clearAllMocks());
21 |
22 | it('run cdk deploy command', async () => {
23 | await executor(options, context);
24 |
25 | expect(childProcess.exec).toHaveBeenCalledWith(
26 | 'cdk deploy',
27 | expect.objectContaining({
28 | cwd: expect.stringContaining(path.join(context.root, context.workspace.projects['proj'].root)),
29 | env: process.env,
30 | maxBuffer: LARGE_BUFFER,
31 | })
32 | );
33 | expect(logger.debug).toHaveBeenLastCalledWith(`Executing command: cdk deploy`);
34 | });
35 |
36 | it('run cdk deploy command stack', async () => {
37 | const option: any = Object.assign({}, options);
38 | const stackName = 'test';
39 | option['stacks'] = stackName;
40 | await executor(option, context);
41 |
42 | expect(childProcess.exec).toHaveBeenCalledWith(
43 | `cdk deploy ${stackName}`,
44 | expect.objectContaining({
45 | env: process.env,
46 | maxBuffer: LARGE_BUFFER,
47 | })
48 | );
49 |
50 | expect(logger.debug).toHaveBeenLastCalledWith(`Executing command: cdk deploy ${stackName}`);
51 | });
52 |
53 | it('run cdk deploy command context options', async () => {
54 | const option: any = Object.assign({}, options);
55 | const contextOptionString = 'key=value';
56 | option['context'] = contextOptionString;
57 | await executor(option, context);
58 |
59 | expect(childProcess.exec).toHaveBeenCalledWith(
60 | `cdk deploy --context ${contextOptionString}`,
61 | expect.objectContaining({
62 | env: process.env,
63 | maxBuffer: LARGE_BUFFER,
64 | })
65 | );
66 |
67 | expect(logger.debug).toHaveBeenLastCalledWith(`Executing command: cdk deploy --context ${contextOptionString}`);
68 | });
69 | });
70 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/executors/deploy/deploy.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import type { ExecutorContext } from '@nx/devkit';
3 |
4 | import { DeployExecutorSchema } from './schema';
5 | import { createCommand, parseArgs } from '../../utils/executor.util';
6 | import { ParsedExecutorInterface } from '../../interfaces/parsed-executor.interface';
7 | import { runCommandProcess } from '@codebrew/utils';
8 |
9 | export interface ParsedDeployExecutorOption extends ParsedExecutorInterface {
10 | parseArgs?: Record;
11 | stacks?: string[];
12 | sourceRoot: string;
13 | root: string;
14 | }
15 |
16 | export default async function runExecutor(options: DeployExecutorSchema, context: ExecutorContext) {
17 | const normalizedOptions = normalizeOptions(options, context);
18 | const result = await runDeploy(normalizedOptions, context);
19 |
20 | return {
21 | success: result,
22 | };
23 | }
24 |
25 | async function runDeploy(options: ParsedDeployExecutorOption, context: ExecutorContext) {
26 | const command = createCommand('deploy', options);
27 | return runCommandProcess(command, path.join(context.root, options.root));
28 | }
29 |
30 | function normalizeOptions(options: DeployExecutorSchema, context: ExecutorContext): ParsedDeployExecutorOption {
31 | const parsedArgs = parseArgs(options);
32 | let stacks;
33 |
34 | if (Object.prototype.hasOwnProperty.call(options, 'stacks')) {
35 | stacks = options.stacks;
36 | }
37 |
38 | const { sourceRoot, root } = context.workspace.projects[context.projectName];
39 |
40 | return {
41 | ...options,
42 | parseArgs: parsedArgs,
43 | stacks,
44 | sourceRoot,
45 | root,
46 | };
47 | }
48 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/executors/deploy/schema.d.ts:
--------------------------------------------------------------------------------
1 | export interface DeployExecutorSchema {
2 | stacks?: string;
3 | }
4 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/executors/deploy/schema.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 2,
3 | "outputCapture": "direct-nodejs",
4 | "$schema": "http://json-schema.org/schema",
5 | "title": "deploy executor",
6 | "description": "",
7 | "type": "object",
8 | "properties": {
9 | "stacks": {
10 | "type": "string",
11 | "description": "use deploy named STACKS"
12 | }
13 | },
14 | "required": []
15 | }
16 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/executors/destroy/destroy.spec.ts:
--------------------------------------------------------------------------------
1 | import * as childProcess from 'child_process';
2 | import * as path from 'path';
3 |
4 | import { logger } from '@nx/devkit';
5 |
6 | import { DestroyExecutorSchema } from './schema';
7 | import executor from './destroy';
8 | import { LARGE_BUFFER } from '../../utils/executor.util';
9 | import { mockExecutorContext } from '../../utils/testing';
10 |
11 | const options: DestroyExecutorSchema = {};
12 |
13 | describe('nx-aws-cdk Destroy Executor', () => {
14 | const context = mockExecutorContext('destroy');
15 |
16 | beforeEach(async () => {
17 | jest.spyOn(logger, 'debug');
18 | jest.spyOn(childProcess, 'exec');
19 | });
20 |
21 | afterEach(() => jest.clearAllMocks());
22 |
23 | it('run cdk destroy command', async () => {
24 | await executor(options, context);
25 |
26 | expect(childProcess.exec).toHaveBeenCalledWith(
27 | 'cdk destroy',
28 | expect.objectContaining({
29 | cwd: expect.stringContaining(path.join(context.root, context.workspace.projects['proj'].root)),
30 | env: process.env,
31 | maxBuffer: LARGE_BUFFER,
32 | })
33 | );
34 |
35 | expect(logger.debug).toHaveBeenLastCalledWith(`Executing command: cdk destroy`);
36 | });
37 |
38 | it('run cdk destroy command stack', async () => {
39 | const option: any = Object.assign({}, options);
40 | const stackName = 'test';
41 | option['stacks'] = stackName;
42 | await executor(option, context);
43 |
44 | expect(childProcess.exec).toHaveBeenCalledWith(
45 | `cdk destroy ${stackName}`,
46 | expect.objectContaining({
47 | env: process.env,
48 | maxBuffer: LARGE_BUFFER,
49 | })
50 | );
51 |
52 | expect(logger.debug).toHaveBeenLastCalledWith(`Executing command: cdk destroy ${stackName}`);
53 | });
54 | });
55 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/executors/destroy/destroy.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 |
3 | import { DestroyExecutorSchema } from './schema';
4 | import { createCommand, parseArgs } from '../../utils/executor.util';
5 | import { ParsedExecutorInterface } from '../../interfaces/parsed-executor.interface';
6 | import type { ExecutorContext } from '@nx/devkit';
7 | import { runCommandProcess } from '@codebrew/utils';
8 |
9 | export interface ParsedDestroyExecutorOption extends ParsedExecutorInterface {
10 | parseArgs?: Record;
11 | stacks?: string[];
12 | app?: string;
13 | sourceRoot: string;
14 | root: string;
15 | }
16 |
17 | export default async function runExecutor(options: DestroyExecutorSchema, context: ExecutorContext) {
18 | const normalizedOptions = normalizeOptions(options, context);
19 | const result = await runDestroy(normalizedOptions, context);
20 |
21 | return {
22 | success: result,
23 | };
24 | }
25 |
26 | function runDestroy(options: ParsedDestroyExecutorOption, context: ExecutorContext) {
27 | const command = createCommand('destroy', options);
28 | return runCommandProcess(command, path.join(context.root, options.root));
29 | }
30 |
31 | function normalizeOptions(options: DestroyExecutorSchema, context: ExecutorContext): ParsedDestroyExecutorOption {
32 | const parsedArgs = parseArgs(options);
33 | let stacks;
34 |
35 | if (Object.prototype.hasOwnProperty.call(options, 'stacks')) {
36 | stacks = options.stacks;
37 | }
38 |
39 | const { sourceRoot, root } = context.workspace.projects[context.projectName];
40 |
41 | return {
42 | ...options,
43 | parseArgs: parsedArgs,
44 | stacks,
45 | sourceRoot,
46 | root,
47 | };
48 | }
49 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/executors/destroy/schema.d.ts:
--------------------------------------------------------------------------------
1 | export interface DestroyExecutorSchema {
2 | stacks?: string;
3 | }
4 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/executors/destroy/schema.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 2,
3 | "outputCapture": "direct-nodejs",
4 | "$schema": "http://json-schema.org/schema",
5 | "title": "Destroy executor",
6 | "description": "",
7 | "type": "object",
8 | "properties": {
9 | "stacks": {
10 | "type": "string",
11 | "description": "use destroy named STACKS"
12 | }
13 | },
14 | "required": []
15 | }
16 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/application.spec.ts:
--------------------------------------------------------------------------------
1 | import { createTreeWithEmptyV1Workspace } 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 = createTreeWithEmptyV1Workspace();
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 | });
31 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/application.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import {
3 | addProjectConfiguration,
4 | convertNxGenerator,
5 | formatFiles,
6 | generateFiles,
7 | GeneratorCallback,
8 | getWorkspaceLayout,
9 | joinPathFragments,
10 | names,
11 | offsetFromRoot,
12 | ProjectConfiguration,
13 | runTasksInSerial,
14 | Tree,
15 | updateJson,
16 | } from '@nx/devkit';
17 | import { Linter, lintProjectGenerator } from '@nx/eslint';
18 |
19 | import { ApplicationSchema } from './schema';
20 | import { initGenerator } from '../init/init';
21 | import configurationGenerator from '@nx/jest/src/generators/configuration/configuration';
22 |
23 | interface NormalizedSchema extends ApplicationSchema {
24 | projectName: string;
25 | projectRoot: string;
26 | projectDirectory: string;
27 | parsedTags: string[];
28 | }
29 |
30 | function normalizeOptions(host: Tree, options: ApplicationSchema): NormalizedSchema {
31 | const name = names(options.name).fileName;
32 | const projectDirectory = options.directory ? `${names(options.directory).fileName}/${name}` : name;
33 | const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
34 | const projectRoot = `${getWorkspaceLayout(host).appsDir}/${projectDirectory}`;
35 | const parsedTags = options.tags ? options.tags.split(',').map((s) => s.trim()) : [];
36 |
37 | return {
38 | ...options,
39 | projectName,
40 | projectRoot,
41 | projectDirectory,
42 | parsedTags,
43 | linter: options.linter ?? Linter.EsLint,
44 | unitTestRunner: options.unitTestRunner ?? 'jest',
45 | };
46 | }
47 |
48 | function addFiles(host: Tree, options: NormalizedSchema) {
49 | const templateOptions = {
50 | ...options,
51 | ...names(options.projectName),
52 | offsetFromRoot: offsetFromRoot(options.projectRoot),
53 | template: '',
54 | };
55 |
56 | generateFiles(host, path.join(__dirname, 'files'), options.projectRoot, templateOptions);
57 | }
58 |
59 | function addJestFiles(host: Tree, options: NormalizedSchema) {
60 | const templateOptions = {
61 | ...options,
62 | ...names(options.projectName),
63 | offsetFromRoot: offsetFromRoot(options.projectRoot),
64 | template: '',
65 | };
66 | generateFiles(host, path.join(__dirname, 'jest-files'), options.projectRoot, templateOptions);
67 | }
68 | async function addLintingToApplication(tree: Tree, options: NormalizedSchema): Promise {
69 | return await lintProjectGenerator(tree, {
70 | linter: options.linter,
71 | project: options.projectName,
72 | tsConfigPaths: [joinPathFragments(options.projectRoot, 'tsconfig.*?.json')],
73 | eslintFilePatterns: [`${options.projectRoot}/**/*.ts`],
74 | skipFormat: true,
75 | setParserOptionsProject: options.setParserOptionsProject,
76 | });
77 | }
78 |
79 | function updateLintConfig(tree: Tree, options: NormalizedSchema) {
80 | updateJson(tree, `${options.projectRoot}/.eslintrc.json`, (json) => {
81 | json.plugins = json?.plugins || [];
82 | const plugins: string[] = json.plugins;
83 |
84 | const hasCdkPlugin = plugins.findIndex((row) => row === 'cdk') >= 0;
85 | if (!hasCdkPlugin) {
86 | plugins.push('cdk');
87 | }
88 | return json;
89 | });
90 | }
91 |
92 | export async function applicationGenerator(host: Tree, options: ApplicationSchema) {
93 | const tasks: GeneratorCallback[] = [];
94 | const normalizedOptions = normalizeOptions(host, options);
95 | const initTask = await initGenerator(host, {
96 | ...options,
97 | skipFormat: true,
98 | });
99 |
100 | tasks.push(initTask);
101 |
102 | const project: ProjectConfiguration = {
103 | root: normalizedOptions.projectRoot,
104 | projectType: 'application',
105 | sourceRoot: `${normalizedOptions.projectRoot}/src`,
106 | targets: {
107 | deploy: {
108 | executor: '@codebrew/nx-aws-cdk:deploy',
109 | options: {},
110 | },
111 | destroy: {
112 | executor: '@codebrew/nx-aws-cdk:destroy',
113 | options: {},
114 | },
115 | },
116 | tags: normalizedOptions.parsedTags,
117 | };
118 | addProjectConfiguration(host, normalizedOptions.projectName, project);
119 | addFiles(host, normalizedOptions);
120 |
121 | if (normalizedOptions.linter !== Linter.None) {
122 | const lintTask = await addLintingToApplication(host, normalizedOptions);
123 | tasks.push(lintTask);
124 | updateLintConfig(host, normalizedOptions);
125 | }
126 |
127 | if (normalizedOptions.unitTestRunner === 'jest') {
128 | const jestTask = await configurationGenerator(host, {
129 | project: normalizedOptions.projectName,
130 | setupFile: 'none',
131 | skipSerializers: true,
132 | supportTsx: false,
133 | babelJest: false,
134 | testEnvironment: 'node',
135 | skipFormat: true,
136 | });
137 | tasks.push(jestTask);
138 | addJestFiles(host, normalizedOptions);
139 | }
140 |
141 | if (!options.skipFormat) {
142 | await formatFiles(host);
143 | }
144 |
145 | return runTasksInSerial(...tasks);
146 | }
147 | export default applicationGenerator;
148 | export const applicationSchematic = convertNxGenerator(applicationGenerator);
149 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/files/cdk.json__template__:
--------------------------------------------------------------------------------
1 | {
2 | "app": "npx ts-node src/main.ts",
3 | "output": "<%= offsetFromRoot %>dist/apps/<%= projectName %>",
4 | "context": {
5 | "@aws-cdk/core:enableStackNameDuplicates": "true",
6 | "aws-cdk:enableDiffNoFail": "true"
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/files/src/main.ts__template__:
--------------------------------------------------------------------------------
1 | import * as cdk from '@aws-cdk/core';
2 | import { AppStack } from './stacks/app-stack';
3 |
4 | const app = new cdk.App();
5 | new AppStack(app, '<%= projectName %>');
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/files/src/stacks/app-stack.ts__template__:
--------------------------------------------------------------------------------
1 | import * as cdk from '@aws-cdk/core';
2 |
3 | export class AppStack extends cdk.Stack {
4 | constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
5 | super(scope, id, props);
6 |
7 | // defines your stack here
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/files/tsconfig.app.json__template__:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5 | "types": ["node"]
6 | },
7 | "exclude": ["**/*.spec.ts", "**/*.test.ts"],
8 | "include": ["**/*.ts"]
9 | }
10 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/files/tsconfig.json__template__:
--------------------------------------------------------------------------------
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 | }
16 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/jest-files/src/main.test.ts__template__:
--------------------------------------------------------------------------------
1 | import { expect as expectCDK, matchTemplate, MatchStyle } from '@aws-cdk/assert';
2 | import * as cdk from '@aws-cdk/core';
3 | import { AppStack } from './stacks/app-stack';
4 |
5 | test('Empty Stack', () => {
6 | const app = new cdk.App();
7 | // WHEN
8 | const stack = new AppStack(app, '<%= projectName %>TestStack');
9 | // THEN
10 | expectCDK(stack).to(matchTemplate({
11 | "Resources": {}
12 | }, MatchStyle.EXACT))
13 | });
14 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/schema.d.ts:
--------------------------------------------------------------------------------
1 | import { Linter } from '@nx/eslint';
2 |
3 | export interface ApplicationSchema {
4 | name: string;
5 | tags?: string;
6 | directory?: string;
7 | skipFormat?: boolean;
8 | linter?: Linter;
9 | unitTestRunner?: 'jest' | 'none';
10 | setParserOptionsProject?: boolean;
11 | }
12 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/application/schema.json:
--------------------------------------------------------------------------------
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 | "linter": {
38 | "description": "The tool to use for running lint checks.",
39 | "type": "string",
40 | "enum": ["eslint", "tslint"],
41 | "default": "eslint"
42 | },
43 | "setParserOptionsProject": {
44 | "type": "boolean",
45 | "description": "Whether or not to configure the ESLint \"parserOptions.project\" option. We do not do this by default for lint performance reasons.",
46 | "default": false
47 | }
48 | },
49 | "required": ["name"]
50 | }
51 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/init/init.spec.ts:
--------------------------------------------------------------------------------
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']).toBeDefined();
20 | expect(packageJson.dependencies['aws-cdk-lib']).toBeDefined();
21 | expect(packageJson.dependencies['constructs']).toBeDefined();
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/init/init.ts:
--------------------------------------------------------------------------------
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_ESLINT_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 | 'eslint-plugin-cdk': CDK_ESLINT_VERSION,
31 | }
32 | );
33 |
34 | if (!schema.skipFormat) {
35 | await formatFiles(host);
36 | }
37 |
38 | return async () => {
39 | if (jestInstall) {
40 | await jestInstall();
41 | }
42 | await installTask();
43 | };
44 | }
45 |
46 | export default initGenerator;
47 | export const initSchematic = convertNxGenerator(initGenerator);
48 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/init/schema.d.ts:
--------------------------------------------------------------------------------
1 | export interface InitGeneratorSchema {
2 | unitTestRunner?: 'jest' | 'none';
3 | skipFormat?: boolean;
4 | }
5 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/generators/init/schema.json:
--------------------------------------------------------------------------------
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 | }
21 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/index.ts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codebrewlab/nx-plugins/638a9529d49628bc3c9b1d403fd1e51e34a21639/packages/nx-aws-cdk/src/index.ts
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/interfaces/parsed-executor.interface.ts:
--------------------------------------------------------------------------------
1 | export interface ParsedExecutorInterface {
2 | parseArgs?: Record;
3 | stacks?: string[];
4 | sourceRoot: string;
5 | root: string;
6 | }
7 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/utils/cdk-shared.ts:
--------------------------------------------------------------------------------
1 | export const CDK_VERSION = '^2.77.0';
2 | export const CDK_ESLINT_VERSION = '^1.8.0';
3 | export const CDK_CONSTRUCTS_VERSION = '^10.2.10';
4 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/utils/executor.util.ts:
--------------------------------------------------------------------------------
1 | import { DeployExecutorSchema } from '../executors/deploy/schema';
2 | import { ParsedExecutorInterface } from '../interfaces/parsed-executor.interface';
3 |
4 | export const executorPropKeys = ['stacks'];
5 | export const LARGE_BUFFER = 1024 * 1000000;
6 |
7 | export function parseArgs(options: DeployExecutorSchema): Record {
8 | const keys = Object.keys(options);
9 | return keys
10 | .filter((prop) => executorPropKeys.indexOf(prop) < 0)
11 | .reduce((acc, key) => ((acc[key] = options[key]), acc), {});
12 | }
13 |
14 | export function createCommand(command: string, options: ParsedExecutorInterface): string {
15 | const commands = [`cdk ${command}`];
16 |
17 | if (typeof options.stacks === 'string') {
18 | commands.push(options.stacks);
19 | }
20 |
21 | for (const arg in options.parseArgs) {
22 | commands.push(`--${arg} ${options.parseArgs[arg]}`);
23 | }
24 |
25 | return commands.join(' ');
26 | }
27 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/src/utils/testing.ts:
--------------------------------------------------------------------------------
1 | import type { ExecutorContext } from '@nrwl/devkit';
2 |
3 | export function mockExecutorContext(executorName: string, workspaceVersion = 2): ExecutorContext {
4 | return {
5 | projectName: 'proj',
6 | root: '/root',
7 | cwd: '/root',
8 | workspace: {
9 | version: workspaceVersion,
10 | projects: {
11 | proj: {
12 | root: 'apps/proj',
13 | targets: {
14 | test: {
15 | executor: `@codebrew/nx-aws-cdk:${executorName}`,
16 | },
17 | },
18 | },
19 | },
20 | },
21 | target: {
22 | executor: `@codebrew/nx-aws-cdk:${executorName}`,
23 | },
24 | isVerbose: true,
25 | };
26 | }
27 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.base.json",
3 | "compilerOptions": {
4 | "module": "commonjs"
5 | },
6 | "files": [],
7 | "include": [],
8 | "references": [
9 | {
10 | "path": "./tsconfig.lib.json"
11 | },
12 | {
13 | "path": "./tsconfig.spec.json"
14 | }
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/tsconfig.lib.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "module": "commonjs",
5 | "outDir": "../../dist/out-tsc",
6 | "types": ["node"]
7 | },
8 | "include": ["src/**/*.ts"],
9 | "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10 | }
11 |
--------------------------------------------------------------------------------
/packages/nx-aws-cdk/tsconfig.spec.json:
--------------------------------------------------------------------------------
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 | }
21 |
--------------------------------------------------------------------------------
/packages/nx-ncc/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["../../.eslintrc.json"],
3 | "ignorePatterns": ["!**/*"],
4 | "overrides": [
5 | {
6 | "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7 | "rules": {}
8 | },
9 | {
10 | "files": ["*.ts", "*.tsx"],
11 | "rules": {}
12 | },
13 | {
14 | "files": ["*.js", "*.jsx"],
15 | "rules": {}
16 | },
17 | {
18 | "files": ["*.json"],
19 | "parser": "jsonc-eslint-parser",
20 | "rules": {
21 | "@nx/dependency-checks": "error"
22 | }
23 | },
24 | {
25 | "files": ["./package.json", "./generators.json", "./executors.json"],
26 | "parser": "jsonc-eslint-parser",
27 | "rules": {
28 | "@nx/nx-plugin-checks": "error"
29 | }
30 | }
31 | ]
32 | }
33 |
--------------------------------------------------------------------------------
/packages/nx-ncc/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/RichardLitt/standard-readme)
2 | [](https://github.com/codebrewlab/nx-plugins/tree/master/packages/nx-ncc)
3 | [](https://www.typescriptlang.org/)
4 | [](https://www.npmjs.com/package/@codebrew/nx-aws-cdk)
5 | [](https://www.npmjs.com/package/@codebrew/nx-ncc)
6 | [](https://www.npmjs.com/package/@codebrew/nx-ncc)
7 |
8 |
9 |
10 | # @codebrew/nx-ncc
11 |
12 | An Nx plugin for developing [@vercel/ncc](https://github.com/vercel/ncc)
13 |
14 | ## Table of Contents
15 |
16 | - [Install](#install)
17 | - [Usage](#usage)
18 | - [Executors](#executors)
19 | - [Maintainers](#maintainers)
20 | - [Contributing](#contributing)
21 | - [License](#license)
22 |
23 | ## Install
24 |
25 | ```shell
26 | # npm
27 | npm install --save-dev @codebrew/nx-ncc
28 |
29 | # yarn
30 | yarn add --dev @codebrew/nx-ncc
31 |
32 | # pnpm
33 | pnpm install --save-dev @codebrew/nx-ncc
34 | ```
35 |
36 | ## Usage
37 |
38 | ### Executors
39 |
40 | Generated applications expose several functions to the CLI that allow users to deploy, destroy and so on.
41 |
42 | ```shell
43 | nx deploy {Project Name}
44 | nx destroy {Project Name}
45 | ```
46 |
47 | ## Maintainers
48 |
49 | [@tienne](https://github.com/tienne)
50 |
51 | ## Contributing
52 |
53 | See [the contributing file](../../contributing.md)!
54 |
55 | PRs accepted.
56 |
57 | If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
58 |
59 | ## License
60 |
61 | This project is MIT licensed 2021 David Kwon.
62 |
--------------------------------------------------------------------------------
/packages/nx-ncc/executors.json:
--------------------------------------------------------------------------------
1 | {
2 | "executors": {
3 | "build": {
4 | "implementation": "./src/executors/build/executor",
5 | "schema": "./src/executors/build/schema.json",
6 | "description": "build executor"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/nx-ncc/generators.json:
--------------------------------------------------------------------------------
1 | {
2 | "generators": {
3 | "init": {
4 | "factory": "./src/generators/init/generator",
5 | "schema": "./src/generators/init/schema.json",
6 | "description": "init generator",
7 | "hidden": true
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/packages/nx-ncc/jest.config.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | export default {
3 | displayName: 'nx-ncc',
4 | preset: '../../jest.preset.js',
5 | transform: {
6 | '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }],
7 | },
8 | moduleFileExtensions: ['ts', 'js', 'html'],
9 | coverageDirectory: '../../coverage/packages/nx-ncc',
10 | };
11 |
--------------------------------------------------------------------------------
/packages/nx-ncc/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codebrew/nx-ncc",
3 | "version": "0.0.1",
4 | "dependencies": {
5 | "@nx/js": "19.6.3",
6 | "@nrwl/devkit": "19.6.3",
7 | "tslib": "^2.3.0"
8 | },
9 | "devDependencies": {
10 | "tslib": "^2.3.0",
11 | "@nx/js": "^19.6.3"
12 | },
13 | "peerDependencies": {
14 | "@nx/devkit": "^19.6.3",
15 | "@nx/jest": "^19.6.3"
16 | },
17 | "type": "commonjs",
18 | "main": "./src/index.js",
19 | "typings": "./src/index.d.ts",
20 | "private": true,
21 | "generators": "./generators.json",
22 | "executors": "./executors.json"
23 | }
24 |
--------------------------------------------------------------------------------
/packages/nx-ncc/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nx-ncc",
3 | "$schema": "../../node_modules/nx/schemas/project-schema.json",
4 | "sourceRoot": "packages/nx-ncc/src",
5 | "projectType": "library",
6 | "tags": [],
7 | "targets": {
8 | "build": {
9 | "executor": "@nx/js:tsc",
10 | "outputs": ["{options.outputPath}"],
11 | "options": {
12 | "outputPath": "dist/packages/nx-ncc",
13 | "main": "packages/nx-ncc/src/index.ts",
14 | "tsConfig": "packages/nx-ncc/tsconfig.lib.json",
15 | "assets": [
16 | "packages/nx-ncc/*.md",
17 | {
18 | "input": "./packages/nx-ncc/src",
19 | "glob": "**/!(*.ts)",
20 | "output": "./src"
21 | },
22 | {
23 | "input": "./packages/nx-ncc/src",
24 | "glob": "**/*.d.ts",
25 | "output": "./src"
26 | },
27 | {
28 | "input": "./packages/nx-ncc",
29 | "glob": "generators.json",
30 | "output": "."
31 | },
32 | {
33 | "input": "./packages/nx-ncc",
34 | "glob": "executors.json",
35 | "output": "."
36 | }
37 | ],
38 | "external": ["packages/utils"]
39 | }
40 | },
41 | "lint": {
42 | "executor": "@nx/eslint:lint"
43 | },
44 | "test": {
45 | "executor": "@nx/jest:jest",
46 | "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
47 | "options": {
48 | "jestConfig": "packages/nx-ncc/jest.config.ts"
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/executors/build/executor.spec.ts:
--------------------------------------------------------------------------------
1 | import { BuildExecutorSchema } from './schema';
2 | import executor from './executor';
3 | import { mockExecutorContext } from '../../utils/testing';
4 | import { logger } from '@nx/devkit';
5 | import * as childProcess from 'child_process';
6 | import * as path from 'path';
7 |
8 | const options: BuildExecutorSchema = {
9 | main: '',
10 | outputPath: '',
11 | };
12 |
13 | describe('Build Executor', () => {
14 | const mockContext = mockExecutorContext('build');
15 | let spyExec;
16 |
17 | beforeEach(async () => {
18 | jest.spyOn(logger, 'debug');
19 | spyExec = jest.spyOn(childProcess, 'exec');
20 | });
21 |
22 | afterEach(() => jest.clearAllMocks());
23 |
24 | it('run ncc build command', async () => {
25 | await executor(options, mockContext);
26 |
27 | expect(childProcess.exec).toHaveBeenCalledWith(
28 | 'ncc build /root -C',
29 | expect.objectContaining({
30 | cwd: expect.stringContaining(path.join(mockContext.root, mockContext.cwd)),
31 | env: process.env,
32 | maxBuffer: expect.anything(),
33 | })
34 | );
35 |
36 | expect(logger.debug).toHaveBeenLastCalledWith(`Executing command: ncc build /root -C`);
37 | });
38 | });
39 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/executors/build/executor.ts:
--------------------------------------------------------------------------------
1 | import { logger, PromiseExecutor } from '@nx/devkit';
2 | import { runCommandProcess } from '@codebrew/utils';
3 |
4 | import { BuildExecutorSchema } from './schema';
5 | import { normalizeOptions } from '../../utils/normalize-options';
6 | import { createNccCommand } from '../../utils';
7 | import { CopyAssetsHandler } from '@nx/js/src/utils/assets/copy-assets-handler';
8 |
9 | const runExecutor: PromiseExecutor = async (options, context) => {
10 | const normalizedOptions = normalizeOptions(options, context);
11 |
12 | const command = createNccCommand('build', normalizedOptions);
13 |
14 | const assetHandler = new CopyAssetsHandler({
15 | projectDir: normalizedOptions.projectRoot,
16 | rootDir: context.root,
17 | outputDir: normalizedOptions.outputPath,
18 | assets: normalizedOptions.assets,
19 | });
20 |
21 | try {
22 | const result = await runCommandProcess(command, context.root);
23 |
24 | if (result) {
25 | await assetHandler.processAllAssetsOnce();
26 | }
27 | return { success: result };
28 | } catch (e) {
29 | logger.debug('nx-ncc:build Error: ', e);
30 | return { success: false };
31 | }
32 | };
33 |
34 | export default runExecutor;
35 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/executors/build/schema.d.ts:
--------------------------------------------------------------------------------
1 | import { BaseExecutorSchemaInterface } from '../../interfaces/base-executor-schema.interface';
2 |
3 | export interface BuildExecutorSchema extends BaseExecutorSchemaInterface {
4 | outputPath: string;
5 | generatePackageJson?: boolean;
6 | watch?: boolean;
7 | }
8 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/executors/build/schema.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json-schema.org/schema",
3 | "version": 2,
4 | "title": "Build executor",
5 | "description": "",
6 | "type": "object",
7 | "properties": {},
8 | "required": []
9 | }
10 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/generators/init/generator.spec.ts:
--------------------------------------------------------------------------------
1 | import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2 | import { Tree, readJson } from '@nx/devkit';
3 |
4 | import { initGenerator } from './generator';
5 | import { InitGeneratorSchema } from './schema';
6 |
7 | describe('init generator', () => {
8 | let tree: Tree;
9 | const options: InitGeneratorSchema = {};
10 |
11 | beforeEach(() => {
12 | tree = createTreeWithEmptyWorkspace();
13 | });
14 |
15 | it('should add @vercel/ncc devDependency', async () => {
16 | await initGenerator(tree, options);
17 | const packageJson = readJson(tree, 'package.json');
18 |
19 | expect(packageJson.devDependencies['@vercel/ncc']).toBeDefined();
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/generators/init/generator.ts:
--------------------------------------------------------------------------------
1 | import { addDependenciesToPackageJson, convertNxGenerator, formatFiles, GeneratorCallback, Tree } from '@nx/devkit';
2 | import { InitGeneratorSchema } from './schema';
3 | import { jestInitGenerator } from '@nx/jest';
4 |
5 | function normalizeOptions(schema: InitGeneratorSchema) {
6 | return {
7 | ...schema,
8 | unitTestRunner: schema.unitTestRunner ?? 'jest',
9 | };
10 | }
11 |
12 | export async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
13 | let jestInstall: GeneratorCallback;
14 | const schema = normalizeOptions(options);
15 |
16 | if (schema.unitTestRunner === 'jest') {
17 | jestInstall = await jestInitGenerator(tree, {});
18 | }
19 |
20 | const installTask = addDependenciesToPackageJson(
21 | tree,
22 | {},
23 | {
24 | '@vercel/ncc': '^0.38.1',
25 | }
26 | );
27 |
28 | if (!schema.skipFormat) {
29 | await formatFiles(tree);
30 | }
31 |
32 | return async () => {
33 | if (jestInstall) {
34 | await jestInstall();
35 | }
36 | await installTask();
37 | };
38 | }
39 |
40 | export default initGenerator;
41 | export const initSchematic = convertNxGenerator(initGenerator);
42 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/generators/init/schema.d.ts:
--------------------------------------------------------------------------------
1 | export interface InitGeneratorSchema {
2 | unitTestRunner?: 'jest' | 'none';
3 | skipFormat?: boolean;
4 | }
5 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/generators/init/schema.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json-schema.org/schema",
3 | "$id": "Init",
4 | "title": "",
5 | "type": "object",
6 | "properties": {},
7 | "required": []
8 | }
9 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/index.ts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codebrewlab/nx-plugins/638a9529d49628bc3c9b1d403fd1e51e34a21639/packages/nx-ncc/src/index.ts
--------------------------------------------------------------------------------
/packages/nx-ncc/src/interfaces/base-executor-schema.interface.ts:
--------------------------------------------------------------------------------
1 | import type { AssetGlob } from '@nx/js/src/utils/assets/assets';
2 |
3 | export interface BaseExecutorSchemaInterface {
4 | main: string;
5 | sourceMap?: boolean;
6 | minify?: boolean;
7 | quiet?: boolean;
8 | target?: string;
9 | externalDependencies?: string[];
10 | assets?: (string | AssetGlob)[];
11 | }
12 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/interfaces/normalized-executor-schema.interface.ts:
--------------------------------------------------------------------------------
1 | import { BaseExecutorSchemaInterface } from './base-executor-schema.interface';
2 |
3 | export type NormalizedExecutorSchemaInterface =
4 | T & {
5 | root: string;
6 | sourceRoot: string;
7 | projectRoot: string;
8 | };
9 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/utils/create-ncc-command.ts:
--------------------------------------------------------------------------------
1 | import { NormalizedExecutorSchemaInterface } from '../interfaces/normalized-executor-schema.interface';
2 | import { normalizeArguments } from './normalize-arguments';
3 |
4 | export const createNccCommand = (command: string, options: NormalizedExecutorSchemaInterface) => {
5 | const commands = [`ncc ${command} ${options.main}`];
6 |
7 | const args = normalizeArguments(options);
8 |
9 | commands.push(args);
10 |
11 | return commands.join(' ');
12 | };
13 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/utils/index.ts:
--------------------------------------------------------------------------------
1 | export * from './create-ncc-command';
2 | export * from './should-watch';
3 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/utils/normalize-arguments.ts:
--------------------------------------------------------------------------------
1 | import { NormalizedExecutorSchemaInterface } from '../interfaces/normalized-executor-schema.interface';
2 |
3 | export const normalizeArguments = (options: T) => {
4 | const args = [];
5 |
6 | args.push('-C');
7 |
8 | if (options['outputPath']) {
9 | args.push(`-o ${options['outputPath']}`);
10 | }
11 |
12 | if (options.sourceMap) {
13 | args.push(`-s`);
14 | }
15 |
16 | if (options.minify) {
17 | args.push('-m');
18 | }
19 |
20 | if (options.quiet) {
21 | args.push('-q');
22 | }
23 |
24 | if (options['watch']) {
25 | args.push('-w');
26 | }
27 |
28 | if (options.externalDependencies?.length) {
29 | args.push(...options.externalDependencies.map((module) => `--external ${module}`));
30 | }
31 |
32 | return args.join(' ');
33 | };
34 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/utils/normalize-options.ts:
--------------------------------------------------------------------------------
1 | import { resolve } from 'path';
2 |
3 | import { ExecutorContext } from '@nx/devkit';
4 |
5 | import { BaseExecutorSchemaInterface } from '../interfaces/base-executor-schema.interface';
6 | import { NormalizedExecutorSchemaInterface } from '../interfaces/normalized-executor-schema.interface';
7 |
8 | export const normalizeOptions = (
9 | options: T,
10 | context: ExecutorContext
11 | ): NormalizedExecutorSchemaInterface => {
12 | const root = resolve(context.root);
13 | const projectConfig = context.workspace.projects[context.projectName];
14 | const projectRoot = resolve(root, projectConfig.root);
15 |
16 | return {
17 | ...options,
18 | main: resolve(root, options.main),
19 | assets: options.assets ?? [],
20 | root,
21 | projectRoot,
22 | sourceRoot: resolve(root, projectConfig.sourceRoot || ''),
23 | };
24 | };
25 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/utils/should-watch.ts:
--------------------------------------------------------------------------------
1 | export const shouldWatch = (command: string, options: any) => {
2 | return command === 'run' || !!(options as any).watch;
3 | };
4 |
--------------------------------------------------------------------------------
/packages/nx-ncc/src/utils/testing.ts:
--------------------------------------------------------------------------------
1 | import type { ExecutorContext } from '@nrwl/devkit';
2 |
3 | export function mockExecutorContext(executorName: string, workspaceVersion = 2): ExecutorContext {
4 | return {
5 | projectName: 'proj',
6 | root: '/root',
7 | cwd: '/root',
8 | workspace: {
9 | version: workspaceVersion,
10 | projects: {
11 | proj: {
12 | root: 'apps/proj',
13 | targets: {
14 | test: {
15 | executor: `@codebrew/nx-ncc:${executorName}`,
16 | },
17 | },
18 | },
19 | },
20 | },
21 | target: {
22 | executor: `@codebrew/nx-ncc:${executorName}`,
23 | },
24 | isVerbose: true,
25 | };
26 | }
27 |
--------------------------------------------------------------------------------
/packages/nx-ncc/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.base.json",
3 | "compilerOptions": {
4 | "module": "commonjs"
5 | },
6 | "files": [],
7 | "include": [],
8 | "references": [
9 | {
10 | "path": "./tsconfig.lib.json"
11 | },
12 | {
13 | "path": "./tsconfig.spec.json"
14 | }
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/packages/nx-ncc/tsconfig.lib.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "declaration": true,
6 | "types": ["node"]
7 | },
8 | "include": ["src/**/*.ts"],
9 | "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10 | }
11 |
--------------------------------------------------------------------------------
/packages/nx-ncc/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "module": "commonjs",
6 | "types": ["jest", "node"]
7 | },
8 | "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
9 | }
10 |
--------------------------------------------------------------------------------
/packages/utils/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["../../.eslintrc.json"],
3 | "ignorePatterns": ["!**/*"],
4 | "overrides": [
5 | {
6 | "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7 | "rules": {}
8 | },
9 | {
10 | "files": ["*.ts", "*.tsx"],
11 | "rules": {}
12 | },
13 | {
14 | "files": ["*.js", "*.jsx"],
15 | "rules": {}
16 | }
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/packages/utils/README.md:
--------------------------------------------------------------------------------
1 | # utils
2 |
3 | This library only @codebrew/nx-plugins shared util library
4 |
5 | ## Running unit tests
6 |
7 | Run `nx test utils` to execute the unit tests via [Jest](https://jestjs.io).
8 |
--------------------------------------------------------------------------------
/packages/utils/jest.config.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | export default {
3 | displayName: 'utils',
4 | preset: '../../jest.preset.js',
5 | testEnvironment: 'node',
6 | transform: {
7 | '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }],
8 | },
9 | moduleFileExtensions: ['ts', 'js', 'html'],
10 | coverageDirectory: '../../coverage/packages/utils',
11 | };
12 |
--------------------------------------------------------------------------------
/packages/utils/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codebrew/utils",
3 | "$schema": "../../node_modules/nx/schemas/project-schema.json",
4 | "sourceRoot": "packages/utils/src",
5 | "projectType": "library",
6 | "tags": [],
7 | "targets": {
8 | "build": {
9 | "executor": "@nx/js:tsc",
10 | "outputs": ["{options.outputPath}"],
11 | "options": {
12 | "outputPath": "dist/packages/utils",
13 | "tsConfig": "packages/utils/tsconfig.lib.json",
14 | "packageJson": "packages/utils/package.json",
15 | "main": "packages/utils/src/index.ts",
16 | "assets": ["packages/utils/*.md"]
17 | }
18 | },
19 | "lint": {
20 | "executor": "@nx/eslint:lint"
21 | },
22 | "test": {
23 | "executor": "@nx/jest:jest",
24 | "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
25 | "options": {
26 | "jestConfig": "packages/utils/jest.config.ts"
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/packages/utils/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './lib/run-command-process';
2 |
--------------------------------------------------------------------------------
/packages/utils/src/lib/run-command-process.ts:
--------------------------------------------------------------------------------
1 | import { logger } from '@nx/devkit';
2 | import { exec } from 'child_process';
3 |
4 | export const LARGE_BUFFER = 1024 * 1000000;
5 |
6 | export function runCommandProcess(command: string, cwd: string, maxBuffer: number = LARGE_BUFFER): Promise {
7 | return new Promise((resolve, reject) => {
8 | logger.debug(`Executing command: ${command}, cwd: ${cwd}`);
9 |
10 | const childProcess = exec(command, {
11 | maxBuffer: LARGE_BUFFER,
12 | env: process.env,
13 | cwd: cwd,
14 | });
15 |
16 | // Ensure the child process is killed when the parent exits
17 | const processExitListener = () => childProcess.kill(0);
18 | process.on('exit', processExitListener);
19 | process.on('SIGTERM', processExitListener);
20 |
21 | process.stdin.on('data', (data) => {
22 | childProcess.stdin.write(data);
23 | childProcess.stdin.end();
24 | });
25 |
26 | childProcess.stdout.on('data', (data) => {
27 | logger.info(data);
28 | process.stdout.write(data);
29 | });
30 |
31 | childProcess.stderr.on('data', (err) => {
32 | logger.fatal(err);
33 | process.stderr.write(err);
34 | });
35 |
36 | childProcess.on('close', (code) => {
37 | console.log(`${command} on Close: `, code);
38 | if (code === 0) {
39 | resolve(true);
40 | } else {
41 | resolve(false);
42 | }
43 |
44 | process.removeListener('exit', processExitListener);
45 |
46 | process.stdin.end();
47 | process.stdin.removeListener('data', processExitListener);
48 | });
49 | });
50 | }
51 |
--------------------------------------------------------------------------------
/packages/utils/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.base.json",
3 | "compilerOptions": {
4 | "module": "commonjs"
5 | },
6 | "files": [],
7 | "include": [],
8 | "references": [
9 | {
10 | "path": "./tsconfig.lib.json"
11 | },
12 | {
13 | "path": "./tsconfig.spec.json"
14 | }
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/packages/utils/tsconfig.lib.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "module": "commonjs",
5 | "outDir": "../../dist/out-tsc",
6 | "declaration": true,
7 | "types": ["node"]
8 | },
9 | "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
10 | "include": ["src/**/*.ts"]
11 | }
12 |
--------------------------------------------------------------------------------
/packages/utils/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "module": "commonjs",
6 | "types": ["jest", "node"]
7 | },
8 | "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
9 | }
10 |
--------------------------------------------------------------------------------
/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codebrew/sources",
3 | "$schema": "node_modules/nx/schemas/project-schema.json",
4 | "targets": {
5 | "local-registry": {
6 | "executor": "@nx/js:verdaccio",
7 | "options": {
8 | "port": 4873,
9 | "config": ".verdaccio/config.yml",
10 | "storage": "tmp/local-registry/storage"
11 | }
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tools/scripts/start-local-registry.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This script starts a local registry for e2e testing purposes.
3 | * It is meant to be called in jest's globalSetup.
4 | */
5 | import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
6 | import { execFileSync } from 'child_process';
7 | import { releasePublish, releaseVersion } from 'nx/release';
8 |
9 | export default async () => {
10 | // local registry target to run
11 | const localRegistryTarget = '@codebrew/sources:local-registry';
12 | // storage folder for the local registry
13 | const storage = './tmp/local-registry/storage';
14 |
15 | global.stopLocalRegistry = await startLocalRegistry({
16 | localRegistryTarget,
17 | storage,
18 | verbose: false,
19 | });
20 |
21 | await releaseVersion({
22 | specifier: '0.0.0-e2e',
23 | stageChanges: false,
24 | gitCommit: false,
25 | gitTag: false,
26 | firstRelease: true,
27 | generatorOptionsOverrides: {
28 | skipLockFileUpdate: true,
29 | },
30 | });
31 | await releasePublish({
32 | tag: 'e2e',
33 | firstRelease: true,
34 | });
35 | };
36 |
--------------------------------------------------------------------------------
/tools/scripts/stop-local-registry.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This script stops the local registry for e2e testing purposes.
3 | * It is meant to be called in jest's globalTeardown.
4 | */
5 |
6 | export default () => {
7 | if (global.stopLocalRegistry) {
8 | global.stopLocalRegistry();
9 | }
10 | };
11 |
--------------------------------------------------------------------------------
/tools/tsconfig.tools.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.base.json",
3 | "compilerOptions": {
4 | "outDir": "../dist/out-tsc/tools",
5 | "rootDir": ".",
6 | "module": "commonjs",
7 | "target": "es5",
8 | "types": ["node"],
9 | "importHelpers": false
10 | },
11 | "include": ["**/*.ts"]
12 | }
13 |
--------------------------------------------------------------------------------
/tsconfig.base.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "rootDir": ".",
5 | "sourceMap": true,
6 | "declaration": false,
7 | "moduleResolution": "node",
8 | "emitDecoratorMetadata": true,
9 | "experimentalDecorators": true,
10 | "importHelpers": true,
11 | "target": "es2015",
12 | "module": "esnext",
13 | "lib": ["es2017", "dom"],
14 | "skipLibCheck": true,
15 | "skipDefaultLibCheck": true,
16 | "baseUrl": ".",
17 | "paths": {
18 | "@codebrew/nx-aws-cdk": ["packages/nx-aws-cdk/src/index.ts"],
19 | "@codebrew/nx-ncc": ["packages/nx-ncc/src/index.ts"],
20 | "@codebrew/utils": ["packages/utils/src/index.ts"]
21 | }
22 | },
23 | "exclude": ["node_modules", "tmp"]
24 | }
25 |
--------------------------------------------------------------------------------