fscr 6.2.3 → 6.2.6

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.
@@ -1,191 +0,0 @@
1
- import fs from "fs-extra";
2
- import chalk from "chalk";
3
- import boxen from "boxen";
4
- const ONE_SIXTH = 1 / 6;
5
- const ONE_THIRD = 1 / 3;
6
- const TWO_THIRDS = 2 / 3;
7
- const utils = {};
8
-
9
- /**
10
- * Output json file
11
- * @param f - file name with directory
12
- * @return {boolean}
13
- * @example
14
- const file = "/tmp/this/path/does/not/exist/file.json";
15
- removeFile(file);
16
- */
17
- utils.emptyDir = async f => {
18
- try {
19
- await fs.emptyDir(f);
20
- // console.log(`${chalk.green.underline("Directory")} ${chalk.bold(f)} emptied!`);
21
- } catch (err) {
22
- console.error(err);
23
- }
24
- };
25
- const desiredMode = 0o2775;
26
- const defaultOptions = {
27
- mode: desiredMode
28
- };
29
- utils.ensureDir = async (directory, options = defaultOptions) => {
30
- try {
31
- await fs.ensureDir(directory, options);
32
- } catch (err) {
33
- console.error(err);
34
- }
35
- };
36
- utils.ensureFile = async f => {
37
- try {
38
- await fs.ensureFile(f);
39
- } catch (err) {
40
- console.error(err);
41
- }
42
- };
43
-
44
- /**
45
- * Ensure path exists with dirs
46
- * @param f the file path
47
- * @return {boolean}
48
- * @example
49
- const file = ".fsr/config.json";
50
- pathExists(file);
51
- */
52
- utils.pathExists = async f => {
53
- const exists = await fs.pathExists(f);
54
- return exists;
55
- };
56
-
57
- /**
58
- * Read json file
59
- * @param f - file name with directory
60
- * @return {Promise<void>}
61
- * @example
62
- const file = "/tmp/this/path/does/not/exist/file.json";
63
- outputJson(file);
64
- */
65
- utils.readJson = async f => {
66
- try {
67
- const packageObj = await fs.readJson(f);
68
- // console.log(`${chalk.green.underline("File")} ${chalk.bold(f)} read!`);
69
- return packageObj;
70
- } catch (err) {
71
- console.error(err);
72
- return {};
73
- }
74
- };
75
- utils.readFile = async f => {
76
- try {
77
- let fl = await fs.readFileSync(f, "utf8");
78
- return fl;
79
- } catch (err) {
80
- console.error(err);
81
- return {};
82
- }
83
- };
84
- utils.removeFile = async f => {
85
- try {
86
- // console.log(`${chalk.green.underline("File")} ${chalk.bold(f)} removed!`);
87
- return await fs.remove(f);
88
- } catch (err) {
89
- console.error(`File ${f} NOT REMOVED! ${err}`);
90
- return false;
91
- }
92
- };
93
-
94
- /**
95
- * Write file
96
- * @param f - file name with directory
97
- * @param contents - text inside the file
98
- * @return {Promise<void>}
99
- * @example
100
- const file = "/tmp/this/path/does/not/exist/file.json";
101
- writeFile(file);
102
- */
103
- utils.writeFile = async (f, contents = "") => {
104
- try {
105
- return fs.writeFileSync(f, contents, "utf-8");
106
- // console.log(`${chalk.green.underline("File")} ${chalk.bold(f)} written!`);
107
- } catch (err) {
108
- console.error(err);
109
- }
110
- };
111
- utils.writeJson = async (f, json = {}) => {
112
- try {
113
- await fs.writeJson(f, json);
114
- // console.log(`${chalk.green.underline("File")} ${chalk.bold(f)} written!`);
115
- } catch (err) {
116
- console.error(err);
117
- }
118
- };
119
- utils.chainAsync = fns => {
120
- let curr = 0;
121
- const last = fns[fns.length - 1];
122
- const next = () => {
123
- const fn = fns[curr++];
124
- fn === last ? fn() : fn(next);
125
- };
126
- next();
127
- };
128
- utils.appendToFile = async (f, contents = "") => {
129
- try {
130
- await fs.appendFileSync(f, contents);
131
- } catch (err) {
132
- console.error(err);
133
- }
134
- };
135
- utils.boxInform = async (msg, secondary = "", padding = 0, margin = {
136
- left: 2,
137
- top: 0,
138
- bottom: 0,
139
- right: 0
140
- }) => {
141
- console.log(boxen(chalk.hex("#717877")(msg) + "\n" + chalk.bold.underline.hex("#438b34")(secondary) + chalk.hex("#717877")(" "), {
142
- padding,
143
- margin,
144
- borderStyle: {
145
- topLeft: chalk.hex("#5a596d")("╔"),
146
- topRight: chalk.hex("#5a596d")("╗"),
147
- bottomLeft: chalk.hex("#5a596d")("╚"),
148
- bottomRight: chalk.hex("#5a596d")("╝"),
149
- horizontal: chalk.hex("#5a596d")("═"),
150
- vertical: chalk.hex("#5a596d")("║")
151
- },
152
- //"round",
153
- align: "center" //,
154
- }));
155
- };
156
- const hue2rgb = (p, q, t) => {
157
- if (t < 0) {
158
- t += 1;
159
- }
160
- if (t > 1) {
161
- t -= 1;
162
- }
163
- if (t < ONE_SIXTH) {
164
- return p + (q - p) * 6 * t;
165
- }
166
- if (t < 0.5) {
167
- return q;
168
- }
169
- if (t < TWO_THIRDS) {
170
- return p + (q - p) * (TWO_THIRDS - t) * 6;
171
- }
172
- return p;
173
- };
174
- const hsl2rgb = (h, s, l) => {
175
- if (s === 0) {
176
- return new Array(3).fill(l);
177
- }
178
- const q = l < 0.5 ? l * s + l : l + s - l * s;
179
- const p = 2 * l - q;
180
- return [hue2rgb(p, q, h + ONE_THIRD), hue2rgb(p, q, h), hue2rgb(p, q, h - ONE_THIRD)];
181
- };
182
- utils.rainbowGradient = (len, saturation = 1, lightness = 0.5) => {
183
- const gradient = [];
184
- for (let x = 0; x < len; x++) {
185
- gradient.push(hsl2rgb(x / len, saturation, lightness).map(c => Math.round(c * 255)));
186
- }
187
- return gradient;
188
- };
189
-
190
- // utils.emptyDir = async () => {};
191
- export default utils;
@@ -1,85 +0,0 @@
1
- import path from "path";
2
- import chalk from "chalk";
3
- import fs from "fs";
4
- const flattenObject = (obj, prefix = "") => Object.keys(obj).reduce((acc, k) => {
5
- const pre = prefix.length ? prefix + "." : "";
6
- if (typeof obj[k] === "object") Object.assign(acc, flattenObject(obj[k], pre + k));else acc[pre + k] = obj[k];
7
- return acc;
8
- }, {});
9
- import marked from "marked";
10
- let parse = function (mdContent) {
11
- let js = marked.lexer(mdContent);
12
- js = js.filter(e => e.type !== "space");
13
-
14
- // let firstHeading = js.findIndex(e => e.type === "heading" && e.depth === 1); //?
15
- let listMe = js.slice();
16
- let tempItem = {};
17
- let currentCategory = "";
18
- let currentTask = "";
19
- let taskOrder = 0;
20
- listMe.forEach((item, indx) => {
21
- if (item.type === "heading" && item.depth === 1) {
22
- taskOrder = 0;
23
- currentCategory = item.text;
24
- tempItem[currentCategory] = {
25
- name: item.text,
26
- tasks: {},
27
- description: ""
28
- };
29
- let descriptor = js[indx + 1];
30
- if (descriptor.type === "paragraph") {
31
- tempItem[currentCategory].description = descriptor.text;
32
- }
33
- } else if (item.type === "heading" && item.depth === 2) {
34
- currentTask = item.text;
35
- tempItem[currentCategory].tasks[currentTask] = {
36
- script: "",
37
- name: currentTask,
38
- description: "",
39
- order: taskOrder
40
- };
41
- taskOrder++;
42
- let descriptor = js[indx + 1];
43
- let code = js[indx + 2];
44
- if (descriptor.type === "paragraph" && code.type === "code") {
45
- tempItem[currentCategory].tasks[currentTask].description = descriptor.text;
46
- tempItem[currentCategory].tasks[currentTask].script = code.text;
47
- } else if (descriptor.type === "code") {
48
- tempItem[currentCategory].tasks[currentTask].script = descriptor.text;
49
- }
50
- }
51
- });
52
- let allTasks = [];
53
- let categories = Object.keys(tempItem).map(catName => {
54
- let ts = tempItem[catName].tasks;
55
- let tasksArr = Object.keys(ts).map(tn => ts[tn]);
56
- allTasks = [...allTasks, ...tasksArr];
57
- return {
58
- name: catName,
59
- ...tempItem[catName]
60
- };
61
- });
62
- return {
63
- categories,
64
- allTasks
65
- };
66
- };
67
- const parseScriptFile = async () => {
68
- const data = await fs.readFileSync(path.resolve(process.cwd(), "fscripts.md"), "utf-8");
69
- if (!data) {
70
- // console.warn(
71
- // `${chalk.bold.red("You're missing the fscripts.md file!")}
72
- // ${chalk.green("Please run 'fsr generate' to get started!")}`
73
- // );
74
- //
75
- // process.exit(0);
76
- // return null;
77
- return false;
78
- } else {
79
- // console.warn(`${chalk.bold.green("Located fscripts.md file!")}`);
80
- let newContent = data.split("<!-- end toc -->");
81
- newContent = newContent[newContent.length === 2 ? 1 : 0];
82
- return parse(newContent);
83
- }
84
- };
85
- export default parseScriptFile;
@@ -1,9 +0,0 @@
1
- import path from "path";
2
- import chalk from "chalk";
3
- const projectPath = path.join(process.cwd(), "./package.json");
4
- import { readJson } from "./utils/helpers.js";
5
- const parseScriptFile = async () => {
6
- const packageFile = await readJson(projectPath);
7
- return packageFile.scripts;
8
- };
9
- export default parseScriptFile;
@@ -1,4 +0,0 @@
1
- import bump from "./bump.js";
2
- (async () => {
3
- await bump();
4
- })();