@hanzo/docs-cli 1.1.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/index.d.ts +147 -149
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +260 -410
- package/dist/build/index.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +581 -665
- package/dist/index.js.map +1 -0
- package/dist/schema/default.json +1 -0
- package/dist/schema/src.json +1 -0
- package/package.json +18 -18
package/dist/build/index.js
CHANGED
|
@@ -1,423 +1,273 @@
|
|
|
1
|
-
|
|
2
|
-
import * as
|
|
3
|
-
import * as path2 from "path";
|
|
1
|
+
import * as fs$1 from "node:fs/promises";
|
|
2
|
+
import * as path$1 from "node:path";
|
|
4
3
|
import picocolors from "picocolors";
|
|
5
|
-
|
|
6
|
-
// src/build/shadcn.ts
|
|
7
|
-
function mapDeps(deps) {
|
|
8
|
-
return Object.entries(deps).map(([k, v]) => {
|
|
9
|
-
if (v) return `${k}@${v}`;
|
|
10
|
-
return k;
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function escapeName(name) {
|
|
14
|
-
return name;
|
|
15
|
-
}
|
|
16
|
-
function toShadcnRegistry(out, baseUrl) {
|
|
17
|
-
const registry = {
|
|
18
|
-
homepage: baseUrl,
|
|
19
|
-
name: out.name,
|
|
20
|
-
items: out.components.map((comp) => componentToShadcn(comp, baseUrl))
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
registry,
|
|
24
|
-
index: {
|
|
25
|
-
...registry,
|
|
26
|
-
items: out.components.map(
|
|
27
|
-
(comp) => componentToShadcn(comp, baseUrl, true)
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function componentToShadcn(comp, baseUrl, noFile = false) {
|
|
33
|
-
const FileType = {
|
|
34
|
-
components: "registry:component",
|
|
35
|
-
lib: "registry:lib",
|
|
36
|
-
css: "registry:style",
|
|
37
|
-
route: "registry:page",
|
|
38
|
-
ui: "registry:ui",
|
|
39
|
-
block: "registry:block"
|
|
40
|
-
};
|
|
41
|
-
function onFile(file) {
|
|
42
|
-
return {
|
|
43
|
-
type: FileType[file.type],
|
|
44
|
-
content: file.content,
|
|
45
|
-
path: file.path,
|
|
46
|
-
target: file.target
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
extends: "none",
|
|
51
|
-
type: "registry:block",
|
|
52
|
-
name: escapeName(comp.name),
|
|
53
|
-
title: comp.title ?? comp.name,
|
|
54
|
-
description: comp.description,
|
|
55
|
-
dependencies: mapDeps(comp.dependencies),
|
|
56
|
-
devDependencies: mapDeps(comp.devDependencies),
|
|
57
|
-
registryDependencies: comp.subComponents?.map((comp2) => {
|
|
58
|
-
if (comp2.startsWith("https://") || comp2.startsWith("http://"))
|
|
59
|
-
return comp2;
|
|
60
|
-
return new URL(`/r/${escapeName(comp2)}.json`, baseUrl).toString();
|
|
61
|
-
}),
|
|
62
|
-
files: noFile ? [] : comp.files.map(onFile)
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/build/validate.ts
|
|
67
|
-
function validateOutput(registry) {
|
|
68
|
-
const validatedComps = /* @__PURE__ */ new Set();
|
|
69
|
-
const fileToComps = /* @__PURE__ */ new Map();
|
|
70
|
-
function validateComponent(comp) {
|
|
71
|
-
if (validatedComps.has(comp.name)) return;
|
|
72
|
-
validatedComps.add(comp.name);
|
|
73
|
-
for (const file of comp.files) {
|
|
74
|
-
const parents = fileToComps.get(file.path);
|
|
75
|
-
if (parents) {
|
|
76
|
-
parents.add(comp.name);
|
|
77
|
-
} else {
|
|
78
|
-
fileToComps.set(file.path, /* @__PURE__ */ new Set([comp.name]));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
for (const name of comp.subComponents ?? []) {
|
|
82
|
-
const subComp = registry.components.find((item) => item.name === name);
|
|
83
|
-
if (!subComp) {
|
|
84
|
-
console.warn(`skipped component ${name}: not found`);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
validateComponent(subComp);
|
|
88
|
-
}
|
|
89
|
-
for (const file of comp.files) {
|
|
90
|
-
const parents = fileToComps.get(file.path);
|
|
91
|
-
if (!parents || parents.size <= 1) continue;
|
|
92
|
-
throw new Error(
|
|
93
|
-
`Duplicated file in same component ${Array.from(parents).join(", ")}: ${file.path}`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
for (const comp of registry.components) {
|
|
98
|
-
fileToComps.clear();
|
|
99
|
-
validateComponent(comp);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/build/compiler.ts
|
|
104
|
-
import * as fs from "fs/promises";
|
|
105
|
-
import * as path from "path";
|
|
106
4
|
import { Project, ts } from "ts-morph";
|
|
5
|
+
|
|
6
|
+
//#region src/build/compiler.ts
|
|
107
7
|
var RegistryCompiler = class {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
output.components.push(comp);
|
|
148
|
-
}
|
|
149
|
-
return output;
|
|
150
|
-
}
|
|
8
|
+
constructor(registry) {
|
|
9
|
+
this.raw = registry;
|
|
10
|
+
this.project = new Project({ tsConfigFilePath: path$1.join(registry.dir, registry.tsconfigPath) });
|
|
11
|
+
}
|
|
12
|
+
async readPackageJson() {
|
|
13
|
+
if (typeof this.raw.packageJson !== "string") return this.raw.packageJson;
|
|
14
|
+
return fs$1.readFile(path$1.join(this.raw.dir, this.raw.packageJson)).then((res) => JSON.parse(res.toString())).catch(() => void 0);
|
|
15
|
+
}
|
|
16
|
+
async createSourceFile(file) {
|
|
17
|
+
const content = await fs$1.readFile(file);
|
|
18
|
+
return this.project.createSourceFile(file, content.toString(), { overwrite: true });
|
|
19
|
+
}
|
|
20
|
+
async compile() {
|
|
21
|
+
const registry = this.raw;
|
|
22
|
+
this.resolver = new RegistryResolver(this, await this.readPackageJson());
|
|
23
|
+
const output = {
|
|
24
|
+
name: registry.name,
|
|
25
|
+
info: {
|
|
26
|
+
indexes: [],
|
|
27
|
+
env: registry.env,
|
|
28
|
+
variables: registry.variables
|
|
29
|
+
},
|
|
30
|
+
components: []
|
|
31
|
+
};
|
|
32
|
+
const builtComps = await Promise.all(registry.components.map(async (component) => {
|
|
33
|
+
return [component, await new ComponentCompiler(this, component).build()];
|
|
34
|
+
}));
|
|
35
|
+
for (const [input, comp] of builtComps) {
|
|
36
|
+
if (!input.unlisted) output.info.indexes.push({
|
|
37
|
+
name: input.name,
|
|
38
|
+
title: input.title,
|
|
39
|
+
description: input.description
|
|
40
|
+
});
|
|
41
|
+
output.components.push(comp);
|
|
42
|
+
}
|
|
43
|
+
return output;
|
|
44
|
+
}
|
|
151
45
|
};
|
|
152
46
|
var RegistryResolver = class {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const comp = this.fileToComponent.get(relativeFile);
|
|
199
|
-
if (!comp) return;
|
|
200
|
-
return {
|
|
201
|
-
component: comp[0],
|
|
202
|
-
file: comp[1]
|
|
203
|
-
};
|
|
204
|
-
}
|
|
47
|
+
constructor(compiler, packageJson = {}) {
|
|
48
|
+
this.compiler = compiler;
|
|
49
|
+
this.fileToComponent = /* @__PURE__ */ new Map();
|
|
50
|
+
const registry = compiler.raw;
|
|
51
|
+
for (const comp of registry.components) for (const file of comp.files) {
|
|
52
|
+
if (this.fileToComponent.has(file.path)) console.warn(`the same file ${file.path} exists in multiple component, you should make the shared file a separate component.`);
|
|
53
|
+
this.fileToComponent.set(file.path, [comp, file]);
|
|
54
|
+
}
|
|
55
|
+
this.deps = {
|
|
56
|
+
...packageJson?.dependencies,
|
|
57
|
+
...registry.dependencies
|
|
58
|
+
};
|
|
59
|
+
this.devDeps = {
|
|
60
|
+
...packageJson?.devDependencies,
|
|
61
|
+
...registry.devDependencies
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
getDepFromSpecifier(specifier) {
|
|
65
|
+
return specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0];
|
|
66
|
+
}
|
|
67
|
+
getDepInfo(name) {
|
|
68
|
+
if (name in this.deps) return {
|
|
69
|
+
name,
|
|
70
|
+
type: "runtime",
|
|
71
|
+
version: this.deps[name]
|
|
72
|
+
};
|
|
73
|
+
if (name in this.devDeps) return {
|
|
74
|
+
name,
|
|
75
|
+
type: "dev",
|
|
76
|
+
version: this.devDeps[name]
|
|
77
|
+
};
|
|
78
|
+
console.warn(`dep info for ${name} cannot be found`);
|
|
79
|
+
}
|
|
80
|
+
getComponentByName(name) {
|
|
81
|
+
return this.compiler.raw.components.find((comp) => comp.name === name);
|
|
82
|
+
}
|
|
83
|
+
getSubComponent(file) {
|
|
84
|
+
const relativeFile = path$1.relative(this.compiler.raw.dir, file);
|
|
85
|
+
const comp = this.fileToComponent.get(relativeFile);
|
|
86
|
+
if (!comp) return;
|
|
87
|
+
return {
|
|
88
|
+
component: comp[0],
|
|
89
|
+
file: comp[1]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
205
92
|
};
|
|
206
93
|
var ComponentCompiler = class {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
process2(item.getModuleSpecifier(), item.getModuleSpecifierSourceFile());
|
|
325
|
-
}
|
|
326
|
-
for (const item of sourceFile.getExportDeclarations()) {
|
|
327
|
-
const specifier = item.getModuleSpecifier();
|
|
328
|
-
if (!specifier) continue;
|
|
329
|
-
process2(specifier, item.getModuleSpecifierSourceFile());
|
|
330
|
-
}
|
|
331
|
-
const calls = sourceFile.getDescendantsOfKind(ts.SyntaxKind.CallExpression);
|
|
332
|
-
for (const expression of calls) {
|
|
333
|
-
if (expression.getExpression().isKind(ts.SyntaxKind.ImportKeyword) && expression.getArguments().length === 1) {
|
|
334
|
-
const argument = expression.getArguments()[0];
|
|
335
|
-
if (!argument.isKind(ts.SyntaxKind.StringLiteral)) continue;
|
|
336
|
-
process2(
|
|
337
|
-
argument,
|
|
338
|
-
argument.getSymbol()?.getDeclarations()[0].getSourceFile()
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return {
|
|
343
|
-
content: sourceFile.getFullText(),
|
|
344
|
-
type: file.type,
|
|
345
|
-
path: file.path,
|
|
346
|
-
target: file.target
|
|
347
|
-
};
|
|
348
|
-
}
|
|
94
|
+
constructor(compiler, component) {
|
|
95
|
+
this.compiler = compiler;
|
|
96
|
+
this.component = component;
|
|
97
|
+
this.processedFiles = /* @__PURE__ */ new Set();
|
|
98
|
+
this.subComponents = /* @__PURE__ */ new Set();
|
|
99
|
+
this.devDependencies = /* @__PURE__ */ new Map();
|
|
100
|
+
this.dependencies = /* @__PURE__ */ new Map();
|
|
101
|
+
this.registry = compiler.raw;
|
|
102
|
+
}
|
|
103
|
+
toImportPath(file) {
|
|
104
|
+
let filePath = file.target ?? file.path;
|
|
105
|
+
if (filePath.startsWith("./")) filePath = filePath.slice(2);
|
|
106
|
+
return `@/${filePath.replaceAll(path$1.sep, "/")}`;
|
|
107
|
+
}
|
|
108
|
+
async build() {
|
|
109
|
+
return {
|
|
110
|
+
name: this.component.name,
|
|
111
|
+
title: this.component.title,
|
|
112
|
+
description: this.component.description,
|
|
113
|
+
files: (await Promise.all(this.component.files.map((file) => this.buildFileAndDeps(file)))).flat(),
|
|
114
|
+
subComponents: Array.from(this.subComponents),
|
|
115
|
+
dependencies: Object.fromEntries(this.dependencies),
|
|
116
|
+
devDependencies: Object.fromEntries(this.devDependencies)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async buildFileAndDeps(file) {
|
|
120
|
+
if (this.processedFiles.has(file.path)) return [];
|
|
121
|
+
this.processedFiles.add(file.path);
|
|
122
|
+
const resolver = this.compiler.resolver;
|
|
123
|
+
const queue = [];
|
|
124
|
+
return [await this.buildFile(file, (reference) => {
|
|
125
|
+
if (reference.type === "custom") return reference.specifier;
|
|
126
|
+
if (reference.type === "file") {
|
|
127
|
+
const refFile = this.registry.onUnknownFile?.(reference.file);
|
|
128
|
+
if (refFile) {
|
|
129
|
+
queue.push(refFile);
|
|
130
|
+
return this.toImportPath(refFile);
|
|
131
|
+
}
|
|
132
|
+
if (refFile === false) return;
|
|
133
|
+
throw new Error(`Unknown file ${reference.file} referenced by ${file.path}`);
|
|
134
|
+
}
|
|
135
|
+
if (reference.type === "sub-component") {
|
|
136
|
+
const resolved = reference.resolved;
|
|
137
|
+
if (resolved.component.name !== this.component.name) if (resolved.type === "remote") this.subComponents.add({
|
|
138
|
+
type: "http",
|
|
139
|
+
baseUrl: resolved.registryName,
|
|
140
|
+
component: resolved.component.name
|
|
141
|
+
});
|
|
142
|
+
else this.subComponents.add(resolved.component.name);
|
|
143
|
+
return this.toImportPath(resolved.file);
|
|
144
|
+
}
|
|
145
|
+
const dep = resolver.getDepInfo(reference.dep);
|
|
146
|
+
if (dep) (dep.type === "dev" ? this.devDependencies : this.dependencies).set(dep.name, dep.version);
|
|
147
|
+
return reference.specifier;
|
|
148
|
+
}), ...(await Promise.all(queue.map((file$1) => this.buildFileAndDeps(file$1)))).flat()];
|
|
149
|
+
}
|
|
150
|
+
resolveImport(sourceFilePath, specifier, specified) {
|
|
151
|
+
let filePath;
|
|
152
|
+
if (specified) filePath = specified.getFilePath();
|
|
153
|
+
else if (specifier.startsWith("./") || specifier.startsWith("../")) filePath = path$1.join(path$1.dirname(sourceFilePath), specifier);
|
|
154
|
+
else {
|
|
155
|
+
if (!specifier.startsWith("node:")) console.warn(`Unknown specifier ${specifier}, skipping for now`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const resolver = this.compiler.resolver;
|
|
159
|
+
if (path$1.relative(this.registry.dir, filePath).startsWith("../")) return {
|
|
160
|
+
type: "dependency",
|
|
161
|
+
dep: resolver.getDepFromSpecifier(specifier),
|
|
162
|
+
specifier
|
|
163
|
+
};
|
|
164
|
+
const sub = resolver.getSubComponent(filePath);
|
|
165
|
+
if (sub) return {
|
|
166
|
+
type: "sub-component",
|
|
167
|
+
resolved: {
|
|
168
|
+
type: "local",
|
|
169
|
+
component: sub.component,
|
|
170
|
+
file: sub.file
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
type: "file",
|
|
175
|
+
file: filePath
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
async buildFile(file, writeReference) {
|
|
179
|
+
const sourceFilePath = path$1.join(this.registry.dir, file.path);
|
|
180
|
+
/**
|
|
181
|
+
* Process import paths
|
|
182
|
+
*/
|
|
183
|
+
const process$1 = (specifier, specifiedFile) => {
|
|
184
|
+
const onResolve = this.component.onResolve ?? this.registry.onResolve;
|
|
185
|
+
let resolved = this.resolveImport(sourceFilePath, specifier.getLiteralValue(), specifiedFile);
|
|
186
|
+
if (!resolved) return;
|
|
187
|
+
if (onResolve) resolved = onResolve(resolved);
|
|
188
|
+
const out = writeReference(resolved);
|
|
189
|
+
if (out) specifier.setLiteralValue(out);
|
|
190
|
+
};
|
|
191
|
+
const sourceFile = await this.compiler.createSourceFile(sourceFilePath);
|
|
192
|
+
for (const item of sourceFile.getImportDeclarations()) process$1(item.getModuleSpecifier(), item.getModuleSpecifierSourceFile());
|
|
193
|
+
for (const item of sourceFile.getExportDeclarations()) {
|
|
194
|
+
const specifier = item.getModuleSpecifier();
|
|
195
|
+
if (!specifier) continue;
|
|
196
|
+
process$1(specifier, item.getModuleSpecifierSourceFile());
|
|
197
|
+
}
|
|
198
|
+
const calls = sourceFile.getDescendantsOfKind(ts.SyntaxKind.CallExpression);
|
|
199
|
+
for (const expression of calls) if (expression.getExpression().isKind(ts.SyntaxKind.ImportKeyword) && expression.getArguments().length === 1) {
|
|
200
|
+
const argument = expression.getArguments()[0];
|
|
201
|
+
if (!argument.isKind(ts.SyntaxKind.StringLiteral)) continue;
|
|
202
|
+
process$1(argument, argument.getSymbol()?.getDeclarations()[0].getSourceFile());
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
content: sourceFile.getFullText(),
|
|
206
|
+
type: file.type,
|
|
207
|
+
path: file.path,
|
|
208
|
+
target: file.target
|
|
209
|
+
};
|
|
210
|
+
}
|
|
349
211
|
};
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
212
|
+
function resolveFromRemote(r, component, selectFile) {
|
|
213
|
+
const comp = r.components.find((comp$1) => comp$1.name === component);
|
|
214
|
+
if (!comp) return;
|
|
215
|
+
const file = comp.files.find(selectFile);
|
|
216
|
+
if (!file) return;
|
|
217
|
+
return {
|
|
218
|
+
type: "sub-component",
|
|
219
|
+
resolved: {
|
|
220
|
+
type: "remote",
|
|
221
|
+
registryName: r.name,
|
|
222
|
+
component: comp,
|
|
223
|
+
file
|
|
224
|
+
}
|
|
225
|
+
};
|
|
364
226
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
await writeFile2(file, JSON.stringify(item, null, 2));
|
|
378
|
-
});
|
|
379
|
-
write.push(
|
|
380
|
-
writeFile2(path2.join(dir, "registry.json"), JSON.stringify(index, null, 2))
|
|
381
|
-
);
|
|
382
|
-
await Promise.all(write);
|
|
227
|
+
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/build/index.ts
|
|
230
|
+
function combineRegistry(root, ...items) {
|
|
231
|
+
return {
|
|
232
|
+
...root,
|
|
233
|
+
info: {
|
|
234
|
+
...root.info,
|
|
235
|
+
registries: items.map((item) => item.name)
|
|
236
|
+
},
|
|
237
|
+
registries: items
|
|
238
|
+
};
|
|
383
239
|
}
|
|
384
240
|
async function writeFumadocsRegistry(out, options) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
241
|
+
const { dir, cleanDir = false, log = true } = options;
|
|
242
|
+
if (cleanDir) {
|
|
243
|
+
await fs$1.rm(dir, {
|
|
244
|
+
recursive: true,
|
|
245
|
+
force: true
|
|
246
|
+
});
|
|
247
|
+
console.log(picocolors.bold(picocolors.greenBright("Cleaned directory")));
|
|
248
|
+
}
|
|
249
|
+
async function writeInfo() {
|
|
250
|
+
await writeFile(path$1.join(dir, "_registry.json"), JSON.stringify(out.info, null, 2), log);
|
|
251
|
+
}
|
|
252
|
+
const write = out.components.map(async (comp) => {
|
|
253
|
+
await writeFile(path$1.join(dir, `${comp.name}.json`), JSON.stringify(comp, null, 2), log);
|
|
254
|
+
});
|
|
255
|
+
write.push(writeInfo());
|
|
256
|
+
if ("registries" in out) for (const child of out.registries) write.push(writeFumadocsRegistry(child, {
|
|
257
|
+
dir: path$1.join(dir, child.name),
|
|
258
|
+
log: options.log
|
|
259
|
+
}));
|
|
260
|
+
await Promise.all(write);
|
|
405
261
|
}
|
|
406
|
-
async function
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
);
|
|
414
|
-
}
|
|
262
|
+
async function writeFile(file, content, log = true) {
|
|
263
|
+
await fs$1.mkdir(path$1.dirname(file), { recursive: true });
|
|
264
|
+
await fs$1.writeFile(file, content);
|
|
265
|
+
if (log) {
|
|
266
|
+
const size = (Buffer.byteLength(content) / 1024).toFixed(2);
|
|
267
|
+
console.log(`${picocolors.greenBright("+")} ${path$1.relative(process.cwd(), file)} ${picocolors.dim(`${size} KB`)}`);
|
|
268
|
+
}
|
|
415
269
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
toShadcnRegistry,
|
|
421
|
-
writeFumadocsRegistry,
|
|
422
|
-
writeShadcnRegistry
|
|
423
|
-
};
|
|
270
|
+
|
|
271
|
+
//#endregion
|
|
272
|
+
export { ComponentCompiler, RegistryCompiler, combineRegistry, resolveFromRemote, writeFumadocsRegistry };
|
|
273
|
+
//# sourceMappingURL=index.js.map
|