UNPKG

7.5 kBJavaScriptView Raw
1#!/usr/bin/env node
2const bump = require("./lib/release/bump.js");
3const chalk = require("chalk");
4const generateFScripts = require("./lib/generateFScripts.js");
5const parseScriptFile = require("./lib/parseScriptsMd.js");
6// const parseScriptPackage = require("./lib/parseScriptsPackage");
7const generateToc = require("./lib/generateToc");
8const upgradePackages = require("./lib/upgradePackages");
9const runSequence = require("./lib/runSequence");
10const runParallel = require("./lib/runParallel");
11const runCLICommand = require("./lib/runCLICommand");
12const { startPackageScripts, startScripts, clearRecent } = require("./lib/startScripts.js");
13const taskName = chalk.rgb(39, 173, 96).bold.underline;
14const textDescription = chalk.rgb(159, 161, 181);
15const optionList = require("./lib/optionList");
16const validateNotInDev = require("./lib/git/validateNotDev.js");
17const encrypt = require("./lib/encryption/encryption");
18
19(async () => {
20 const argv = require("yargs")
21 .usage("Usage: $0 <command> [options]")
22
23 /**
24 * fsr
25 */
26 .command("", "Choose a script runner command", yargs => {}, async function() {})
27 .example(`${taskName("$0")}`, `${textDescription("Choose a script runner command")}`)
28
29 /**
30 * fsr
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 * fsr
44 * start --
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 * fsr
55 * scripts --
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 * fsr
67 * list --
68 */
69 .command("list", "Select any task with text autocompletion", () => {}, async function(
70 argv
71 ) {
72 await startScripts(false);
73 // const tasks = await scriptsParsed().allTasks;
74 })
75 .example(`${taskName("$0 list")}`, `${textDescription("Show you all tasks you can run")}`)
76
77 /**
78 * fsr
79 * run --
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 * fsr
105 * upgrade --
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 * fsr
120 * bump --
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 * fsr
130 * run-s --
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 * fsr
145 * run-p --
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 * fsr
160 * encryption --
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 * fsr
172 * clear --
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})();