fscr 5.4.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin +1 -1
- package/dist/index.js +196 -49
- package/dist/lib/auth/auth-conf.js +63 -0
- package/dist/lib/codemod/arrow.js +13 -0
- package/dist/lib/codemod/arrow2.js +67 -0
- package/dist/lib/codemod/funcs.js +25 -0
- package/dist/lib/codemod/removeConsole.js +12 -0
- package/dist/lib/codemod/test.js +8 -0
- package/dist/lib/components/App.js +64 -0
- package/dist/lib/components/Selector.js +133 -0
- package/dist/lib/components/TabChanger.js +113 -0
- package/dist/lib/components/Table.js +177 -0
- package/dist/lib/components/Tabs.js +221 -0
- package/dist/lib/encryption/decryptConfig.js +81 -0
- package/dist/lib/encryption/encryption.js +135 -0
- package/dist/lib/generateFScripts.js +25 -0
- package/dist/lib/generateToc.js +36 -0
- package/dist/lib/generators/generateFScripts.js +25 -0
- package/dist/lib/generators/generateToc.js +38 -0
- package/dist/lib/generators/index.js +2 -0
- package/dist/lib/git/files.js +26 -0
- package/dist/lib/git/pub.js +42 -0
- package/dist/lib/git/taskRunner.js +80 -0
- package/dist/lib/git/validateNotDev.js +71 -0
- package/dist/lib/helpers.js +191 -0
- package/dist/lib/optionList.js +61 -0
- package/dist/lib/parseScriptsMd.js +93 -0
- package/dist/lib/parseScriptsPackage.js +9 -0
- package/dist/lib/parsers/parseScriptsMd.js +96 -0
- package/dist/lib/parsers/parseScriptsPackage.js +9 -0
- package/dist/lib/release/bump.js +52 -0
- package/dist/lib/release/commitWithMessage.js +65 -0
- package/dist/lib/release/index.js +4 -0
- package/dist/lib/release/publish.js +23 -0
- package/dist/lib/release/publish.sh +1 -0
- package/dist/lib/release/pushToGit.js +43 -0
- package/dist/lib/release/releasenotes.js +158 -0
- package/dist/lib/release/seeChangedFiles.js +89 -0
- package/dist/lib/release/sort.js +136 -0
- package/dist/lib/release/tree.js +163 -0
- package/dist/lib/release/validateNotDev.js +63 -0
- package/dist/lib/run/lib.js +454 -0
- package/dist/lib/run/main-p.js +59 -0
- package/dist/lib/run/main-s.js +56 -0
- package/dist/lib/run/parse-cli-args.js +222 -0
- package/dist/lib/run/run-p.js +30 -0
- package/dist/lib/run/run-s.js +57 -0
- package/dist/lib/runCLICommand.js +30 -0
- package/dist/lib/runParallel.js +20 -0
- package/dist/lib/runSequence.js +38 -0
- package/dist/lib/running/index.js +3 -0
- package/dist/lib/running/runCLICommand.js +38 -0
- package/dist/lib/running/runParallel.js +33 -0
- package/dist/lib/running/runSequence.js +43 -0
- package/dist/lib/startScripts.js +135 -0
- package/dist/lib/taskList.js +93 -0
- package/dist/lib/taskListAutoComplete.js +10 -0
- package/dist/lib/upgradePackages.js +65 -0
- package/dist/lib/utils/clear.js +18 -0
- package/dist/lib/utils/console.js +33 -0
- package/dist/lib/utils/encryption.js +18 -0
- package/dist/lib/utils/helpers.js +228 -0
- package/dist/lib/utils/index.js +2 -0
- package/dist/lib/utils/prompt.js +34 -0
- package/package.json +10 -8
- /package/dist/{index.html → lib/auth/index.html} +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Toru Nagashima
|
|
3
|
+
* @copyright 2016 Toru Nagashima. All rights reserved.
|
|
4
|
+
* See LICENSE file in root directory for full license.
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
/*eslint-disable no-process-env */
|
|
9
|
+
|
|
10
|
+
//------------------------------------------------------------------------------
|
|
11
|
+
// Helpers
|
|
12
|
+
//------------------------------------------------------------------------------
|
|
13
|
+
const OVERWRITE_OPTION = /^--([^:]+?):([^=]+?)(?:=(.+))?$/;
|
|
14
|
+
const CONFIG_OPTION = /^--([^=]+?)(?:=(.+))$/;
|
|
15
|
+
const PACKAGE_CONFIG_PATTERN = /^npm_package_config_(.+)$/;
|
|
16
|
+
const CONCAT_OPTIONS = /^-[clnprs]+$/;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Overwrites a specified package config.
|
|
20
|
+
*
|
|
21
|
+
* @param {object} config - A config object to be overwritten.
|
|
22
|
+
* @param {string} packageName - A package name to overwrite.
|
|
23
|
+
* @param {string} variable - A variable name to overwrite.
|
|
24
|
+
* @param {string} value - A new value to overwrite.
|
|
25
|
+
* @returns {void}
|
|
26
|
+
*/
|
|
27
|
+
function overwriteConfig(config, packageName, variable, value) {
|
|
28
|
+
const scope = config[packageName] || (config[packageName] = {});
|
|
29
|
+
scope[variable] = value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a package config object.
|
|
34
|
+
* This checks `process.env` and creates the default value.
|
|
35
|
+
*
|
|
36
|
+
* @returns {object} Created config object.
|
|
37
|
+
*/
|
|
38
|
+
function createPackageConfig() {
|
|
39
|
+
const retv = {};
|
|
40
|
+
const packageName = process.env.npm_package_name;
|
|
41
|
+
if (!packageName) {
|
|
42
|
+
return retv;
|
|
43
|
+
}
|
|
44
|
+
for (const key of Object.keys(process.env)) {
|
|
45
|
+
const m = PACKAGE_CONFIG_PATTERN.exec(key);
|
|
46
|
+
if (m != null) {
|
|
47
|
+
overwriteConfig(retv, packageName, m[1], process.env[key]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return retv;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Adds a new group into a given list.
|
|
55
|
+
*
|
|
56
|
+
* @param {object[]} groups - A group list to add.
|
|
57
|
+
* @param {object} initialValues - A key-value map for the default of new value.
|
|
58
|
+
* @returns {void}
|
|
59
|
+
*/
|
|
60
|
+
function addGroup(groups, initialValues) {
|
|
61
|
+
groups.push(Object.assign({
|
|
62
|
+
parallel: false,
|
|
63
|
+
patterns: []
|
|
64
|
+
}, initialValues || {}));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* ArgumentSet is values of parsed CLI arguments.
|
|
69
|
+
* This class provides the getter to get the last group.
|
|
70
|
+
*/
|
|
71
|
+
class ArgumentSet {
|
|
72
|
+
/**
|
|
73
|
+
* @param {object} initialValues - A key-value map for the default of new value.
|
|
74
|
+
* @param {object} options - A key-value map for the options.
|
|
75
|
+
*/
|
|
76
|
+
constructor(initialValues, options) {
|
|
77
|
+
this.config = {};
|
|
78
|
+
this.continueOnError = false;
|
|
79
|
+
this.groups = [];
|
|
80
|
+
this.maxParallel = 0;
|
|
81
|
+
this.npmPath = null;
|
|
82
|
+
this.packageConfig = createPackageConfig();
|
|
83
|
+
this.printLabel = false;
|
|
84
|
+
this.printName = false;
|
|
85
|
+
this.race = false;
|
|
86
|
+
this.rest = [];
|
|
87
|
+
this.silent = process.env.npm_config_loglevel === "silent";
|
|
88
|
+
this.singleMode = Boolean(options && options.singleMode);
|
|
89
|
+
addGroup(this.groups, initialValues);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Gets the last group.
|
|
94
|
+
*/
|
|
95
|
+
get lastGroup() {
|
|
96
|
+
return this.groups[this.groups.length - 1];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Gets "parallel" flag.
|
|
101
|
+
*/
|
|
102
|
+
get parallel() {
|
|
103
|
+
return this.groups.some(g => g.parallel);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Parses CLI arguments.
|
|
109
|
+
*
|
|
110
|
+
* @param {ArgumentSet} set - The parsed CLI arguments.
|
|
111
|
+
* @param {string[]} args - CLI arguments.
|
|
112
|
+
* @returns {ArgumentSet} set itself.
|
|
113
|
+
*/
|
|
114
|
+
function parseCLIArgsCore(set, args) {
|
|
115
|
+
// eslint-disable-line complexity
|
|
116
|
+
LOOP: for (let i = 0; i < args.length; ++i) {
|
|
117
|
+
const arg = args[i];
|
|
118
|
+
switch (arg) {
|
|
119
|
+
case "--":
|
|
120
|
+
set.rest = args.slice(1 + i);
|
|
121
|
+
break LOOP;
|
|
122
|
+
case "--color":
|
|
123
|
+
case "--no-color":
|
|
124
|
+
// do nothing.
|
|
125
|
+
break;
|
|
126
|
+
case "-c":
|
|
127
|
+
case "--continue-on-error":
|
|
128
|
+
set.continueOnError = true;
|
|
129
|
+
break;
|
|
130
|
+
case "-l":
|
|
131
|
+
case "--print-label":
|
|
132
|
+
set.printLabel = true;
|
|
133
|
+
break;
|
|
134
|
+
case "-n":
|
|
135
|
+
case "--print-name":
|
|
136
|
+
set.printName = true;
|
|
137
|
+
break;
|
|
138
|
+
case "-r":
|
|
139
|
+
case "--race":
|
|
140
|
+
set.race = true;
|
|
141
|
+
break;
|
|
142
|
+
case "--silent":
|
|
143
|
+
set.silent = true;
|
|
144
|
+
break;
|
|
145
|
+
case "--max-parallel":
|
|
146
|
+
set.maxParallel = parseInt(args[++i], 10);
|
|
147
|
+
if (!Number.isFinite(set.maxParallel) || set.maxParallel <= 0) {
|
|
148
|
+
throw new Error(`Invalid Option: --max-parallel ${args[i]}`);
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
case "-s":
|
|
152
|
+
case "--sequential":
|
|
153
|
+
case "--serial":
|
|
154
|
+
if (set.singleMode && arg === "-s") {
|
|
155
|
+
set.silent = true;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
if (set.singleMode) {
|
|
159
|
+
throw new Error(`Invalid Option: ${arg}`);
|
|
160
|
+
}
|
|
161
|
+
addGroup(set.groups);
|
|
162
|
+
break;
|
|
163
|
+
case "--aggregate-output":
|
|
164
|
+
set.aggregateOutput = true;
|
|
165
|
+
break;
|
|
166
|
+
case "-p":
|
|
167
|
+
case "--parallel":
|
|
168
|
+
if (set.singleMode) {
|
|
169
|
+
throw new Error(`Invalid Option: ${arg}`);
|
|
170
|
+
}
|
|
171
|
+
addGroup(set.groups, {
|
|
172
|
+
parallel: true
|
|
173
|
+
});
|
|
174
|
+
break;
|
|
175
|
+
case "--npm-path":
|
|
176
|
+
set.npmPath = args[++i] || null;
|
|
177
|
+
break;
|
|
178
|
+
default:
|
|
179
|
+
{
|
|
180
|
+
let matched = null;
|
|
181
|
+
if (matched = OVERWRITE_OPTION.exec(arg)) {
|
|
182
|
+
overwriteConfig(set.packageConfig, matched[1], matched[2], matched[3] || args[++i]);
|
|
183
|
+
} else if (matched = CONFIG_OPTION.exec(arg)) {
|
|
184
|
+
set.config[matched[1]] = matched[2];
|
|
185
|
+
} else if (CONCAT_OPTIONS.test(arg)) {
|
|
186
|
+
parseCLIArgsCore(set, arg.slice(1).split("").map(c => `-${c}`));
|
|
187
|
+
} else if (arg[0] === "-") {
|
|
188
|
+
throw new Error(`Invalid Option: ${arg}`);
|
|
189
|
+
} else {
|
|
190
|
+
set.lastGroup.patterns.push(arg);
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (!set.parallel && set.aggregateOutput) {
|
|
197
|
+
throw new Error("Invalid Option: --aggregate-output (without parallel)");
|
|
198
|
+
}
|
|
199
|
+
if (!set.parallel && set.race) {
|
|
200
|
+
const race = args.indexOf("--race") !== -1 ? "--race" : "-r";
|
|
201
|
+
throw new Error(`Invalid Option: ${race} (without parallel)`);
|
|
202
|
+
}
|
|
203
|
+
if (!set.parallel && set.maxParallel !== 0) {
|
|
204
|
+
throw new Error("Invalid Option: --max-parallel (without parallel)");
|
|
205
|
+
}
|
|
206
|
+
return set;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Parses CLI arguments.
|
|
211
|
+
*
|
|
212
|
+
* @param {string[]} args - CLI arguments.
|
|
213
|
+
* @param {object} initialValues - A key-value map for the default of new value.
|
|
214
|
+
* @param {object} options - A key-value map for the options.
|
|
215
|
+
* @param {boolean} options.singleMode - The flag to be single group mode.
|
|
216
|
+
* @returns {ArgumentSet} The parsed CLI arguments.
|
|
217
|
+
*/
|
|
218
|
+
module.exports = function parseCLIArgs(args, initialValues, options) {
|
|
219
|
+
return parseCLIArgsCore(new ArgumentSet(initialValues, options), args);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/*eslint-enable */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//------------------------------------------------------------------------------
|
|
2
|
+
// Public Interface
|
|
3
|
+
//------------------------------------------------------------------------------
|
|
4
|
+
/*eslint-disable no-process-exit */
|
|
5
|
+
|
|
6
|
+
function bootstrap(name) {
|
|
7
|
+
const argv = process.argv.slice(2);
|
|
8
|
+
switch (argv[0]) {
|
|
9
|
+
case undefined:
|
|
10
|
+
default:
|
|
11
|
+
// https://github.com/mysticatea/npm-run-all/issues/105
|
|
12
|
+
// Avoid MaxListenersExceededWarnings.
|
|
13
|
+
process.stdout.setMaxListeners(0);
|
|
14
|
+
process.stderr.setMaxListeners(0);
|
|
15
|
+
process.stdin.setMaxListeners(0);
|
|
16
|
+
|
|
17
|
+
// Main
|
|
18
|
+
return import("./main-p.js").then(mod => mod.default(argv, process.stdout, process.stderr)).then(() => {
|
|
19
|
+
// I'm not sure why, but maybe the process never exits
|
|
20
|
+
// on Git Bash (MINGW64)
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}, () => {
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/*eslint-enable */
|
|
29
|
+
|
|
30
|
+
bootstrap("run-p");
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Toru Nagashima
|
|
3
|
+
* @copyright 2015 Toru Nagashima. All rights reserved.
|
|
4
|
+
* See LICENSE file in root directory for full license.
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
// Main
|
|
10
|
+
//------------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* @author Toru Nagashima
|
|
13
|
+
* @copyright 2016 Toru Nagashima. All rights reserved.
|
|
14
|
+
* See LICENSE file in root directory for full license.
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync } from "fs";
|
|
17
|
+
import { fileURLToPath } from "url";
|
|
18
|
+
import path from "path";
|
|
19
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
20
|
+
const __dirname = path.dirname(__filename);
|
|
21
|
+
function printVersion(output) {
|
|
22
|
+
const version = JSON.parse(readFileSync(path.resolve(__dirname, "../../package.json"), "utf-8")).version;
|
|
23
|
+
output.write(`v${version}\n`);
|
|
24
|
+
return Promise.resolve(null);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//------------------------------------------------------------------------------
|
|
28
|
+
// Public Interface
|
|
29
|
+
//------------------------------------------------------------------------------
|
|
30
|
+
/*eslint-disable no-process-exit */
|
|
31
|
+
function bootstrap(name) {
|
|
32
|
+
const argv = process.argv.slice(2);
|
|
33
|
+
switch (argv[0]) {
|
|
34
|
+
case undefined:
|
|
35
|
+
case "-v":
|
|
36
|
+
case "--version":
|
|
37
|
+
return printVersion(process.stdout);
|
|
38
|
+
default:
|
|
39
|
+
// https://github.com/mysticatea/npm-run-all/issues/105
|
|
40
|
+
// Avoid MaxListenersExceededWarnings.
|
|
41
|
+
process.stdout.setMaxListeners(0);
|
|
42
|
+
process.stderr.setMaxListeners(0);
|
|
43
|
+
process.stdin.setMaxListeners(0);
|
|
44
|
+
|
|
45
|
+
// Main
|
|
46
|
+
return import(`./main-s.js`).then(mod => mod.default(argv, process.stdout, process.stderr)).then(() => {
|
|
47
|
+
// I'm not sure why, but maybe the process never exits
|
|
48
|
+
// on Git Bash (MINGW64)
|
|
49
|
+
process.exit(0);
|
|
50
|
+
}, () => {
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/*eslint-enable */
|
|
57
|
+
bootstrap("run-s");
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import moment from "moment-mini";
|
|
4
|
+
import spawn from "cross-spawn";
|
|
5
|
+
export default async ({
|
|
6
|
+
script,
|
|
7
|
+
task,
|
|
8
|
+
type = script.type
|
|
9
|
+
}, quiet = false) => {
|
|
10
|
+
if (!quiet) {
|
|
11
|
+
console.log(`${chalk.green.bgHex("#181c24").bold("[" + moment().format("HH:MM:SS") + "]")}${chalk.bgHex("#181c24").bold.hex("#8c91a7")(" " + task.name + ": ")}`);
|
|
12
|
+
}
|
|
13
|
+
return new Promise(resolve => {
|
|
14
|
+
const cmd = spawn(type, [...script.rest], {
|
|
15
|
+
stdio: "inherit",
|
|
16
|
+
env: Object.assign({}, process.env, {
|
|
17
|
+
FORCE_COLOR: true,
|
|
18
|
+
PATH: `${path.resolve("node_modules/.bin")}:${process.env.PATH}`,
|
|
19
|
+
...script.env
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
cmd.on("close", code => {
|
|
23
|
+
if (code === 0) {
|
|
24
|
+
resolve();
|
|
25
|
+
} else {
|
|
26
|
+
console.error(`${chalk.red("ERROR")} ${code}`);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import runCLICommand from "./running/runCLICommand.js";
|
|
2
|
+
const runParallel = async (tasks, FcScripts) => {
|
|
3
|
+
for (let t in tasks) {
|
|
4
|
+
let taskName = tasks[t];
|
|
5
|
+
let taskIndex = FcScripts.allTasks.findIndex(t => t.name === taskName);
|
|
6
|
+
let script = FcScripts.allTasks[taskIndex].script;
|
|
7
|
+
let params = script.split(" ");
|
|
8
|
+
let type = params.shift();
|
|
9
|
+
runCLICommand({
|
|
10
|
+
task: {
|
|
11
|
+
name: taskName
|
|
12
|
+
},
|
|
13
|
+
script: {
|
|
14
|
+
type: type,
|
|
15
|
+
rest: params
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export default runParallel;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import runCLICommand from "./running/runCLICommand.js";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
const runSequence = async (tasks, FcScripts) => {
|
|
4
|
+
for (let t in tasks) {
|
|
5
|
+
let taskName = tasks[t];
|
|
6
|
+
let taskIndex = FcScripts.allTasks.findIndex(t => t.name === taskName);
|
|
7
|
+
if (taskIndex === -1) {
|
|
8
|
+
console.log(`${chalk.red.underline("Skipping task " + taskName + ", as it cannot be found in .md file")}`);
|
|
9
|
+
} else {
|
|
10
|
+
let script = FcScripts.allTasks[taskIndex].script;
|
|
11
|
+
let pars = script.split(" ");
|
|
12
|
+
let type = pars[0];
|
|
13
|
+
let env = {};
|
|
14
|
+
if (pars[0].includes("=")) {
|
|
15
|
+
let envs = type.split("=");
|
|
16
|
+
env[envs[0]] = envs[1];
|
|
17
|
+
type = pars[1];
|
|
18
|
+
pars.shift();
|
|
19
|
+
pars.shift();
|
|
20
|
+
script = pars.join(" ");
|
|
21
|
+
} else {
|
|
22
|
+
pars.shift();
|
|
23
|
+
script = pars.join(" ");
|
|
24
|
+
}
|
|
25
|
+
await runCLICommand({
|
|
26
|
+
task: {
|
|
27
|
+
name: taskName
|
|
28
|
+
},
|
|
29
|
+
script: {
|
|
30
|
+
type: type,
|
|
31
|
+
rest: script.split(" "),
|
|
32
|
+
env: env
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export default runSequence;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import moment from "moment-mini";
|
|
4
|
+
import spawn from "cross-spawn";
|
|
5
|
+
import requireFromString from "require-from-string";
|
|
6
|
+
export default async ({
|
|
7
|
+
script,
|
|
8
|
+
task,
|
|
9
|
+
type = script.type
|
|
10
|
+
}, quiet = false) => {
|
|
11
|
+
if (!quiet) {
|
|
12
|
+
console.log(`${chalk.green.bgHex("#181c24").bold("[" + moment().format("HH:MM:SS") + "]")}${chalk.bgHex("#181c24").bold.hex("#8c91a7")(" " + task.name + ": ")}`);
|
|
13
|
+
}
|
|
14
|
+
return new Promise(resolve => {
|
|
15
|
+
if (script.lang === "javascript") {
|
|
16
|
+
requireFromString(script.full, "./fscripts.md");
|
|
17
|
+
resolve();
|
|
18
|
+
} else {
|
|
19
|
+
const cmd = spawn(type, [...script.rest], {
|
|
20
|
+
stdio: "inherit",
|
|
21
|
+
env: Object.assign({}, process.env, {
|
|
22
|
+
FORCE_COLOR: true,
|
|
23
|
+
PATH: `${path.resolve("node_modules/.bin")}:${process.env.PATH}`,
|
|
24
|
+
...script.env
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
cmd.on("close", code => {
|
|
28
|
+
if (code === 0) {
|
|
29
|
+
resolve();
|
|
30
|
+
} else {
|
|
31
|
+
console.error(`${chalk.red("ERROR")} ${code} runCli`);
|
|
32
|
+
resolve();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
// }
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import runCLICommand from "./runCLICommand.js";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
const runParallel = async (tasks, FcScripts) => {
|
|
4
|
+
const promises = tasks.map(async taskName => {
|
|
5
|
+
return new Promise(async resolve => {
|
|
6
|
+
const taskData = FcScripts.allTasks.find(z => z.name === taskName);
|
|
7
|
+
if (!taskData) {
|
|
8
|
+
console.error(`${chalk.bold.underline.red("Task not found")}`);
|
|
9
|
+
resolve();
|
|
10
|
+
} else {
|
|
11
|
+
let {
|
|
12
|
+
script,
|
|
13
|
+
lang
|
|
14
|
+
} = taskData;
|
|
15
|
+
let type = script.split(" ");
|
|
16
|
+
await runCLICommand({
|
|
17
|
+
task: {
|
|
18
|
+
name: taskName
|
|
19
|
+
},
|
|
20
|
+
script: {
|
|
21
|
+
lang: lang,
|
|
22
|
+
type: type.shift(),
|
|
23
|
+
full: script,
|
|
24
|
+
rest: script.split(" ").slice(1)
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
resolve();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
let results = await Promise.all(promises);
|
|
32
|
+
};
|
|
33
|
+
export default runParallel;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import runCLICommand from "./runCLICommand.js";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
const runSequence = async (tasks, FcScripts) => {
|
|
4
|
+
for (let t in tasks) {
|
|
5
|
+
let taskName = tasks[t];
|
|
6
|
+
const taskData = FcScripts.allTasks.find(z => z.name === taskName);
|
|
7
|
+
if (!taskData) {
|
|
8
|
+
console.error(`${chalk.bold.underline.red("Task not found")}`);
|
|
9
|
+
} else {
|
|
10
|
+
let {
|
|
11
|
+
script,
|
|
12
|
+
lang
|
|
13
|
+
} = taskData;
|
|
14
|
+
let pars = script.split(" ");
|
|
15
|
+
let type = pars[0];
|
|
16
|
+
let env = {};
|
|
17
|
+
if (pars[0].includes("=")) {
|
|
18
|
+
let envs = type.split("=");
|
|
19
|
+
env[envs[0]] = envs[1];
|
|
20
|
+
type = pars[1];
|
|
21
|
+
pars.shift();
|
|
22
|
+
pars.shift();
|
|
23
|
+
script = pars.join(" ");
|
|
24
|
+
} else {
|
|
25
|
+
pars.shift();
|
|
26
|
+
script = pars.join(" ");
|
|
27
|
+
}
|
|
28
|
+
await runCLICommand({
|
|
29
|
+
task: {
|
|
30
|
+
name: taskName
|
|
31
|
+
},
|
|
32
|
+
script: {
|
|
33
|
+
lang: lang,
|
|
34
|
+
env: env,
|
|
35
|
+
type: type,
|
|
36
|
+
full: script,
|
|
37
|
+
rest: script.split(" ")
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export default runSequence;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import taskList from "./taskList.js";
|
|
2
|
+
const separator = " ~ ";
|
|
3
|
+
import Conf from "conf";
|
|
4
|
+
import moment from "moment-mini";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import parseScriptFile from "./parsers/parseScriptsMd.js";
|
|
7
|
+
import parsePackageFile from "./parsers/parseScriptsPackage.js";
|
|
8
|
+
import runCLICommand from "./running/runCLICommand.js";
|
|
9
|
+
import enquirerPkg from "enquirer";
|
|
10
|
+
const {
|
|
11
|
+
prompt
|
|
12
|
+
} = enquirerPkg;
|
|
13
|
+
import path from "path";
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
let packagePath = path.resolve(process.cwd(), "package.json");
|
|
16
|
+
const packageJsonAfter = JSON.parse(fs.readFileSync(packagePath));
|
|
17
|
+
console.info("Console --- packageJsonAfter.name", packageJsonAfter.name);
|
|
18
|
+
const config = new Conf({
|
|
19
|
+
configName: packageJsonAfter.name
|
|
20
|
+
});
|
|
21
|
+
const taskListAutoComplete = async tasks => {
|
|
22
|
+
try {
|
|
23
|
+
let {
|
|
24
|
+
answer
|
|
25
|
+
} = await prompt({
|
|
26
|
+
type: "autocomplete",
|
|
27
|
+
message: `${chalk.green.bold.underline("Choose task to run")}`,
|
|
28
|
+
choices: tasks,
|
|
29
|
+
name: `answer`
|
|
30
|
+
});
|
|
31
|
+
return answer.split(separator)[0].trim();
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const startScripts = async (categories = true) => {
|
|
37
|
+
const FcScripts = await parseScriptFile();
|
|
38
|
+
if (FcScripts === false) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
let recentTasks = config.get("recentTasks", {});
|
|
42
|
+
let recentTaskArr = Object.keys(recentTasks).map(taskName => {
|
|
43
|
+
let task = recentTasks[taskName];
|
|
44
|
+
return {
|
|
45
|
+
name: taskName,
|
|
46
|
+
lastExecuted: task.lastExecuted
|
|
47
|
+
};
|
|
48
|
+
}).sort((a, b) => a.lastExecuted > b.lastExecuted ? 1 : b.lastExecuted > a.lastExecuted ? -1 : 0).reverse().slice(0, 3);
|
|
49
|
+
let recentTaskOptions = recentTaskArr.map(task => {
|
|
50
|
+
return task.name + separator + moment(task.lastExecuted).calendar();
|
|
51
|
+
});
|
|
52
|
+
let taskToRun;
|
|
53
|
+
if (categories) {
|
|
54
|
+
taskToRun = await taskList(FcScripts, recentTaskOptions);
|
|
55
|
+
} else {
|
|
56
|
+
let tasks = FcScripts.allTasks;
|
|
57
|
+
taskToRun = await taskListAutoComplete(tasks.map(task => {
|
|
58
|
+
return `${task.name}${separator}${task.description}`;
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
if (recentTasks[taskToRun] === undefined) {
|
|
62
|
+
recentTasks[taskToRun] = {
|
|
63
|
+
lastExecuted: Date.now()
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
recentTasks[taskToRun].lastExecuted = Date.now();
|
|
67
|
+
}
|
|
68
|
+
config.set("recentTasks", recentTasks);
|
|
69
|
+
const taskData = FcScripts.allTasks.find(t => t.name === taskToRun);
|
|
70
|
+
if (!taskData) {
|
|
71
|
+
console.error(`${chalk.bold.underline.red("Task not found")}`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
let {
|
|
75
|
+
script,
|
|
76
|
+
lang
|
|
77
|
+
} = taskData;
|
|
78
|
+
let pars = script.split(" ");
|
|
79
|
+
let type = pars[0];
|
|
80
|
+
let env = {};
|
|
81
|
+
if (pars[0].includes("=")) {
|
|
82
|
+
let envs = type.split("=");
|
|
83
|
+
env[envs[0]] = envs[1];
|
|
84
|
+
type = pars[1];
|
|
85
|
+
pars.shift();
|
|
86
|
+
pars.shift();
|
|
87
|
+
script = pars.join(" ");
|
|
88
|
+
} else {
|
|
89
|
+
pars.shift();
|
|
90
|
+
script = pars.join(" ");
|
|
91
|
+
}
|
|
92
|
+
await runCLICommand({
|
|
93
|
+
task: {
|
|
94
|
+
name: taskToRun
|
|
95
|
+
},
|
|
96
|
+
script: {
|
|
97
|
+
lang: lang,
|
|
98
|
+
type: type,
|
|
99
|
+
env: env,
|
|
100
|
+
full: script,
|
|
101
|
+
rest: script.split(" ")
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
const startPackageScripts = async () => {
|
|
106
|
+
const packageScripts = await parsePackageFile();
|
|
107
|
+
let tasks = Object.keys(packageScripts).map(e => {
|
|
108
|
+
return {
|
|
109
|
+
name: e,
|
|
110
|
+
script: packageScripts[e]
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
let taskToRun = await taskListAutoComplete(tasks.map(task => {
|
|
114
|
+
return `${task.name}${separator}${task.script}`;
|
|
115
|
+
}));
|
|
116
|
+
if (taskToRun === false) {
|
|
117
|
+
console.log(chalk.green.bold("See you soon!"));
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
await runCLICommand({
|
|
121
|
+
task: {
|
|
122
|
+
name: taskToRun
|
|
123
|
+
},
|
|
124
|
+
script: {
|
|
125
|
+
lang: taskToRun.lang,
|
|
126
|
+
type: "yarn",
|
|
127
|
+
full: taskToRun.script,
|
|
128
|
+
rest: taskToRun.script.split(" ").slice(1)
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
const clearRecent = async () => {
|
|
133
|
+
config.set("recentTasks", {});
|
|
134
|
+
};
|
|
135
|
+
export { startScripts, taskListAutoComplete, clearRecent, startPackageScripts };
|