@p-buddy/parkdown 0.0.32 → 0.0.34
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.
- package/dist/cli.js +1 -1
- package/package.json +50 -53
- package/src/cli.ts +0 -33
- package/src/index.ts +0 -45
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Command as r } from "@commander-js/extra-typings";
|
|
3
3
|
import { populateMarkdownInclusions as l, depopulateMarkdownInclusions as a } from "@p-buddy/parkdown";
|
|
4
4
|
import f from "chokidar";
|
|
5
|
-
const c = "0.0.
|
|
5
|
+
const c = "0.0.34", p = new r().version(c).option("--nw, --no-write", "Do NOT write result to file (defaults to false)", !1).option("--ni, --no-inclusions", "Do NOT process file inclusions (defaults to false)", !1).option("-d, --depopulate", "Remove populated inclusions from the file", !1).option("-f, --file <flag>", "The file(s) to process", (e, o) => (o.push(e), o), new Array()).option("-w, --watch", "Watch the file(s) for changes and update automatically", !1).parse(), { inclusions: u, depopulate: d, file: t, write: n, watch: h } = p.opts();
|
|
6
6
|
t.length === 0 && t.push("README.md");
|
|
7
7
|
const m = [
|
|
8
8
|
[l, !u],
|
package/package.json
CHANGED
|
@@ -1,54 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
"unist-util-visit": "^5.0.0"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
2
|
+
"name": "@p-buddy/parkdown",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"private": false,
|
|
5
|
+
"version": "0.0.34",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"bin": "./dist/cli.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "^22.13.10",
|
|
18
|
+
"@types/unist": "^3.0.3",
|
|
19
|
+
"typescript": "^5.8.2",
|
|
20
|
+
"vite": "^6.2.1",
|
|
21
|
+
"vite-plugin-dts": "^4.5.3",
|
|
22
|
+
"vite-plugin-externalize-deps": "^0.9.0",
|
|
23
|
+
"vitest": "^3.0.8"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@commander-js/extra-typings": "^13.1.0",
|
|
27
|
+
"chokidar": "^4.0.3",
|
|
28
|
+
"remark-parse": "^11.0.0",
|
|
29
|
+
"ts-dedent": "^2.2.0",
|
|
30
|
+
"unified": "^11.0.5",
|
|
31
|
+
"unist-util-visit": "^5.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"auto:commit:tracked": "git add -u && (git diff-index --quiet HEAD -- || git commit -m \"Automated commit.\")",
|
|
35
|
+
"build:lib": "vite build",
|
|
36
|
+
"build:cli": "vite build --config vite.cli.config.ts",
|
|
37
|
+
"build": "pnpm build:lib && pnpm build:cli",
|
|
38
|
+
"test": "vitest",
|
|
39
|
+
"test:run": "vitest run",
|
|
40
|
+
"cli": "npx tsx src/cli.ts",
|
|
41
|
+
"doc:commit": "pnpm cli && pnpm auto:commit:tracked"
|
|
42
|
+
},
|
|
43
|
+
"typings": "./dist/index.d.ts",
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"types": "./dist/index.d.ts",
|
|
47
|
+
"import": "./dist/index.js",
|
|
48
|
+
"require": "./dist/index.umd.cjs"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/cli.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command } from '@commander-js/extra-typings';
|
|
3
|
-
import { version } from '../package.json';
|
|
4
|
-
import { populateMarkdownInclusions, depopulateMarkdownInclusions } from '.';
|
|
5
|
-
import chokidar from 'chokidar';
|
|
6
|
-
|
|
7
|
-
const program = new Command()
|
|
8
|
-
.version(version)
|
|
9
|
-
.option('--nw, --no-write', 'Do NOT write result to file (defaults to false)', false as boolean)
|
|
10
|
-
.option('--ni, --no-inclusions', 'Do NOT process file inclusions (defaults to false)', false as boolean)
|
|
11
|
-
.option('-d, --depopulate', 'Remove populated inclusions from the file', false as boolean)
|
|
12
|
-
.option('-f, --file <flag>', 'The file(s) to process', (value, arr) => (arr.push(value), arr), new Array<string>())
|
|
13
|
-
.option('-w, --watch', 'Watch the file(s) for changes and update automatically', false as boolean)
|
|
14
|
-
.parse();
|
|
15
|
-
|
|
16
|
-
const { inclusions: noInclusions, depopulate, file, write: noWrite, watch } = program.opts();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (file.length === 0) file.push("README.md");
|
|
20
|
-
|
|
21
|
-
/** pd: process-order */
|
|
22
|
-
const processors = [
|
|
23
|
-
[populateMarkdownInclusions, !noInclusions],
|
|
24
|
-
[depopulateMarkdownInclusions, depopulate],
|
|
25
|
-
] as const;
|
|
26
|
-
/** pd: process-order */
|
|
27
|
-
|
|
28
|
-
for (const [processor] of processors.filter(([_, condition]) => condition))
|
|
29
|
-
for (const _file of file) {
|
|
30
|
-
const watcher = watch ? chokidar.watch([], { persistent: true, awaitWriteFinish: true, atomic: true }) : undefined;
|
|
31
|
-
const result = processor(_file, !noWrite, watcher);
|
|
32
|
-
if (noWrite) console.log(result);
|
|
33
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { dirname, resolve } from "node:path";
|
|
3
|
-
import { recursivelyPopulateInclusions, removePopulatedInclusions } from "./include";
|
|
4
|
-
import { removeQueryParams } from "./utils";
|
|
5
|
-
import type chokidar from 'chokidar';
|
|
6
|
-
|
|
7
|
-
const read = (path: string) => readFileSync(path, "utf-8");
|
|
8
|
-
|
|
9
|
-
const tryResolveFile = (file: string) => {
|
|
10
|
-
const path = resolve(file);
|
|
11
|
-
const dir = dirname(path);
|
|
12
|
-
const content = read(path);
|
|
13
|
-
return { content, dir, path };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type Watcher = ReturnType<typeof chokidar.watch>;
|
|
17
|
-
|
|
18
|
-
export const populateMarkdownInclusions = (file: string, writeFile = true, watcher?: Watcher) => {
|
|
19
|
-
const { dir, path, content } = tryResolveFile(file);
|
|
20
|
-
|
|
21
|
-
watcher?.unwatch(path);
|
|
22
|
-
|
|
23
|
-
watcher?.once("change", (change, stats) => {
|
|
24
|
-
console.log(`Change detected in "${change}". Regenerating "${path}"...`);
|
|
25
|
-
populateMarkdownInclusions(file, writeFile, watcher);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const getContent = (relative: string) => {
|
|
29
|
-
const resolved = resolve(dir, removeQueryParams(relative));
|
|
30
|
-
watcher?.add(resolved);
|
|
31
|
-
return read(resolved);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const result = recursivelyPopulateInclusions(content, 0, getContent, path);
|
|
35
|
-
if (writeFile) writeFileSync(path, result);
|
|
36
|
-
watcher?.add(path);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const depopulateMarkdownInclusions = (file: string, writeFile = true, watcher?: Watcher) => {
|
|
41
|
-
const { path, content } = tryResolveFile(file);
|
|
42
|
-
const result = removePopulatedInclusions(content);
|
|
43
|
-
if (writeFile) writeFileSync(path, result);
|
|
44
|
-
return result;
|
|
45
|
-
};
|