This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·84 lines (64 loc) · 1.9 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
#!/usr/bin/env node
const chalk = require("chalk");
const clear = require("clear");
const figlet = require("figlet");
const minimist = require("minimist");
const figures = require("figures");
const icon = require("./lib/icon");
const splash = require("./lib/splash");
const path = require("path");
const fs = require("fs");
const { Spinner } = require("clui");
const { log } = console;
const params = minimist(process.argv.slice(2));
const parametersList = {
icon: "Icon path in 512x512px (PNG, JPG, SVG)",
splash: "iOS splash screen path in 2048x2732px (PNG, JPG, SVG)",
r: "Export icons with rounded corners",
fill: "Background fill for splash screens"
};
if (params.h === true) {
clear();
log(
chalk.hex("#7159C1").bold(
figlet.textSync("Rocketseat", {
font: "Standard"
})
)
);
log(chalk.green(" RocketPWA parameters: \n"));
Object.keys(parametersList).forEach(key => {
log(
chalk.default(
` ${chalk.hex("#7159C1").bold(key)}: ${parametersList[key]}`
)
);
});
log(chalk.default("\n Example: rocketpwa --icon image.png -r \n"));
process.exit();
}
if (!params.icon && !params.splash) {
log(chalk.red("You need provide icon and/or splash parameters."));
log(chalk.default("Type rocketpwa -h to instructions."));
process.exit();
}
try {
const status = new Spinner(chalk.green("Generating resources..."));
status.start();
const promises = [];
if (params.icon) {
fs.accessSync(params.icon, fs.constants.R_OK);
promises.push(icon(params.icon, !!params.r));
}
if (params.splash) {
fs.accessSync(params.splash, fs.constants.R_OK);
promises.push(splash(params.splash, params.fill));
}
Promise.all(promises).then(() => {
status.stop();
log(chalk.green(figures("✔︎ Resources generated successfully.")));
});
} catch (err) {
log(chalk.red(`Check if files exists in specified path.`));
process.exit();
}