1 | const path = require("path");
|
2 | const chalk = require("chalk");
|
3 | require("markdown-toc");
|
4 | const JoyCon = require("joycon");
|
5 | const toc = require("markdown-toc");
|
6 |
|
7 | const joyRead = new JoyCon({
|
8 |
|
9 |
|
10 | stopDir: path.dirname(process.cwd())
|
11 | });
|
12 | const { writeFile } = require("./helpers.js");
|
13 |
|
14 |
|
15 | const generateToc = async () => {
|
16 | const { path: filepath, data } = joyRead.loadSync(["fscripts.md"]);
|
17 | if (!filepath) {
|
18 | console.warn(
|
19 | `${chalk.bold.red("You're missing the fscripts.md file!")}
|
20 | ${chalk.green("Please run 'fsr generate' to get started!")}`
|
21 | );
|
22 | process.exit(0);
|
23 | return null;
|
24 | } else {
|
25 | console.warn(`${chalk.bold.green("Located fscripts.md file!")}`);
|
26 | let newFile = ``;
|
27 | let tocSplit = data.split("<!-- end toc -->");
|
28 | if (tocSplit.length === 2) {
|
29 | newFile = toc(tocSplit[1]).content + "\n<!-- end toc -->\n\n" + tocSplit[1].trim();
|
30 | } else {
|
31 | newFile = toc(data).content + "\n<!-- end toc -->\n\n" + data.trim();
|
32 | }
|
33 | await writeFile("./fscripts.md", newFile);
|
34 | }
|
35 | };
|
36 |
|
37 | module.exports = generateToc;
|