@tenzir/codemirror-lang-tql 0.3.2

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.
@@ -0,0 +1,110 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import rehypeStringify from "rehype-stringify";
4
+ import remarkParse from "remark-parse";
5
+ import remarkRehype from "remark-rehype";
6
+ import strip from "strip-markdown";
7
+ import { remark } from "remark";
8
+ import { unified } from "unified";
9
+ import { promisify } from "util";
10
+ import remarkFlexibleContainers from "remark-flexible-containers";
11
+
12
+ const readFile = promisify(fs.readFile);
13
+ const readDirectory = promisify(fs.readdir);
14
+ const writeFile = promisify(fs.writeFile);
15
+ const lstat = promisify(fs.lstat);
16
+
17
+ const infoProcessor = unified()
18
+ .use(remarkParse)
19
+ .use(remarkFlexibleContainers)
20
+ .use(remarkRehype, { allowDangerousHtml: true })
21
+ .use(rehypeStringify);
22
+
23
+ const detailProcessor = remark().use(strip);
24
+
25
+ let output = [];
26
+
27
+ const processFile = async (filePath) => {
28
+ try {
29
+ const data = await readFile(filePath, "utf8");
30
+ let lines = data.split("\n");
31
+ let detail = undefined;
32
+ let infoArr = [];
33
+
34
+ for (let i = 1; i < lines.length; i++) {
35
+ if (detail == undefined && lines[i].trim() !== "") {
36
+ detail = lines[i];
37
+ } else if (detail != null) {
38
+ infoArr.push(lines[i]);
39
+ }
40
+ }
41
+ let info = infoArr.join("\n");
42
+
43
+ // get relative path to docs from filePath
44
+ const docRoute = filePath.split("docs")[1].split(".md")[0];
45
+ const docLink = `https://docs.tenzir.com${docRoute}`;
46
+
47
+ const infoFile = await infoProcessor.process(info);
48
+
49
+ const detailFile = await detailProcessor.process(detail);
50
+
51
+ output.push({
52
+ label: path.basename(filePath, ".md"),
53
+ type: "keyword",
54
+ detail: String(detailFile).trim(), // remove trailing whitespace
55
+ processedHTML: String(infoFile),
56
+ docLink,
57
+ });
58
+ } catch (err) {
59
+ console.error(err);
60
+ }
61
+ };
62
+
63
+ const processDirectory = async (directoryPath, outputPath) => {
64
+ try {
65
+ const files = await readDirectory(directoryPath);
66
+ for (let file of files) {
67
+ file = path.resolve(directoryPath, file);
68
+
69
+ // Also ignore README.md files
70
+ if (path.basename(file) === "README.md") {
71
+ continue;
72
+ }
73
+
74
+ // ignore files that are not inside sources, transformations, or sinks subdirectories
75
+ // TODO: this is a hacky way to do this, but it works for now
76
+ if (
77
+ !file.includes("sources") &&
78
+ !file.includes("transformations") &&
79
+ !file.includes("sinks")
80
+ ) {
81
+ continue;
82
+ }
83
+
84
+ const stat = await lstat(file);
85
+
86
+ if (stat.isDirectory()) {
87
+ await processDirectory(file, outputPath);
88
+ } else if (path.extname(file) === ".md") {
89
+ await processFile(file);
90
+ }
91
+ }
92
+
93
+ await writeFile(
94
+ outputPath,
95
+ `export const data = ${JSON.stringify(output)};`,
96
+ "utf8",
97
+ );
98
+ } catch (err) {
99
+ console.error(err);
100
+ }
101
+ };
102
+
103
+ const directoryPath = process.argv[2];
104
+ const outputPath = process.argv[3];
105
+
106
+ if (directoryPath && outputPath) {
107
+ processDirectory(directoryPath, outputPath);
108
+ } else {
109
+ console.log("Usage: node index.js <directoryPath> <outputFile.js>");
110
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "scripts",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "type": "module",
13
+ "dependencies": {
14
+ "rehype-document": "^6.1.0",
15
+ "rehype-format": "^4.0.1",
16
+ "rehype-stringify": "^9.0.3",
17
+ "remark": "^14.0.3",
18
+ "remark-flexible-containers": "^1.0.6",
19
+ "remark-parse": "^10.0.2",
20
+ "remark-rehype": "^10.1.0",
21
+ "strip-markdown": "^5.0.1",
22
+ "to-vfile": "^8.0.0",
23
+ "unified": "^10.1.2",
24
+ "vfile-reporter": "^8.0.0"
25
+ }
26
+ }