@o2b/meta 1.0.0-dev.6 → 1.0.0-dev.9
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/dist/cli.js.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",
|
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,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,KAAK;AAErB,QAAM,WAAW,KAAK,SAAS,GAAG;AAClC,MAAI,aAAa,KAAM,OAAM,IAAI,MAAM,qBAAqB;AAC5D,MAAI,SAAS,SAAS,MAAO,OAAM,IAAI,MAAM,YAAY;AAEzD,SAAO,UAAU,SAAS,QAAQ;AAClC,QAAM,EAAE,OAAO,UAAU,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 { 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;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,cAAg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AC3B,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"]}
|