Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Commit 504e1ef

Browse files
committed
feat: Schematic for extracting libraries from projects
JIRA-Ticket: AV-27910
1 parent 528c54d commit 504e1ef

11 files changed

+263
-2
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/collection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"description": "Create an Avrios library",
3131
"factory": "./library",
3232
"schema": "./library/schema.json"
33+
},
34+
"extract-app-libs": {
35+
"description": "Extract app libs from an Avrios project",
36+
"factory": "./extract-app-libs",
37+
"schema": "./extract-app-libs/schema.json"
3338
}
3439
}
3540
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NgModule } from '@angular/core';
2+
import { <%= classify(name) %> } from './<%= dasherize(name) %>';
3+
4+
@NgModule({
5+
providers: [<%= classify(name) %>]
6+
})
7+
export class <%= classify(name) %>Module {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { <%= classify(name) %> } from './<%= dasherize(name) %>';
4+
5+
describe('<%= classify(name) %>', () => {
6+
let lib: <%= classify(name) %>;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
lib = TestBed.inject(<%= classify(name) %>);
11+
});
12+
13+
it('should be instantiated', () => {
14+
expect(lib).toBeTruthy();
15+
});
16+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class <%= classify(name) %> {
2+
constructor() {
3+
}
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
export class <%= classify(name) %> {
3+
constructor() {
4+
}
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class <%= classify(name) %> {
2+
constructor() {
3+
}
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class <%= classify(name) %> {
2+
constructor() {
3+
}
4+
}

src/extract-app-libs/index.js

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extract-app-libs/index.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { strings } from '@angular-devkit/core';
2+
import {
3+
Rule,
4+
Tree,
5+
apply,
6+
applyTemplates,
7+
chain,
8+
move,
9+
url
10+
} from '@angular-devkit/schematics';
11+
12+
import { validateName } from '../utilities/validation';
13+
import { parseName } from '../utilities/parse-name';
14+
15+
interface LibraryOptions {
16+
project: string;
17+
prefix: string;
18+
skipStartConfig: boolean;
19+
tags?: string;
20+
namespace?: string;
21+
path?: string;
22+
}
23+
24+
export default function (options: LibraryOptions): Rule {
25+
return (host: Tree) => {
26+
const projectJsonFile = '/project.json';
27+
const { prefix, project, skipStartConfig, tags: tagsString } = options;
28+
const dasherizedName = strings.dasherize(project);
29+
30+
const parsedPath = parseName(`libs/${dasherizedName}`, project);
31+
32+
validateName(parsedPath.name);
33+
34+
const projectLibsRoot = parsedPath.path;
35+
const tags = tagsString ? tagsString.split(',').map(s => s.trim()) : [];
36+
37+
const libraryNames = host.getDir(projectLibsRoot).subdirs;
38+
libraryNames.forEach(libraryName => {
39+
validateName(libraryName);
40+
const sourceRoot = `${projectLibsRoot}/src/lib/${libraryName}`;
41+
42+
const projectConfig = {
43+
sourceRoot,
44+
prefix,
45+
tags,
46+
projectType: 'library',
47+
generators: {},
48+
targets: {
49+
lint: {
50+
executor: '@nrwl/linter:eslint',
51+
options: {
52+
lintFilePatterns: [
53+
`${sourceRoot}/**/*.ts`,
54+
`${sourceRoot}/**/*.html`
55+
],
56+
eslintConfig: `${projectLibsRoot}/.eslintrc.json`
57+
}
58+
},
59+
test: {
60+
executor: '@nrwl/jest:jest',
61+
options: {
62+
jestConfig: `${projectLibsRoot}/jest.config.ts`,
63+
passWithNoTests: true,
64+
testPathPattern: [`lib/${libraryName}/`]
65+
}
66+
}
67+
}
68+
};
69+
70+
host.exists(`${projectLibsRoot}/${libraryName}/${projectJsonFile}`) || host.create(`${projectLibsRoot}/${libraryName}/${projectJsonFile}`, JSON.stringify(projectConfig));
71+
});
72+
73+
options.project = parsedPath.name;
74+
options.path = parsedPath.path;
75+
76+
const rules: any[] = [
77+
(_: any) => host
78+
]
79+
80+
if (!skipStartConfig) {
81+
rules.push(
82+
apply(url('./files'), [
83+
applyTemplates({
84+
...strings,
85+
...options
86+
}),
87+
move(projectLibsRoot)
88+
])
89+
);
90+
}
91+
92+
93+
return chain(rules);
94+
};
95+
}

0 commit comments

Comments
 (0)