Skip to content

Commit

Permalink
chore: add local plugin with generator to show tmp index issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Roozenboom committed Sep 15, 2023
1 parent 1e895a0 commit f284197
Show file tree
Hide file tree
Showing 23 changed files with 853 additions and 28 deletions.
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"]
}
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"
}
}
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"@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",
Expand All @@ -53,9 +55,8 @@
"react-router-dom": "6.11.2",
"react-test-renderer": "18.2.0",
"rxjs": "7.8.1",
"tslib": "^2.0.0",
"zone.js": "0.13.3",
"@nx/angular": "16.8.1"
"tslib": "^2.3.0",
"zone.js": "0.13.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "16.2.2",
Expand All @@ -76,12 +77,16 @@
"@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.2",
"@svgr/webpack": "^6.1.2",
"@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",
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;
}
18 changes: 18 additions & 0 deletions tools/local-nx-plugin/src/generators/example-generator/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "http://json-schema.org/schema",
"$id": "ExampleGenerator",
"title": "",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use?"
}
},
"required": ["name"]
}
Empty file.
16 changes: 16 additions & 0 deletions tools/local-nx-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions tools/local-nx-plugin/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
14 changes: 14 additions & 0 deletions tools/local-nx-plugin/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"baseUrl": ".",
"paths": {
"@nx-example/cart/cart-page": ["libs/cart/cart-page/src/index.ts"],
"@nx-example/local-nx-plugin": ["tools/local-nx-plugin/src/index.ts"],
"@nx-example/products/home-page": [
"libs/products/home-page/src/index.ts"
],
Expand Down

0 comments on commit f284197

Please sign in to comment.