-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathmaterial.ts
More file actions
89 lines (79 loc) · 2.68 KB
/
material.ts
File metadata and controls
89 lines (79 loc) · 2.68 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { appendFile } from 'node:fs/promises';
import { getGlobalVariable } from '../../utils/env';
import { readFile, replaceInFile } from '../../utils/fs';
import {
getActivePackageManager,
installPackage,
installWorkspacePackages,
} from '../../utils/packages';
import { ng } from '../../utils/process';
import { isPrereleaseCli, updateJsonFile } from '../../utils/project';
import { executeBrowserTest } from '../../utils/puppeteer';
const snapshots = require('../../ng-snapshot/package.json');
export default async function () {
const isPrerelease = await isPrereleaseCli();
let tag = isPrerelease ? '@next' : '';
if (getActivePackageManager() === 'npm') {
await appendFile('.npmrc', '\nlegacy-peer-deps=true');
}
await ng('add', `@angular/material${tag}`, '--skip-confirmation');
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
if (isSnapshotBuild) {
await updateJsonFile('package.json', (packageJson) => {
const dependencies = packageJson['dependencies'];
// Angular material adds dependencies on other Angular packages
// Iterate over all of the packages to update them to the snapshot version.
for (const [name, version] of Object.entries(snapshots.dependencies)) {
if (name in dependencies) {
dependencies[name] = version;
}
}
dependencies['@angular/material-moment-adapter'] =
snapshots.dependencies['@angular/material-moment-adapter'];
});
await installWorkspacePackages();
} else {
if (!tag) {
const installedMaterialVersion = JSON.parse(await readFile('package.json'))['dependencies'][
'@angular/material'
];
tag = `@${installedMaterialVersion}`;
}
await installPackage(`@angular/material-moment-adapter${tag}`);
}
await installPackage('moment');
await ng('build');
// Ensure moment adapter works (uses unique importing mechanism for moment)
// Issue: https://github.com/angular/angular-cli/issues/17320
await replaceInFile(
'src/app/app.config.ts',
`from '@angular/core';`,
`
from '@angular/core';
import {
MomentDateAdapter,
MAT_MOMENT_DATE_FORMATS
} from '@angular/material-moment-adapter';
import {
DateAdapter,
MAT_DATE_LOCALE,
MAT_DATE_FORMATS
} from '@angular/material/core';
`,
);
await replaceInFile(
'src/app/app.config.ts',
`provideRouter(routes)`,
`provideRouter(routes),
{
provide: DateAdapter,
useClass: MomentDateAdapter,
deps: [MAT_DATE_LOCALE]
},
{
provide: MAT_DATE_FORMATS,
useValue: MAT_MOMENT_DATE_FORMATS
}`,
);
await executeBrowserTest({ configuration: 'production' });
}