This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ns-ngcc-config-gen.ts
68 lines (64 loc) · 2.15 KB
/
ns-ngcc-config-gen.ts
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
import { writeFile, existsSync, mkdirSync, unlinkSync } from "fs";
import * as lineReader from 'line-reader';
const pluginNamesFilePath = "plugin-names.txt";
const distPath = "./dist";
const outputConfigPath = distPath + "/ngcc.config.js";
let names: Array<string> = [];
lineReader.eachLine(pluginNamesFilePath, function (line: any, last: any) {
names.push(line);
if (last) {
writeToDist();
return false;
}
});
function writeToDist() {
let configStart = `module.exports = {
"packages": {
<packages-placeholder>
}
}`;
let packagesPlaceholderKey = "<packages-placeholder>";
let pluginNamePlaceHolderKey = "<plugin-name>";
let configPluginTemplate =
`"<plugin-name>": {
"entryPoints": {
".": {
"ignoreMissingDependencies": true,
},
"angular": {
"override": {
"main": "./index.js",
"typings": "./index.d.ts",
},
"ignoreMissingDependencies": true,
}
}
}`;
var packagesJson: any = {};
packagesJson.packages = [];
if (names.length > 0) {
try {
if (!existsSync(distPath)) {
mkdirSync(distPath);
}
if (existsSync(outputConfigPath)) {
unlinkSync(outputConfigPath)
}
names.forEach(name => {
let ngccConfig = configPluginTemplate.replace(pluginNamePlaceHolderKey, name);
if (packagesJson.packages.length !== 0) {
packagesJson.packages.push("\r\n " + ngccConfig);
} else {
packagesJson.packages.push(ngccConfig);
}
});
let appNgccConfig = configStart.replace(packagesPlaceholderKey, packagesJson.packages);
writeFile(outputConfigPath, appNgccConfig, (err) => {
if (err) throw err;
console.log("'ngcc.config.js' file created at './dist");
});
} catch (err) {
console.error(err)
}
}
}