-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (32 loc) · 1.05 KB
/
index.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
let ui5 = "\nVue.config.ignoredElements = [/^ui5-/];";
module.exports = (api, options, rootOptions) => {
api.extendPackage({
dependencies: {
"@ui5/webcomponents": "^0.9.0"
}
});
if (options.addExample) {
api.render("./template", {
...options
});
}
api.onCreateComplete(() => {
// inject to main.js
const fs = require("fs");
const ext = api.hasPlugin("typescript")
? "ts"
: "js";
const mainPath = api.resolve(`./src/main.${ext}`);
let contentMain = fs.readFileSync(mainPath, {encoding: "utf-8"});
const lines = contentMain
.split(/\r?\n/g)
.reverse();
const lastImportIndex = lines.findIndex(line => line.match(/^import/));
lines[lastImportIndex] += ui5;
contentMain = lines
.reverse()
.join("\n");
fs.writeFileSync(mainPath, contentMain, {encoding: "utf-8"});
api.exitLog("Successfully installed UI5 Web Components", "done");
});
};