Skip to content

Commit

Permalink
feat: add SDK library generator (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
domjtalbot authored Aug 13, 2022
1 parent 4830b77 commit 329c391
Show file tree
Hide file tree
Showing 172 changed files with 3,901 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-apples-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nx-plugin-graphql-mesh': major
---

Add SDK generator
14 changes: 7 additions & 7 deletions .lintstagedrc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export default {
'{nx,workspace}.json': () => 'nx workspace-lint --fix',
'**/*.{js,jsx,ts,tsx}': () => 'nx affected --target=lint --fix',
'{apps,libs}/**/*.*': () => [
'nx affected --target=build',
'nx affected --target=validate',
'nx affected --target=test',
'nx affected --target=e2e',
'nx affected --target=e2e --configuration=start',
'nx affected --target=e2e --configuration=serve',
'nx affected --target=e2e --configuration=serve-dev',
'nx affected --target=build --parallel=1',
'nx affected --target=validate --parallel=1',
'nx affected --target=test --parallel=1',
'nx affected --target=e2e --parallel=1',
'nx affected --target=e2e --configuration=start --parallel=1',
'nx affected --target=e2e --configuration=serve --parallel=1',
'nx affected --target=e2e --configuration=serve-dev --parallel=1',
],
};
95 changes: 89 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Create a GraphQL Mesh API Gateway application for Nx.
```bash
nx generate @domjtalbot/nx-plugin-graphql-mesh:application my-api-gateway

# Shorthand
# Alias
nx generate @domjtalbot/nx-plugin-graphql-mesh:app my-api-gateway
```

Expand Down Expand Up @@ -75,15 +75,98 @@ CREATE apps/my-api-gateway/.eslintrc.json
| **`name`** | - | `string` || - | What name would you like to use for the application? |
| **`directory`** | `d` | `string` | - | - | The directory of the new application. |
| **`meshConfig`** | `mc` | `cjs`, `js`, `json`, `yml` | - | `yml` | Which config format would you like to use? |
| **`linter`** | - | `eslint`, `tslint` | - | `eslint` | The tool to use for running lint checks |
| **`babelJest`** | - | `boolean` | - | `false` | Use `babel` instead of `ts-jest`? |
| **`skipFormat`** | - | `boolean` | - | `false` | Skip formatting files. |
| **`skipWorkspaceJson`** | - | `boolean` | - | `false` | Skip updating `workspace.json` with default options based on values provided to this app (e.g. `babel`). |
| **`unitTestRunner`** | - | `jest`, `none` | - | `jest` | Test runner to use for unit tests. |
| **`e2eTestRunner`** | - | `cypress`, `none` | - | `cypress` | Test runner to use for end to end (E2E) tests. |
| **`tags`** | `t` | `string` | - | - | Add tags to the application (used for linting). |
| **`linter`** | - | `eslint`, `tslint` | - | `eslint` | The tool to use for running lint checks |
| **`setParserOptionsProject`** | - | `boolean` | - | `false` | Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons. |
| **`skipFormat`** | - | `boolean` | - | `false` | Skip formatting files. |
| **`skipWorkspaceJson`** | - | `boolean` | - | `false` | Skip updating `workspace.json` with default options based on values provided to this app (e.g. `babel`). |
| **`standaloneConfig`** | - | `boolean` | - | `false` | Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json` |
| **`tags`** | `t` | `string` | - | - | Add tags to the application (used for linting). |
| **`unitTestRunner`** | - | `jest`, `none` | - | `jest` | Test runner to use for unit tests. |

<br/>

### `sdk`

Create a GraphQL Mesh SDK library for Nx.

```bash
nx generate @domjtalbot/nx-plugin-graphql-mesh:sdk my-mesh-sdk

# Alias
nx generate @domjtalbot/nx-plugin-graphql-mesh:sdk-library my-mesh-sdk
nx generate @domjtalbot/nx-plugin-graphql-mesh:library my-mesh-sdk
```

#### Example Output

##### TSC

```bash
> NX Generating @domjtalbot/nx-plugin-graphql-mesh:sdk

CREATE libs/my-mesh-sdk/README.md
CREATE libs/my-mesh-sdk/.babelrc
CREATE libs/my-mesh-sdk/package.json
CREATE libs/my-mesh-sdk/src/index.ts
CREATE libs/my-mesh-sdk/tsconfig.json
CREATE libs/my-mesh-sdk/tsconfig.lib.json
UPDATE tsconfig.base.json
CREATE libs/my-mesh-sdk/project.json
UPDATE workspace.json
CREATE libs/my-mesh-sdk/.eslintrc.json
CREATE libs/my-mesh-sdk/jest.config.ts
CREATE libs/my-mesh-sdk/tsconfig.spec.json
CREATE libs/my-mesh-sdk/.meshrc.yml
CREATE libs/my-mesh-sdk/src/lib/sdk.ts
UPDATE nx.json
```

##### SWC

```bash
> NX Generating @domjtalbot/nx-plugin-graphql-mesh:sdk

CREATE libs/my-mesh-sdk/README.md
CREATE libs/my-mesh-sdk/package.json
CREATE libs/my-mesh-sdk/src/index.ts
CREATE libs/my-mesh-sdk/tsconfig.json
CREATE libs/my-mesh-sdk/tsconfig.lib.json
UPDATE tsconfig.base.json
CREATE libs/my-mesh-sdk/project.json
UPDATE workspace.json
CREATE libs/my-mesh-sdk/.eslintrc.json
CREATE libs/my-mesh-sdk/jest.config.ts
CREATE libs/my-mesh-sdk/tsconfig.spec.json
CREATE libs/my-mesh-sdk/.lib.swcrc
CREATE libs/my-mesh-sdk/.meshrc.json
CREATE libs/my-mesh-sdk/src/lib/sdk.ts
```

#### Options

| Name | Alias | Type | Required | Default | Description |
| ----------------------------- | ----- | -------------------------- | :------: | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`name`** | - | `string` || - | What name would you like to use? |
| **`directory`** | `d` | `string` | - | - | The directory of the new sdk. |
| **`meshConfig`** | `mc` | `cjs`, `js`, `json`, `yml` | - | `yml` | Which config format would you like to use? |
| **`babelJest`** | - | `boolean` | - | `false` | Use `babel` instead of `ts-jest`. |
| **`compiler`** | - | `tsc`, `swc` | - | `tsc` | The compiler used by the build and test targets. |
| **`importPath`** | - | `string` | - | - | The library name used to import it, like `@myorg/my-awesome-lib`. Must be a valid npm name. |
| **`js`** | - | `boolean` | - | `false` | Generate JavaScript files rather than TypeScript files. |
| **`linter`** | - | `eslint`, `tslint` | - | `eslint` | The tool to use for running lint checks.? |
| **`pascalCaseFiles`** | `p` | `boolean` | - | `false` | Use pascal case file names. |
| **`rootDir`** | - | `string` | - | - | Sets the `rootDir` for TypeScript compilation. When not defined, it uses the project's root property, or `srcRootForCompilationRoot` if it is defined. |
| **`setParserOptionsProject`** | - | `boolean` | - | `false` | Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons. |
| **`simpleModuleName`** | - | `boolean` | - | `false` | Keep the module name simple (when using `--directory`). |
| **`skipFormat`** | - | `boolean` | - | `false` | Skip formatting files. |
| **`skipTsConfig`** | - | `boolean` | - | `false` | Do not update `tsconfig.base.json` for development experience. |
| **`standaloneConfig`** | - | `boolean` | - | `false` | Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json` |
| **`strict`** | - | `boolean` | - | `false` | Whether to enable tsconfig strict mode or not. |
| **`tags`** | `t` | `string` | - | - | Add tags to the application (used for linting). |
| **`testEnvironment`** | - | `jsdom`, `none` | - | `jsdom` | The test environment to use if `unitTestRunner` is set to `jest`. |
| **`unitTestRunner`** | - | `jest`, `none` | - | `jest` | Test runner to use for unit tests. |

<br/>

Expand Down
17 changes: 17 additions & 0 deletions apps/nextjs/javascript-wiki-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": ["plugin:cypress/recommended", "../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["src/plugins/index.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"no-undef": "off"
}
}
]
}
12 changes: 12 additions & 0 deletions apps/nextjs/javascript-wiki-e2e/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fileServerFolder": ".",
"fixturesFolder": "./src/fixtures",
"integrationFolder": "./src/integration",
"modifyObstructiveCode": false,
"supportFile": "./src/support/index.ts",
"pluginsFile": false,
"video": true,
"videosFolder": "../../../dist/cypress/apps/nextjs/javascript-wiki-e2e/videos",
"screenshotsFolder": "../../../dist/cypress/apps/nextjs/javascript-wiki-e2e/screenshots",
"chromeWebSecurity": false
}
23 changes: 23 additions & 0 deletions apps/nextjs/javascript-wiki-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/nextjs/javascript-wiki-e2e/src",
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/nextjs/javascript-wiki-e2e/cypress.json",
"devServerTarget": "nextjs-javascript-wiki:serve:e2e"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/nextjs/javascript-wiki-e2e/**/*.{js,ts}"]
}
}
},
"tags": [],
"implicitDependencies": ["nextjs-javascript-wiki"]
}
7 changes: 7 additions & 0 deletions apps/nextjs/javascript-wiki-e2e/src/integration/app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe('nextjs-javascript-wiki', () => {
beforeEach(() => cy.visit('/'));

it('should display wiki data', () => {
cy.get('[data-wiki]').should('have.length.greaterThan', 0);
});
});
1 change: 1 addition & 0 deletions apps/nextjs/javascript-wiki-e2e/src/support/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getGreeting = () => cy.get('h1');
33 changes: 33 additions & 0 deletions apps/nextjs/javascript-wiki-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}
//
// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
console.log('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions apps/nextjs/javascript-wiki-e2e/src/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';
10 changes: 10 additions & 0 deletions apps/nextjs/javascript-wiki-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"]
},
"include": ["src/**/*.ts", "src/**/*.js"]
}
17 changes: 17 additions & 0 deletions apps/nextjs/javascript-wiki-swc-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": ["plugin:cypress/recommended", "../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["src/plugins/index.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"no-undef": "off"
}
}
]
}
12 changes: 12 additions & 0 deletions apps/nextjs/javascript-wiki-swc-e2e/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fileServerFolder": ".",
"fixturesFolder": "./src/fixtures",
"integrationFolder": "./src/integration",
"modifyObstructiveCode": false,
"supportFile": "./src/support/index.ts",
"pluginsFile": false,
"video": true,
"videosFolder": "../../../dist/cypress/apps/nextjs/javascript-wiki-swc-e2e/videos",
"screenshotsFolder": "../../../dist/cypress/apps/nextjs/javascript-wiki-swc-e2e/screenshots",
"chromeWebSecurity": false
}
23 changes: 23 additions & 0 deletions apps/nextjs/javascript-wiki-swc-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/nextjs/javascript-wiki-swc-e2e/src",
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/nextjs/javascript-wiki-swc-e2e/cypress.json",
"devServerTarget": "nextjs-javascript-wiki:serve:e2e"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/nextjs/javascript-wiki-swc-e2e/**/*.{js,ts}"]
}
}
},
"tags": [],
"implicitDependencies": ["nextjs-javascript-wiki"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe('nextjs-javascript-wiki', () => {
beforeEach(() => cy.visit('/'));

it('should display wiki data', () => {
cy.get('[data-wiki]').should('have.length.greaterThan', 0);
});
});
1 change: 1 addition & 0 deletions apps/nextjs/javascript-wiki-swc-e2e/src/support/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getGreeting = () => cy.get('h1');
33 changes: 33 additions & 0 deletions apps/nextjs/javascript-wiki-swc-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}
//
// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
console.log('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions apps/nextjs/javascript-wiki-swc-e2e/src/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';
10 changes: 10 additions & 0 deletions apps/nextjs/javascript-wiki-swc-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"]
},
"include": ["src/**/*.ts", "src/**/*.js"]
}
Loading

0 comments on commit 329c391

Please sign in to comment.