@o2b/meta 1.0.0-dev.6 → 1.0.0-dev.7
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 +11 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +21 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -29,7 +29,7 @@ var import_cac = __toESM(require("cac"));
|
|
|
29
29
|
// package.json
|
|
30
30
|
var package_default = {
|
|
31
31
|
name: "@o2b/meta",
|
|
32
|
-
version: "1.0.0-dev.
|
|
32
|
+
version: "1.0.0-dev.6",
|
|
33
33
|
description: "filetree generator for o2b",
|
|
34
34
|
main: "./dist/index.js",
|
|
35
35
|
module: "./dist/index.mjs",
|
|
@@ -196,14 +196,18 @@ function normalize(fileTree) {
|
|
|
196
196
|
return id2;
|
|
197
197
|
});
|
|
198
198
|
const dirs = dir.dirs.map((dir2) => aux(dir2));
|
|
199
|
-
dirNodes.push({ ...dir, id, files, dirs });
|
|
200
|
-
return
|
|
199
|
+
dirNodes.push({ ...dir, id, files, dirs: dirs.map((dir2) => dir2.id) });
|
|
200
|
+
return {
|
|
201
|
+
id,
|
|
202
|
+
files,
|
|
203
|
+
dirs
|
|
204
|
+
};
|
|
201
205
|
}
|
|
202
|
-
aux(fileTree);
|
|
206
|
+
const normedFileTree = aux(fileTree);
|
|
203
207
|
return {
|
|
204
208
|
dirNodes,
|
|
205
209
|
fileNodes,
|
|
206
|
-
|
|
210
|
+
fileTree: normedFileTree
|
|
207
211
|
};
|
|
208
212
|
}
|
|
209
213
|
|
|
@@ -251,8 +255,8 @@ function runO2B(config) {
|
|
|
251
255
|
if (fileTree === null) throw new Error("No content in vault");
|
|
252
256
|
if (fileTree.type !== "dir") throw new Error("No Vault?!");
|
|
253
257
|
mirror(fileTree, srcPath, destPath);
|
|
254
|
-
const {
|
|
255
|
-
generateJson(
|
|
258
|
+
const { fileTree: normedFileTree, dirNodes, fileNodes } = normalize(fileTree);
|
|
259
|
+
generateJson(normedFileTree, "fileTree", destPath);
|
|
256
260
|
generateJson(dirNodes, "dirNodes", destPath);
|
|
257
261
|
generateJson(fileNodes, "fileNodes", destPath);
|
|
258
262
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../package.json","../src/core/sync/mirror.ts","../src/core/sync/scan.ts","../src/utils/path.ts","../src/types/path.ts","../src/utils/id.ts","../src/core/sync/normalize.ts","../src/utils/file.ts","../src/utils/ignore.ts","../src/runO2B.ts"],"sourcesContent":["import cac from \"cac\";\nimport pkg from \"../package.json\";\nimport runO2B from \"./runO2B\";\nimport { toAbsPath } from \"@utils/path\";\n\nconst cli = cac(\"o2b-meta\");\n\ncli\n .command(\"<srcPath>\", \"target vault file\")\n .option(\"--destPath [destPath]\", \"dist\", {\n default: \"./o2b\",\n })\n .option(\"--ignore\", \"read the .o2bIgnore if exists\", {\n default: true,\n })\n .option(\"--sync\", \"synchro\", {\n default: true,\n })\n .action((srcPath, option) => {\n const { destPath, ignore, sync } = option;\n\n const startTime = performance.now();\n\n if (sync) {\n runO2B({\n srcPath: toAbsPath(srcPath),\n destPath: toAbsPath(destPath),\n ignore,\n });\n }\n\n const endTime = performance.now();\n const duration = (endTime - startTime).toFixed(2); // 소수점 2자리까지\n\n console.log(`\\n✅ Build Success!`);\n console.log(` Time: ${duration}ms`);\n // console.log(` Dest: ${config.destPath}\\n`);\n });\n\ncli.help();\ncli.version(pkg.version);\n\n// production에 대한 에러처리\ncli.parse();\n","{\n \"name\": \"@o2b/meta\",\n \"version\": \"1.0.0-dev.5\",\n \"description\": \"filetree generator for o2b\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n }\n },\n \"bin\": {\n \"o2b-meta\": \"dist/cli.js\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"test\": \"vitest\",\n \"test:run\": \"vitest run\"\n },\n \"keywords\": [],\n \"author\": \"goonco\",\n \"license\": \"ISC\",\n \"type\": \"commonjs\",\n \"files\": [\n \"dist\"\n ],\n \"devDependencies\": {\n \"@biomejs/biome\": \"2.3.10\",\n \"@types/node\": \"^25.0.3\",\n \"@vitest/ui\": \"^4.0.16\",\n \"tsup\": \"^8.5.1\",\n \"typescript\": \"^5.9.3\",\n \"vite-tsconfig-paths\": \"^6.0.5\",\n \"vitest\": \"^4.0.16\",\n \"zod\": \"^3.25.76\"\n },\n \"dependencies\": {\n \"cac\": \"^6.7.14\",\n \"gray-matter\": \"^4.0.3\",\n \"ignore\": \"^7.0.5\",\n \"lilconfig\": \"^3.1.3\"\n },\n \"peerDependencies\": {\n \"zod\": \"^3.23.8\"\n }\n}\n","import { copyFileSync, existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport type { FileTree } from \"@o2bTypes/filetree\";\n\nexport function mirror(\n filetree: FileTree,\n srcPath: AbsPath,\n destPath: AbsPath,\n) {\n function aux(filetree: FileTree) {\n const from = join(srcPath, filetree.path);\n const to = join(destPath, filetree.path);\n\n if (filetree.type === \"dir\") {\n if (!existsSync(to)) mkdirSync(to, { recursive: true });\n\n filetree.files.forEach((file) => {\n aux(file);\n });\n\n filetree.dirs.forEach((dir) => {\n aux(dir);\n });\n }\n\n if (filetree.type === \"file\") {\n copyFileSync(from, to);\n }\n }\n\n aux(filetree);\n}\n","import { lstatSync, readdirSync, readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport matter from \"gray-matter\";\nimport type {\n DirNode,\n FileNode,\n FileTree,\n Frontmatter,\n} from \"@o2bTypes/filetree\";\nimport { toAbsPath, toRelPath } from \"@utils/path\";\nimport { AbsPath } from \"@o2bTypes/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport function scan(rootPath: AbsPath, ign: VaultIgnorer): FileTree | null {\n function aux(path: AbsPath): FileTree | null {\n if (ign?.ignore(path)) return null;\n\n const stat = lstatSync(path);\n const name = basename(path);\n\n if (stat.isFile() && name.endsWith(\".md\")) {\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"file\",\n frontmatter: fetchFrontmatter(path, stat.mtime),\n };\n }\n\n if (stat.isDirectory()) {\n const dirs: DirNode[] = [];\n const files: FileNode[] = [];\n const entries = readdirSync(path);\n\n for (const entry of entries) {\n const fullPath = toAbsPath(join(path, entry));\n const node = aux(fullPath);\n\n if (node?.type === \"dir\") dirs.push(node);\n if (node?.type === \"file\") files.push(node);\n }\n\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"dir\",\n dirs,\n files,\n };\n }\n\n return null;\n }\n\n return aux(rootPath);\n}\n\nfunction fetchFrontmatter(path: AbsPath, mtime: Date): Frontmatter {\n const { data } = matter(readFileSync(path, \"utf-8\"));\n return {\n title: basename(path).replace(/\\.md$/, \"\"),\n description: \"No description provided.\",\n last_modified: mtime.toISOString().split(\"T\")[0],\n ...data,\n };\n}\n","import { lstatSync, readdirSync } from \"node:fs\";\nimport { isAbsolute, relative, resolve } from \"node:path\";\nimport { absPath, relPath, type AbsPath, type RelPath } from \"@o2bTypes/path\";\n\nfunction toAbsPath(path: string): AbsPath {\n if (!isAbsolute(path)) path = resolve(path);\n return absPath.parse(path);\n}\n\nfunction toRelPath(from: AbsPath, to: AbsPath): RelPath {\n return relPath.parse(relative(from, to));\n}\n\nfunction isObsidianDirectory(path: AbsPath) {\n const stat = lstatSync(path);\n\n if (!stat.isDirectory()) return false;\n\n const obsMetaDir = readdirSync(path, { withFileTypes: true })\n .filter((node) => node.isDirectory())\n .filter((node) => node.name === \".obsidian\");\n\n if (obsMetaDir.length !== 1) return false;\n\n return true;\n}\n\nexport { toAbsPath, toRelPath, isObsidianDirectory };\n","import z from \"zod\";\n\ntype AbsPath = z.infer<typeof absPath>;\nconst absPath = z.string().brand<\"absPath\">();\n\ntype RelPath = z.infer<typeof relPath>;\nconst relPath = z.string().brand<\"relpath\">();\n\nexport { type AbsPath, type RelPath, absPath, relPath };\n","import { Id } from \"@o2bTypes/filetree\";\n\nexport const idCounter: (start?: number) => () => Id = (start: number = 0) => {\n let count = start;\n return () => count++;\n};\n","import { DirNode, Id, NormedDirNode, NormedFileNode } from \"@o2bTypes/filetree\";\nimport { idCounter } from \"@utils/id\";\n\nexport function normalize(fileTree: DirNode): {\n vault: NormedDirNode;\n dirNodes: NormedDirNode[];\n fileNodes: NormedFileNode[];\n} {\n const dirNodes: NormedDirNode[] = [];\n const fileNodes: NormedFileNode[] = [];\n\n const fileId = idCounter();\n const dirId = idCounter();\n\n function aux(dir: DirNode): Id {\n const id = dirId();\n\n const files = dir.files.map((file) => {\n const id = fileId();\n fileNodes.push({ id, ...file });\n return id;\n });\n\n const dirs = dir.dirs.map((dir) => aux(dir));\n dirNodes.push({ ...dir, id, files, dirs });\n\n return id;\n }\n aux(fileTree);\n\n return {\n dirNodes,\n fileNodes,\n vault: dirNodes[dirNodes.length - 1],\n };\n}\n","import { writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { AbsPath } from \"@o2bTypes/path\";\n\nexport function generateJson(\n content: unknown,\n name: string,\n destPath: AbsPath,\n) {\n const jsonFilePath = join(destPath, `${name}.json`);\n writeFileSync(jsonFilePath, JSON.stringify(content, null, 2), \"utf-8\");\n}\n","import { existsSync, lstatSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport ignore, { type Ignore } from \"ignore\";\n\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport { toRelPath } from \"@utils/path\";\n\nexport class VaultIgnorer {\n private ign: Ignore;\n private rootPath: AbsPath;\n\n constructor(rootPath: AbsPath) {\n this.rootPath = rootPath;\n this.ign = ignore();\n\n this.ign.add([\".*\"]);\n }\n\n public load() {\n const ignorePath = join(this.rootPath, \".o2bignore\");\n if (existsSync(ignorePath))\n this.ign.add(readFileSync(ignorePath).toString());\n }\n\n public ignore(path: AbsPath): boolean {\n if (path === this.rootPath) return false;\n\n if (!existsSync(path)) throw new Error(\"somethings wrong!\");\n\n const stat = lstatSync(path);\n\n const relPath =\n toRelPath(this.rootPath, path) + (stat.isDirectory() ? \"/\" : \"\");\n\n return this.ign.ignores(relPath);\n }\n}\n","import { mirror, scan, normalize } from \"@core/sync\";\nimport type { Config } from \"@o2bTypes/config\";\nimport { generateJson } from \"@utils/file\";\nimport { isObsidianDirectory } from \"@utils/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport default function runO2B(config: Config) {\n const { srcPath, destPath, ignore } = config;\n\n if (!isObsidianDirectory(srcPath)) throw new Error(\"Not a obsidian vault\");\n\n const ign = new VaultIgnorer(srcPath);\n if (ignore) ign.load();\n\n const fileTree = scan(srcPath, ign);\n if (fileTree === null) throw new Error(\"No content in vault\");\n if (fileTree.type !== \"dir\") throw new Error(\"No Vault?!\");\n\n mirror(fileTree, srcPath, destPath);\n const { vault, dirNodes, fileNodes } = normalize(fileTree);\n\n generateJson(vault, \"vault\", destPath);\n generateJson(dirNodes, \"dirNodes\", destPath);\n generateJson(fileNodes, \"fileNodes\", destPath);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAAgB;;;ACAhB;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,QAAU;AAAA,EACV,OAAS;AAAA,EACT,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACb;AAAA,EACF;AAAA,EACA,KAAO;AAAA,IACL,YAAY;AAAA,EACd;AAAA,EACA,SAAW;AAAA,IACT,OAAS;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AAU,UAAU,IAAI,UAAU,QAAQ;AAEzD,eAAa,OAAO,SAAS,QAAQ;AACrC,eAAa,UAAU,YAAY,QAAQ;AAC3C,eAAa,WAAW,aAAa,QAAQ;AAC/C;;;AVnBA,IAAM,UAAM,WAAAC,SAAI,UAAU;AAE1B,IACG,QAAQ,aAAa,mBAAmB,EACxC,OAAO,yBAAyB,QAAQ;AAAA,EACvC,SAAS;AACX,CAAC,EACA,OAAO,YAAY,iCAAiC;AAAA,EACnD,SAAS;AACX,CAAC,EACA,OAAO,UAAU,WAAW;AAAA,EAC3B,SAAS;AACX,CAAC,EACA,OAAO,CAAC,SAAS,WAAW;AAC3B,QAAM,EAAE,UAAU,QAAAC,SAAQ,KAAK,IAAI;AAEnC,QAAM,YAAY,YAAY,IAAI;AAElC,MAAI,MAAM;AACR,WAAO;AAAA,MACL,SAAS,UAAU,OAAO;AAAA,MAC1B,UAAU,UAAU,QAAQ;AAAA,MAC5B,QAAAA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,UAAU,YAAY,IAAI;AAChC,QAAM,YAAY,UAAU,WAAW,QAAQ,CAAC;AAEhD,UAAQ,IAAI;AAAA,sBAAoB;AAChC,UAAQ,IAAI,YAAY,QAAQ,IAAI;AAEtC,CAAC;AAEH,IAAI,KAAK;AACT,IAAI,QAAQ,gBAAI,OAAO;AAGvB,IAAI,MAAM;","names":["filetree","import_node_fs","import_node_path","import_node_fs","import_node_path","z","matter","id","dir","import_node_fs","import_node_path","import_node_fs","import_node_path","ignore","relPath","ignore","cac","ignore"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../package.json","../src/core/sync/mirror.ts","../src/core/sync/scan.ts","../src/utils/path.ts","../src/types/path.ts","../src/utils/id.ts","../src/core/sync/normalize.ts","../src/utils/file.ts","../src/utils/ignore.ts","../src/runO2B.ts"],"sourcesContent":["import cac from \"cac\";\nimport pkg from \"../package.json\";\nimport runO2B from \"./runO2B\";\nimport { toAbsPath } from \"@utils/path\";\n\nconst cli = cac(\"o2b-meta\");\n\ncli\n .command(\"<srcPath>\", \"target vault file\")\n .option(\"--destPath [destPath]\", \"dist\", {\n default: \"./o2b\",\n })\n .option(\"--ignore\", \"read the .o2bIgnore if exists\", {\n default: true,\n })\n .option(\"--sync\", \"synchro\", {\n default: true,\n })\n .action((srcPath, option) => {\n const { destPath, ignore, sync } = option;\n\n const startTime = performance.now();\n\n if (sync) {\n runO2B({\n srcPath: toAbsPath(srcPath),\n destPath: toAbsPath(destPath),\n ignore,\n });\n }\n\n const endTime = performance.now();\n const duration = (endTime - startTime).toFixed(2); // 소수점 2자리까지\n\n console.log(`\\n✅ Build Success!`);\n console.log(` Time: ${duration}ms`);\n // console.log(` Dest: ${config.destPath}\\n`);\n });\n\ncli.help();\ncli.version(pkg.version);\n\n// production에 대한 에러처리\ncli.parse();\n","{\n \"name\": \"@o2b/meta\",\n \"version\": \"1.0.0-dev.6\",\n \"description\": \"filetree generator for o2b\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n }\n },\n \"bin\": {\n \"o2b-meta\": \"dist/cli.js\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"test\": \"vitest\",\n \"test:run\": \"vitest run\"\n },\n \"keywords\": [],\n \"author\": \"goonco\",\n \"license\": \"ISC\",\n \"type\": \"commonjs\",\n \"files\": [\n \"dist\"\n ],\n \"devDependencies\": {\n \"@biomejs/biome\": \"2.3.10\",\n \"@types/node\": \"^25.0.3\",\n \"@vitest/ui\": \"^4.0.16\",\n \"tsup\": \"^8.5.1\",\n \"typescript\": \"^5.9.3\",\n \"vite-tsconfig-paths\": \"^6.0.5\",\n \"vitest\": \"^4.0.16\",\n \"zod\": \"^3.25.76\"\n },\n \"dependencies\": {\n \"cac\": \"^6.7.14\",\n \"gray-matter\": \"^4.0.3\",\n \"ignore\": \"^7.0.5\",\n \"lilconfig\": \"^3.1.3\"\n },\n \"peerDependencies\": {\n \"zod\": \"^3.23.8\"\n }\n}\n","import { copyFileSync, existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport type { FileTree } from \"@o2bTypes/filetree\";\n\nexport function mirror(\n filetree: FileTree,\n srcPath: AbsPath,\n destPath: AbsPath,\n) {\n function aux(filetree: FileTree) {\n const from = join(srcPath, filetree.path);\n const to = join(destPath, filetree.path);\n\n if (filetree.type === \"dir\") {\n if (!existsSync(to)) mkdirSync(to, { recursive: true });\n\n filetree.files.forEach((file) => {\n aux(file);\n });\n\n filetree.dirs.forEach((dir) => {\n aux(dir);\n });\n }\n\n if (filetree.type === \"file\") {\n copyFileSync(from, to);\n }\n }\n\n aux(filetree);\n}\n","import { lstatSync, readdirSync, readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport matter from \"gray-matter\";\nimport type {\n DirNode,\n FileNode,\n FileTree,\n Frontmatter,\n} from \"@o2bTypes/filetree\";\nimport { toAbsPath, toRelPath } from \"@utils/path\";\nimport { AbsPath } from \"@o2bTypes/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport function scan(rootPath: AbsPath, ign: VaultIgnorer): FileTree | null {\n function aux(path: AbsPath): FileTree | null {\n if (ign?.ignore(path)) return null;\n\n const stat = lstatSync(path);\n const name = basename(path);\n\n if (stat.isFile() && name.endsWith(\".md\")) {\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"file\",\n frontmatter: fetchFrontmatter(path, stat.mtime),\n };\n }\n\n if (stat.isDirectory()) {\n const dirs: DirNode[] = [];\n const files: FileNode[] = [];\n const entries = readdirSync(path);\n\n for (const entry of entries) {\n const fullPath = toAbsPath(join(path, entry));\n const node = aux(fullPath);\n\n if (node?.type === \"dir\") dirs.push(node);\n if (node?.type === \"file\") files.push(node);\n }\n\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"dir\",\n dirs,\n files,\n };\n }\n\n return null;\n }\n\n return aux(rootPath);\n}\n\nfunction fetchFrontmatter(path: AbsPath, mtime: Date): Frontmatter {\n const { data } = matter(readFileSync(path, \"utf-8\"));\n return {\n title: basename(path).replace(/\\.md$/, \"\"),\n description: \"No description provided.\",\n last_modified: mtime.toISOString().split(\"T\")[0],\n ...data,\n };\n}\n","import { lstatSync, readdirSync } from \"node:fs\";\nimport { isAbsolute, relative, resolve } from \"node:path\";\nimport { absPath, relPath, type AbsPath, type RelPath } from \"@o2bTypes/path\";\n\nfunction toAbsPath(path: string): AbsPath {\n if (!isAbsolute(path)) path = resolve(path);\n return absPath.parse(path);\n}\n\nfunction toRelPath(from: AbsPath, to: AbsPath): RelPath {\n return relPath.parse(relative(from, to));\n}\n\nfunction isObsidianDirectory(path: AbsPath) {\n const stat = lstatSync(path);\n\n if (!stat.isDirectory()) return false;\n\n const obsMetaDir = readdirSync(path, { withFileTypes: true })\n .filter((node) => node.isDirectory())\n .filter((node) => node.name === \".obsidian\");\n\n if (obsMetaDir.length !== 1) return false;\n\n return true;\n}\n\nexport { toAbsPath, toRelPath, isObsidianDirectory };\n","import z from \"zod\";\n\ntype AbsPath = z.infer<typeof absPath>;\nconst absPath = z.string().brand<\"absPath\">();\n\ntype RelPath = z.infer<typeof relPath>;\nconst relPath = z.string().brand<\"relpath\">();\n\nexport { type AbsPath, type RelPath, absPath, relPath };\n","import { Id } from \"@o2bTypes/filetree\";\n\nexport const idCounter: (start?: number) => () => Id = (start: number = 0) => {\n let count = start;\n return () => count++;\n};\n","import {\n DirNode,\n NormedDirNode,\n NormedFileNode,\n NormedFileTree,\n} from \"@o2bTypes/filetree\";\nimport { idCounter } from \"@utils/id\";\n\nexport function normalize(fileTree: DirNode): {\n fileTree: NormedFileTree;\n dirNodes: NormedDirNode[];\n fileNodes: NormedFileNode[];\n} {\n const dirNodes: NormedDirNode[] = [];\n const fileNodes: NormedFileNode[] = [];\n\n const fileId = idCounter();\n const dirId = idCounter();\n\n function aux(dir: DirNode): NormedFileTree {\n const id = dirId();\n\n const files = dir.files.map((file) => {\n const id = fileId();\n fileNodes.push({ id, ...file });\n return id;\n });\n\n const dirs = dir.dirs.map((dir) => aux(dir));\n dirNodes.push({ ...dir, id, files, dirs: dirs.map((dir) => dir.id) });\n\n return {\n id,\n files,\n dirs,\n };\n }\n const normedFileTree = aux(fileTree);\n\n return {\n dirNodes,\n fileNodes,\n fileTree: normedFileTree,\n };\n}\n","import { writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { AbsPath } from \"@o2bTypes/path\";\n\nexport function generateJson(\n content: unknown,\n name: string,\n destPath: AbsPath,\n) {\n const jsonFilePath = join(destPath, `${name}.json`);\n writeFileSync(jsonFilePath, JSON.stringify(content, null, 2), \"utf-8\");\n}\n","import { existsSync, lstatSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport ignore, { type Ignore } from \"ignore\";\n\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport { toRelPath } from \"@utils/path\";\n\nexport class VaultIgnorer {\n private ign: Ignore;\n private rootPath: AbsPath;\n\n constructor(rootPath: AbsPath) {\n this.rootPath = rootPath;\n this.ign = ignore();\n\n this.ign.add([\".*\"]);\n }\n\n public load() {\n const ignorePath = join(this.rootPath, \".o2bignore\");\n if (existsSync(ignorePath))\n this.ign.add(readFileSync(ignorePath).toString());\n }\n\n public ignore(path: AbsPath): boolean {\n if (path === this.rootPath) return false;\n\n if (!existsSync(path)) throw new Error(\"somethings wrong!\");\n\n const stat = lstatSync(path);\n\n const relPath =\n toRelPath(this.rootPath, path) + (stat.isDirectory() ? \"/\" : \"\");\n\n return this.ign.ignores(relPath);\n }\n}\n","import { mirror, scan, normalize } from \"@core/sync\";\nimport type { Config } from \"@o2bTypes/config\";\nimport { generateJson } from \"@utils/file\";\nimport { isObsidianDirectory } from \"@utils/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport default function runO2B(config: Config) {\n const { srcPath, destPath, ignore } = config;\n\n if (!isObsidianDirectory(srcPath)) throw new Error(\"Not a obsidian vault\");\n\n const ign = new VaultIgnorer(srcPath);\n if (ignore) ign.load();\n\n const fileTree = scan(srcPath, ign);\n if (fileTree === null) throw new Error(\"No content in vault\");\n if (fileTree.type !== \"dir\") throw new Error(\"No Vault?!\");\n\n mirror(fileTree, srcPath, destPath);\n const { fileTree: normedFileTree, dirNodes, fileNodes } = normalize(fileTree);\n\n generateJson(normedFileTree, \"fileTree\", destPath);\n generateJson(dirNodes, \"dirNodes\", destPath);\n generateJson(fileNodes, \"fileNodes\", destPath);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAAgB;;;ACAhB;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,QAAU;AAAA,EACV,OAAS;AAAA,EACT,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACb;AAAA,EACF;AAAA,EACA,KAAO;AAAA,IACL,YAAY;AAAA,EACd;AAAA,EACA,SAAW;AAAA,IACT,OAAS;AAAA,IACT,MAAQ;AAAA,IACR,YAAY;AAAA,EACd;AAAA,EACA,UAAY,CAAC;AAAA,EACb,QAAU;AAAA,EACV,SAAW;AAAA,EACX,MAAQ;AAAA,EACR,OAAS;AAAA,IACP;AAAA,EACF;AAAA,EACA,iBAAmB;AAAA,IACjB,kBAAkB;AAAA,IAClB,eAAe;AAAA,IACf,cAAc;AAAA,IACd,MAAQ;AAAA,IACR,YAAc;AAAA,IACd,uBAAuB;AAAA,IACvB,QAAU;AAAA,IACV,KAAO;AAAA,EACT;AAAA,EACA,cAAgB;AAAA,IACd,KAAO;AAAA,IACP,eAAe;AAAA,IACf,QAAU;AAAA,IACV,WAAa;AAAA,EACf;AAAA,EACA,kBAAoB;AAAA,IAClB,KAAO;AAAA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AC,SAAS,WAAW;AAC3B,QAAM,EAAE,UAAU,QAAAC,SAAQ,KAAK,IAAI;AAEnC,QAAM,YAAY,YAAY,IAAI;AAElC,MAAI,MAAM;AACR,WAAO;AAAA,MACL,SAAS,UAAU,OAAO;AAAA,MAC1B,UAAU,UAAU,QAAQ;AAAA,MAC5B,QAAAA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,UAAU,YAAY,IAAI;AAChC,QAAM,YAAY,UAAU,WAAW,QAAQ,CAAC;AAEhD,UAAQ,IAAI;AAAA,sBAAoB;AAChC,UAAQ,IAAI,YAAY,QAAQ,IAAI;AAEtC,CAAC;AAEH,IAAI,KAAK;AACT,IAAI,QAAQ,gBAAI,OAAO;AAGvB,IAAI,MAAM;","names":["filetree","import_node_fs","import_node_path","import_node_fs","import_node_path","z","matter","id","dir","import_node_fs","import_node_path","import_node_fs","import_node_path","ignore","relPath","ignore","cac","ignore"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
|
|
3
|
+
declare const id: z.ZodNumber;
|
|
3
4
|
declare const normedFileNode: z.ZodObject<{
|
|
4
5
|
path: z.ZodBranded<z.ZodString, "relpath">;
|
|
5
6
|
name: z.ZodString;
|
|
@@ -64,6 +65,13 @@ declare const normedDirNode: z.ZodObject<{
|
|
|
64
65
|
dirs: number[];
|
|
65
66
|
id: number;
|
|
66
67
|
}>;
|
|
68
|
+
type NormedFileTree = {
|
|
69
|
+
id: Id;
|
|
70
|
+
files: Id[];
|
|
71
|
+
dirs: NormedFileTree[];
|
|
72
|
+
};
|
|
73
|
+
declare const normedFileTree: z.ZodType<NormedFileTree>;
|
|
74
|
+
type Id = z.infer<typeof id>;
|
|
67
75
|
type NormedFileNode = z.infer<typeof normedFileNode>;
|
|
68
76
|
type NormedDirNode = z.infer<typeof normedDirNode>;
|
|
69
77
|
|
|
@@ -78,4 +86,4 @@ type Config = {
|
|
|
78
86
|
|
|
79
87
|
declare function runO2B(config: Config): void;
|
|
80
88
|
|
|
81
|
-
export { type NormedDirNode, type NormedFileNode, runO2B as default, normedDirNode, normedFileNode };
|
|
89
|
+
export { type NormedDirNode as DirNode, type NormedFileNode as FileNode, type NormedFileTree as FileTree, runO2B as default, normedDirNode as dirNodeSchema, normedFileNode as fileNodeScheam, normedFileTree as fileTreeSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
|
|
3
|
+
declare const id: z.ZodNumber;
|
|
3
4
|
declare const normedFileNode: z.ZodObject<{
|
|
4
5
|
path: z.ZodBranded<z.ZodString, "relpath">;
|
|
5
6
|
name: z.ZodString;
|
|
@@ -64,6 +65,13 @@ declare const normedDirNode: z.ZodObject<{
|
|
|
64
65
|
dirs: number[];
|
|
65
66
|
id: number;
|
|
66
67
|
}>;
|
|
68
|
+
type NormedFileTree = {
|
|
69
|
+
id: Id;
|
|
70
|
+
files: Id[];
|
|
71
|
+
dirs: NormedFileTree[];
|
|
72
|
+
};
|
|
73
|
+
declare const normedFileTree: z.ZodType<NormedFileTree>;
|
|
74
|
+
type Id = z.infer<typeof id>;
|
|
67
75
|
type NormedFileNode = z.infer<typeof normedFileNode>;
|
|
68
76
|
type NormedDirNode = z.infer<typeof normedDirNode>;
|
|
69
77
|
|
|
@@ -78,4 +86,4 @@ type Config = {
|
|
|
78
86
|
|
|
79
87
|
declare function runO2B(config: Config): void;
|
|
80
88
|
|
|
81
|
-
export { type NormedDirNode, type NormedFileNode, runO2B as default, normedDirNode, normedFileNode };
|
|
89
|
+
export { type NormedDirNode as DirNode, type NormedFileNode as FileNode, type NormedFileTree as FileTree, runO2B as default, normedDirNode as dirNodeSchema, normedFileNode as fileNodeScheam, normedFileTree as fileTreeSchema };
|
package/dist/index.js
CHANGED
|
@@ -31,8 +31,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
default: () => runO2B,
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
dirNodeSchema: () => normedDirNode,
|
|
35
|
+
fileNodeScheam: () => normedFileNode,
|
|
36
|
+
fileTreeSchema: () => normedFileTree
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(index_exports);
|
|
38
39
|
|
|
@@ -74,6 +75,11 @@ var normedDirNode = baseNode.extend({
|
|
|
74
75
|
files: import_zod2.default.array(id),
|
|
75
76
|
dirs: import_zod2.default.array(id)
|
|
76
77
|
});
|
|
78
|
+
var normedFileTree = import_zod2.default.object({
|
|
79
|
+
id,
|
|
80
|
+
files: import_zod2.default.array(id),
|
|
81
|
+
dirs: import_zod2.default.lazy(() => import_zod2.default.array(normedFileTree))
|
|
82
|
+
});
|
|
77
83
|
|
|
78
84
|
// src/core/sync/mirror.ts
|
|
79
85
|
var import_node_fs = require("fs");
|
|
@@ -187,14 +193,18 @@ function normalize(fileTree2) {
|
|
|
187
193
|
return id3;
|
|
188
194
|
});
|
|
189
195
|
const dirs = dir.dirs.map((dir2) => aux(dir2));
|
|
190
|
-
dirNodes.push({ ...dir, id: id2, files, dirs });
|
|
191
|
-
return
|
|
196
|
+
dirNodes.push({ ...dir, id: id2, files, dirs: dirs.map((dir2) => dir2.id) });
|
|
197
|
+
return {
|
|
198
|
+
id: id2,
|
|
199
|
+
files,
|
|
200
|
+
dirs
|
|
201
|
+
};
|
|
192
202
|
}
|
|
193
|
-
aux(fileTree2);
|
|
203
|
+
const normedFileTree2 = aux(fileTree2);
|
|
194
204
|
return {
|
|
195
205
|
dirNodes,
|
|
196
206
|
fileNodes,
|
|
197
|
-
|
|
207
|
+
fileTree: normedFileTree2
|
|
198
208
|
};
|
|
199
209
|
}
|
|
200
210
|
|
|
@@ -242,14 +252,15 @@ function runO2B(config) {
|
|
|
242
252
|
if (fileTree2 === null) throw new Error("No content in vault");
|
|
243
253
|
if (fileTree2.type !== "dir") throw new Error("No Vault?!");
|
|
244
254
|
mirror(fileTree2, srcPath, destPath);
|
|
245
|
-
const {
|
|
246
|
-
generateJson(
|
|
255
|
+
const { fileTree: normedFileTree2, dirNodes, fileNodes } = normalize(fileTree2);
|
|
256
|
+
generateJson(normedFileTree2, "fileTree", destPath);
|
|
247
257
|
generateJson(dirNodes, "dirNodes", destPath);
|
|
248
258
|
generateJson(fileNodes, "fileNodes", destPath);
|
|
249
259
|
}
|
|
250
260
|
// Annotate the CommonJS export names for ESM import in node:
|
|
251
261
|
0 && (module.exports = {
|
|
252
|
-
|
|
253
|
-
|
|
262
|
+
dirNodeSchema,
|
|
263
|
+
fileNodeScheam,
|
|
264
|
+
fileTreeSchema
|
|
254
265
|
});
|
|
255
266
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types/filetree.ts","../src/types/path.ts","../src/core/sync/mirror.ts","../src/core/sync/scan.ts","../src/utils/path.ts","../src/utils/id.ts","../src/core/sync/normalize.ts","../src/utils/file.ts","../src/utils/ignore.ts","../src/runO2B.ts"],"sourcesContent":["export {\n NormedDirNode,\n NormedFileNode,\n normedDirNode,\n normedFileNode,\n} from \"@o2bTypes/filetree\";\nexport { default } from \"./runO2B\";\n","import z from \"zod\";\nimport { relPath, type RelPath } from \"@o2bTypes/path\";\n\n/* ********** Schemas ********** */\n\nconst frontmatter = z.object({\n title: z.string(),\n description: z.string(),\n last_modified: z.string(),\n});\n\nconst baseNode = z.object({\n path: relPath,\n name: z.string(),\n});\n\nconst fileNode = baseNode.extend({\n type: z.literal(\"file\"),\n frontmatter: frontmatter,\n});\n\nconst dirNode: z.ZodType<DirNodeOutput, z.ZodTypeDef, DirNodeInput> =\n baseNode.extend({\n type: z.literal(\"dir\"),\n files: z.array(fileNode),\n dirs: z.lazy(() => dirNode.array()),\n });\n\nconst fileTree = z.union([dirNode, fileNode]);\n\n/* ********** Types ********** */\n\ntype BaseNodeOutput = z.infer<typeof baseNode>;\ntype BaseNodeInput = z.input<typeof baseNode>;\n\ntype FileNodeOutput = z.infer<typeof fileNode>;\ntype FileNodeInput = z.input<typeof fileNode>;\n\n// https://v3.zod.dev/?id=recursive-types\ntype DirNodeOutput = BaseNodeOutput & {\n type: \"dir\";\n files: FileNodeOutput[];\n dirs: DirNodeOutput[];\n};\ntype DirNodeInput = BaseNodeInput & {\n type: \"dir\";\n files: FileNodeInput[];\n dirs: DirNodeInput[];\n};\n\nexport type FileTree = z.infer<typeof fileTree>;\nexport type DirNode = DirNodeOutput;\nexport type FileNode = FileNodeOutput;\nexport type Frontmatter = z.infer<typeof frontmatter>;\n\n/* ********** Normalized ********** */\n\nconst id = z.number().int();\n\nexport const normedFileNode = fileNode.extend({\n id,\n});\n\nexport const normedDirNode = baseNode.extend({\n id,\n type: z.literal(\"dir\"),\n files: z.array(id),\n dirs: z.array(id),\n});\n\nexport type Id = z.infer<typeof id>;\nexport type NormedFileNode = z.infer<typeof normedFileNode>;\nexport type NormedDirNode = z.infer<typeof normedDirNode>;\n","import z from \"zod\";\n\ntype AbsPath = z.infer<typeof absPath>;\nconst absPath = z.string().brand<\"absPath\">();\n\ntype RelPath = z.infer<typeof relPath>;\nconst relPath = z.string().brand<\"relpath\">();\n\nexport { type AbsPath, type RelPath, absPath, relPath };\n","import { copyFileSync, existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport type { FileTree } from \"@o2bTypes/filetree\";\n\nexport function mirror(\n filetree: FileTree,\n srcPath: AbsPath,\n destPath: AbsPath,\n) {\n function aux(filetree: FileTree) {\n const from = join(srcPath, filetree.path);\n const to = join(destPath, filetree.path);\n\n if (filetree.type === \"dir\") {\n if (!existsSync(to)) mkdirSync(to, { recursive: true });\n\n filetree.files.forEach((file) => {\n aux(file);\n });\n\n filetree.dirs.forEach((dir) => {\n aux(dir);\n });\n }\n\n if (filetree.type === \"file\") {\n copyFileSync(from, to);\n }\n }\n\n aux(filetree);\n}\n","import { lstatSync, readdirSync, readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport matter from \"gray-matter\";\nimport type {\n DirNode,\n FileNode,\n FileTree,\n Frontmatter,\n} from \"@o2bTypes/filetree\";\nimport { toAbsPath, toRelPath } from \"@utils/path\";\nimport { AbsPath } from \"@o2bTypes/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport function scan(rootPath: AbsPath, ign: VaultIgnorer): FileTree | null {\n function aux(path: AbsPath): FileTree | null {\n if (ign?.ignore(path)) return null;\n\n const stat = lstatSync(path);\n const name = basename(path);\n\n if (stat.isFile() && name.endsWith(\".md\")) {\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"file\",\n frontmatter: fetchFrontmatter(path, stat.mtime),\n };\n }\n\n if (stat.isDirectory()) {\n const dirs: DirNode[] = [];\n const files: FileNode[] = [];\n const entries = readdirSync(path);\n\n for (const entry of entries) {\n const fullPath = toAbsPath(join(path, entry));\n const node = aux(fullPath);\n\n if (node?.type === \"dir\") dirs.push(node);\n if (node?.type === \"file\") files.push(node);\n }\n\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"dir\",\n dirs,\n files,\n };\n }\n\n return null;\n }\n\n return aux(rootPath);\n}\n\nfunction fetchFrontmatter(path: AbsPath, mtime: Date): Frontmatter {\n const { data } = matter(readFileSync(path, \"utf-8\"));\n return {\n title: basename(path).replace(/\\.md$/, \"\"),\n description: \"No description provided.\",\n last_modified: mtime.toISOString().split(\"T\")[0],\n ...data,\n };\n}\n","import { lstatSync, readdirSync } from \"node:fs\";\nimport { isAbsolute, relative, resolve } from \"node:path\";\nimport { absPath, relPath, type AbsPath, type RelPath } from \"@o2bTypes/path\";\n\nfunction toAbsPath(path: string): AbsPath {\n if (!isAbsolute(path)) path = resolve(path);\n return absPath.parse(path);\n}\n\nfunction toRelPath(from: AbsPath, to: AbsPath): RelPath {\n return relPath.parse(relative(from, to));\n}\n\nfunction isObsidianDirectory(path: AbsPath) {\n const stat = lstatSync(path);\n\n if (!stat.isDirectory()) return false;\n\n const obsMetaDir = readdirSync(path, { withFileTypes: true })\n .filter((node) => node.isDirectory())\n .filter((node) => node.name === \".obsidian\");\n\n if (obsMetaDir.length !== 1) return false;\n\n return true;\n}\n\nexport { toAbsPath, toRelPath, isObsidianDirectory };\n","import { Id } from \"@o2bTypes/filetree\";\n\nexport const idCounter: (start?: number) => () => Id = (start: number = 0) => {\n let count = start;\n return () => count++;\n};\n","import { DirNode, Id, NormedDirNode, NormedFileNode } from \"@o2bTypes/filetree\";\nimport { idCounter } from \"@utils/id\";\n\nexport function normalize(fileTree: DirNode): {\n vault: NormedDirNode;\n dirNodes: NormedDirNode[];\n fileNodes: NormedFileNode[];\n} {\n const dirNodes: NormedDirNode[] = [];\n const fileNodes: NormedFileNode[] = [];\n\n const fileId = idCounter();\n const dirId = idCounter();\n\n function aux(dir: DirNode): Id {\n const id = dirId();\n\n const files = dir.files.map((file) => {\n const id = fileId();\n fileNodes.push({ id, ...file });\n return id;\n });\n\n const dirs = dir.dirs.map((dir) => aux(dir));\n dirNodes.push({ ...dir, id, files, dirs });\n\n return id;\n }\n aux(fileTree);\n\n return {\n dirNodes,\n fileNodes,\n vault: dirNodes[dirNodes.length - 1],\n };\n}\n","import { writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { AbsPath } from \"@o2bTypes/path\";\n\nexport function generateJson(\n content: unknown,\n name: string,\n destPath: AbsPath,\n) {\n const jsonFilePath = join(destPath, `${name}.json`);\n writeFileSync(jsonFilePath, JSON.stringify(content, null, 2), \"utf-8\");\n}\n","import { existsSync, lstatSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport ignore, { type Ignore } from \"ignore\";\n\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport { toRelPath } from \"@utils/path\";\n\nexport class VaultIgnorer {\n private ign: Ignore;\n private rootPath: AbsPath;\n\n constructor(rootPath: AbsPath) {\n this.rootPath = rootPath;\n this.ign = ignore();\n\n this.ign.add([\".*\"]);\n }\n\n public load() {\n const ignorePath = join(this.rootPath, \".o2bignore\");\n if (existsSync(ignorePath))\n this.ign.add(readFileSync(ignorePath).toString());\n }\n\n public ignore(path: AbsPath): boolean {\n if (path === this.rootPath) return false;\n\n if (!existsSync(path)) throw new Error(\"somethings wrong!\");\n\n const stat = lstatSync(path);\n\n const relPath =\n toRelPath(this.rootPath, path) + (stat.isDirectory() ? \"/\" : \"\");\n\n return this.ign.ignores(relPath);\n }\n}\n","import { mirror, scan, normalize } from \"@core/sync\";\nimport type { Config } from \"@o2bTypes/config\";\nimport { generateJson } from \"@utils/file\";\nimport { isObsidianDirectory } from \"@utils/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport default function runO2B(config: Config) {\n const { srcPath, destPath, ignore } = config;\n\n if (!isObsidianDirectory(srcPath)) throw new Error(\"Not a obsidian vault\");\n\n const ign = new VaultIgnorer(srcPath);\n if (ignore) ign.load();\n\n const fileTree = scan(srcPath, ign);\n if (fileTree === null) throw new Error(\"No content in vault\");\n if (fileTree.type !== \"dir\") throw new Error(\"No Vault?!\");\n\n mirror(fileTree, srcPath, destPath);\n const { vault, dirNodes, fileNodes } = normalize(fileTree);\n\n generateJson(vault, \"vault\", destPath);\n generateJson(dirNodes, \"dirNodes\", destPath);\n generateJson(fileNodes, \"fileNodes\", destPath);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,cAAc;;;ACAd,iBAAc;AAGd,IAAM,UAAU,WAAAC,QAAE,OAAO,EAAE,MAAiB;AAG5C,IAAM,UAAU,WAAAA,QAAE,OAAO,EAAE,MAAiB;;;ADD5C,IAAM,cAAc,YAAAC,QAAE,OAAO;AAAA,EAC3B,OAAO,YAAAA,QAAE,OAAO;AAAA,EAChB,aAAa,YAAAA,QAAE,OA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KAAI,KAAK;AAErB,QAAMC,YAAW,KAAK,SAAS,GAAG;AAClC,MAAIA,cAAa,KAAM,OAAM,IAAI,MAAM,qBAAqB;AAC5D,MAAIA,UAAS,SAAS,MAAO,OAAM,IAAI,MAAM,YAAY;AAEzD,SAAOA,WAAU,SAAS,QAAQ;AAClC,QAAM,EAAE,OAAO,UAAU,UAAU,IAAI,UAAUA,SAAQ;AAEzD,eAAa,OAAO,SAAS,QAAQ;AACrC,eAAa,UAAU,YAAY,QAAQ;AAC3C,eAAa,WAAW,aAAa,QAAQ;AAC/C;","names":["import_zod","z","z","filetree","import_node_fs","import_node_path","import_node_fs","import_node_path","matter","fileTree","id","dir","import_node_fs","import_node_path","import_node_fs","import_node_path","ignore","relPath","ignore","fileTree"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types/filetree.ts","../src/types/path.ts","../src/core/sync/mirror.ts","../src/core/sync/scan.ts","../src/utils/path.ts","../src/utils/id.ts","../src/core/sync/normalize.ts","../src/utils/file.ts","../src/utils/ignore.ts","../src/runO2B.ts"],"sourcesContent":["export {\n NormedDirNode as DirNode,\n NormedFileNode as FileNode,\n NormedFileTree as FileTree,\n normedDirNode as dirNodeSchema,\n normedFileNode as fileNodeScheam,\n normedFileTree as fileTreeSchema,\n} from \"@o2bTypes/filetree\";\nexport { default } from \"./runO2B\";\n","import z from \"zod\";\nimport { relPath, type RelPath } from \"@o2bTypes/path\";\n\n/* ********** Schemas ********** */\n\nconst frontmatter = z.object({\n title: z.string(),\n description: z.string(),\n last_modified: z.string(),\n});\n\nconst baseNode = z.object({\n path: relPath,\n name: z.string(),\n});\n\nconst fileNode = baseNode.extend({\n type: z.literal(\"file\"),\n frontmatter: frontmatter,\n});\n\nconst dirNode: z.ZodType<DirNodeOutput, z.ZodTypeDef, DirNodeInput> =\n baseNode.extend({\n type: z.literal(\"dir\"),\n files: z.array(fileNode),\n dirs: z.lazy(() => dirNode.array()),\n });\n\nconst fileTree = z.union([dirNode, fileNode]);\n\n/* ********** Types ********** */\n\ntype BaseNodeOutput = z.infer<typeof baseNode>;\ntype BaseNodeInput = z.input<typeof baseNode>;\n\ntype FileNodeOutput = z.infer<typeof fileNode>;\ntype FileNodeInput = z.input<typeof fileNode>;\n\n// https://v3.zod.dev/?id=recursive-types\ntype DirNodeOutput = BaseNodeOutput & {\n type: \"dir\";\n files: FileNodeOutput[];\n dirs: DirNodeOutput[];\n};\ntype DirNodeInput = BaseNodeInput & {\n type: \"dir\";\n files: FileNodeInput[];\n dirs: DirNodeInput[];\n};\n\nexport type FileTree = z.infer<typeof fileTree>;\nexport type DirNode = DirNodeOutput;\nexport type FileNode = FileNodeOutput;\nexport type Frontmatter = z.infer<typeof frontmatter>;\n\n/* ********** Normalized ********** */\n\nconst id = z.number().int();\n\nexport const normedFileNode = fileNode.extend({\n id,\n});\n\nexport const normedDirNode = baseNode.extend({\n id,\n type: z.literal(\"dir\"),\n files: z.array(id),\n dirs: z.array(id),\n});\n\nexport type NormedFileTree = {\n id: Id;\n files: Id[];\n dirs: NormedFileTree[];\n};\nexport const normedFileTree: z.ZodType<NormedFileTree> = z.object({\n id,\n files: z.array(id),\n dirs: z.lazy(() => z.array(normedFileTree)),\n});\n\ntype Id = z.infer<typeof id>;\nexport type NormedFileNode = z.infer<typeof normedFileNode>;\nexport type NormedDirNode = z.infer<typeof normedDirNode>;\n","import z from \"zod\";\n\ntype AbsPath = z.infer<typeof absPath>;\nconst absPath = z.string().brand<\"absPath\">();\n\ntype RelPath = z.infer<typeof relPath>;\nconst relPath = z.string().brand<\"relpath\">();\n\nexport { type AbsPath, type RelPath, absPath, relPath };\n","import { copyFileSync, existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport type { FileTree } from \"@o2bTypes/filetree\";\n\nexport function mirror(\n filetree: FileTree,\n srcPath: AbsPath,\n destPath: AbsPath,\n) {\n function aux(filetree: FileTree) {\n const from = join(srcPath, filetree.path);\n const to = join(destPath, filetree.path);\n\n if (filetree.type === \"dir\") {\n if (!existsSync(to)) mkdirSync(to, { recursive: true });\n\n filetree.files.forEach((file) => {\n aux(file);\n });\n\n filetree.dirs.forEach((dir) => {\n aux(dir);\n });\n }\n\n if (filetree.type === \"file\") {\n copyFileSync(from, to);\n }\n }\n\n aux(filetree);\n}\n","import { lstatSync, readdirSync, readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport matter from \"gray-matter\";\nimport type {\n DirNode,\n FileNode,\n FileTree,\n Frontmatter,\n} from \"@o2bTypes/filetree\";\nimport { toAbsPath, toRelPath } from \"@utils/path\";\nimport { AbsPath } from \"@o2bTypes/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport function scan(rootPath: AbsPath, ign: VaultIgnorer): FileTree | null {\n function aux(path: AbsPath): FileTree | null {\n if (ign?.ignore(path)) return null;\n\n const stat = lstatSync(path);\n const name = basename(path);\n\n if (stat.isFile() && name.endsWith(\".md\")) {\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"file\",\n frontmatter: fetchFrontmatter(path, stat.mtime),\n };\n }\n\n if (stat.isDirectory()) {\n const dirs: DirNode[] = [];\n const files: FileNode[] = [];\n const entries = readdirSync(path);\n\n for (const entry of entries) {\n const fullPath = toAbsPath(join(path, entry));\n const node = aux(fullPath);\n\n if (node?.type === \"dir\") dirs.push(node);\n if (node?.type === \"file\") files.push(node);\n }\n\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"dir\",\n dirs,\n files,\n };\n }\n\n return null;\n }\n\n return aux(rootPath);\n}\n\nfunction fetchFrontmatter(path: AbsPath, mtime: Date): Frontmatter {\n const { data } = matter(readFileSync(path, \"utf-8\"));\n return {\n title: basename(path).replace(/\\.md$/, \"\"),\n description: \"No description provided.\",\n last_modified: mtime.toISOString().split(\"T\")[0],\n ...data,\n };\n}\n","import { lstatSync, readdirSync } from \"node:fs\";\nimport { isAbsolute, relative, resolve } from \"node:path\";\nimport { absPath, relPath, type AbsPath, type RelPath } from \"@o2bTypes/path\";\n\nfunction toAbsPath(path: string): AbsPath {\n if (!isAbsolute(path)) path = resolve(path);\n return absPath.parse(path);\n}\n\nfunction toRelPath(from: AbsPath, to: AbsPath): RelPath {\n return relPath.parse(relative(from, to));\n}\n\nfunction isObsidianDirectory(path: AbsPath) {\n const stat = lstatSync(path);\n\n if (!stat.isDirectory()) return false;\n\n const obsMetaDir = readdirSync(path, { withFileTypes: true })\n .filter((node) => node.isDirectory())\n .filter((node) => node.name === \".obsidian\");\n\n if (obsMetaDir.length !== 1) return false;\n\n return true;\n}\n\nexport { toAbsPath, toRelPath, isObsidianDirectory };\n","import { Id } from \"@o2bTypes/filetree\";\n\nexport const idCounter: (start?: number) => () => Id = (start: number = 0) => {\n let count = start;\n return () => count++;\n};\n","import {\n DirNode,\n NormedDirNode,\n NormedFileNode,\n NormedFileTree,\n} from \"@o2bTypes/filetree\";\nimport { idCounter } from \"@utils/id\";\n\nexport function normalize(fileTree: DirNode): {\n fileTree: NormedFileTree;\n dirNodes: NormedDirNode[];\n fileNodes: NormedFileNode[];\n} {\n const dirNodes: NormedDirNode[] = [];\n const fileNodes: NormedFileNode[] = [];\n\n const fileId = idCounter();\n const dirId = idCounter();\n\n function aux(dir: DirNode): NormedFileTree {\n const id = dirId();\n\n const files = dir.files.map((file) => {\n const id = fileId();\n fileNodes.push({ id, ...file });\n return id;\n });\n\n const dirs = dir.dirs.map((dir) => aux(dir));\n dirNodes.push({ ...dir, id, files, dirs: dirs.map((dir) => dir.id) });\n\n return {\n id,\n files,\n dirs,\n };\n }\n const normedFileTree = aux(fileTree);\n\n return {\n dirNodes,\n fileNodes,\n fileTree: normedFileTree,\n };\n}\n","import { writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { AbsPath } from \"@o2bTypes/path\";\n\nexport function generateJson(\n content: unknown,\n name: string,\n destPath: AbsPath,\n) {\n const jsonFilePath = join(destPath, `${name}.json`);\n writeFileSync(jsonFilePath, JSON.stringify(content, null, 2), \"utf-8\");\n}\n","import { existsSync, lstatSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport ignore, { type Ignore } from \"ignore\";\n\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport { toRelPath } from \"@utils/path\";\n\nexport class VaultIgnorer {\n private ign: Ignore;\n private rootPath: AbsPath;\n\n constructor(rootPath: AbsPath) {\n this.rootPath = rootPath;\n this.ign = ignore();\n\n this.ign.add([\".*\"]);\n }\n\n public load() {\n const ignorePath = join(this.rootPath, \".o2bignore\");\n if (existsSync(ignorePath))\n this.ign.add(readFileSync(ignorePath).toString());\n }\n\n public ignore(path: AbsPath): boolean {\n if (path === this.rootPath) return false;\n\n if (!existsSync(path)) throw new Error(\"somethings wrong!\");\n\n const stat = lstatSync(path);\n\n const relPath =\n toRelPath(this.rootPath, path) + (stat.isDirectory() ? \"/\" : \"\");\n\n return this.ign.ignores(relPath);\n }\n}\n","import { mirror, scan, normalize } from \"@core/sync\";\nimport type { Config } from \"@o2bTypes/config\";\nimport { generateJson } from \"@utils/file\";\nimport { isObsidianDirectory } from \"@utils/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport default function runO2B(config: Config) {\n const { srcPath, destPath, ignore } = config;\n\n if (!isObsidianDirectory(srcPath)) throw new Error(\"Not a obsidian vault\");\n\n const ign = new VaultIgnorer(srcPath);\n if (ignore) ign.load();\n\n const fileTree = scan(srcPath, ign);\n if (fileTree === null) throw new Error(\"No content in vault\");\n if (fileTree.type !== \"dir\") throw new Error(\"No Vault?!\");\n\n mirror(fileTree, srcPath, destPath);\n const { fileTree: normedFileTree, dirNodes, fileNodes } = normalize(fileTree);\n\n generateJson(normedFileTree, \"fileTree\", destPath);\n generateJson(dirNodes, \"dirNodes\", destPath);\n generateJson(fileNodes, \"fileNodes\", destPath);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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EAAE,SAAS,CAAC;AAAA,EACpD;AAAA,EAEO,OAAO,MAAwB;AACpC,QAAI,SAAS,KAAK,SAAU,QAAO;AAEnC,QAAI,KAAC,4BAAW,IAAI,EAAG,OAAM,IAAI,MAAM,mBAAmB;AAE1D,UAAM,WAAO,2BAAU,IAAI;AAE3B,UAAMC,WACJ,UAAU,KAAK,UAAU,IAAI,KAAK,KAAK,YAAY,IAAI,MAAM;AAE/D,WAAO,KAAK,IAAI,QAAQA,QAAO;AAAA,EACjC;AACF;;;AC9Be,SAAR,OAAwB,QAAgB;AAC7C,QAAM,EAAE,SAAS,UAAU,QAAAC,QAAO,IAAI;AAEtC,MAAI,CAAC,oBAAoB,OAAO,EAAG,OAAM,IAAI,MAAM,sBAAsB;AAEzE,QAAM,MAAM,IAAI,aAAa,OAAO;AACpC,MAAIA,QAAQ,KAAI,KAAK;AAErB,QAAMC,YAAW,KAAK,SAAS,GAAG;AAClC,MAAIA,cAAa,KAAM,OAAM,IAAI,MAAM,qBAAqB;AAC5D,MAAIA,UAAS,SAAS,MAAO,OAAM,IAAI,MAAM,YAAY;AAEzD,SAAOA,WAAU,SAAS,QAAQ;AAClC,QAAM,EAAE,UAAUC,iBAAgB,UAAU,UAAU,IAAI,UAAUD,SAAQ;AAE5E,eAAaC,iBAAgB,YAAY,QAAQ;AACjD,eAAa,UAAU,YAAY,QAAQ;AAC3C,eAAa,WAAW,aAAa,QAAQ;AAC/C;","names":["import_zod","z","z","filetree","import_node_fs","import_node_path","import_node_fs","import_node_path","matter","fileTree","id","dir","normedFileTree","import_node_fs","import_node_path","import_node_fs","import_node_path","ignore","relPath","ignore","fileTree","normedFileTree"]}
|
package/dist/index.mjs
CHANGED
|
@@ -36,6 +36,11 @@ var normedDirNode = baseNode.extend({
|
|
|
36
36
|
files: z2.array(id),
|
|
37
37
|
dirs: z2.array(id)
|
|
38
38
|
});
|
|
39
|
+
var normedFileTree = z2.object({
|
|
40
|
+
id,
|
|
41
|
+
files: z2.array(id),
|
|
42
|
+
dirs: z2.lazy(() => z2.array(normedFileTree))
|
|
43
|
+
});
|
|
39
44
|
|
|
40
45
|
// src/core/sync/mirror.ts
|
|
41
46
|
import { copyFileSync, existsSync, mkdirSync } from "fs";
|
|
@@ -149,14 +154,18 @@ function normalize(fileTree2) {
|
|
|
149
154
|
return id3;
|
|
150
155
|
});
|
|
151
156
|
const dirs = dir.dirs.map((dir2) => aux(dir2));
|
|
152
|
-
dirNodes.push({ ...dir, id: id2, files, dirs });
|
|
153
|
-
return
|
|
157
|
+
dirNodes.push({ ...dir, id: id2, files, dirs: dirs.map((dir2) => dir2.id) });
|
|
158
|
+
return {
|
|
159
|
+
id: id2,
|
|
160
|
+
files,
|
|
161
|
+
dirs
|
|
162
|
+
};
|
|
154
163
|
}
|
|
155
|
-
aux(fileTree2);
|
|
164
|
+
const normedFileTree2 = aux(fileTree2);
|
|
156
165
|
return {
|
|
157
166
|
dirNodes,
|
|
158
167
|
fileNodes,
|
|
159
|
-
|
|
168
|
+
fileTree: normedFileTree2
|
|
160
169
|
};
|
|
161
170
|
}
|
|
162
171
|
|
|
@@ -204,14 +213,15 @@ function runO2B(config) {
|
|
|
204
213
|
if (fileTree2 === null) throw new Error("No content in vault");
|
|
205
214
|
if (fileTree2.type !== "dir") throw new Error("No Vault?!");
|
|
206
215
|
mirror(fileTree2, srcPath, destPath);
|
|
207
|
-
const {
|
|
208
|
-
generateJson(
|
|
216
|
+
const { fileTree: normedFileTree2, dirNodes, fileNodes } = normalize(fileTree2);
|
|
217
|
+
generateJson(normedFileTree2, "fileTree", destPath);
|
|
209
218
|
generateJson(dirNodes, "dirNodes", destPath);
|
|
210
219
|
generateJson(fileNodes, "fileNodes", destPath);
|
|
211
220
|
}
|
|
212
221
|
export {
|
|
213
222
|
runO2B as default,
|
|
214
|
-
normedDirNode,
|
|
215
|
-
normedFileNode
|
|
223
|
+
normedDirNode as dirNodeSchema,
|
|
224
|
+
normedFileNode as fileNodeScheam,
|
|
225
|
+
normedFileTree as fileTreeSchema
|
|
216
226
|
};
|
|
217
227
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/filetree.ts","../src/types/path.ts","../src/core/sync/mirror.ts","../src/core/sync/scan.ts","../src/utils/path.ts","../src/utils/id.ts","../src/core/sync/normalize.ts","../src/utils/file.ts","../src/utils/ignore.ts","../src/runO2B.ts"],"sourcesContent":["import z from \"zod\";\nimport { relPath, type RelPath } from \"@o2bTypes/path\";\n\n/* ********** Schemas ********** */\n\nconst frontmatter = z.object({\n title: z.string(),\n description: z.string(),\n last_modified: z.string(),\n});\n\nconst baseNode = z.object({\n path: relPath,\n name: z.string(),\n});\n\nconst fileNode = baseNode.extend({\n type: z.literal(\"file\"),\n frontmatter: frontmatter,\n});\n\nconst dirNode: z.ZodType<DirNodeOutput, z.ZodTypeDef, DirNodeInput> =\n baseNode.extend({\n type: z.literal(\"dir\"),\n files: z.array(fileNode),\n dirs: z.lazy(() => dirNode.array()),\n });\n\nconst fileTree = z.union([dirNode, fileNode]);\n\n/* ********** Types ********** */\n\ntype BaseNodeOutput = z.infer<typeof baseNode>;\ntype BaseNodeInput = z.input<typeof baseNode>;\n\ntype FileNodeOutput = z.infer<typeof fileNode>;\ntype FileNodeInput = z.input<typeof fileNode>;\n\n// https://v3.zod.dev/?id=recursive-types\ntype DirNodeOutput = BaseNodeOutput & {\n type: \"dir\";\n files: FileNodeOutput[];\n dirs: DirNodeOutput[];\n};\ntype DirNodeInput = BaseNodeInput & {\n type: \"dir\";\n files: FileNodeInput[];\n dirs: DirNodeInput[];\n};\n\nexport type FileTree = z.infer<typeof fileTree>;\nexport type DirNode = DirNodeOutput;\nexport type FileNode = FileNodeOutput;\nexport type Frontmatter = z.infer<typeof frontmatter>;\n\n/* ********** Normalized ********** */\n\nconst id = z.number().int();\n\nexport const normedFileNode = fileNode.extend({\n id,\n});\n\nexport const normedDirNode = baseNode.extend({\n id,\n type: z.literal(\"dir\"),\n files: z.array(id),\n dirs: z.array(id),\n});\n\nexport type Id = z.infer<typeof id>;\nexport type NormedFileNode = z.infer<typeof normedFileNode>;\nexport type NormedDirNode = z.infer<typeof normedDirNode>;\n","import z from \"zod\";\n\ntype AbsPath = z.infer<typeof absPath>;\nconst absPath = z.string().brand<\"absPath\">();\n\ntype RelPath = z.infer<typeof relPath>;\nconst relPath = z.string().brand<\"relpath\">();\n\nexport { type AbsPath, type RelPath, absPath, relPath };\n","import { copyFileSync, existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport type { FileTree } from \"@o2bTypes/filetree\";\n\nexport function mirror(\n filetree: FileTree,\n srcPath: AbsPath,\n destPath: AbsPath,\n) {\n function aux(filetree: FileTree) {\n const from = join(srcPath, filetree.path);\n const to = join(destPath, filetree.path);\n\n if (filetree.type === \"dir\") {\n if (!existsSync(to)) mkdirSync(to, { recursive: true });\n\n filetree.files.forEach((file) => {\n aux(file);\n });\n\n filetree.dirs.forEach((dir) => {\n aux(dir);\n });\n }\n\n if (filetree.type === \"file\") {\n copyFileSync(from, to);\n }\n }\n\n aux(filetree);\n}\n","import { lstatSync, readdirSync, readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport matter from \"gray-matter\";\nimport type {\n DirNode,\n FileNode,\n FileTree,\n Frontmatter,\n} from \"@o2bTypes/filetree\";\nimport { toAbsPath, toRelPath } from \"@utils/path\";\nimport { AbsPath } from \"@o2bTypes/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport function scan(rootPath: AbsPath, ign: VaultIgnorer): FileTree | null {\n function aux(path: AbsPath): FileTree | null {\n if (ign?.ignore(path)) return null;\n\n const stat = lstatSync(path);\n const name = basename(path);\n\n if (stat.isFile() && name.endsWith(\".md\")) {\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"file\",\n frontmatter: fetchFrontmatter(path, stat.mtime),\n };\n }\n\n if (stat.isDirectory()) {\n const dirs: DirNode[] = [];\n const files: FileNode[] = [];\n const entries = readdirSync(path);\n\n for (const entry of entries) {\n const fullPath = toAbsPath(join(path, entry));\n const node = aux(fullPath);\n\n if (node?.type === \"dir\") dirs.push(node);\n if (node?.type === \"file\") files.push(node);\n }\n\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"dir\",\n dirs,\n files,\n };\n }\n\n return null;\n }\n\n return aux(rootPath);\n}\n\nfunction fetchFrontmatter(path: AbsPath, mtime: Date): Frontmatter {\n const { data } = matter(readFileSync(path, \"utf-8\"));\n return {\n title: basename(path).replace(/\\.md$/, \"\"),\n description: \"No description provided.\",\n last_modified: mtime.toISOString().split(\"T\")[0],\n ...data,\n };\n}\n","import { lstatSync, readdirSync } from \"node:fs\";\nimport { isAbsolute, relative, resolve } from \"node:path\";\nimport { absPath, relPath, type AbsPath, type RelPath } from \"@o2bTypes/path\";\n\nfunction toAbsPath(path: string): AbsPath {\n if (!isAbsolute(path)) path = resolve(path);\n return absPath.parse(path);\n}\n\nfunction toRelPath(from: AbsPath, to: AbsPath): RelPath {\n return relPath.parse(relative(from, to));\n}\n\nfunction isObsidianDirectory(path: AbsPath) {\n const stat = lstatSync(path);\n\n if (!stat.isDirectory()) return false;\n\n const obsMetaDir = readdirSync(path, { withFileTypes: true })\n .filter((node) => node.isDirectory())\n .filter((node) => node.name === \".obsidian\");\n\n if (obsMetaDir.length !== 1) return false;\n\n return true;\n}\n\nexport { toAbsPath, toRelPath, isObsidianDirectory };\n","import { Id } from \"@o2bTypes/filetree\";\n\nexport const idCounter: (start?: number) => () => Id = (start: number = 0) => {\n let count = start;\n return () => count++;\n};\n","import { DirNode, Id, NormedDirNode, NormedFileNode } from \"@o2bTypes/filetree\";\nimport { idCounter } from \"@utils/id\";\n\nexport function normalize(fileTree: DirNode): {\n vault: NormedDirNode;\n dirNodes: NormedDirNode[];\n fileNodes: NormedFileNode[];\n} {\n const dirNodes: NormedDirNode[] = [];\n const fileNodes: NormedFileNode[] = [];\n\n const fileId = idCounter();\n const dirId = idCounter();\n\n function aux(dir: DirNode): Id {\n const id = dirId();\n\n const files = dir.files.map((file) => {\n const id = fileId();\n fileNodes.push({ id, ...file });\n return id;\n });\n\n const dirs = dir.dirs.map((dir) => aux(dir));\n dirNodes.push({ ...dir, id, files, dirs });\n\n return id;\n }\n aux(fileTree);\n\n return {\n dirNodes,\n fileNodes,\n vault: dirNodes[dirNodes.length - 1],\n };\n}\n","import { writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { AbsPath } from \"@o2bTypes/path\";\n\nexport function generateJson(\n content: unknown,\n name: string,\n destPath: AbsPath,\n) {\n const jsonFilePath = join(destPath, `${name}.json`);\n writeFileSync(jsonFilePath, JSON.stringify(content, null, 2), \"utf-8\");\n}\n","import { existsSync, lstatSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport ignore, { type Ignore } from \"ignore\";\n\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport { toRelPath } from \"@utils/path\";\n\nexport class VaultIgnorer {\n private ign: Ignore;\n private rootPath: AbsPath;\n\n constructor(rootPath: AbsPath) {\n this.rootPath = rootPath;\n this.ign = ignore();\n\n this.ign.add([\".*\"]);\n }\n\n public load() {\n const ignorePath = join(this.rootPath, \".o2bignore\");\n if (existsSync(ignorePath))\n this.ign.add(readFileSync(ignorePath).toString());\n }\n\n public ignore(path: AbsPath): boolean {\n if (path === this.rootPath) return false;\n\n if (!existsSync(path)) throw new Error(\"somethings wrong!\");\n\n const stat = lstatSync(path);\n\n const relPath =\n toRelPath(this.rootPath, path) + (stat.isDirectory() ? \"/\" : \"\");\n\n return this.ign.ignores(relPath);\n }\n}\n","import { mirror, scan, normalize } from \"@core/sync\";\nimport type { Config } from \"@o2bTypes/config\";\nimport { generateJson } from \"@utils/file\";\nimport { isObsidianDirectory } from \"@utils/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport default function runO2B(config: Config) {\n const { srcPath, destPath, ignore } = config;\n\n if (!isObsidianDirectory(srcPath)) throw new Error(\"Not a obsidian vault\");\n\n const ign = new VaultIgnorer(srcPath);\n if (ignore) ign.load();\n\n const fileTree = scan(srcPath, ign);\n if (fileTree === null) throw new Error(\"No content in vault\");\n if (fileTree.type !== \"dir\") throw new Error(\"No Vault?!\");\n\n mirror(fileTree, srcPath, destPath);\n const { vault, dirNodes, fileNodes } = normalize(fileTree);\n\n generateJson(vault, \"vault\", destPath);\n generateJson(dirNodes, \"dirNodes\", destPath);\n generateJson(fileNodes, \"fileNodes\", destPath);\n}\n"],"mappings":";AAAA,OAAOA,QAAO;;;ACAd,OAAO,OAAO;AAGd,IAAM,UAAU,EAAE,OAAO,EAAE,MAAiB;AAG5C,IAAM,UAAU,EAAE,OAAO,EAAE,MAAiB;;;ADD5C,IAAM,cAAcC,GAAE,OAAO;AAAA,EAC3B,OAAOA,GAAE,OAAO;AAAA,EAChB,aAAaA,GAAE,OAAO;AAAA,EACtB,eAAeA,GAAE,OAAO;AAC1B,CAAC;AAED,IAAM,WAAWA,GAAE,OAAO;AAAA,EACxB,MAAM;AAAA,EACN,MAAMA,GAAE,OAAO;AACjB,CAAC;AAED,IAAM,WAAW,SAAS,OAAO;AAAA,EAC/B,MAAMA,GAAE,QAAQ,MAAM;AAAA,EACtB;AACF,CAAC;AAED,IAAM,UACJ,SAAS,OAAO;AAAA,EACd,MAAMA,GAAE,QAAQ,KAAK;AAAA,EACrB,OAAOA,GAAE,MAAM,QAAQ;AAAA,EACvB,MAAMA,GAAE,KAAK,MAAM,QAAQ,MAAM,CAAC;AACpC,CAAC;AAEH,IAAM,WAAWA,GAAE,MAAM,CAAC,SAAS,QAAQ,CAAC;AA6B5C,IAAM,KAAKA,GAAE,OAAO,EAAE,IAAI;AAEnB,IAAM,iBAAiB,SAAS,OAAO;AAAA,EAC5C;AACF,CAAC;AAEM,IAAM,gBAAgB,SAAS,OAAO;AAAA,EAC3C;AAAA,EACA,MAAMA,GAAE,QAA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AAM,aAAaC,MAAK,KAAK,UAAU,YAAY;AACnD,QAAIC,YAAW,UAAU;AACvB,WAAK,IAAI,IAAIC,cAAa,UAAU,EAAE,SAAS,CAAC;AAAA,EACpD;AAAA,EAEO,OAAO,MAAwB;AACpC,QAAI,SAAS,KAAK,SAAU,QAAO;AAEnC,QAAI,CAACD,YAAW,IAAI,EAAG,OAAM,IAAI,MAAM,mBAAmB;AAE1D,UAAM,OAAOE,WAAU,IAAI;AAE3B,UAAMC,WACJ,UAAU,KAAK,UAAU,IAAI,KAAK,KAAK,YAAY,IAAI,MAAM;AAE/D,WAAO,KAAK,IAAI,QAAQA,QAAO;AAAA,EACjC;AACF;;;AC9Be,SAAR,OAAwB,QAAgB;AAC7C,QAAM,EAAE,SAAS,UAAU,QAAAC,QAAO,IAAI;AAEtC,MAAI,CAAC,oBAAoB,OAAO,EAAG,OAAM,IAAI,MAAM,sBAAsB;AAEzE,QAAM,MAAM,IAAI,aAAa,OAAO;AACpC,MAAIA,QAAQ,KAAI,KAAK;AAErB,QAAMC,YAAW,KAAK,SAAS,GAAG;AAClC,MAAIA,cAAa,KAAM,OAAM,IAAI,MAAM,qBAAqB;AAC5D,MAAIA,UAAS,SAAS,MAAO,OAAM,IAAI,MAAM,YAAY;AAEzD,SAAOA,WAAU,SAAS,QAAQ;AAClC,QAAM,EAAE,OAAO,UAAU,UAAU,IAAI,UAAUA,SAAQ;AAEzD,eAAa,OAAO,SAAS,QAAQ;AACrC,eAAa,UAAU,YAAY,QAAQ;AAC3C,eAAa,WAAW,aAAa,QAAQ;AAC/C;","names":["z","z","filetree","lstatSync","readdirSync","join","lstatSync","readdirSync","join","fileTree","id","dir","writeFileSync","join","existsSync","lstatSync","readFileSync","join","join","existsSync","readFileSync","lstatSync","relPath","ignore","fileTree"]}
|
|
1
|
+
{"version":3,"sources":["../src/types/filetree.ts","../src/types/path.ts","../src/core/sync/mirror.ts","../src/core/sync/scan.ts","../src/utils/path.ts","../src/utils/id.ts","../src/core/sync/normalize.ts","../src/utils/file.ts","../src/utils/ignore.ts","../src/runO2B.ts"],"sourcesContent":["import z from \"zod\";\nimport { relPath, type RelPath } from \"@o2bTypes/path\";\n\n/* ********** Schemas ********** */\n\nconst frontmatter = z.object({\n title: z.string(),\n description: z.string(),\n last_modified: z.string(),\n});\n\nconst baseNode = z.object({\n path: relPath,\n name: z.string(),\n});\n\nconst fileNode = baseNode.extend({\n type: z.literal(\"file\"),\n frontmatter: frontmatter,\n});\n\nconst dirNode: z.ZodType<DirNodeOutput, z.ZodTypeDef, DirNodeInput> =\n baseNode.extend({\n type: z.literal(\"dir\"),\n files: z.array(fileNode),\n dirs: z.lazy(() => dirNode.array()),\n });\n\nconst fileTree = z.union([dirNode, fileNode]);\n\n/* ********** Types ********** */\n\ntype BaseNodeOutput = z.infer<typeof baseNode>;\ntype BaseNodeInput = z.input<typeof baseNode>;\n\ntype FileNodeOutput = z.infer<typeof fileNode>;\ntype FileNodeInput = z.input<typeof fileNode>;\n\n// https://v3.zod.dev/?id=recursive-types\ntype DirNodeOutput = BaseNodeOutput & {\n type: \"dir\";\n files: FileNodeOutput[];\n dirs: DirNodeOutput[];\n};\ntype DirNodeInput = BaseNodeInput & {\n type: \"dir\";\n files: FileNodeInput[];\n dirs: DirNodeInput[];\n};\n\nexport type FileTree = z.infer<typeof fileTree>;\nexport type DirNode = DirNodeOutput;\nexport type FileNode = FileNodeOutput;\nexport type Frontmatter = z.infer<typeof frontmatter>;\n\n/* ********** Normalized ********** */\n\nconst id = z.number().int();\n\nexport const normedFileNode = fileNode.extend({\n id,\n});\n\nexport const normedDirNode = baseNode.extend({\n id,\n type: z.literal(\"dir\"),\n files: z.array(id),\n dirs: z.array(id),\n});\n\nexport type NormedFileTree = {\n id: Id;\n files: Id[];\n dirs: NormedFileTree[];\n};\nexport const normedFileTree: z.ZodType<NormedFileTree> = z.object({\n id,\n files: z.array(id),\n dirs: z.lazy(() => z.array(normedFileTree)),\n});\n\ntype Id = z.infer<typeof id>;\nexport type NormedFileNode = z.infer<typeof normedFileNode>;\nexport type NormedDirNode = z.infer<typeof normedDirNode>;\n","import z from \"zod\";\n\ntype AbsPath = z.infer<typeof absPath>;\nconst absPath = z.string().brand<\"absPath\">();\n\ntype RelPath = z.infer<typeof relPath>;\nconst relPath = z.string().brand<\"relpath\">();\n\nexport { type AbsPath, type RelPath, absPath, relPath };\n","import { copyFileSync, existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport type { FileTree } from \"@o2bTypes/filetree\";\n\nexport function mirror(\n filetree: FileTree,\n srcPath: AbsPath,\n destPath: AbsPath,\n) {\n function aux(filetree: FileTree) {\n const from = join(srcPath, filetree.path);\n const to = join(destPath, filetree.path);\n\n if (filetree.type === \"dir\") {\n if (!existsSync(to)) mkdirSync(to, { recursive: true });\n\n filetree.files.forEach((file) => {\n aux(file);\n });\n\n filetree.dirs.forEach((dir) => {\n aux(dir);\n });\n }\n\n if (filetree.type === \"file\") {\n copyFileSync(from, to);\n }\n }\n\n aux(filetree);\n}\n","import { lstatSync, readdirSync, readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport matter from \"gray-matter\";\nimport type {\n DirNode,\n FileNode,\n FileTree,\n Frontmatter,\n} from \"@o2bTypes/filetree\";\nimport { toAbsPath, toRelPath } from \"@utils/path\";\nimport { AbsPath } from \"@o2bTypes/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport function scan(rootPath: AbsPath, ign: VaultIgnorer): FileTree | null {\n function aux(path: AbsPath): FileTree | null {\n if (ign?.ignore(path)) return null;\n\n const stat = lstatSync(path);\n const name = basename(path);\n\n if (stat.isFile() && name.endsWith(\".md\")) {\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"file\",\n frontmatter: fetchFrontmatter(path, stat.mtime),\n };\n }\n\n if (stat.isDirectory()) {\n const dirs: DirNode[] = [];\n const files: FileNode[] = [];\n const entries = readdirSync(path);\n\n for (const entry of entries) {\n const fullPath = toAbsPath(join(path, entry));\n const node = aux(fullPath);\n\n if (node?.type === \"dir\") dirs.push(node);\n if (node?.type === \"file\") files.push(node);\n }\n\n return {\n path: toRelPath(rootPath, path),\n name,\n type: \"dir\",\n dirs,\n files,\n };\n }\n\n return null;\n }\n\n return aux(rootPath);\n}\n\nfunction fetchFrontmatter(path: AbsPath, mtime: Date): Frontmatter {\n const { data } = matter(readFileSync(path, \"utf-8\"));\n return {\n title: basename(path).replace(/\\.md$/, \"\"),\n description: \"No description provided.\",\n last_modified: mtime.toISOString().split(\"T\")[0],\n ...data,\n };\n}\n","import { lstatSync, readdirSync } from \"node:fs\";\nimport { isAbsolute, relative, resolve } from \"node:path\";\nimport { absPath, relPath, type AbsPath, type RelPath } from \"@o2bTypes/path\";\n\nfunction toAbsPath(path: string): AbsPath {\n if (!isAbsolute(path)) path = resolve(path);\n return absPath.parse(path);\n}\n\nfunction toRelPath(from: AbsPath, to: AbsPath): RelPath {\n return relPath.parse(relative(from, to));\n}\n\nfunction isObsidianDirectory(path: AbsPath) {\n const stat = lstatSync(path);\n\n if (!stat.isDirectory()) return false;\n\n const obsMetaDir = readdirSync(path, { withFileTypes: true })\n .filter((node) => node.isDirectory())\n .filter((node) => node.name === \".obsidian\");\n\n if (obsMetaDir.length !== 1) return false;\n\n return true;\n}\n\nexport { toAbsPath, toRelPath, isObsidianDirectory };\n","import { Id } from \"@o2bTypes/filetree\";\n\nexport const idCounter: (start?: number) => () => Id = (start: number = 0) => {\n let count = start;\n return () => count++;\n};\n","import {\n DirNode,\n NormedDirNode,\n NormedFileNode,\n NormedFileTree,\n} from \"@o2bTypes/filetree\";\nimport { idCounter } from \"@utils/id\";\n\nexport function normalize(fileTree: DirNode): {\n fileTree: NormedFileTree;\n dirNodes: NormedDirNode[];\n fileNodes: NormedFileNode[];\n} {\n const dirNodes: NormedDirNode[] = [];\n const fileNodes: NormedFileNode[] = [];\n\n const fileId = idCounter();\n const dirId = idCounter();\n\n function aux(dir: DirNode): NormedFileTree {\n const id = dirId();\n\n const files = dir.files.map((file) => {\n const id = fileId();\n fileNodes.push({ id, ...file });\n return id;\n });\n\n const dirs = dir.dirs.map((dir) => aux(dir));\n dirNodes.push({ ...dir, id, files, dirs: dirs.map((dir) => dir.id) });\n\n return {\n id,\n files,\n dirs,\n };\n }\n const normedFileTree = aux(fileTree);\n\n return {\n dirNodes,\n fileNodes,\n fileTree: normedFileTree,\n };\n}\n","import { writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { AbsPath } from \"@o2bTypes/path\";\n\nexport function generateJson(\n content: unknown,\n name: string,\n destPath: AbsPath,\n) {\n const jsonFilePath = join(destPath, `${name}.json`);\n writeFileSync(jsonFilePath, JSON.stringify(content, null, 2), \"utf-8\");\n}\n","import { existsSync, lstatSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport ignore, { type Ignore } from \"ignore\";\n\nimport type { AbsPath } from \"@o2bTypes/path\";\nimport { toRelPath } from \"@utils/path\";\n\nexport class VaultIgnorer {\n private ign: Ignore;\n private rootPath: AbsPath;\n\n constructor(rootPath: AbsPath) {\n this.rootPath = rootPath;\n this.ign = ignore();\n\n this.ign.add([\".*\"]);\n }\n\n public load() {\n const ignorePath = join(this.rootPath, \".o2bignore\");\n if (existsSync(ignorePath))\n this.ign.add(readFileSync(ignorePath).toString());\n }\n\n public ignore(path: AbsPath): boolean {\n if (path === this.rootPath) return false;\n\n if (!existsSync(path)) throw new Error(\"somethings wrong!\");\n\n const stat = lstatSync(path);\n\n const relPath =\n toRelPath(this.rootPath, path) + (stat.isDirectory() ? \"/\" : \"\");\n\n return this.ign.ignores(relPath);\n }\n}\n","import { mirror, scan, normalize } from \"@core/sync\";\nimport type { Config } from \"@o2bTypes/config\";\nimport { generateJson } from \"@utils/file\";\nimport { isObsidianDirectory } from \"@utils/path\";\nimport { VaultIgnorer } from \"@utils/ignore\";\n\nexport default function runO2B(config: Config) {\n const { srcPath, destPath, ignore } = config;\n\n if (!isObsidianDirectory(srcPath)) throw new Error(\"Not a obsidian vault\");\n\n const ign = new VaultIgnorer(srcPath);\n if (ignore) ign.load();\n\n const fileTree = scan(srcPath, ign);\n if (fileTree === null) throw new Error(\"No content in vault\");\n if (fileTree.type !== \"dir\") throw new Error(\"No Vault?!\");\n\n mirror(fileTree, srcPath, destPath);\n const { fileTree: normedFileTree, dirNodes, fileNodes } = normalize(fileTree);\n\n generateJson(normedFileTree, \"fileTree\", destPath);\n generateJson(dirNodes, \"dirNodes\", destPath);\n generateJson(fileNodes, \"fileNodes\", destPath);\n}\n"],"mappings":";AAAA,OAAOA,QAAO;;;ACAd,OAAO,OAAO;AAGd,IAAM,UAAU,EAAE,OAAO,EAAE,MAAiB;AAG5C,IAAM,UAAU,EAAE,OAAO,EAAE,MAAiB;;;ADD5C,IAAM,cAAcC,GAAE,OAAO;AAAA,EAC3B,OAAOA,GAAE,OAAO;AAAA,EAChB,aAAaA,GAAE,OAAO;AAAA,EACtB,eAAeA,GAAE,OAAO;AAC1B,CAAC;AAED,IAAM,WAAWA,GAAE,OAAO;AAAA,EACxB,MAAM;AAAA,EACN,MAAMA,GAAE,OAAO;AACjB,CAAC;AAED,IAAM,WAAW,SAAS,OAAO;AAAA,EAC/B,MAAMA,GAAE,QAAQ,MAAM;AAAA,EACtB;AACF,CAAC;AAED,IAAM,UACJ,SAAS,OAAO;AAAA,EACd,MAAMA,GAAE,QAAQ,KAAK;AAAA,EACrB,OAAOA,GAAE,MAAM,QAAQ;AAAA,EACvB,MAAMA,GAAE,KAAK,MAAM,QAAQ,MAAM,CAAC;AACpC,CAAC;AAEH,IAAM,WAAWA,GAAE,MAAM,CAAC,SAAS,QAAQ,CAAC;AA6B5C,IAAM,KAAKA,GAAE,OAAO,EAAE,IAAI;AAEnB,IAAM,iBAAiB,SAAS,OAAO;AAAA,EAC5C;AACF,CAAC;AAEM,IAAM,gBAAgB,SAAS,OAAO;AAAA,EAC3C;AAAA,EACA,MAAMA,GAAE,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","names":["z","z","filetree","lstatSync","readdirSync","join","lstatSync","readdirSync","join","fileTree","id","dir","normedFileTree","writeFileSync","join","existsSync","lstatSync","readFileSync","join","join","existsSync","readFileSync","lstatSync","relPath","ignore","fileTree","normedFileTree"]}
|