Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Add preset generator #105

Merged
merged 3 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libs/nx-mesh/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"description": "Create a GraphQL Mesh SDK library for Nx",
"x-type": "library",
"aliases": ["library", "sdk-library"]
},
"preset": {
"factory": "./src/generators/preset/generator",
"schema": "./src/generators/preset/schema.json",
"description": "Create a GraphQL Mesh SDK in an empty workspace.",
"hidden": true
}
},
"schematics": {
Expand Down
9 changes: 9 additions & 0 deletions libs/nx-mesh/src/generators/preset/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { convertNxGenerator } from '@nrwl/devkit';

import { presetGenerator } from './preset';

export const presetSchematic = convertNxGenerator(presetGenerator);

export { presetGenerator } from './preset';

export default presetGenerator;
34 changes: 34 additions & 0 deletions libs/nx-mesh/src/generators/preset/preset.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Tree } from '@nrwl/devkit';

import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { readProjectConfiguration } from '@nrwl/devkit';

import { presetGenerator } from './preset';

describe('generators/preset', () => {
let tree: Tree;

beforeEach(() => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

tree = createTreeWithEmptyWorkspace();

tree.write(
'workspace.json',
JSON.stringify({
version: 2,
projects: {},
})
);
});

it('should create a workspace with the graphql-mesh sdk preset', async () => {
await presetGenerator(tree, {
name: 'hello-world',
compiler: 'tsc',
});

const config = readProjectConfiguration(tree, 'hello-world');

expect(config).toBeDefined();
expect(tree.exists('/libs/hello-world/.meshrc.yml')).toBe(true);
});
});
18 changes: 18 additions & 0 deletions libs/nx-mesh/src/generators/preset/preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Tree } from '@nrwl/devkit';

import type { PresetGeneratorSchema } from './schema';

import { convertNxGenerator } from '@nrwl/devkit';

import { sdkGenerator } from '../sdk';

export async function presetGenerator(
tree: Tree,
options: PresetGeneratorSchema
) {
return await sdkGenerator(tree, options);
}

export const presetSchematic = convertNxGenerator(presetGenerator);

export default presetGenerator;
3 changes: 3 additions & 0 deletions libs/nx-mesh/src/generators/preset/schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { SdkGeneratorSchema } from '../sdk/schema';

export type PresetGeneratorSchema = SdkGeneratorSchema;
155 changes: 155 additions & 0 deletions libs/nx-mesh/src/generators/preset/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "Preset",
"title": "Create a GraphQL Mesh SDK in an empty workspace.",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use?"
},
"directory": {
"description": "The directory of the new sdk.",
"type": "string",
"alias": "d"
},
"meshConfig": {
"description": "The file extension to use for the Mesh config",
"type": "string",
"default": "yml",
"alias": "mc",
"x-prompt": {
"message": "Which config format would you like to use?",
"type": "list",
"items": [
{ "value": "json", "label": "JSON" },
{
"value": "yml",
"label": "YAML"
},
{
"value": "js",
"label": "JavaScript"
},
{
"value": "cjs",
"label": "Common JS"
}
]
}
},
"example": {
"description": "Which example project would you like to start with?",
"type": "string",
"default": "star-wars-api",
"x-prompt": {
"message": "Which example project would you like to start with?",
"type": "list",
"items": [
{ "value": "country-info", "label": "Country Info (SOAP)" },
{ "value": "fake-api", "label": "Fake API (JSON Schema)" },
{ "value": "javascript-wiki", "label": "JavaScript Wiki (OpenAPI)" },
{ "value": "movies", "label": "Movies (Neo4j)" },
{ "value": "rfam", "label": "RFam (MySQL)" },
{ "value": "stackexchange", "label": "StackExchange (OpenAPI)" },
{ "value": "star-wars-api", "label": "Star Wars API (GraphQL)" },
{ "value": "trippin", "label": "Trip Pin (odata)" }
]
}
},
"codegen": {
"description": "Use `graphql-codegen` to generate custom files from the GraphQL Mesh schema.",
"type": "boolean",
"default": true
},
"simpleModuleName": {
"description": "Keep the module name simple (when using `--directory`).",
"type": "boolean",
"default": false
},
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint", "tslint"],
"default": "eslint"
},
"unitTestRunner": {
"type": "string",
"enum": ["jest", "none"],
"description": "Test runner to use for unit tests.",
"default": "jest"
},
"tags": {
"type": "string",
"description": "Add tags to the library (used for linting).",
"alias": "t"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false
},
"skipTsConfig": {
"type": "boolean",
"default": false,
"description": "Do not update `tsconfig.base.json` for development experience."
},
"compiler": {
"type": "string",
"enum": ["tsc", "swc"],
"default": "tsc",
"description": "The compiler used by the build and test targets."
},
"importPath": {
"type": "string",
"description": "The library name used to import it, like `@myorg/my-awesome-lib`. Must be a valid npm name."
},
"rootDir": {
"type": "string",
"description": "Sets the `rootDir` for TypeScript compilation. When not defined, it uses the project's root property, or `srcRootForCompilationRoot` if it is defined."
},
"testEnvironment": {
"type": "string",
"enum": ["jsdom", "node"],
"description": "The test environment to use if `unitTestRunner` is set to `jest`.",
"default": "jsdom"
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead of `ts-jest`.",
"default": false
},
"pascalCaseFiles": {
"type": "boolean",
"description": "Use pascal case file names.",
"alias": "P",
"default": false
},
"js": {
"type": "boolean",
"description": "Generate JavaScript files rather than TypeScript files.",
"default": false
},
"strict": {
"type": "boolean",
"description": "Whether to enable tsconfig strict mode or not.",
"default": false
},
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean"
},
"setParserOptionsProject": {
"type": "boolean",
"description": "Whether or not to configure the ESLint `parserOptions.project`. We do not do this by default for lint performance reasons.",
"default": false
}
},
"required": ["name"]
}
9 changes: 9 additions & 0 deletions libs/nx-mesh/src/generators/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { convertNxGenerator } from '@nrwl/devkit';

import { sdkGenerator } from './sdk';

export const sdkSchematic = convertNxGenerator(sdkGenerator);

export { sdkGenerator } from './sdk';

export default sdkGenerator;