-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.ts
More file actions
86 lines (75 loc) · 2.59 KB
/
main.ts
File metadata and controls
86 lines (75 loc) · 2.59 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
import * as core from '@actions/core';
import * as fs from 'fs';
import {AngularJson} from './types/angular-json';
import {AngularVersion} from './types/angular-version';
import {getAngularVersions} from './get-angular-versions';
import {overrideAngularVersions} from './override-angular-versions';
import {replaceLibrariesNgPackagrBuilder} from './replace-libraries-ngpackagr-builder';
import {PackageJson} from './types/package-json';
import path from 'path';
function ensureCorrectNgPackagrBuilder(
angularVersion: AngularVersion,
angularJsonPath: string
): void {
core.debug(
`Accessing angular.json and replacing all ng-packagr targets to use the builder corresponding to the specified Angular version: ${angularVersion}`
);
const angularJson: AngularJson = JSON.parse(
fs.readFileSync(angularJsonPath).toString()
);
const modifiedAngularJson = replaceLibrariesNgPackagrBuilder(
angularVersion,
angularJson
);
fs.writeFileSync(
angularJsonPath,
JSON.stringify(modifiedAngularJson, null, 2)
);
core.debug(
'ng-packagr targets replaced to be compatible with the specified Angular version'
);
}
function replaceAngularRelatedDependenciesInPackageJson(
angularVersion: AngularVersion,
packageJsonPath: string
): void {
core.debug(`Finding dependencies for Angular version ${angularVersion}`);
const angularVersions = getAngularVersions(angularVersion);
core.debug(
`Dependencies found: \n ${JSON.stringify(angularVersions, null, 2)}`
);
core.debug(`Merging found dependencies with file ${packageJsonPath}`);
const projectVersions: PackageJson = JSON.parse(
fs.readFileSync(packageJsonPath).toString()
);
const mergedVersions = overrideAngularVersions({
angularVersions,
projectVersions
});
fs.writeFileSync(packageJsonPath, JSON.stringify(mergedVersions, null, 2));
core.debug(
`Dependencies merged in package.json: \n ${JSON.stringify(
mergedVersions,
null,
2
)}`
);
}
function run(): void {
try {
const angularVersion = core.getInput('angular-version') as AngularVersion;
const rootPath: string = core.getInput('root-path');
const packageJsonPath = path.join(rootPath, 'package.json');
const angularJsonPath = path.join(rootPath, 'angular.json');
replaceAngularRelatedDependenciesInPackageJson(
angularVersion,
packageJsonPath
);
ensureCorrectNgPackagrBuilder(angularVersion, angularJsonPath);
core.debug(new Date().toISOString());
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
core.setFailed(error.message);
}
}
run();