-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathmerge_requirements.js
86 lines (74 loc) · 2.24 KB
/
merge_requirements.js
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 fs from "fs";
let rawcore = fs.readFileSync("./homeassistant-frontend/package.json");
let rawhacs = fs.readFileSync("./package.json");
const core = JSON.parse(rawcore);
const hacs = JSON.parse(rawhacs);
fs.writeFileSync(
".yarnrc.yml",
`
compressionLevel: mixed
defaultSemverRangePrefix: ""
enableGlobalCache: false
nodeLinker: node-modules
yarnPath: ./homeassistant-frontend/.yarn/releases/yarn-${core.packageManager.split("@")[1]}.cjs
`,
);
fs.copyFileSync(`./homeassistant-frontend/.browserslistrc`, `.browserslistrc`);
fs.rmSync("./src/resources/polyfills", { recursive: true, force: true });
fs.mkdirSync("./src/resources/polyfills", { recursive: true });
for (const file of fs.readdirSync("./homeassistant-frontend/src/resources/polyfills", {
recursive: true,
})) {
fs.copyFileSync(
`./homeassistant-frontend/src/resources/polyfills/${file}`,
`./src/resources/polyfills/${file}`,
);
}
const intlPolyfill = fs.readFileSync("./src/resources/polyfills/intl-polyfill.ts", {
encoding: "utf-8",
});
fs.writeFileSync(
"./src/resources/polyfills/intl-polyfill.ts",
intlPolyfill.replace(
"../../util/common-translation",
"../../../homeassistant-frontend/src/util/common-translation",
),
{ encoding: "utf-8" },
);
fs.copyFileSync(
`./homeassistant-frontend/src/translations/translationMetadata.json`,
`./src/localize/languages/translationMetadata.json`,
);
const replacePatches = (deps) =>
Object.fromEntries(
Object.entries(deps).map(([key, val]) => [
key,
val
.replace("#.yarn/patches/", "#./homeassistant-frontend/.yarn/patches/")
.replace("#./.yarn/patches/", "#./homeassistant-frontend/.yarn/patches/")
.replace("#~/.yarn/patches/", "#~/homeassistant-frontend/.yarn/patches/"),
]),
);
fs.writeFileSync(
"./package.json",
JSON.stringify(
{
...hacs,
resolutions: {
...replacePatches(core.resolutions),
...hacs.resolutionsOverride,
},
dependencies: {
...replacePatches(core.dependencies),
...hacs.dependenciesOverride,
},
devDependencies: {
...replacePatches(core.devDependencies),
...hacs.devDependenciesOverride,
},
packageManager: core.packageManager,
},
null,
2,
),
);