@o2b/meta 1.0.0-dev.5 → 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 +104 -97
- package/dist/cli.js.map +1 -1
- package/dist/index.d.mts +41 -117
- package/dist/index.d.ts +41 -117
- package/dist/index.js +133 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +130 -84
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
declare const
|
|
5
|
-
|
|
6
|
-
type Config = {
|
|
7
|
-
srcPath: AbsPath;
|
|
8
|
-
destPath: AbsPath;
|
|
9
|
-
ignore: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
declare const fileTree: z.ZodUnion<[z.ZodObject<{
|
|
3
|
+
declare const id: z.ZodNumber;
|
|
4
|
+
declare const normedFileNode: z.ZodObject<{
|
|
13
5
|
path: z.ZodBranded<z.ZodString, "relpath">;
|
|
14
6
|
name: z.ZodString;
|
|
15
7
|
} & {
|
|
@@ -27,6 +19,8 @@ declare const fileTree: z.ZodUnion<[z.ZodObject<{
|
|
|
27
19
|
description: string;
|
|
28
20
|
last_modified: string;
|
|
29
21
|
}>;
|
|
22
|
+
} & {
|
|
23
|
+
id: z.ZodNumber;
|
|
30
24
|
}, "strip", z.ZodTypeAny, {
|
|
31
25
|
path: string & z.BRAND<"relpath">;
|
|
32
26
|
type: "file";
|
|
@@ -36,6 +30,7 @@ declare const fileTree: z.ZodUnion<[z.ZodObject<{
|
|
|
36
30
|
description: string;
|
|
37
31
|
last_modified: string;
|
|
38
32
|
};
|
|
33
|
+
id: number;
|
|
39
34
|
}, {
|
|
40
35
|
path: string;
|
|
41
36
|
type: "file";
|
|
@@ -45,121 +40,50 @@ declare const fileTree: z.ZodUnion<[z.ZodObject<{
|
|
|
45
40
|
description: string;
|
|
46
41
|
last_modified: string;
|
|
47
42
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
type: "dir";
|
|
53
|
-
files: {
|
|
54
|
-
path: string & z.BRAND<"relpath">;
|
|
55
|
-
type: "file";
|
|
56
|
-
name: string;
|
|
57
|
-
frontmatter: {
|
|
58
|
-
title: string;
|
|
59
|
-
description: string;
|
|
60
|
-
last_modified: string;
|
|
61
|
-
};
|
|
62
|
-
}[];
|
|
63
|
-
dirs: ({
|
|
64
|
-
path: string & z.BRAND<"relpath">;
|
|
65
|
-
name: string;
|
|
66
|
-
} & /*elided*/ any)[];
|
|
67
|
-
}, z.ZodTypeDef, {
|
|
68
|
-
path: string;
|
|
69
|
-
name: string;
|
|
70
|
-
} & {
|
|
71
|
-
type: "dir";
|
|
72
|
-
files: {
|
|
73
|
-
path: string;
|
|
74
|
-
type: "file";
|
|
75
|
-
name: string;
|
|
76
|
-
frontmatter: {
|
|
77
|
-
title: string;
|
|
78
|
-
description: string;
|
|
79
|
-
last_modified: string;
|
|
80
|
-
};
|
|
81
|
-
}[];
|
|
82
|
-
dirs: ({
|
|
83
|
-
path: string;
|
|
84
|
-
name: string;
|
|
85
|
-
} & /*elided*/ any)[];
|
|
86
|
-
}>]>;
|
|
87
|
-
declare const jsonFileTree: z.ZodUnion<[z.ZodObject<{
|
|
88
|
-
path: z.ZodString;
|
|
43
|
+
id: number;
|
|
44
|
+
}>;
|
|
45
|
+
declare const normedDirNode: z.ZodObject<{
|
|
46
|
+
path: z.ZodBranded<z.ZodString, "relpath">;
|
|
89
47
|
name: z.ZodString;
|
|
90
48
|
} & {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
last_modified: z.ZodString;
|
|
96
|
-
}, "strip", z.ZodTypeAny, {
|
|
97
|
-
title: string;
|
|
98
|
-
description: string;
|
|
99
|
-
last_modified: string;
|
|
100
|
-
}, {
|
|
101
|
-
title: string;
|
|
102
|
-
description: string;
|
|
103
|
-
last_modified: string;
|
|
104
|
-
}>;
|
|
49
|
+
id: z.ZodNumber;
|
|
50
|
+
type: z.ZodLiteral<"dir">;
|
|
51
|
+
files: z.ZodArray<z.ZodNumber, "many">;
|
|
52
|
+
dirs: z.ZodArray<z.ZodNumber, "many">;
|
|
105
53
|
}, "strip", z.ZodTypeAny, {
|
|
106
|
-
path: string
|
|
107
|
-
type: "
|
|
54
|
+
path: string & z.BRAND<"relpath">;
|
|
55
|
+
type: "dir";
|
|
108
56
|
name: string;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
last_modified: string;
|
|
113
|
-
};
|
|
57
|
+
files: number[];
|
|
58
|
+
dirs: number[];
|
|
59
|
+
id: number;
|
|
114
60
|
}, {
|
|
115
61
|
path: string;
|
|
116
|
-
type: "file";
|
|
117
|
-
name: string;
|
|
118
|
-
frontmatter: {
|
|
119
|
-
title: string;
|
|
120
|
-
description: string;
|
|
121
|
-
last_modified: string;
|
|
122
|
-
};
|
|
123
|
-
}>, z.ZodType<{
|
|
124
|
-
path: string;
|
|
125
|
-
name: string;
|
|
126
|
-
} & {
|
|
127
62
|
type: "dir";
|
|
128
|
-
files: {
|
|
129
|
-
path: string;
|
|
130
|
-
type: "file";
|
|
131
|
-
name: string;
|
|
132
|
-
frontmatter: {
|
|
133
|
-
title: string;
|
|
134
|
-
description: string;
|
|
135
|
-
last_modified: string;
|
|
136
|
-
};
|
|
137
|
-
}[];
|
|
138
|
-
dirs: ({
|
|
139
|
-
path: string;
|
|
140
|
-
name: string;
|
|
141
|
-
} & /*elided*/ any)[];
|
|
142
|
-
}, z.ZodTypeDef, {
|
|
143
|
-
path: string;
|
|
144
63
|
name: string;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
64
|
+
files: number[];
|
|
65
|
+
dirs: number[];
|
|
66
|
+
id: number;
|
|
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>;
|
|
75
|
+
type NormedFileNode = z.infer<typeof normedFileNode>;
|
|
76
|
+
type NormedDirNode = z.infer<typeof normedDirNode>;
|
|
77
|
+
|
|
78
|
+
type AbsPath = z.infer<typeof absPath>;
|
|
79
|
+
declare const absPath: z.ZodBranded<z.ZodString, "absPath">;
|
|
80
|
+
|
|
81
|
+
type Config = {
|
|
82
|
+
srcPath: AbsPath;
|
|
83
|
+
destPath: AbsPath;
|
|
84
|
+
ignore: boolean;
|
|
85
|
+
};
|
|
162
86
|
|
|
163
87
|
declare function runO2B(config: Config): void;
|
|
164
88
|
|
|
165
|
-
export { runO2B as default,
|
|
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
|
|
|
@@ -50,27 +51,35 @@ var frontmatter = import_zod2.default.object({
|
|
|
50
51
|
description: import_zod2.default.string(),
|
|
51
52
|
last_modified: import_zod2.default.string()
|
|
52
53
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
54
|
+
var baseNode = import_zod2.default.object({
|
|
55
|
+
path: relPath,
|
|
56
|
+
name: import_zod2.default.string()
|
|
57
|
+
});
|
|
58
|
+
var fileNode = baseNode.extend({
|
|
59
|
+
type: import_zod2.default.literal("file"),
|
|
60
|
+
frontmatter
|
|
61
|
+
});
|
|
62
|
+
var dirNode = baseNode.extend({
|
|
63
|
+
type: import_zod2.default.literal("dir"),
|
|
64
|
+
files: import_zod2.default.array(fileNode),
|
|
65
|
+
dirs: import_zod2.default.lazy(() => dirNode.array())
|
|
66
|
+
});
|
|
67
|
+
var fileTree = import_zod2.default.union([dirNode, fileNode]);
|
|
68
|
+
var id = import_zod2.default.number().int();
|
|
69
|
+
var normedFileNode = fileNode.extend({
|
|
70
|
+
id
|
|
71
|
+
});
|
|
72
|
+
var normedDirNode = baseNode.extend({
|
|
73
|
+
id,
|
|
74
|
+
type: import_zod2.default.literal("dir"),
|
|
75
|
+
files: import_zod2.default.array(id),
|
|
76
|
+
dirs: import_zod2.default.array(id)
|
|
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
|
+
});
|
|
74
83
|
|
|
75
84
|
// src/core/sync/mirror.ts
|
|
76
85
|
var import_node_fs = require("fs");
|
|
@@ -93,22 +102,12 @@ function mirror(filetree, srcPath, destPath) {
|
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
aux(filetree);
|
|
96
|
-
generateFileTree(filetree, destPath);
|
|
97
|
-
}
|
|
98
|
-
function generateFileTree(filetree, destPath) {
|
|
99
|
-
const jsonFilePath = (0, import_node_path.join)(destPath, "o2bFileTree.json");
|
|
100
|
-
(0, import_node_fs.writeFileSync)(jsonFilePath, JSON.stringify(filetree, null, 2), "utf-8");
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
// src/core/sync/scan.ts
|
|
104
|
-
var import_node_fs4 = require("fs");
|
|
105
|
-
var import_node_path4 = require("path");
|
|
106
|
-
var import_gray_matter = __toESM(require("gray-matter"));
|
|
107
|
-
|
|
108
|
-
// src/utils/ignore.ts
|
|
109
108
|
var import_node_fs3 = require("fs");
|
|
110
109
|
var import_node_path3 = require("path");
|
|
111
|
-
var
|
|
110
|
+
var import_gray_matter = __toESM(require("gray-matter"));
|
|
112
111
|
|
|
113
112
|
// src/utils/path.ts
|
|
114
113
|
var import_node_fs2 = require("fs");
|
|
@@ -128,79 +127,121 @@ function isObsidianDirectory(path) {
|
|
|
128
127
|
return true;
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
// src/utils/ignore.ts
|
|
132
|
-
var VaultIgnorer = class {
|
|
133
|
-
ign;
|
|
134
|
-
rootPath;
|
|
135
|
-
constructor(rootPath) {
|
|
136
|
-
this.rootPath = rootPath;
|
|
137
|
-
this.ign = (0, import_ignore.default)();
|
|
138
|
-
this.ign.add([".*"]);
|
|
139
|
-
}
|
|
140
|
-
load() {
|
|
141
|
-
const ignorePath = (0, import_node_path3.join)(this.rootPath, ".o2bignore");
|
|
142
|
-
if ((0, import_node_fs3.existsSync)(ignorePath))
|
|
143
|
-
this.ign.add((0, import_node_fs3.readFileSync)(ignorePath).toString());
|
|
144
|
-
}
|
|
145
|
-
ignore(path) {
|
|
146
|
-
if (path === this.rootPath) return false;
|
|
147
|
-
if (!(0, import_node_fs3.existsSync)(path)) throw new Error("somethings wrong!");
|
|
148
|
-
const stat = (0, import_node_fs3.lstatSync)(path);
|
|
149
|
-
const relPath2 = toRelPath(this.rootPath, path) + (stat.isDirectory() ? "/" : "");
|
|
150
|
-
return this.ign.ignores(relPath2);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
130
|
// src/core/sync/scan.ts
|
|
155
131
|
function scan(rootPath, ign) {
|
|
156
132
|
function aux(path) {
|
|
157
133
|
if (ign == null ? void 0 : ign.ignore(path)) return null;
|
|
158
|
-
const stat = (0,
|
|
159
|
-
const name = (0,
|
|
160
|
-
if (stat.
|
|
161
|
-
const { dirs, files } = (0, import_node_fs4.readdirSync)(path).reduce(
|
|
162
|
-
(acc, entry) => {
|
|
163
|
-
const node = aux(toAbsPath((0, import_node_path4.join)(path, entry)));
|
|
164
|
-
if ((node == null ? void 0 : node.type) === "dir") acc.dirs.push(node);
|
|
165
|
-
if ((node == null ? void 0 : node.type) === "file") acc.files.push(node);
|
|
166
|
-
return acc;
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
dirs: [],
|
|
170
|
-
files: []
|
|
171
|
-
}
|
|
172
|
-
);
|
|
134
|
+
const stat = (0, import_node_fs3.lstatSync)(path);
|
|
135
|
+
const name = (0, import_node_path3.basename)(path);
|
|
136
|
+
if (stat.isFile() && name.endsWith(".md")) {
|
|
173
137
|
return {
|
|
174
138
|
path: toRelPath(rootPath, path),
|
|
175
139
|
name,
|
|
176
|
-
type: "
|
|
177
|
-
|
|
178
|
-
files
|
|
140
|
+
type: "file",
|
|
141
|
+
frontmatter: fetchFrontmatter(path, stat.mtime)
|
|
179
142
|
};
|
|
180
143
|
}
|
|
181
|
-
if (stat.
|
|
144
|
+
if (stat.isDirectory()) {
|
|
145
|
+
const dirs = [];
|
|
146
|
+
const files = [];
|
|
147
|
+
const entries = (0, import_node_fs3.readdirSync)(path);
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
const fullPath = toAbsPath((0, import_node_path3.join)(path, entry));
|
|
150
|
+
const node = aux(fullPath);
|
|
151
|
+
if ((node == null ? void 0 : node.type) === "dir") dirs.push(node);
|
|
152
|
+
if ((node == null ? void 0 : node.type) === "file") files.push(node);
|
|
153
|
+
}
|
|
182
154
|
return {
|
|
183
155
|
path: toRelPath(rootPath, path),
|
|
184
156
|
name,
|
|
185
|
-
type: "
|
|
186
|
-
|
|
157
|
+
type: "dir",
|
|
158
|
+
dirs,
|
|
159
|
+
files
|
|
187
160
|
};
|
|
188
161
|
}
|
|
189
162
|
return null;
|
|
190
163
|
}
|
|
191
164
|
return aux(rootPath);
|
|
192
165
|
}
|
|
193
|
-
function
|
|
194
|
-
const { data
|
|
166
|
+
function fetchFrontmatter(path, mtime) {
|
|
167
|
+
const { data } = (0, import_gray_matter.default)((0, import_node_fs3.readFileSync)(path, "utf-8"));
|
|
195
168
|
return {
|
|
196
|
-
title: (0,
|
|
169
|
+
title: (0, import_node_path3.basename)(path).replace(/\.md$/, ""),
|
|
197
170
|
description: "No description provided.",
|
|
198
|
-
last_modified:
|
|
199
|
-
|
|
200
|
-
...srcFrontmatter
|
|
171
|
+
last_modified: mtime.toISOString().split("T")[0],
|
|
172
|
+
...data
|
|
201
173
|
};
|
|
202
174
|
}
|
|
203
175
|
|
|
176
|
+
// src/utils/id.ts
|
|
177
|
+
var idCounter = (start = 0) => {
|
|
178
|
+
let count = start;
|
|
179
|
+
return () => count++;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/core/sync/normalize.ts
|
|
183
|
+
function normalize(fileTree2) {
|
|
184
|
+
const dirNodes = [];
|
|
185
|
+
const fileNodes = [];
|
|
186
|
+
const fileId = idCounter();
|
|
187
|
+
const dirId = idCounter();
|
|
188
|
+
function aux(dir) {
|
|
189
|
+
const id2 = dirId();
|
|
190
|
+
const files = dir.files.map((file) => {
|
|
191
|
+
const id3 = fileId();
|
|
192
|
+
fileNodes.push({ id: id3, ...file });
|
|
193
|
+
return id3;
|
|
194
|
+
});
|
|
195
|
+
const dirs = dir.dirs.map((dir2) => aux(dir2));
|
|
196
|
+
dirNodes.push({ ...dir, id: id2, files, dirs: dirs.map((dir2) => dir2.id) });
|
|
197
|
+
return {
|
|
198
|
+
id: id2,
|
|
199
|
+
files,
|
|
200
|
+
dirs
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const normedFileTree2 = aux(fileTree2);
|
|
204
|
+
return {
|
|
205
|
+
dirNodes,
|
|
206
|
+
fileNodes,
|
|
207
|
+
fileTree: normedFileTree2
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/utils/file.ts
|
|
212
|
+
var import_node_fs4 = require("fs");
|
|
213
|
+
var import_node_path4 = require("path");
|
|
214
|
+
function generateJson(content, name, destPath) {
|
|
215
|
+
const jsonFilePath = (0, import_node_path4.join)(destPath, `${name}.json`);
|
|
216
|
+
(0, import_node_fs4.writeFileSync)(jsonFilePath, JSON.stringify(content, null, 2), "utf-8");
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/utils/ignore.ts
|
|
220
|
+
var import_node_fs5 = require("fs");
|
|
221
|
+
var import_node_path5 = require("path");
|
|
222
|
+
var import_ignore = __toESM(require("ignore"));
|
|
223
|
+
var VaultIgnorer = class {
|
|
224
|
+
ign;
|
|
225
|
+
rootPath;
|
|
226
|
+
constructor(rootPath) {
|
|
227
|
+
this.rootPath = rootPath;
|
|
228
|
+
this.ign = (0, import_ignore.default)();
|
|
229
|
+
this.ign.add([".*"]);
|
|
230
|
+
}
|
|
231
|
+
load() {
|
|
232
|
+
const ignorePath = (0, import_node_path5.join)(this.rootPath, ".o2bignore");
|
|
233
|
+
if ((0, import_node_fs5.existsSync)(ignorePath))
|
|
234
|
+
this.ign.add((0, import_node_fs5.readFileSync)(ignorePath).toString());
|
|
235
|
+
}
|
|
236
|
+
ignore(path) {
|
|
237
|
+
if (path === this.rootPath) return false;
|
|
238
|
+
if (!(0, import_node_fs5.existsSync)(path)) throw new Error("somethings wrong!");
|
|
239
|
+
const stat = (0, import_node_fs5.lstatSync)(path);
|
|
240
|
+
const relPath2 = toRelPath(this.rootPath, path) + (stat.isDirectory() ? "/" : "");
|
|
241
|
+
return this.ign.ignores(relPath2);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
204
245
|
// src/runO2B.ts
|
|
205
246
|
function runO2B(config) {
|
|
206
247
|
const { srcPath, destPath, ignore: ignore2 } = config;
|
|
@@ -209,11 +250,17 @@ function runO2B(config) {
|
|
|
209
250
|
if (ignore2) ign.load();
|
|
210
251
|
const fileTree2 = scan(srcPath, ign);
|
|
211
252
|
if (fileTree2 === null) throw new Error("No content in vault");
|
|
253
|
+
if (fileTree2.type !== "dir") throw new Error("No Vault?!");
|
|
212
254
|
mirror(fileTree2, srcPath, destPath);
|
|
255
|
+
const { fileTree: normedFileTree2, dirNodes, fileNodes } = normalize(fileTree2);
|
|
256
|
+
generateJson(normedFileTree2, "fileTree", destPath);
|
|
257
|
+
generateJson(dirNodes, "dirNodes", destPath);
|
|
258
|
+
generateJson(fileNodes, "fileNodes", destPath);
|
|
213
259
|
}
|
|
214
260
|
// Annotate the CommonJS export names for ESM import in node:
|
|
215
261
|
0 && (module.exports = {
|
|
216
|
-
|
|
217
|
-
|
|
262
|
+
dirNodeSchema,
|
|
263
|
+
fileNodeScheam,
|
|
264
|
+
fileTreeSchema
|
|
218
265
|
});
|
|
219
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/ignore.ts","../src/utils/path.ts","../src/runO2B.ts"],"sourcesContent":["export { fileTree, jsonFileTree } from \"./types\";\nexport { default } from \"./runO2B\";\n","import z from \"zod\";\nimport { relPath, type RelPath } from \"./path\";\n\nconst frontmatter = z.object({\n title: z.string(),\n description: z.string(),\n last_modified: z.string(),\n});\n\nfunction createFileTreeSchema<P extends typeof relPath | z.ZodString>(path: P) {\n type BaseNode = z.infer<typeof baseNode>;\n const baseNode = z.object({\n path,\n name: z.string(),\n });\n\n type FileNodeOutput = z.infer<typeof fileNode>;\n type FileNodeInput = z.input<typeof fileNode>;\n const fileNode = baseNode.extend({\n type: z.literal(\"file\"),\n frontmatter: frontmatter,\n });\n\n // https://v3.zod.dev/?id=recursive-types\n type DirNodeOutput = BaseNode & {\n type: \"dir\";\n files: FileNodeOutput[];\n dirs: DirNodeOutput[];\n };\n type DirNodeInput = z.input<typeof baseNode> & {\n type: \"dir\";\n files: FileNodeInput[];\n dirs: DirNodeInput[];\n };\n\n const 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\n const fileTree = z.union([fileNode, dirNode]);\n\n return { fileTree, dirNode, fileNode };\n}\n\nconst defaultSchema = createFileTreeSchema(relPath);\nconst jsonSchema = createFileTreeSchema(z.string());\n\nexport const fileTree = defaultSchema.fileTree;\nexport const jsonFileTree = jsonSchema.fileTree;\n\nexport type FileTree = z.infer<typeof defaultSchema.fileTree>;\nexport type FileNode = z.infer<typeof defaultSchema.fileNode>;\nexport type DirNode = z.infer<typeof defaultSchema.dirNode>;\nexport type Frontmatter = z.infer<typeof frontmatter>;\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, FileTree } from \"../../types\";\n\nexport function mirror(\n\tfiletree: FileTree,\n\tsrcPath: AbsPath,\n\tdestPath: AbsPath,\n) {\n\tfunction aux(filetree: FileTree) {\n\t\tconst from = join(srcPath, filetree.path);\n\t\tconst to = join(destPath, filetree.path);\n\n\t\tif (filetree.type === \"dir\") {\n\t\t\tif (!existsSync(to)) mkdirSync(to, { recursive: true });\n\n\t\t\tfiletree.files.forEach((file) => {\n\t\t\t\taux(file);\n\t\t\t});\n\n\t\t\tfiletree.dirs.forEach((dir) => {\n\t\t\t\taux(dir);\n\t\t\t});\n\t\t}\n\n\t\tif (filetree.type === \"file\") {\n\t\t\tcopyFileSync(from, to);\n\t\t}\n\t}\n\n\taux(filetree);\n\tgenerateFileTree(filetree, destPath);\n}\n\nfunction generateFileTree(filetree: FileTree, destPath: AbsPath) {\n\tconst jsonFilePath = join(destPath, \"o2bFileTree.json\");\n\twriteFileSync(jsonFilePath, JSON.stringify(filetree, null, 2), \"utf-8\");\n}\n","import { lstatSync, readdirSync, readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport matter from \"gray-matter\";\nimport type {\n\tAbsPath,\n\tDirNode,\n\tFileNode,\n\tFileTree,\n\tFrontmatter,\n} from \"../../types\";\nimport { toAbsPath, toRelPath, type VaultIgnorer } from \"../../utils\";\n\nexport function scan(rootPath: AbsPath, ign: VaultIgnorer): FileTree | null {\n\tfunction aux(path: AbsPath): FileTree | null {\n\t\tif (ign?.ignore(path)) return null;\n\n\t\tconst stat = lstatSync(path);\n\t\tconst name = basename(path);\n\n\t\tif (stat.isDirectory()) {\n\t\t\tconst { dirs, files } = readdirSync(path).reduce(\n\t\t\t\t(acc, entry) => {\n\t\t\t\t\tconst node = aux(toAbsPath(join(path, entry)));\n\n\t\t\t\t\tif (node?.type === \"dir\") acc.dirs.push(node);\n\t\t\t\t\tif (node?.type === \"file\") acc.files.push(node);\n\n\t\t\t\t\treturn acc;\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdirs: [] as DirNode[],\n\t\t\t\t\tfiles: [] as FileNode[],\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tpath: toRelPath(rootPath, path),\n\t\t\t\tname,\n\t\t\t\ttype: \"dir\",\n\t\t\t\tdirs,\n\t\t\t\tfiles,\n\t\t\t};\n\t\t}\n\n\t\tif (stat.isFile() && name.endsWith(\".md\")) {\n\t\t\treturn {\n\t\t\t\tpath: toRelPath(rootPath, path),\n\t\t\t\tname,\n\t\t\t\ttype: \"file\",\n\t\t\t\tfrontmatter: getFrontmatter(path),\n\t\t\t};\n\t\t}\n\n\t\treturn null;\n\t}\n\n\treturn aux(rootPath);\n}\n\nfunction getFrontmatter(path: AbsPath): Frontmatter {\n\tconst { data: srcFrontmatter } = matter(readFileSync(path, \"utf-8\"));\n\treturn {\n\t\ttitle: basename(path).replace(/\\.md$/, \"\"),\n\t\tdescription: \"No description provided.\",\n\t\tlast_modified: lstatSync(path).mtime.toLocaleDateString(\"sv-SE\"), // \"sv-SE\" (스웨덴어)는 YYYY-MM-DD 형식으로 출력되는 유명한 트릭입니다.\n\t\t...srcFrontmatter,\n\t};\n}\n","import { existsSync, lstatSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport ignore, { type Ignore } from \"ignore\";\nimport type { AbsPath } from \"../types\";\nimport { toRelPath } from \"./path\";\n\nexport class VaultIgnorer {\n\tprivate ign: Ignore;\n\tprivate rootPath: AbsPath;\n\n\tconstructor(rootPath: AbsPath) {\n\t\tthis.rootPath = rootPath;\n\t\tthis.ign = ignore();\n\n\t\tthis.ign.add([\".*\"]);\n\t}\n\n\tpublic load() {\n\t\tconst ignorePath = join(this.rootPath, \".o2bignore\");\n\t\tif (existsSync(ignorePath))\n\t\t\tthis.ign.add(readFileSync(ignorePath).toString());\n\t}\n\n\tpublic ignore(path: AbsPath): boolean {\n\t\tif (path === this.rootPath) return false;\n\n\t\tif (!existsSync(path)) throw new Error(\"somethings wrong!\");\n\n\t\tconst stat = lstatSync(path);\n\n\t\tconst relPath =\n\t\t\ttoRelPath(this.rootPath, path) + (stat.isDirectory() ? \"/\" : \"\");\n\n\t\treturn this.ign.ignores(relPath);\n\t}\n}\n","import { lstatSync, readdirSync } from \"node:fs\";\nimport { isAbsolute, relative, resolve } from \"node:path\";\nimport { absPath, relPath, type AbsPath, type RelPath } from \"../types\";\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 { mirror, scan } from \"./core/sync\";\nimport type { Config } from \"./types\";\nimport { isObsidianDirectory, VaultIgnorer } from \"./utils\";\n\nexport default function runO2B(config: Config) {\n const { srcPath, destPath, ignore } = config;\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\n mirror(fileTree, srcPath, 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;;;ADH5C,IAAM,cAAc,YAAAC,QAAE,OAAO;AAAA,EAC3B,OAAO,YAAAA,QAAE,OAAO;AAAA,EAChB,aAAa,YAAAA,QAAE,OAAO;AAAA,EACtB,eAAe,YAAAA,QAAE,OAAO;AAC1B,CAAC;AAED,SAAS,qBAA6D,MAAS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BAAa,MAAM,OAAO,CAAC;AACnE,SAAO;AAAA,IACN,WAAO,4BAAS,IAAI,EAAE,QAAQ,SAAS,EAAE;AAAA,IACzC,aAAa;AAAA,IACb,mBAAe,2BAAU,IAAI,EAAE,MAAM,mBAAmB,OAAO;AAAA;AAAA,IAC/D,GAAG;AAAA,EACJ;AACD;;;AG/De,SAAR,OAAwB,QAAgB;AAC7C,QAAM,EAAE,SAAS,UAAU,QAAAC,QAAO,IAAI;AACtC,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;AAE5D,SAAOA,WAAU,SAAS,QAAQ;AACpC;","names":["import_zod","z","z","fileTree","filetree","import_node_fs","import_node_path","import_node_fs","import_node_path","import_node_fs","import_node_path","ignore","relPath","matter","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(norm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AAElB,SAAK,IAAI,IAAI,CAAC,IAAI,CAAC;AAAA,EACrB;AAAA,EAEO,OAAO;AACZ,UAAM,iBAAa,wBAAK,KAAK,UAAU,YAAY;AACnD,YAAI,4BAAW,UAAU;AACvB,WAAK,IAAI,QAAI,8BAAa,UAAU,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"]}
|