-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·46 lines (40 loc) · 1.07 KB
/
app.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
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const yargs = require("yargs/yargs");
const prompts = require("prompts");
const tasks = require("./src/tasks");
const argv = yargs(process.argv.slice(2))
.usage("Usage: $0 <homey-app> [options]")
.option("y", {
alias: "yes",
describe: "Skip the questionnaire",
})
.alias("v", "version")
.alias("h", "help")
.epilog("copyright 2021").argv;
const homeyPath = path.join(process.cwd(), argv._[0] || "./");
if (argv.yes) {
runTasks();
} else {
(async () => {
const response = await prompts({
type: "confirm",
name: "value",
message: `${fs.existsSync(homeyPath) ? "Update" : "Create"} homey-app to ${homeyPath}?`,
initial: true,
});
if (response.value) {
runTasks();
}
})();
}
function runTasks() {
Promise.resolve(true)
.then(tasks.initHomeyApp(homeyPath))
.then(tasks.createHomeyApp())
.then(tasks.copyAppTemplates())
.then(tasks.handleGitRepo())
.then(tasks.logSuccess(`create-homey-app on: ${homeyPath} finished`))
.catch((err) => tasks.logError(err.message));
}