-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin): add plugin for generators
closes #4 This PR adds: - `plugin` for the main `ngxtension` plugin that provides generators such as `ng add` (at the moment) - `local-plugin` for various tasks in the repo itself. Right now, it has `convert-entry-point-to-project` generator
- Loading branch information
Showing
46 changed files
with
1,632 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"eslint.validate": ["json"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# local-plugin | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build local-plugin` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test local-plugin` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"generators": { | ||
"convert-entry-point-to-project": { | ||
"factory": "./src/generators/convert-entry-point-to-project/generator", | ||
"schema": "./src/generators/convert-entry-point-to-project/schema.json", | ||
"description": "convert-entry-point-to-project generator" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'local-plugin', | ||
preset: '../../jest.preset.js', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/libs/local-plugin', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "local-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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"name": "local-plugin", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/local-plugin/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/libs/local-plugin", | ||
"main": "libs/local-plugin/src/index.ts", | ||
"tsConfig": "libs/local-plugin/tsconfig.lib.json", | ||
"assets": [ | ||
"libs/local-plugin/*.md", | ||
{ | ||
"input": "./libs/local-plugin/src", | ||
"glob": "**/!(*.ts)", | ||
"output": "./src" | ||
}, | ||
{ | ||
"input": "./libs/local-plugin/src", | ||
"glob": "**/*.d.ts", | ||
"output": "./src" | ||
}, | ||
{ | ||
"input": "./libs/local-plugin", | ||
"glob": "generators.json", | ||
"output": "." | ||
}, | ||
{ | ||
"input": "./libs/local-plugin", | ||
"glob": "executors.json", | ||
"output": "." | ||
} | ||
] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"libs/local-plugin/**/*.ts", | ||
"libs/local-plugin/package.json", | ||
"libs/local-plugin/generators.json" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "libs/local-plugin/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
12 changes: 12 additions & 0 deletions
12
libs/local-plugin/src/generators/convert-entry-point-to-project/generator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
describe('convert-entry-point-to-project generator', () => { | ||
// let tree: Tree; | ||
// const options: ConvertEntryPointToProjectGeneratorSchema = { name: 'test' }; | ||
// | ||
// beforeEach(() => { | ||
// tree = createTreeWithEmptyWorkspace(); | ||
// }); | ||
// | ||
it('should run successfully', async () => { | ||
expect(true).toBeTruthy(); | ||
}); | ||
}); |
105 changes: 105 additions & 0 deletions
105
libs/local-plugin/src/generators/convert-entry-point-to-project/generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { | ||
Tree, | ||
addProjectConfiguration, | ||
formatFiles, | ||
getWorkspaceLayout, | ||
logger, | ||
readJson, | ||
readProjectConfiguration, | ||
updateJson, | ||
} from '@nx/devkit'; | ||
import type { ConvertEntryPointToProjectGeneratorSchema } from './schema'; | ||
|
||
export async function convertEntryPointToProjectGenerator( | ||
tree: Tree, | ||
options: ConvertEntryPointToProjectGeneratorSchema | ||
) { | ||
const { name, project } = options; | ||
if (name === 'src') { | ||
logger.warn(`[local-plugin] entry point "src" is invalid`); | ||
return; | ||
} | ||
|
||
const projectConfiguration = readProjectConfiguration(tree, project); | ||
|
||
if (!projectConfiguration) { | ||
logger.error(`[local-plugin] project ${project} not found`); | ||
return; | ||
} | ||
|
||
const projectPackageJson = readJson( | ||
tree, | ||
projectConfiguration.root + '/package.json' | ||
); | ||
|
||
if (!projectPackageJson.name) { | ||
logger.error( | ||
`[local-plugin] project ${project} does not have a name in package.json` | ||
); | ||
return; | ||
} | ||
|
||
const { libsDir } = getWorkspaceLayout(tree); | ||
|
||
const entryPointPath = libsDir | ||
? `${libsDir}/${project}/${name}` | ||
: `${project}/${name}`; | ||
|
||
const isExist = tree.exists(entryPointPath); | ||
if (!isExist) { | ||
logger.error(`[local-plugin] ${name} not found as an entry point`); | ||
return; | ||
} | ||
|
||
const isProjectJsonExist = tree.exists(`${entryPointPath}/project.json`); | ||
if (isProjectJsonExist) { | ||
logger.info(`[local-plugin] ${name} entry point is already a Project`); | ||
return; | ||
} | ||
|
||
addProjectConfiguration(tree, `${projectPackageJson.name}/${name}`, { | ||
root: entryPointPath, | ||
projectType: 'library', | ||
sourceRoot: `${entryPointPath}/src`, | ||
targets: { | ||
test: { | ||
executor: '@nx/jest:jest', | ||
outputs: ['{workspaceRoot}/coverage/{projectRoot}'], | ||
options: { | ||
jestConfig: `${projectConfiguration.root}/jest.config.ts`, | ||
passWithNoTests: true, | ||
}, | ||
configurations: { | ||
ci: { | ||
ci: true, | ||
codeCoverage: true, | ||
}, | ||
}, | ||
}, | ||
lint: { | ||
executor: '@nx/linter:eslint', | ||
outputs: ['{options.outputFile}'], | ||
options: { | ||
lintFilePatterns: [ | ||
`${entryPointPath}/**/*.ts`, | ||
`${entryPointPath}/**/*.html`, | ||
], | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
updateJson(tree, `${projectConfiguration.root}/project.json`, (json) => { | ||
if (json.targets?.lint?.options?.lintFilePatterns) { | ||
json.targets.lint.options.lintFilePatterns = | ||
json.targets.lint.options.lintFilePatterns.filter( | ||
(pattern: string) => !pattern.includes(entryPointPath) | ||
); | ||
} | ||
return json; | ||
}); | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
export default convertEntryPointToProjectGenerator; |
4 changes: 4 additions & 0 deletions
4
libs/local-plugin/src/generators/convert-entry-point-to-project/schema.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface ConvertEntryPointToProjectGeneratorSchema { | ||
name: string; | ||
project: string; | ||
} |
27 changes: 27 additions & 0 deletions
27
libs/local-plugin/src/generators/convert-entry-point-to-project/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "ConvertEntryPointToProject", | ||
"title": "", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "The name of the entry point to convert", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
}, | ||
"x-prompt": "What entry point would you like to convert to a Project?" | ||
}, | ||
"project": { | ||
"type": "string", | ||
"description": "The project that contains the entry point", | ||
"$default": { | ||
"$source": "projectName" | ||
}, | ||
"x-priority": "important", | ||
"x-prompt": "What is the project that contains the entry point?" | ||
} | ||
}, | ||
"required": ["name", "project"] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.