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