1 | #!/usr/bin/env node
|
2 | const bump = require("./lib/release/bump.js");
|
3 | const chalk = require("chalk");
|
4 | const generateFScripts = require("./lib/generateFScripts.js");
|
5 | const parseScriptFile = require("./lib/parseScriptsMd.js");
|
6 |
|
7 | const generateToc = require("./lib/generateToc");
|
8 | const upgradePackages = require("./lib/upgradePackages");
|
9 | const runSequence = require("./lib/runSequence");
|
10 | const runParallel = require("./lib/runParallel");
|
11 | const runCLICommand = require("./lib/runCLICommand");
|
12 | const { startPackageScripts, startScripts, clearRecent } = require("./lib/startScripts.js");
|
13 | const taskName = chalk.rgb(39, 173, 96).bold.underline;
|
14 | const textDescription = chalk.rgb(159, 161, 181);
|
15 | const optionList = require("./lib/optionList");
|
16 | const validateNotInDev = require("./lib/git/validateNotDev.js");
|
17 | const encrypt = require("./lib/encryption/encryption");
|
18 |
|
19 | (async () => {
|
20 | await validateNotInDev();
|
21 |
|
22 | const argv = require("yargs")
|
23 | .usage("Usage: $0 <command> [options]")
|
24 |
|
25 | |
26 |
|
27 |
|
28 | .command("", "Choose a script runner command", yargs => {}, async function() {})
|
29 | .example(`${taskName("$0")}`, `${textDescription("Choose a script runner command")}`)
|
30 |
|
31 | |
32 |
|
33 |
|
34 |
|
35 | .command("start", "Choose category then task to run", yargs => {}, async function() {
|
36 | if ((await startScripts()) === false) {
|
37 | await startPackageScripts();
|
38 | }
|
39 | })
|
40 | .example(`${taskName("$0 start")}`, `${textDescription("Open a task selection selector")}`)
|
41 |
|
42 | |
43 |
|
44 |
|
45 |
|
46 | .command("scripts", "Choose a script from package.json", yargs => {}, async function() {
|
47 | await startPackageScripts();
|
48 | })
|
49 | .example(
|
50 | `${taskName("$0 scripts")}`,
|
51 | `${textDescription("Choose a script from package.json")}`
|
52 | )
|
53 |
|
54 | |
55 |
|
56 |
|
57 |
|
58 | .command("list", "Select any task with text autocompletion", () => {}, async function(
|
59 | argv
|
60 | ) {
|
61 | await startScripts(false);
|
62 |
|
63 | })
|
64 | .example(`${taskName("$0 list")}`, `${textDescription("Show you all tasks you can run")}`)
|
65 |
|
66 | |
67 |
|
68 |
|
69 |
|
70 | .command("run", "Run a specific task", () => {}, async function(argv) {
|
71 | let task = argv._[1];
|
72 | const FcScripts = await parseScriptFile();
|
73 | let taskIndex = FcScripts.allTasks.findIndex(t => t.name === task);
|
74 | let taskData = FcScripts.allTasks[taskIndex];
|
75 | let runCommand = taskData["script"].split(" ");
|
76 | let type = runCommand.shift();
|
77 | let params = runCommand.join(" ");
|
78 | let args = Object.keys(argv)
|
79 | .filter(e => e !== "_" && e !== "$0")
|
80 | .map(e => ` --${e}=${argv[e]}`);
|
81 | params += " " + args.join(" ");
|
82 | await runCLICommand({
|
83 | task: { name: task },
|
84 | script: {
|
85 | type: type,
|
86 | rest: params.split(" ")
|
87 | }
|
88 | });
|
89 | })
|
90 | .example(`${taskName("$0 run start:web")}`, `${textDescription("Run task 'start:web'")}`)
|
91 |
|
92 | |
93 |
|
94 |
|
95 |
|
96 | .command(
|
97 | "upgrade",
|
98 | "Upgrade all your packages except ones specified by 'ignore-upgrade':[]",
|
99 | () => {},
|
100 | async function(argv) {
|
101 | let task = argv._[1];
|
102 | await upgradePackages();
|
103 | }
|
104 | )
|
105 | .example(`${taskName("$0 upgrade")}`, `${textDescription("Upgraded!")}`)
|
106 |
|
107 | |
108 |
|
109 |
|
110 |
|
111 | .command("bump", "Bump package.json and beautify it!", () => {}, async function(argv) {
|
112 | let task = argv._[1];
|
113 | await bump();
|
114 | })
|
115 | .example(`${taskName("$0 bump")}`, `${textDescription("BUMPED AND PRETTY!")}`)
|
116 |
|
117 | |
118 |
|
119 |
|
120 |
|
121 | .command("run-s", "Run a set of tasks one after another", () => {}, async function(argv) {
|
122 | let tasks = argv._.slice();
|
123 | tasks.shift();
|
124 | const FcScripts = await parseScriptFile();
|
125 | await runSequence(tasks, FcScripts);
|
126 | })
|
127 | .example(
|
128 | `${taskName("$0 run-s start:web start:desktop")}`,
|
129 | `${textDescription("Run task 'start:web' and afterwards 'start:desktop'")}`
|
130 | )
|
131 |
|
132 | |
133 |
|
134 |
|
135 |
|
136 | .command("run-p", "Run tasks in parallel", () => {}, async function(argv) {
|
137 | let tasks = argv._.slice();
|
138 | tasks.shift();
|
139 | const FcScripts = await parseScriptFile();
|
140 | await runParallel(tasks, FcScripts);
|
141 | })
|
142 | .example(
|
143 | `${taskName("$0 run-p start:web start:desktop")}`,
|
144 | `${textDescription("Run task 'start:web' and at the same time 'start:desktop'")}`
|
145 | )
|
146 |
|
147 | |
148 |
|
149 |
|
150 |
|
151 | .command("encryption", "Encrypt/Decrypt secret files", () => {}, async function(argv) {
|
152 | await encrypt.init();
|
153 | })
|
154 | .example(
|
155 | `${taskName("$0 encryption")}`,
|
156 | `${textDescription("Encrypt/Decrypt secret files")}`
|
157 | )
|
158 |
|
159 | |
160 |
|
161 |
|
162 |
|
163 | .command("clear", "Clear recent task history", () => {}, async function(argv) {
|
164 | await clearRecent();
|
165 | })
|
166 | .example(`${taskName("$0 clear")}`, `${textDescription("Clear your recently run tasks")}`)
|
167 | .command(
|
168 | "generate",
|
169 | "Generate a sample fscripts.md file from the package.json",
|
170 | () => {},
|
171 | async function(argv) {
|
172 | await generateFScripts();
|
173 | }
|
174 | )
|
175 | .example(
|
176 | `${taskName("$0 generate")}`,
|
177 | `${textDescription(
|
178 | "Generates a sample.fscripts.md you can use as template for your fscripts file"
|
179 | )}`
|
180 | )
|
181 | .command(
|
182 | "toc",
|
183 | "Generate updated Table of Contents on top of the fscripts.md file",
|
184 | () => {},
|
185 | async function(argv) {
|
186 | await generateToc();
|
187 | }
|
188 | )
|
189 | .example(
|
190 | `${taskName("$0 toc")}`,
|
191 | `${textDescription(
|
192 | "Generate updated Table of Contents on top of the fscripts.md file"
|
193 | )}`
|
194 | ).argv;
|
195 |
|
196 | if (argv._.length === 0) {
|
197 | (async function() {
|
198 | const choice = await optionList();
|
199 | if (choice) {
|
200 | await runCLICommand(
|
201 | { task: { name: choice }, script: { type: "fsr", rest: [choice] } },
|
202 | true
|
203 | );
|
204 | } else {
|
205 | console.log(chalk.green.bold("See you soon!"));
|
206 | }
|
207 | })();
|
208 | }
|
209 | })();
|