-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathlibrary-with-demo-app.ts
More file actions
63 lines (53 loc) · 1.7 KB
/
library-with-demo-app.ts
File metadata and controls
63 lines (53 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { appendToFile, createDir, writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
export default async function () {
await ng('generate', 'library', 'mylib');
await createLibraryEntryPoint('secondary');
await createLibraryEntryPoint('another');
// Scenario #1 where we use wildcard path mappings for secondary entry-points.
await updateJsonFile('tsconfig.json', (json) => {
json.compilerOptions.paths = { 'mylib': ['./dist/mylib'], 'mylib/*': ['./dist/mylib/*'] };
});
await appendToFile(
'src/app/app.config.ts',
`
import * as secondary from 'mylib/secondary';
import * as another from 'mylib/another';
console.log({
secondary,
another
});
`,
);
await ng('build', 'mylib');
await ng('build');
// Scenario #2 where we don't use wildcard path mappings.
await updateJsonFile('tsconfig.json', (json) => {
json.compilerOptions.paths = {
'mylib': ['./dist/mylib'],
'mylib/secondary': ['./dist/mylib/secondary'],
'mylib/another': ['./dist/mylib/another'],
};
});
await ng('build');
}
async function createLibraryEntryPoint(name: string): Promise<void> {
await createDir(`projects/mylib/${name}`);
await writeFile(`projects/mylib/${name}/index.ts`, `export const foo = 'foo';`);
await writeFile(
`projects/mylib/${name}/ng-package.json`,
JSON.stringify({
lib: {
entryFile: 'index.ts',
},
}),
);
}