This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Schematic for extracting libraries from projects
JIRA-Ticket: AV-27910
- Loading branch information
Showing
12 changed files
with
264 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
7 changes: 7 additions & 0 deletions
7
src/extract-app-libs/files/__name@dasherize__..eslintrc.json.template
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,7 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { <%= classify(name) %> } from './<%= dasherize(name) %>'; | ||
|
||
@NgModule({ | ||
providers: [<%= classify(name) %>] | ||
}) | ||
export class <%= classify(name) %>Module {} |
16 changes: 16 additions & 0 deletions
16
src/extract-app-libs/files/__name@dasherize__.jest.config.ts.template
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 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { <%= classify(name) %> } from './<%= dasherize(name) %>'; | ||
|
||
describe('<%= classify(name) %>', () => { | ||
let lib: <%= classify(name) %>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
lib = TestBed.inject(<%= classify(name) %>); | ||
}); | ||
|
||
it('should be instantiated', () => { | ||
expect(lib).toBeTruthy(); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
src/extract-app-libs/files/__name@dasherize__.tsconfig-linter.json.template
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 class <%= classify(name) %> { | ||
constructor() { | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/extract-app-libs/files/__name@dasherize__.tsconfig.json.template
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,5 @@ | ||
|
||
export class <%= classify(name) %> { | ||
constructor() { | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/extract-app-libs/files/__name@dasherize__.tsconfig.lib.json.template
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 class <%= classify(name) %> { | ||
constructor() { | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/extract-app-libs/files/__name@dasherize__.tsconfig.spec.json.template
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 class <%= classify(name) %> { | ||
constructor() { | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,95 @@ | ||
import { strings } from '@angular-devkit/core'; | ||
import { | ||
Rule, | ||
Tree, | ||
apply, | ||
applyTemplates, | ||
chain, | ||
move, | ||
url | ||
} from '@angular-devkit/schematics'; | ||
|
||
import { validateName } from '../utilities/validation'; | ||
import { parseName } from '../utilities/parse-name'; | ||
|
||
interface LibraryOptions { | ||
project: string; | ||
prefix: string; | ||
skipStartConfig: boolean; | ||
tags?: string; | ||
namespace?: string; | ||
path?: string; | ||
} | ||
|
||
export default function (options: LibraryOptions): Rule { | ||
return (host: Tree) => { | ||
const projectJsonFile = '/project.json'; | ||
const { prefix, project, skipStartConfig, tags: tagsString } = options; | ||
const dasherizedName = strings.dasherize(project); | ||
|
||
const parsedPath = parseName(`libs/${dasherizedName}`, project); | ||
|
||
validateName(parsedPath.name); | ||
|
||
const projectLibsRoot = parsedPath.path; | ||
const tags = tagsString ? tagsString.split(',').map(s => s.trim()) : []; | ||
|
||
const libraryNames = host.getDir(projectLibsRoot).subdirs; | ||
libraryNames.forEach(libraryName => { | ||
validateName(libraryName); | ||
const sourceRoot = `${projectLibsRoot}/src/lib/${libraryName}`; | ||
|
||
const projectConfig = { | ||
sourceRoot, | ||
prefix, | ||
tags, | ||
projectType: 'library', | ||
generators: {}, | ||
targets: { | ||
lint: { | ||
executor: '@nrwl/linter:eslint', | ||
options: { | ||
lintFilePatterns: [ | ||
`${sourceRoot}/**/*.ts`, | ||
`${sourceRoot}/**/*.html` | ||
], | ||
eslintConfig: `${projectLibsRoot}/.eslintrc.json` | ||
} | ||
}, | ||
test: { | ||
executor: '@nrwl/jest:jest', | ||
options: { | ||
jestConfig: `${projectLibsRoot}/jest.config.ts`, | ||
passWithNoTests: true, | ||
testPathPattern: [`lib/${libraryName}/`] | ||
} | ||
} | ||
} | ||
}; | ||
|
||
host.exists(`${projectLibsRoot}/${libraryName}/${projectJsonFile}`) || host.create(`${projectLibsRoot}/${libraryName}/${projectJsonFile}`, JSON.stringify(projectConfig)); | ||
}); | ||
|
||
options.project = parsedPath.name; | ||
options.path = parsedPath.path; | ||
|
||
const rules: any[] = [ | ||
(_: any) => host | ||
] | ||
|
||
if (!skipStartConfig) { | ||
rules.push( | ||
apply(url('./files'), [ | ||
applyTemplates({ | ||
...strings, | ||
...options | ||
}), | ||
move(projectLibsRoot) | ||
]) | ||
); | ||
} | ||
|
||
|
||
return chain(rules); | ||
}; | ||
} |
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,57 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "SchematicsAngularComponent", | ||
"title": "Angular Extract libraries", | ||
"type": "object", | ||
"description": "Creates a new generic Library definition in the given or default project.", | ||
"properties": { | ||
"project": { | ||
"type": "string", | ||
"description": "The name of the project this libraries belong to. If none given then the libraries are added to the the shared scope.", | ||
"$default": { | ||
"$source": "projectName" | ||
} | ||
}, | ||
"namespace": { | ||
"type": "string", | ||
"description": "The namespace of the Library. Normally matches the project name.", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
}, | ||
"x-prompt": "What namespace would you like to use for the Libraries?" | ||
}, | ||
"tags": { | ||
"type": "string", | ||
"description": "The list if tags the libraries are allowed to use.", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 1 | ||
}, | ||
"x-prompt": "Enter the set of tags that determine the boundaries of the libraries, delimited by comma. You can check the available list of tags in .eslintrc file. Ex: scope:shared." | ||
}, | ||
"prefix": { | ||
"type": "string", | ||
"description": "The prefix to apply to the generated libraries.", | ||
"alias": "p", | ||
"default": "avr", | ||
"oneOf": [ | ||
{ | ||
"maxLength": 0 | ||
}, | ||
{ | ||
"minLength": 1, | ||
"format": "html-selector" | ||
} | ||
] | ||
}, | ||
"skipStartConfig": { | ||
"type": "boolean", | ||
"description": "When true, does not create ... files for the new libraries.", | ||
"default": true | ||
} | ||
}, | ||
"required": [ | ||
"project" | ||
] | ||
} |