fscr 6.2.6 → 7.3.0

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.
Files changed (72) hide show
  1. package/README.md +48 -30
  2. package/dist/index.js +502 -186
  3. package/dist/lib/auth/auth-conf.js +49 -45
  4. package/dist/lib/cache/README.md +341 -0
  5. package/dist/lib/cache/cli.js +152 -0
  6. package/dist/lib/cache/file-watcher.js +193 -0
  7. package/dist/lib/cache/index.js +422 -0
  8. package/dist/lib/cache/monitor.js +224 -0
  9. package/dist/lib/commands/doctor.js +225 -0
  10. package/dist/lib/completions/completion.js +342 -0
  11. package/dist/lib/completions/generator.js +152 -0
  12. package/dist/lib/completions/scripts/bash.sh +108 -0
  13. package/dist/lib/completions/scripts/fish.sh +105 -0
  14. package/dist/lib/completions/scripts/powershell.ps1 +168 -0
  15. package/dist/lib/completions/scripts/zsh.sh +124 -0
  16. package/dist/lib/diagnostics/cache.js +121 -0
  17. package/dist/lib/diagnostics/fileSystem.js +236 -0
  18. package/dist/lib/diagnostics/gitCheck.js +41 -0
  19. package/dist/lib/diagnostics/nodeVersion.js +68 -0
  20. package/dist/lib/diagnostics/packageManager.js +64 -0
  21. package/dist/lib/diagnostics/performance.js +141 -0
  22. package/dist/lib/encryption/decryptConfig.js +3 -2
  23. package/dist/lib/encryption/encryption.js +153 -113
  24. package/dist/lib/generators/generateFScripts.js +16 -13
  25. package/dist/lib/generators/generateToc.js +23 -14
  26. package/dist/lib/generators/index.js +1 -1
  27. package/dist/lib/git/pub.js +27 -17
  28. package/dist/lib/git/taskRunner.js +79 -69
  29. package/dist/lib/git/validateNotDev.js +65 -54
  30. package/dist/lib/optionList.js +69 -57
  31. package/dist/lib/parsers/parseScriptsMd.cached.js +208 -0
  32. package/dist/lib/parsers/parseScriptsMd.js +88 -79
  33. package/dist/lib/parsers/parseScriptsPackage.js +4 -3
  34. package/dist/lib/performance/cache.js +199 -0
  35. package/dist/lib/performance/lazy-loader.js +189 -0
  36. package/dist/lib/performance/monitor.js +303 -0
  37. package/dist/lib/plugins/deployment/index.js +113 -0
  38. package/dist/lib/plugins/hooks.js +17 -0
  39. package/dist/lib/plugins/loader.js +91 -0
  40. package/dist/lib/plugins/task-notifier/index.js +72 -0
  41. package/dist/lib/release/bump.js +50 -45
  42. package/dist/lib/release/commitWithMessage.js +80 -52
  43. package/dist/lib/release/publish.js +19 -14
  44. package/dist/lib/release/pushToGit.js +40 -31
  45. package/dist/lib/release/releasenotes.js +116 -97
  46. package/dist/lib/release/seeChangedFiles.js +68 -60
  47. package/dist/lib/release/sort.js +200 -116
  48. package/dist/lib/release/tree.js +161 -147
  49. package/dist/lib/release/validateNotDev.js +52 -44
  50. package/dist/lib/running/index.js +1 -1
  51. package/dist/lib/running/runCLICommand.js +41 -31
  52. package/dist/lib/running/runParallel.js +61 -59
  53. package/dist/lib/running/runSequence.js +55 -53
  54. package/dist/lib/startScripts.js +129 -114
  55. package/dist/lib/taskList.js +97 -90
  56. package/dist/lib/test-files/.fscripts.md +113 -0
  57. package/dist/lib/test-files/.fscripts.test.md +103 -0
  58. package/dist/lib/test-files/.fscriptsb.md +107 -0
  59. package/dist/lib/test-files/.mdtest.md +40 -0
  60. package/dist/lib/test-files/consoleSample.js +13 -9
  61. package/dist/lib/test-files/inputSample.js +17 -14
  62. package/dist/lib/test-files/testConsole.js +1 -1
  63. package/dist/lib/test-files/testInput.js +1 -1
  64. package/dist/lib/upgradePackages.js +56 -46
  65. package/dist/lib/utils/clear.js +16 -13
  66. package/dist/lib/utils/console.js +27 -21
  67. package/dist/lib/utils/encryption.js +55 -13
  68. package/dist/lib/utils/hash.js +128 -0
  69. package/dist/lib/utils/helpers.js +153 -142
  70. package/dist/lib/utils/index.js +1 -1
  71. package/dist/lib/utils/prompt.js +24 -29
  72. package/package.json +11 -29
@@ -1,135 +1,175 @@
1
1
  import chalk from "chalk";
2
+ import fcFilepicker from "fc-filepick";
2
3
  import inquirer from "inquirer";
3
- import { encrypt, decrypt } from "../utils/encryption.js";
4
- import { appendToFile, ensureFile, writeFile, boxInform, readJson, readFile } from "../utils/helpers.js";
4
+ import {decrypt, encrypt} from "../utils/encryption.js";
5
+ import {appendToFile, boxInform, ensureFile, readFile, readJson, writeFile} from "../utils/helpers.js";
5
6
  import path from "path";
7
+
6
8
  const scriptsDir = process.cwd();
7
9
  const rootDir = path.join(scriptsDir, "./");
8
10
  const packagePath = path.join(rootDir, "package.json");
9
11
  const igPath = path.join(rootDir, ".gitignore");
10
- const encrypted = {
11
- encryptedFiles: []
12
- };
12
+ const encrypted = {encryptedFiles: []};
13
13
 
14
14
  // prettier-ignore
15
- encrypted.encrypt = async (pass, encryptedFile, decryptedFile) => {
16
- let willEncrypt = true;
17
- let sureSure = await ensureFile(encryptedFile);
18
- if (sureSure) {
19
- console.log(`${chalk.bold.red("FILE ALREADY EXISTS ARE YOU SURE?")}`);
20
- willEncrypt = await new Promise(resolve => {
21
- inquirer.prompt([{
22
- type: "confirm",
23
- message: chalk.bold.hex("#38be18")(`Sure? (y/n): `),
24
- name: "sure"
25
- }]).then(({
26
- sure
27
- }) => {
28
- resolve(sure);
29
- });
30
- });
31
- }
32
- if (willEncrypt) {
33
- let toEncrypt = await readFile(decryptedFile);
34
- const ciphertext = encrypt(toEncrypt, pass);
35
- await writeFile(encryptedFile, ciphertext.toString());
36
- }
15
+ encrypted.encrypt = async (pass = null, encryptedFile = null, decryptedFile = null) => {
16
+ if (pass === null) {
17
+ pass = await encrypted.getPass();
18
+ }
19
+ if (decryptedFile === null) {
20
+ decryptedFile = await fcFilepicker.default({type: "file"});
21
+ decryptedFile = path.join(scriptsDir, decryptedFile.split("/").pop());
22
+ encryptedFile = `${decryptedFile}.encrypted`;
23
+ }
24
+ let willEncrypt = true;
25
+ let sureSure = await ensureFile(encryptedFile);
26
+ if (sureSure) {
27
+ console.log(`${chalk.bold.red("FILE ALREADY EXISTS ARE YOU SURE?")}`
28
+ );
29
+ willEncrypt = await new Promise(resolve => {
30
+ inquirer
31
+ .prompt([
32
+ {
33
+ type: "confirm",
34
+ message: chalk.bold.hex("#38be18")(
35
+ `Sure? (y/n): `
36
+ ),
37
+ name: "sure"
38
+ }
39
+ ])
40
+ .then(({sure}) => {
41
+ resolve(sure);
42
+ });
43
+ });
44
+ }
45
+ if (willEncrypt) {
46
+ let toEncrypt = await readFile(decryptedFile);
47
+ const ciphertext = encrypt(toEncrypt, pass);
48
+ await writeFile(encryptedFile, ciphertext.toString());
49
+ }
50
+
37
51
  };
38
52
  // prettier-ignore
39
- encrypted.decrypt = async (pass, encryptedFileLocation, decryptedFileLocation) => {
40
- // let encryptedFileLocation = path.join(rootDir,"."+encryptedFile);
41
- // let decryptedFileLocation = path.join(rootDir,encryptedFile);
42
- let willEncrypt = true;
43
- let sureSure = await ensureFile(decryptedFileLocation);
44
- if (sureSure) {
45
- console.log(`${chalk.bold.red("FILE ALREADY EXISTS ARE YOU SURE?")}`);
46
- willEncrypt = await new Promise(resolve => {
47
- inquirer.prompt([{
48
- type: "confirm",
49
- message: chalk.bold.hex("#38be18")(`Sure wanna override file ${decryptedFileLocation}? (y/n): `),
50
- name: "sure"
51
- }]).then(({
52
- sure
53
- }) => {
54
- resolve(sure);
55
- });
56
- });
57
- }
58
- if (willEncrypt) {
59
- let toDecrypt = await readFile(encryptedFileLocation);
60
- const decryptedData = decrypt(toDecrypt, pass);
61
- await writeFile(decryptedFileLocation, decryptedData);
62
- console.warn(`${chalk.bold.green.underline("DECRYPTED FILE:")} ${chalk.bold.dim(path.join(scriptsDir, decryptedFileLocation))}`);
63
- }
53
+ encrypted.decrypt = async (pass = null, encryptedFileLocation = null, decryptedFileLocation = null) => {
54
+ // let encryptedFileLocation = path.join(rootDir,"."+encryptedFile);
55
+ // let decryptedFileLocation = path.join(rootDir,encryptedFile);
56
+ if (pass === null) {
57
+ pass = await encrypted.getPass();
58
+ }
59
+ if (encryptedFileLocation === null) {
60
+ encryptedFileLocation = await fcFilepicker.default({type: "file"});
61
+ encryptedFileLocation = path.join(scriptsDir, encryptedFileLocation.split("/").pop());
62
+ decryptedFileLocation = encryptedFileLocation.replace(".encrypted", "");
63
+ }
64
+ let willEncrypt = true;
65
+ let sureSure = await ensureFile(decryptedFileLocation);
66
+ if (sureSure) {
67
+ console.log(
68
+ `${chalk.bold.red("FILE ALREADY EXISTS ARE YOU SURE?")}`
69
+ );
70
+ willEncrypt = await new Promise(resolve => {
71
+ inquirer
72
+ .prompt([
73
+ {
74
+ type: "confirm",
75
+ message: chalk.bold.hex("#38be18")(
76
+ `Sure wanna override file ${decryptedFileLocation}? (y/n): `
77
+ ),
78
+ name: "sure"
79
+ }
80
+ ])
81
+ .then(({sure}) => {
82
+ resolve(sure);
83
+ });
84
+ });
85
+ }
86
+ if (willEncrypt) {
87
+ let toDecrypt = await readFile(encryptedFileLocation);
88
+ const decryptedData = decrypt(toDecrypt, pass);
89
+ await writeFile(decryptedFileLocation, decryptedData);
90
+ console.warn(
91
+ `${chalk.bold.green.underline("DECRYPTED FILE:")} ${chalk.bold.dim(path.join(scriptsDir, decryptedFileLocation))}`
92
+ );
93
+ }
94
+
64
95
  };
96
+
65
97
  encrypted.init = async () => {
66
- try {
67
- let pass = await encrypted.getPass();
68
- let toEncrypt = await encrypted.toEncrypt();
69
- encrypted.packageJson = await readJson(packagePath);
70
- encrypted.ignore = await readFile(igPath);
71
- encrypted.ignoredFiles = encrypted.ignore.split("\n");
72
- if (encrypted.packageJson.fscripts) {
73
- if (encrypted.packageJson.fscripts.encryptedFiles) {
74
- encrypted.encryptedFiles = encrypted.packageJson.fscripts.encryptedFiles;
75
- let filesToAdd = "\n";
76
- for (const e of encrypted.encryptedFiles) {
77
- if (encrypted.ignoredFiles.indexOf(e) === -1) {
78
- filesToAdd += e + "\n";
79
- }
80
- let file = e + "";
81
- let fileSplit = file.split("/");
82
- let name = fileSplit.pop();
83
- let encryptedFile = fileSplit.slice();
84
- let decryptedFile = fileSplit.slice();
85
- encryptedFile.push("." + name);
86
- encryptedFile = path.join(rootDir, encryptedFile.join("/"));
87
- decryptedFile.push(name);
88
- decryptedFile = path.join(rootDir, decryptedFile.join("/"));
89
- if (toEncrypt) {
90
- await encrypted.encrypted(pass, encryptedFile, decryptedFile);
91
- } else {
92
- await encrypted.decrypt(pass, encryptedFile, decryptedFile);
93
- }
94
- }
95
- if (filesToAdd.trim().length > 0) {
96
- await appendToFile(igPath, filesToAdd + "\n");
97
- boxInform(" Added files to .gitignore: ", filesToAdd);
98
+ try {
99
+ let pass = await encrypted.getPass();
100
+ let toEncrypt = await encrypted.toEncrypt();
101
+ encrypted.packageJson = await readJson(packagePath);
102
+ encrypted.ignore = await readFile(igPath);
103
+ encrypted.ignoredFiles = encrypted.ignore.split("\n");
104
+ if (encrypted.packageJson.fscripts) {
105
+ if (encrypted.packageJson.fscripts.encryptedFiles) {
106
+ encrypted.encryptedFiles = encrypted.packageJson.fscripts.encryptedFiles;
107
+ let filesToAdd = "\n";
108
+ for (const e of encrypted.encryptedFiles) {
109
+ if (encrypted.ignoredFiles.indexOf(e) === -1) {
110
+ filesToAdd += e + "\n";
111
+ }
112
+ let file = e + "";
113
+ let fileSplit = file.split("/");
114
+ let name = fileSplit.pop();
115
+ let encryptedFile = fileSplit.slice();
116
+ let decryptedFile = fileSplit.slice();
117
+ encryptedFile.push("." + name);
118
+ encryptedFile = path.join(rootDir, encryptedFile.join("/"));
119
+ decryptedFile.push(name);
120
+ decryptedFile = path.join(rootDir, decryptedFile.join("/"));
121
+
122
+ if (toEncrypt) {
123
+ await encrypted.encrypt(pass, encryptedFile, decryptedFile);
124
+ } else {
125
+ await encrypted.decrypt(pass, encryptedFile, decryptedFile);
126
+ }
127
+ }
128
+
129
+ if (filesToAdd.trim().length > 0) {
130
+ await appendToFile(igPath, filesToAdd + "\n");
131
+ boxInform(" Added files to .gitignore: ", filesToAdd);
132
+ }
133
+ }
98
134
  }
99
- }
135
+ } catch (err) {
136
+ console.error(err);
100
137
  }
101
- } catch (err) {
102
- console.error(err);
103
- }
104
138
  };
139
+
105
140
  encrypted.getPass = async () => {
106
- return await new Promise(resolve => {
107
- inquirer.prompt([{
108
- type: "password",
109
- mask: chalk.underline(" ●"),
110
- message: chalk.bold.hex("#38be18")(`Enter a SECRET key (same as pass app) : `),
111
- name: "pass"
112
- }]).then(({
113
- pass
114
- }) => {
115
- resolve(pass);
141
+ return await new Promise((resolve) => {
142
+ inquirer
143
+ .prompt([
144
+ {
145
+ type: "password",
146
+ mask: chalk.underline(""),
147
+ message: chalk.bold.hex("#38be18")(
148
+ `Enter a SECRET key (same as pass app) : `
149
+ ),
150
+ name: "pass"
151
+ }
152
+ ])
153
+ .then(({pass}) => {
154
+ resolve(pass);
155
+ });
116
156
  });
117
- });
118
157
  };
119
158
  encrypted.toEncrypt = async () => {
120
- return await new Promise(resolve => {
121
- inquirer.prompt([{
122
- type: "list",
123
- message: chalk.bold.hex("#38be18")("Which direction?"),
124
- choices: ["encrypt", "decrypt"],
125
- name: "encryptDecrypt"
126
- }]).then(async ({
127
- encryptDecrypt
128
- }) => {
129
- resolve(encryptDecrypt === "encrypt");
159
+ return await new Promise((resolve) => {
160
+ inquirer
161
+ .prompt([
162
+ {
163
+ type: "list",
164
+ message: chalk.bold.hex("#38be18")("Which direction?"),
165
+ choices: ["encrypt", "decrypt"],
166
+ name: "encryptDecrypt"
167
+ }
168
+ ])
169
+ .then(async ({encryptDecrypt}) => {
170
+ resolve(encryptDecrypt === "encrypt");
171
+ });
130
172
  });
131
- });
132
173
  };
133
- export default {
134
- ...encrypted
135
- };
174
+
175
+ export default {...encrypted};
@@ -4,22 +4,25 @@ import { appendToFile, writeFile, boxInform, readJson, readFile } from "../utils
4
4
  import path from "path";
5
5
  const projectDir = process.cwd();
6
6
  const packagePath = path.join(projectDir, "package.json");
7
- const gen = {
8
- scripts: []
9
- };
7
+
8
+ const gen = { scripts: [] };
10
9
  let mdfile = `# First category of scripts
11
10
 
12
11
  Welcome to your new amazing fscripts.md file. It replaces the headaches of npm scripts! But so much more.
13
12
  `;
13
+
14
14
  gen.init = async () => {
15
- try {
16
- gen.packageJson = await readJson(packagePath);
17
- Object.keys(gen.packageJson.scripts).forEach(scriptName => {
18
- mdfile += `\n## ${scriptName}\n\n${gen.packageJson.scripts[scriptName]}\n\n\`\`\`bash\n${gen.packageJson.scripts[scriptName]}\n\`\`\`\n\n`;
19
- });
20
- await writeFile("./sample.fscripts.md", mdfile);
21
- } catch (err) {
22
- console.error(err);
23
- }
15
+ try {
16
+ gen.packageJson = await readJson(packagePath);
17
+ Object.keys(gen.packageJson.scripts).forEach(scriptName => {
18
+ mdfile += `\n## ${scriptName}\n\n${
19
+ gen.packageJson.scripts[scriptName]
20
+ }\n\n\`\`\`bash\n${gen.packageJson.scripts[scriptName]}\n\`\`\`\n\n`;
21
+ });
22
+ await writeFile("./sample.fscripts.md", mdfile);
23
+ } catch (err) {
24
+ console.error(err);
25
+ }
24
26
  };
25
- export default gen.init;
27
+
28
+ export default gen.init;
@@ -3,30 +3,39 @@ import chalk from "chalk";
3
3
  import fs from "fs";
4
4
  import tocPkg from "markdown-toc";
5
5
  const toc = tocPkg.default || tocPkg;
6
+
6
7
  import { writeFile } from "../utils/helpers.js";
7
8
  // const projectDir = process.cwd();
8
9
 
9
10
  const generateToc = async (fileToLoad = "fscripts.md") => {
10
- const filepath = path.resolve(process.cwd(), fileToLoad);
11
- if (!fs.existsSync(filepath)) {
12
- console.warn(`${chalk.bold.red("You're missing the fscripts.md file!")}
13
- ${chalk.green("Please run 'fsr generate' to get started!")}`);
14
- process.exit(0);
15
- return null;
16
- }
17
- const data = fs.readFileSync(filepath, "utf-8");
18
- if (data) {
11
+ const filepath = path.resolve(process.cwd(), fileToLoad);
12
+
13
+ if (!fs.existsSync(filepath)) {
14
+ console.warn(
15
+ `${chalk.bold.red("You're missing the fscripts.md file!")}
16
+ ${chalk.green("Please run 'fsr generate' to get started!")}`
17
+ );
18
+ process.exit(0);
19
+ return null;
20
+ }
21
+
22
+ const data = fs.readFileSync(filepath, "utf-8");
19
23
  console.warn(`${chalk.bold.green("Located fscripts.md file!")}`);
24
+
20
25
  let newFile = ``;
21
26
  let tocSplit = data.split("<!-- end toc -->");
22
27
  let mdContent = "";
23
28
  if (tocSplit.length === 2) {
24
- mdContent = tocSplit[1];
29
+ mdContent = tocSplit[1];
25
30
  } else {
26
- mdContent = data;
31
+ mdContent = data;
27
32
  }
28
- newFile = toc(mdContent).content + "\n<!-- end toc -->\n\n" + mdContent.trim();
33
+
34
+ // Generate TOC even for empty files
35
+ const tocContent = data === "" ? "" : toc(mdContent).content;
36
+ newFile = tocContent + "\n<!-- end toc -->\n\n" + mdContent.trim();
37
+
29
38
  await writeFile(fileToLoad, newFile);
30
- }
31
39
  };
32
- export default generateToc;
40
+
41
+ export default generateToc;
@@ -1,2 +1,2 @@
1
1
  export { default as generateToc } from "./generateToc.js";
2
- export { default as generateFScripts } from "./generateFScripts.js";
2
+ export { default as generateFScripts } from "./generateFScripts.js";
@@ -6,23 +6,33 @@ const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = path.dirname(__filename);
7
7
  import { readJson } from "../utils/helpers.js";
8
8
  import simple from "simple-git";
9
+
9
10
  import validateNotInDev from "./validateNotDev.js";
11
+
10
12
  (async () => {
11
- await validateNotInDev();
12
- await new Promise(resolve => {
13
- let pack = readJson(path.resolve(__dirname + "package.json"));
14
- inquirer.prompt([{
15
- type: "input",
16
- message: chalk.bold.hex("#38be18")(`What's new this version ${pack.version}: `),
17
- name: "commitmsg"
18
- }]).then(async ({
19
- commitmsg
20
- }) => {
21
- simple().add("./*").commit(`VERSION ${pack.version}\n${commitmsg}`).push(["-u"], () => console.log("done")).addTag(`${pack.version}`, () => console.warn("")).pushTags("origin", () => {
22
- console.warn("-- Console 3", 3);
23
- resolve();
24
- });
25
- // await require("simple-git")()
13
+ await validateNotInDev();
14
+ await new Promise(resolve => {
15
+ let pack = readJson(path.resolve(__dirname + "package.json"));
16
+
17
+ inquirer
18
+ .prompt([
19
+ {
20
+ type: "input",
21
+ message: chalk.bold.hex("#38be18")(`What's new this version ${pack.version}: `),
22
+ name: "commitmsg"
23
+ }
24
+ ])
25
+ .then(async ({ commitmsg }) => {
26
+ simple()
27
+ .add("./*")
28
+ .commit(`VERSION ${pack.version}\n${commitmsg}`)
29
+ .push(["-u"], () => console.log("done"))
30
+ .addTag(`${pack.version}`, () => console.warn(""))
31
+ .pushTags("origin", () => {
32
+ console.warn("-- Console 3", 3);
33
+ resolve();
34
+ });
35
+ // await require("simple-git")()
36
+ });
26
37
  });
27
- });
28
- })();
38
+ })();
@@ -5,76 +5,86 @@ import prettyMs from "pretty-ms";
5
5
  import spawn from "cross-spawn";
6
6
  import boxen from "boxen";
7
7
  import helpers from "../utils/helpers.js";
8
+
8
9
  const runTask = async (name, conf = false) => {
9
- let output;
10
- let startTime = Date.now();
11
- let input = name.slice(-1) === "-";
12
- let task = {};
13
- let tasks = [];
14
- if (conf !== false) {
15
- conf.set("tasks." + name + ".lastRan", startTime);
16
- await conf.updateConfigFile();
17
- tasks = conf.get("tasks");
18
- }
19
- let command = conf === false ? name : tasks[name].file ? "node " + tasks[name].file : tasks[name].script;
20
- console.clear();
21
- console.log(input ? chalk.hex("#4b5150")(" Running: ") + chalk.bold.underline.hex("#438b34")(name) : boxen(chalk.hex("#717877")(" Running: ") + chalk.bold.underline.hex("#438b34")(name) + chalk.hex("#717877")(" "), {
22
- padding: 0,
23
- margin: {
24
- left: 2,
25
- top: 0,
26
- bottom: 0,
27
- right: 0
28
- },
29
- borderStyle: {
30
- topLeft: chalk.hex("#5a596d")("╔"),
31
- topRight: chalk.hex("#5a596d")("╗"),
32
- bottomLeft: chalk.hex("#5a596d")("╚"),
33
- bottomRight: chalk.hex("#5a596d")("╝"),
34
- horizontal: chalk.hex("#5a596d")("═"),
35
- vertical: chalk.hex("#5a596d")("║")
36
- },
37
- //"round",
38
- // dimBorder: true,
39
- align: "center" //,
40
- // float: "center"
41
- }));
42
- try {
43
- let pars = command.split(" ");
44
- output = spawn(pars[0], pars.slice(1, pars.length), {
45
- cwd: tryPath,
46
- env: {
47
- ...process.env,
48
- ...{
49
- FORCE_COLOR: true
50
- }
51
- },
52
- stdio: input ? "inherit" : "pipe"
53
- });
54
- if (!input) {
55
- output.stdout.on("data", code => {
56
- code = code + "";
57
- console.log(`${chalk.bgHex("#181c24").hex("#8c91a7")(moment().format("HH:MM:SS") + ":")} ${code}`.trim());
58
- });
59
- output.stderr.on("data", code => {
60
- code = code + "";
61
- console.log(`${chalk.bgHex("#181c24").hex("#a72e32")(moment().format("HH:MM:SS") + "ERR :")} ${code}`.trim());
62
- });
10
+ let output;
11
+ let startTime = Date.now();
12
+ let input = name.slice(-1) === "-";
13
+ let task = {};
14
+ let tasks = [];
15
+ if (conf !== false) {
16
+ conf.set("tasks." + name + ".lastRan", startTime);
17
+ await conf.updateConfigFile();
18
+ tasks = conf.get("tasks");
63
19
  }
64
- return new Promise((resolve, reject) => {
65
- output.on("close", code => {
66
- if (code === 0) {
67
- let elapsed = Date.now() - startTime;
68
- console.log(`${chalk.bold.green("Finished in " + prettyMs(elapsed), code)}`);
69
- resolve();
70
- } else {
71
- // console.log(`${chalk.bold.green("Finished in " + prettyMs(elapsed), code)}`);
72
- reject(`task exited with code ${code}`);
20
+ let command =
21
+ conf === false ? name : tasks[name].file ? "node " + tasks[name].file : tasks[name].script;
22
+ console.clear();
23
+ console.log(
24
+ input
25
+ ? chalk.hex("#4b5150")(" Running: ") + chalk.bold.underline.hex("#438b34")(name)
26
+ : boxen(
27
+ chalk.hex("#717877")(" Running: ") +
28
+ chalk.bold.underline.hex("#438b34")(name) +
29
+ chalk.hex("#717877")(" "),
30
+ {
31
+ padding: 0,
32
+ margin: { left: 2, top: 0, bottom: 0, right: 0 },
33
+ borderStyle: {
34
+ topLeft: chalk.hex("#5a596d")("╔"),
35
+ topRight: chalk.hex("#5a596d")("╗"),
36
+ bottomLeft: chalk.hex("#5a596d")("╚"),
37
+ bottomRight: chalk.hex("#5a596d")("╝"),
38
+ horizontal: chalk.hex("#5a596d")("═"),
39
+ vertical: chalk.hex("#5a596d")("║")
40
+ }, //"round",
41
+ // dimBorder: true,
42
+ align: "center" //,
43
+ // float: "center"
44
+ }
45
+ )
46
+ );
47
+ try {
48
+ let pars = command.split(" ");
49
+
50
+ output = spawn(pars[0], pars.slice(1, pars.length), {
51
+ cwd: tryPath,
52
+ env: { ...process.env, ...{ FORCE_COLOR: true } },
53
+ stdio: input ? "inherit" : "pipe"
54
+ });
55
+ if (!input) {
56
+ output.stdout.on("data", code => {
57
+ code = code + "";
58
+ console.log(
59
+ `${chalk.bgHex("#181c24").hex("#8c91a7")(
60
+ moment().format("HH:MM:SS") + ":"
61
+ )} ${code}`.trim()
62
+ );
63
+ });
64
+ output.stderr.on("data", code => {
65
+ code = code + "";
66
+ console.log(
67
+ `${chalk.bgHex("#181c24").hex("#a72e32")(
68
+ moment().format("HH:MM:SS") + "ERR :"
69
+ )} ${code}`.trim()
70
+ );
71
+ });
73
72
  }
74
- });
75
- });
76
- } catch (error) {
77
- console.log(`${chalk.red.bold(error)}`);
78
- }
73
+ return new Promise((resolve, reject) => {
74
+ output.on("close", code => {
75
+ if (code === 0) {
76
+ let elapsed = Date.now() - startTime;
77
+ console.log(`${chalk.bold.green("Finished in " + prettyMs(elapsed), code)}`);
78
+ resolve();
79
+ } else {
80
+ // console.log(`${chalk.bold.green("Finished in " + prettyMs(elapsed), code)}`);
81
+ reject(`task exited with code ${code}`);
82
+ }
83
+ });
84
+ });
85
+ } catch (error) {
86
+ console.log(`${chalk.red.bold(error)}`);
87
+ }
79
88
  };
80
- export default runTask;
89
+
90
+ export default runTask;