-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
63 lines (56 loc) · 1.74 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
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
const nativefier = require("nativefier").default;
const { MultiSelect } = require("enquirer");
const fs = require("fs");
const YAML = require("yaml");
const apps = YAML.parse(fs.readFileSync("./apps.yaml", "utf8"));
const createNativefierApp = (name = {}) => {
if (typeof name !== "string") {
throw new TypeError(`Expected a string, got ${typeof name}`);
}
if (apps[name].hasOwnProperty("additionalOptions")) {
let additionalOptionsList = Object.keys(apps[name].additionalOptions);
console.log(additionalOptionsList);
const prompt = new MultiSelect({
// TODO: Make options with "default": true selected by default
name: "additionalOptions",
message: "Available Additional Options ",
hint: "(Use <space> to select, <return> to submit)",
choices: additionalOptionsList,
});
prompt
.run()
.then((answer) => runNativefier(getOptions(name, answer)))
.catch(console.error);
} else {
let options = [];
options.name = apps[name].name;
options.targetUrl = apps[name].targetUrl;
runNativefier(options);
}
};
function getOptions(name = {}, selectedAdditionalOptions = {}) {
var options = [];
selectedAdditionalOptions.forEach((element) => {
Object.keys(apps[name].additionalOptions[element].flags).forEach(
(option) => {
options[option] = apps[name].additionalOptions[element].flags[option];
}
);
});
options.name = apps[name].name;
options.targetUrl = apps[name].targetUrl;
console.dir(options);
return options;
}
/*runNativefier(config);*/
//return `${name} & ${postfix}`;
function runNativefier(config = {}) {
nativefier(config, function (error, appPath) {
if (error) {
console.error(error);
return;
}
console.log("App has been nativefied to", appPath);
});
}
module.exports = createNativefierApp;