-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
88 lines (76 loc) · 2.23 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const execa = require("execa");
const chalk = require("chalk");
const branch = require("git-branch");
const Listr = require("listr");
const checkDependencies = require("check-dependencies");
const isOnline = require("is-online");
async function execPrestart() {
const { stdout: nodeVersion } = await execa("node", ["-v"]);
const { stdout: gitEmail } = await execa("git", ["config", "user.email"]);
const branchName = branch.sync();
console.log("🔑 ", "", chalk.bold("PreStart"));
console.log("");
console.log(chalk.bold("Project details"));
console.log(chalk.gray("--------------------------------------------"));
console.log("node ", "version ", nodeVersion.replace("v", ""));
console.log("git ", "branch ", branchName);
console.log(" ", "email ", gitEmail);
console.log(chalk.gray("--------------------------------------------"));
console.log("");
const tasks = new Listr([
{
title: `${chalk.grey("[1/2]")} 🔌 Checking connection...`,
task: (ctx, task) => {
return isOnline({ timeout: 2500 }).then(online => {
ctx.isOnline = online;
});
}
},
{
title: `${chalk.grey("[2/2]")} 🚚 Fetching packages...`,
task: (ctx, task) => {
if (!ctx.isOnline) {
task.skip(
"Looks like you're offline. We'll skip dependency fetching."
);
}
const hasDependencies = checkDependencies.sync({
checkGitUrls: true,
install: false,
packageManager: "npm",
verbose: false
}).depsWereOk;
if (hasDependencies) {
return Promise.resolve();
} else {
return execa("npm", ["install"]);
}
}
}
]);
tasks
.run()
.then(() => {
console.log("");
console.log(chalk.green("Success!"));
console.log("✨ ", "Have fun developing!");
console.log("");
})
.catch(err => {
console.log("");
console.log(chalk.red("Error!"));
console.error(err);
console.log("");
});
}
function Prestart() {
return execPrestart();
}
function sync(cb) {
new Prestart().then(cb).catch(cb);
}
function prestart() {
return new Prestart();
}
prestart.sync = sync;
module.exports = prestart;