Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local generator tmp index #297

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"ignorePatterns": ["**/*"],
"plugins": ["@nx"],
"overrides": [
{
"files": "*.json",
"parser": "jsonc-eslint-parser",
"rules": {}
},
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# compiled output
/dist
/tmp
# /tmp # include tmp folder to illustrate issue with index file
/out-tsc

# dependencies
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint.validate": ["json"]
}
10 changes: 10 additions & 0 deletions jest.preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ module.exports = {
resolver: '@nx/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html'],
coverageReporters: ['html'],
/* TODO: Update to latest Jest snapshotFormat
* By default Nx has kept the older style of Jest Snapshot formats
* to prevent breaking of any existing tests with snapshots.
* It's recommend you update to the latest format.
* You can do this by removing snapshotFormat property
* and running tests with --update-snapshot flag.
* Example: "nx affected --targets=test --update-snapshot"
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
*/
snapshotFormat: { escapeString: true, printBasicPrototype: true },
};
3 changes: 3 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/src/test-setup.[jt]s"
]
},
"workspaceLayout": {
"projectNameAndRootFormat": "as-provided"
}
}
98 changes: 52 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,68 @@
"private": true,
"packageManager": "yarn@1.22.19",
"dependencies": {
"@angular/animations": "16.2.0",
"@angular/common": "16.2.0",
"@angular/compiler": "16.2.0",
"@angular/core": "16.2.0",
"@angular/forms": "16.2.0",
"@angular/platform-browser": "16.2.0",
"@angular/platform-browser-dynamic": "16.2.0",
"@angular/router": "16.2.0",
"@angular/animations": "16.2.5",
"@angular/common": "16.2.5",
"@angular/compiler": "16.2.5",
"@angular/core": "16.2.5",
"@angular/forms": "16.2.5",
"@angular/platform-browser": "16.2.5",
"@angular/platform-browser-dynamic": "16.2.5",
"@angular/router": "16.2.5",
"@emotion/babel-plugin": "11.11.0",
"@emotion/react": "11.11.1",
"@emotion/styled": "11.11.0",
"@ngrx/component-store": "16.0.0",
"@ngrx/effects": "16.0.0",
"@ngrx/entity": "16.0.0",
"@ngrx/router-store": "16.0.0",
"@ngrx/store": "16.0.0",
"@nx/angular": "16.8.0",
"@ngrx/component-store": "16.0.1",
"@ngrx/effects": "16.0.1",
"@ngrx/entity": "16.0.1",
"@ngrx/router-store": "16.0.1",
"@ngrx/store": "16.0.1",
"@nx/angular": "16.8.1",
"@swc/helpers": "~0.5.0",
"core-js": "^2.5.4",
"document-register-element": "1.13.1",
"normalize.css": "^8.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-is": "18.2.0",
"react-router-dom": "6.11.2",
"react-test-renderer": "18.2.0",
"rxjs": "7.8.0",
"tslib": "^2.0.0",
"zone.js": "0.13.0"
"rxjs": "7.8.1",
"tslib": "^2.3.0",
"zone.js": "0.13.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "16.2.0",
"@angular-devkit/core": "16.2.0",
"@angular-devkit/schematics": "16.2.0",
"@angular-eslint/eslint-plugin": "16.0.1",
"@angular-eslint/eslint-plugin-template": "16.0.1",
"@angular-eslint/template-parser": "16.0.1",
"@angular-devkit/build-angular": "16.2.2",
"@angular-devkit/core": "16.2.2",
"@angular-devkit/schematics": "16.2.2",
"@angular-eslint/eslint-plugin": "16.0.3",
"@angular-eslint/eslint-plugin-template": "16.0.3",
"@angular-eslint/template-parser": "16.0.3",
"@angular/cli": "~16.2.0",
"@angular/compiler-cli": "16.2.0",
"@angular/language-service": "16.2.0",
"@angular/compiler-cli": "16.2.5",
"@angular/language-service": "16.2.5",
"@babel/core": "^7.14.5",
"@babel/preset-react": "^7.14.5",
"@ngrx/store-devtools": "16.0.0",
"@nx/cypress": "16.8.0",
"@nx/devkit": "16.8.0",
"@nx/eslint-plugin": "16.8.0",
"@nx/jest": "16.8.0",
"@nx/js": "16.8.0",
"@nx/linter": "16.8.0",
"@nx/react": "16.8.0",
"@nx/web": "16.8.0",
"@nx/workspace": "16.8.0",
"@ngrx/store-devtools": "16.0.1",
"@nx/cypress": "16.8.1",
"@nx/devkit": "16.8.1",
"@nx/eslint-plugin": "16.8.1",
"@nx/jest": "16.8.1",
"@nx/js": "16.8.1",
"@nx/linter": "16.8.1",
"@nx/plugin": "^16.8.1",
"@nx/react": "16.8.1",
"@nx/web": "16.8.1",
"@nx/workspace": "16.8.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@schematics/angular": "16.2.0",
"@schematics/angular": "16.2.2",
"@svgr/webpack": "^6.1.2",
"@testing-library/react": "13.4.0",
"@types/jest": "29.4.0",
"@types/node": "18.11.9",
"@swc-node/register": "~1.4.2",
"@swc/cli": "~0.1.62",
"@swc/core": "~1.3.51",
"@testing-library/react": "14.0.0",
"@types/jest": "29.4.4",
"@types/node": "18.14.2",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
"@types/react-router-dom": "5.3.3",
Expand All @@ -95,9 +101,9 @@
"eslint": "8.46.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "2.14.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "6.6.0",
"eslint-plugin-react": "7.31.11",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-react": "7.32.2",
"eslint-plugin-react-hooks": "4.6.0",
"fuzzy": "^0.1.3",
"inquirer": "^6.2.2",
Expand All @@ -106,16 +112,16 @@
"jest-environment-jsdom": "29.4.3",
"jest-preset-angular": "13.1.1",
"netlify": "^2.4.8",
"nx": "16.8.0",
"nx-cloud": "16.3.0",
"nx": "16.8.1",
"nx-cloud": "16.4.0",
"prettier": "2.6.2",
"react-refresh": "^0.10.0",
"style-loader": "^3.3.0",
"stylus": "0.59.0",
"stylus-loader": "^7.1.0",
"ts-jest": "29.1.0",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"typescript": "5.1.3",
"typescript": "5.1.6",
"url-loader": "^4.1.1",
"webpack": "^5.75.0",
"webpack-merge": "^5.8.0"
Expand Down
1 change: 1 addition & 0 deletions tmp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('>> HELLO FROM THE TMP FOLDER <<');
32 changes: 32 additions & 0 deletions tools/local-nx-plugin/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
},
{
"files": ["./package.json", "./generators.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/nx-plugin-checks": "error"
}
}
]
}
11 changes: 11 additions & 0 deletions tools/local-nx-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# tools/local-nx-plugin

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build local-nx-plugin` to build the library.

## Running unit tests

Run `nx test local-nx-plugin` to execute the unit tests via [Jest](https://jestjs.io).
9 changes: 9 additions & 0 deletions tools/local-nx-plugin/generators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"generators": {
"example-generator": {
"factory": "./src/generators/example-generator/generator",
"schema": "./src/generators/example-generator/schema.json",
"description": "example-generator generator"
}
}
}
10 changes: 10 additions & 0 deletions tools/local-nx-plugin/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
export default {
displayName: 'local-nx-plugin',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/tools/local-nx-plugin',
};
12 changes: 12 additions & 0 deletions tools/local-nx-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@nx-example/local-nx-plugin",
"version": "0.0.1",
"dependencies": {
"@nx/devkit": "16.8.1",
"tslib": "^2.3.0"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"generators": "./generators.json"
}
66 changes: 66 additions & 0 deletions tools/local-nx-plugin/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "local-nx-plugin",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "tools/local-nx-plugin/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/tools/local-nx-plugin",
"main": "tools/local-nx-plugin/src/index.ts",
"tsConfig": "tools/local-nx-plugin/tsconfig.lib.json",
"assets": [
"tools/local-nx-plugin/*.md",
{
"input": "./tools/local-nx-plugin/src",
"glob": "**/!(*.ts)",
"output": "./src"
},
{
"input": "./tools/local-nx-plugin/src",
"glob": "**/*.d.ts",
"output": "./src"
},
{
"input": "./tools/local-nx-plugin",
"glob": "generators.json",
"output": "."
},
{
"input": "./tools/local-nx-plugin",
"glob": "executors.json",
"output": "."
}
]
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"tools/local-nx-plugin/**/*.ts",
"tools/local-nx-plugin/package.json",
"tools/local-nx-plugin/generators.json"
]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "tools/local-nx-plugin/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
}
},
"tags": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const variable = "<%= name %>";
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';

import { exampleGeneratorGenerator } from './generator';
import { ExampleGeneratorGeneratorSchema } from './schema';

describe('example-generator generator', () => {
let tree: Tree;
const options: ExampleGeneratorGeneratorSchema = { name: 'test' };

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

it('should run successfully', async () => {
await exampleGeneratorGenerator(tree, options);
const config = readProjectConfiguration(tree, 'test');
expect(config).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
addProjectConfiguration,
formatFiles,
generateFiles,
joinPathFragments,
Tree,
} from '@nx/devkit';
import { ExampleGeneratorGeneratorSchema } from './schema';

export async function exampleGeneratorGenerator(
tree: Tree,
options: ExampleGeneratorGeneratorSchema
) {
console.log('>> HELLO FROM GENERATOR <<');

const projectRoot = `libs/${options.name}`;
addProjectConfiguration(tree, options.name, {
root: projectRoot,
projectType: 'library',
sourceRoot: `${projectRoot}/src`,
targets: {},
});
generateFiles(
tree,
joinPathFragments(__dirname, 'files'),
projectRoot,
options
);
await formatFiles(tree);
}

export default exampleGeneratorGenerator;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ExampleGeneratorGeneratorSchema {
name: string;
}
Loading