-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathadd-material.ts
More file actions
46 lines (40 loc) · 1.43 KB
/
add-material.ts
File metadata and controls
46 lines (40 loc) · 1.43 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
import { assertIsError } from '../../../utils/utils';
import { readFile, rimraf } from '../../../utils/fs';
import { getActivePackageManager, uninstallPackage } from '../../../utils/packages';
import { ng } from '../../../utils/process';
import { isPrereleaseCli } from '../../../utils/project';
import { appendFile } from 'node:fs/promises';
import assert from 'node:assert';
export default async function () {
// forcibly remove in case another test doesn't clean itself up
await rimraf('node_modules/@angular/material');
const isPrerelease = await isPrereleaseCli();
const tag = isPrerelease ? '@next' : '';
if (getActivePackageManager() === 'npm') {
await appendFile('.npmrc', '\nlegacy-peer-deps=true');
}
try {
await ng('add', `@angular/material${tag}`, '--unknown', '--skip-confirmation');
} catch (error) {
assertIsError(error);
if (!(error as Error).message.includes(`Unknown option: '--unknown'`)) {
throw error;
}
}
await ng(
'add',
`@angular/material${tag}`,
'--theme',
'azure-blue',
'--verbose',
'--skip-confirmation',
);
const { dependencies } = JSON.parse(await readFile('package.json'));
assert.ok(
dependencies['@angular/material'],
'`@angular/material` was not found added to dependencies',
);
// Clean up existing cdk package
// Not doing so can cause adding material to fail if an incompatible cdk is present
await uninstallPackage('@angular/cdk');
}