markdown-maker 1.10.2 → 1.10.4
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/node.js.yml +21 -26
- package/.vscode/extensions.json +3 -0
- package/.vscode/settings.json +8 -3
- package/.vscode/snippets.code-snippets +6 -8
- package/bundle/cltool.d.ts +86 -0
- package/bundle/cltool.js +63 -0
- package/bundle/cltool.js.map +1 -0
- package/bundle/commands.d.ts +23 -0
- package/bundle/commands.js +303 -0
- package/bundle/commands.js.map +1 -0
- package/bundle/errors.d.ts +11 -0
- package/bundle/errors.js +51 -0
- package/bundle/errors.js.map +1 -0
- package/bundle/main.d.ts +6 -0
- package/bundle/main.js +152 -0
- package/bundle/main.js.map +1 -0
- package/bundle/parser.d.ts +35 -0
- package/bundle/parser.js +330 -0
- package/bundle/parser.js.map +1 -0
- package/bundle/templates/mathjax.d.ts +2 -0
- package/bundle/templates/mathjax.js +3 -0
- package/bundle/templates/mathjax.js.map +1 -0
- package/bundle/templates/presentation.d.ts +2 -0
- package/bundle/templates/presentation.js +3 -0
- package/bundle/templates/presentation.js.map +1 -0
- package/bundle/templates.d.ts +10 -0
- package/bundle/templates.js +23 -0
- package/bundle/templates.js.map +1 -0
- package/bundle/types.d.ts +28 -0
- package/bundle/types.js +15 -0
- package/bundle/types.js.map +1 -0
- package/bundle/version.d.ts +1 -0
- package/bundle/version.js +5 -0
- package/bundle/version.js.map +1 -0
- package/jest.config.js +7 -0
- package/package.json +42 -40
- package/src/cltool.ts +115 -72
- package/src/commands.ts +257 -241
- package/src/errors.ts +26 -0
- package/src/main.ts +114 -109
- package/src/parser.ts +378 -350
- package/src/templates.ts +5 -1
- package/src/types.ts +33 -0
- package/src/version.ts +1 -0
- package/tests/_test-util.ts +44 -0
- package/tests/advanced.spec.ts +102 -0
- package/tests/basic.spec.ts +68 -0
- package/tests/clargs.spec.ts +50 -0
- package/tests/errors.spec.ts +64 -0
- package/tests/html.spec.ts +23 -0
- package/tests/line.spec.ts +21 -0
- package/tests/marked.spec.ts +40 -0
- package/tests/target.spec.ts +41 -0
- package/tests/vars.spec.ts +45 -0
- package/tsconfig.json +66 -64
- package/prettierrc.yaml +0 -4
- package/test/advanced.test.js +0 -34
- package/test/basic.test.js +0 -67
- package/test/clargs.test.js +0 -51
- package/test/errors.test.js +0 -47
- package/test/hooks.js +0 -9
- package/test/hooks.test.js +0 -114
- package/test/html.test.js +0 -37
- package/test/line.test.js +0 -21
- package/test/marked.test.js +0 -43
- package/test/target.test.js +0 -43
- package/test/tester.test.js +0 -41
- package/test/vars.test.js +0 -49
package/src/main.ts
CHANGED
@@ -1,122 +1,127 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
1
3
|
import path from "path";
|
2
4
|
import { WebSocketServer } from "ws";
|
3
|
-
import Parser from "./parser";
|
4
5
|
import * as fs from "fs";
|
5
|
-
const choki = require("chokidar");
|
6
6
|
|
7
|
-
import
|
7
|
+
import choki from "chokidar";
|
8
|
+
import Parser from "./parser";
|
9
|
+
|
10
|
+
/* for adding colours to strings */
|
11
|
+
import { enable as ColorsEnable } from "colors.ts";
|
12
|
+
ColorsEnable();
|
13
|
+
|
14
|
+
import { argParser, CommandLineArgs, ParserOptions } from "./cltool";
|
15
|
+
import { log } from "console";
|
8
16
|
const configFileName = ".mdmconfig.json";
|
9
17
|
|
10
18
|
function main() {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
console.log(e.message);
|
113
|
-
}
|
114
|
-
}
|
19
|
+
let clargs: CommandLineArgs;
|
20
|
+
let server: WebSocketServer | undefined;
|
21
|
+
|
22
|
+
/* Read config file or parse args from cmd-line */
|
23
|
+
if (fs.existsSync(configFileName)) {
|
24
|
+
let data: CommandLineArgs = JSON.parse(
|
25
|
+
fs.readFileSync(configFileName).toString()
|
26
|
+
).opts;
|
27
|
+
|
28
|
+
let args: (string | number)[] = [];
|
29
|
+
Object.entries(data).forEach(([key, value]) => {
|
30
|
+
if (key != "src" && value !== false) {
|
31
|
+
args.push("--" + key);
|
32
|
+
}
|
33
|
+
if (typeof value != "boolean") {
|
34
|
+
args.push(value);
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
/* We skip [0] and [1], as it is the binary and source file, even when compiled*/
|
39
|
+
for (let i = 2; i < process.argv.length; i++)
|
40
|
+
args.push(process.argv[i]);
|
41
|
+
|
42
|
+
clargs = argParser.parse_args(args.map((x) => x.toString()));
|
43
|
+
} else {
|
44
|
+
clargs = argParser.parse_args();
|
45
|
+
}
|
46
|
+
|
47
|
+
/* if src is init, create config file and exit */
|
48
|
+
if (clargs.src == "init") {
|
49
|
+
const template = fs.readFileSync(
|
50
|
+
path.join(
|
51
|
+
__dirname,
|
52
|
+
"..",
|
53
|
+
"src",
|
54
|
+
"templates",
|
55
|
+
"configTemplate.json"
|
56
|
+
)
|
57
|
+
);
|
58
|
+
fs.writeFileSync(configFileName, template);
|
59
|
+
fs.writeFileSync("main.md", "# Main\n");
|
60
|
+
console.log(`Created config file ${configFileName.green}`);
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
|
64
|
+
/* helper method for calling parser */
|
65
|
+
const compile = (source, output, cb?) => {
|
66
|
+
/* load data from file, if it exists,
|
67
|
+
* otherwise, interpret as string */
|
68
|
+
|
69
|
+
const parser = new Parser(source, clargs);
|
70
|
+
parser.to(output, (file) => {
|
71
|
+
console.log(`Compiled ${file}`.green);
|
72
|
+
if (cb) cb();
|
73
|
+
});
|
74
|
+
return parser;
|
75
|
+
};
|
76
|
+
|
77
|
+
const internalCooldown = 1000;
|
78
|
+
function watcher(_, path: string) {
|
79
|
+
const now = Date.now();
|
80
|
+
|
81
|
+
if (!this.time) this.time = now;
|
82
|
+
if (now - this.time < internalCooldown) return;
|
83
|
+
console.log(`Detected change in ${path}...`);
|
84
|
+
try {
|
85
|
+
compile(clargs.src, clargs.output, () => {
|
86
|
+
/* after compile, send refresh command to clients */
|
87
|
+
server.clients.forEach((client) => {
|
88
|
+
if (client.OPEN) client.send("refresh");
|
89
|
+
});
|
90
|
+
});
|
91
|
+
} catch (e) {
|
92
|
+
console.log(e.message);
|
93
|
+
}
|
94
|
+
|
95
|
+
this.time = now;
|
96
|
+
}
|
97
|
+
|
98
|
+
/* in case source is a directory, look for entry in directory */
|
99
|
+
if (fs.existsSync(clargs.src) && fs.lstatSync(clargs.src).isDirectory()) {
|
100
|
+
clargs.src = path.join(clargs.src, clargs.entry);
|
101
|
+
}
|
102
|
+
|
103
|
+
if (clargs.debug) console.dir(clargs);
|
104
|
+
|
105
|
+
/* compile once if not watching
|
106
|
+
otherwise watch the folder and recompile on change */
|
107
|
+
if (!clargs.watch) compile(clargs.src, clargs.output);
|
108
|
+
else {
|
109
|
+
const srcDirName = path.dirname(clargs.src);
|
110
|
+
console.log(`Watching ${srcDirName} for changes...`.yellow);
|
111
|
+
server = new WebSocketServer({ port: 7788 });
|
112
|
+
|
113
|
+
const _watcher = choki.watch(srcDirName).on("all", watcher);
|
114
|
+
try {
|
115
|
+
compile(clargs.src, clargs.output);
|
116
|
+
} catch (e) {
|
117
|
+
console.log(e.message);
|
118
|
+
}
|
119
|
+
}
|
115
120
|
}
|
116
121
|
export default {
|
117
|
-
|
122
|
+
Parser,
|
118
123
|
};
|
119
124
|
/* main entrypoint */
|
120
125
|
if (require.main === module) {
|
121
|
-
|
126
|
+
main();
|
122
127
|
}
|