stera-ui 0.8.1 → 0.9.0
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/add-JTKZDMNI.js +2 -0
- package/dist/chunk-42DL2YAQ.js +2 -0
- package/dist/chunk-FZGIVCWE.js +42175 -0
- package/dist/chunk-LUUYMQIF.js +97 -0
- package/dist/chunk-MBBLZJIK.js +2 -0
- package/dist/chunk-OPVLMYW5.js +2 -0
- package/dist/chunk-OSMC63WJ.js +2 -0
- package/dist/chunk-P2O7D5BG.js +2 -0
- package/dist/chunk-UVHQPGZ3.js +7 -0
- package/dist/chunk-XJ6VM67K.js +2 -0
- package/dist/cli.js +29 -32
- package/dist/index.js +2 -86
- package/dist/init-XAKB27HW.js +12 -0
- package/dist/list-W7ECLPKW.js +5 -0
- package/dist/registry/index.d.ts +3 -1
- package/dist/registry/index.js +2 -17
- package/dist/schema/index.js +2 -18
- package/dist/utils/index.d.ts +26 -3
- package/dist/utils/index.js +2 -58
- package/package.json +6 -8
- package/dist/add-DBC33IWM.js +0 -201
- package/dist/chunk-4E46BULJ.js +0 -79
- package/dist/chunk-BJNLGEZJ.js +0 -100
- package/dist/chunk-KGMF6UW4.js +0 -21
- package/dist/chunk-KKUJRJ2N.js +0 -209
- package/dist/chunk-RQ7T7RF5.js +0 -880
- package/dist/chunk-UKHKFX2A.js +0 -376
- package/dist/init-EQHYR7MG.js +0 -763
- package/dist/list-M73QTIWR.js +0 -44
package/dist/add-DBC33IWM.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
CONFIG_FILE,
|
|
4
|
-
findConfigPath,
|
|
5
|
-
installDependencies,
|
|
6
|
-
loadConfig,
|
|
7
|
-
migrateLegacyStyles,
|
|
8
|
-
writeComponentFiles,
|
|
9
|
-
writeStyles
|
|
10
|
-
} from "./chunk-UKHKFX2A.js";
|
|
11
|
-
import {
|
|
12
|
-
ComponentNotFoundError,
|
|
13
|
-
createSpinner,
|
|
14
|
-
resolveDependencies
|
|
15
|
-
} from "./chunk-KKUJRJ2N.js";
|
|
16
|
-
import {
|
|
17
|
-
CHECK,
|
|
18
|
-
CROSS,
|
|
19
|
-
dim
|
|
20
|
-
} from "./chunk-KGMF6UW4.js";
|
|
21
|
-
|
|
22
|
-
// src/commands/add.ts
|
|
23
|
-
import path from "path";
|
|
24
|
-
|
|
25
|
-
// src/utils/transform.ts
|
|
26
|
-
function applyTransforms(content, ctx, transforms2) {
|
|
27
|
-
return transforms2.reduce((acc, fn) => fn(acc, ctx), content);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/utils/transform-imports.ts
|
|
31
|
-
var DEFAULT_ALIASES = {
|
|
32
|
-
utils: "@/lib/utils",
|
|
33
|
-
ui: "@/components/ui",
|
|
34
|
-
components: "@/components",
|
|
35
|
-
lib: "@/lib",
|
|
36
|
-
hooks: "@/hooks"
|
|
37
|
-
};
|
|
38
|
-
var transformImports = (content, ctx) => {
|
|
39
|
-
if (!ctx.filename.endsWith(".ts") && !ctx.filename.endsWith(".tsx")) {
|
|
40
|
-
return content;
|
|
41
|
-
}
|
|
42
|
-
const { aliases } = ctx.config;
|
|
43
|
-
const rules = [];
|
|
44
|
-
if (aliases.utils !== DEFAULT_ALIASES.utils) {
|
|
45
|
-
rules.push({
|
|
46
|
-
type: "exact",
|
|
47
|
-
from: DEFAULT_ALIASES.utils,
|
|
48
|
-
to: aliases.utils
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (aliases.ui !== DEFAULT_ALIASES.ui) {
|
|
52
|
-
rules.push({ type: "prefix", from: DEFAULT_ALIASES.ui, to: aliases.ui });
|
|
53
|
-
}
|
|
54
|
-
if (aliases.components !== DEFAULT_ALIASES.components) {
|
|
55
|
-
rules.push({
|
|
56
|
-
type: "prefix",
|
|
57
|
-
from: DEFAULT_ALIASES.components,
|
|
58
|
-
to: aliases.components
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (aliases.lib !== DEFAULT_ALIASES.lib) {
|
|
62
|
-
rules.push({ type: "prefix", from: DEFAULT_ALIASES.lib, to: aliases.lib });
|
|
63
|
-
}
|
|
64
|
-
if (aliases.hooks !== DEFAULT_ALIASES.hooks) {
|
|
65
|
-
rules.push({
|
|
66
|
-
type: "prefix",
|
|
67
|
-
from: DEFAULT_ALIASES.hooks,
|
|
68
|
-
to: aliases.hooks
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (rules.length === 0) {
|
|
72
|
-
return content;
|
|
73
|
-
}
|
|
74
|
-
return content.replace(
|
|
75
|
-
/from\s+(["'])([^"']+)\1/g,
|
|
76
|
-
(match, quote, importPath) => {
|
|
77
|
-
for (const rule of rules) {
|
|
78
|
-
if (rule.type === "exact" && importPath === rule.from) {
|
|
79
|
-
return `from ${quote}${rule.to}${quote}`;
|
|
80
|
-
}
|
|
81
|
-
if (rule.type === "prefix" && importPath.startsWith(rule.from + "/")) {
|
|
82
|
-
const rest = importPath.slice(rule.from.length);
|
|
83
|
-
return `from ${quote}${rule.to}${rest}${quote}`;
|
|
84
|
-
}
|
|
85
|
-
if (rule.type === "prefix" && importPath === rule.from) {
|
|
86
|
-
return `from ${quote}${rule.to}${quote}`;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return match;
|
|
90
|
-
}
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// src/commands/add.ts
|
|
95
|
-
var transforms = [transformImports];
|
|
96
|
-
async function add(components, options) {
|
|
97
|
-
const cwd = options.cwd ? path.resolve(options.cwd) : process.cwd();
|
|
98
|
-
const configPath = findConfigPath(cwd);
|
|
99
|
-
if (!configPath) {
|
|
100
|
-
console.error(
|
|
101
|
-
` ${CROSS} ${CONFIG_FILE} not found. Run "stera-ui init" first.`
|
|
102
|
-
);
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
const config = loadConfig(cwd);
|
|
106
|
-
if (!config) {
|
|
107
|
-
console.error(` ${CROSS} Failed to parse ${CONFIG_FILE}.`);
|
|
108
|
-
process.exit(1);
|
|
109
|
-
}
|
|
110
|
-
const projectRoot = path.dirname(configPath);
|
|
111
|
-
if (components.includes("globals")) {
|
|
112
|
-
if (components.length > 1) {
|
|
113
|
-
console.error(
|
|
114
|
-
` ${CROSS} "stera-ui add globals" refreshes design tokens and cannot be combined with other components.`
|
|
115
|
-
);
|
|
116
|
-
console.error(
|
|
117
|
-
` Run "stera-ui add globals" and "stera-ui add ${components.filter((c) => c !== "globals").join(" ")}" separately.`
|
|
118
|
-
);
|
|
119
|
-
process.exit(1);
|
|
120
|
-
}
|
|
121
|
-
const spinner2 = createSpinner("Refreshing base styles");
|
|
122
|
-
let result;
|
|
123
|
-
let migrated = null;
|
|
124
|
-
try {
|
|
125
|
-
migrated = await migrateLegacyStyles(config, projectRoot);
|
|
126
|
-
result = await writeStyles(config, projectRoot, {
|
|
127
|
-
overwrite: options.overwrite
|
|
128
|
-
});
|
|
129
|
-
} catch (err) {
|
|
130
|
-
spinner2.fail("Failed to refresh base styles");
|
|
131
|
-
throw err;
|
|
132
|
-
}
|
|
133
|
-
spinner2.succeed(`Refreshed ${result.written.length} style files`);
|
|
134
|
-
if (migrated) {
|
|
135
|
-
console.log(
|
|
136
|
-
` ${CHECK} Migrated ${path.relative(projectRoot, migrated)} to ui/`
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
for (const target of result.written) {
|
|
140
|
-
console.log(` ${CHECK} ${target}`);
|
|
141
|
-
}
|
|
142
|
-
for (const file of result.skipped) {
|
|
143
|
-
const reason = file.reason === "unchanged" ? "unchanged" : "kept your version";
|
|
144
|
-
console.log(` ${dim(`- ${file.path} (${reason})`)}`);
|
|
145
|
-
}
|
|
146
|
-
console.log("");
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const spinner = createSpinner("Fetching registry");
|
|
150
|
-
let resolved;
|
|
151
|
-
try {
|
|
152
|
-
resolved = await resolveDependencies(components);
|
|
153
|
-
} catch (err) {
|
|
154
|
-
if (err instanceof ComponentNotFoundError) {
|
|
155
|
-
spinner.fail(err.message);
|
|
156
|
-
console.error(` Run "stera-ui list" to see available components.`);
|
|
157
|
-
process.exit(1);
|
|
158
|
-
}
|
|
159
|
-
spinner.fail("Failed to fetch registry");
|
|
160
|
-
throw err;
|
|
161
|
-
}
|
|
162
|
-
spinner.succeed("Registry resolved");
|
|
163
|
-
for (const item of resolved) {
|
|
164
|
-
for (const file of item.files ?? []) {
|
|
165
|
-
if (file.content) {
|
|
166
|
-
file.content = applyTransforms(
|
|
167
|
-
file.content,
|
|
168
|
-
{ config, filename: file.path },
|
|
169
|
-
transforms
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const allNpmDeps = [];
|
|
175
|
-
for (const item of resolved) {
|
|
176
|
-
if (item.dependencies) {
|
|
177
|
-
allNpmDeps.push(...item.dependencies);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const uniqueNpmDeps = [...new Set(allNpmDeps)].sort();
|
|
181
|
-
const { written, skipped } = await writeComponentFiles(
|
|
182
|
-
resolved,
|
|
183
|
-
config,
|
|
184
|
-
projectRoot,
|
|
185
|
-
{ overwrite: options.overwrite }
|
|
186
|
-
);
|
|
187
|
-
for (const file of written) {
|
|
188
|
-
console.log(` ${CHECK} ${file}`);
|
|
189
|
-
}
|
|
190
|
-
for (const file of skipped) {
|
|
191
|
-
const label = file.reason === "unchanged" ? "(unchanged)" : "(skipped)";
|
|
192
|
-
console.log(` ${dim(`\xB7 ${file.path} ${label}`)}`);
|
|
193
|
-
}
|
|
194
|
-
if (uniqueNpmDeps.length > 0) {
|
|
195
|
-
await installDependencies(uniqueNpmDeps, projectRoot);
|
|
196
|
-
}
|
|
197
|
-
console.log("");
|
|
198
|
-
}
|
|
199
|
-
export {
|
|
200
|
-
add
|
|
201
|
-
};
|
package/dist/chunk-4E46BULJ.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// src/schema/index.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
var registryItemTypeSchema = z.enum([
|
|
4
|
-
"registry:ui",
|
|
5
|
-
"registry:component",
|
|
6
|
-
"registry:hook",
|
|
7
|
-
"registry:lib",
|
|
8
|
-
"registry:style",
|
|
9
|
-
"registry:font"
|
|
10
|
-
]);
|
|
11
|
-
var registryItemFileSchema = z.object({
|
|
12
|
-
path: z.string(),
|
|
13
|
-
type: registryItemTypeSchema,
|
|
14
|
-
content: z.string().optional(),
|
|
15
|
-
target: z.string().optional()
|
|
16
|
-
});
|
|
17
|
-
var registryItemFontSchema = z.object({
|
|
18
|
-
family: z.string(),
|
|
19
|
-
provider: z.literal("google"),
|
|
20
|
-
import: z.string(),
|
|
21
|
-
variable: z.string(),
|
|
22
|
-
weight: z.array(z.string()).optional(),
|
|
23
|
-
subsets: z.array(z.string()).optional(),
|
|
24
|
-
selector: z.string().optional(),
|
|
25
|
-
dependency: z.string().optional()
|
|
26
|
-
});
|
|
27
|
-
var registryItemCommonSchema = z.object({
|
|
28
|
-
name: z.string(),
|
|
29
|
-
dependencies: z.array(z.string()).optional(),
|
|
30
|
-
registryDependencies: z.array(z.string()).optional(),
|
|
31
|
-
files: z.array(registryItemFileSchema).optional()
|
|
32
|
-
});
|
|
33
|
-
var registryItemSchema = z.discriminatedUnion("type", [
|
|
34
|
-
registryItemCommonSchema.extend({
|
|
35
|
-
type: z.literal("registry:font"),
|
|
36
|
-
font: registryItemFontSchema,
|
|
37
|
-
files: z.array(registryItemFileSchema).optional()
|
|
38
|
-
}),
|
|
39
|
-
registryItemCommonSchema.extend({
|
|
40
|
-
type: registryItemTypeSchema.exclude(["registry:font"]),
|
|
41
|
-
files: z.array(registryItemFileSchema)
|
|
42
|
-
})
|
|
43
|
-
]);
|
|
44
|
-
var registryIndexEntrySchema = z.object({
|
|
45
|
-
name: z.string(),
|
|
46
|
-
type: z.string(),
|
|
47
|
-
dependencies: z.array(z.string()).optional(),
|
|
48
|
-
registryDependencies: z.array(z.string()).optional()
|
|
49
|
-
});
|
|
50
|
-
var registryIndexSchema = z.object({
|
|
51
|
-
name: z.string(),
|
|
52
|
-
items: z.array(registryIndexEntrySchema)
|
|
53
|
-
});
|
|
54
|
-
var configSchema = z.object({
|
|
55
|
-
$schema: z.string().optional(),
|
|
56
|
-
version: z.literal(1),
|
|
57
|
-
css: z.string(),
|
|
58
|
-
aliases: z.object({
|
|
59
|
-
components: z.string(),
|
|
60
|
-
utils: z.string(),
|
|
61
|
-
ui: z.string(),
|
|
62
|
-
lib: z.string(),
|
|
63
|
-
hooks: z.string()
|
|
64
|
-
}),
|
|
65
|
-
fonts: z.object({
|
|
66
|
-
strategy: z.enum(["stera-default", "keep-existing", "skip"]),
|
|
67
|
-
nextFont: z.boolean().optional()
|
|
68
|
-
}).optional()
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
export {
|
|
72
|
-
registryItemTypeSchema,
|
|
73
|
-
registryItemFileSchema,
|
|
74
|
-
registryItemFontSchema,
|
|
75
|
-
registryItemSchema,
|
|
76
|
-
registryIndexEntrySchema,
|
|
77
|
-
registryIndexSchema,
|
|
78
|
-
configSchema
|
|
79
|
-
};
|
package/dist/chunk-BJNLGEZJ.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
registryIndexSchema,
|
|
3
|
-
registryItemSchema
|
|
4
|
-
} from "./chunk-4E46BULJ.js";
|
|
5
|
-
|
|
6
|
-
// src/registry/index.ts
|
|
7
|
-
var REGISTRY_URL = process.env.REGISTRY_URL ?? "https://ui.stera.sh/r";
|
|
8
|
-
var FETCH_TIMEOUT_MS = 15e3;
|
|
9
|
-
var ComponentNotFoundError = class extends Error {
|
|
10
|
-
components;
|
|
11
|
-
constructor(components) {
|
|
12
|
-
super(
|
|
13
|
-
components.length === 1 ? `Component "${components[0]}" not found in registry.` : `Components not found in registry: ${components.map((c) => `"${c}"`).join(", ")}.`
|
|
14
|
-
);
|
|
15
|
-
this.name = "ComponentNotFoundError";
|
|
16
|
-
this.components = components;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var _indexCache = null;
|
|
20
|
-
async function fetchJSON(url) {
|
|
21
|
-
let res;
|
|
22
|
-
try {
|
|
23
|
-
res = await fetch(url, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
24
|
-
} catch (err) {
|
|
25
|
-
if (err instanceof Error && err.name === "TimeoutError") {
|
|
26
|
-
throw new Error(
|
|
27
|
-
`Timed out fetching ${url} after ${FETCH_TIMEOUT_MS / 1e3}s. Check your network connection.`
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
throw new Error(
|
|
31
|
-
`Failed to fetch ${url}: ${err instanceof Error ? err.message : String(err)}`
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
if (!res.ok) {
|
|
35
|
-
throw new Error(`Failed to fetch ${url}: ${res.status} ${res.statusText}`);
|
|
36
|
-
}
|
|
37
|
-
return res.json();
|
|
38
|
-
}
|
|
39
|
-
async function fetchRegistryIndex() {
|
|
40
|
-
if (_indexCache) return _indexCache;
|
|
41
|
-
const data = await fetchJSON(`${REGISTRY_URL}/index.json`);
|
|
42
|
-
const parsed = registryIndexSchema.safeParse(data);
|
|
43
|
-
if (!parsed.success) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
`Registry index at ${REGISTRY_URL}/index.json returned unexpected data.`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
_indexCache = parsed.data.items;
|
|
49
|
-
return _indexCache;
|
|
50
|
-
}
|
|
51
|
-
async function fetchRegistryItem(name) {
|
|
52
|
-
const data = await fetchJSON(`${REGISTRY_URL}/${name}.json`);
|
|
53
|
-
const parsed = registryItemSchema.safeParse(data);
|
|
54
|
-
if (!parsed.success) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
`Registry item "${name}" returned unexpected data from ${REGISTRY_URL}/${name}.json.`
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
return parsed.data;
|
|
60
|
-
}
|
|
61
|
-
async function getComponent(name) {
|
|
62
|
-
const index = await fetchRegistryIndex();
|
|
63
|
-
return index.find((item) => item.name === name);
|
|
64
|
-
}
|
|
65
|
-
async function getAllComponents() {
|
|
66
|
-
return fetchRegistryIndex();
|
|
67
|
-
}
|
|
68
|
-
async function resolveDependencies(names) {
|
|
69
|
-
const index = await fetchRegistryIndex();
|
|
70
|
-
const byName = new Map(index.map((entry) => [entry.name, entry]));
|
|
71
|
-
const needed = [];
|
|
72
|
-
const seen = /* @__PURE__ */ new Set();
|
|
73
|
-
const missing = [];
|
|
74
|
-
const queue = [...names];
|
|
75
|
-
while (queue.length > 0) {
|
|
76
|
-
const name = queue.shift();
|
|
77
|
-
if (seen.has(name)) continue;
|
|
78
|
-
seen.add(name);
|
|
79
|
-
const entry = byName.get(name);
|
|
80
|
-
if (!entry) {
|
|
81
|
-
missing.push(name);
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
needed.push(name);
|
|
85
|
-
queue.push(...entry.registryDependencies ?? []);
|
|
86
|
-
}
|
|
87
|
-
if (missing.length > 0) {
|
|
88
|
-
throw new ComponentNotFoundError(missing);
|
|
89
|
-
}
|
|
90
|
-
return Promise.all(needed.map((name) => fetchRegistryItem(name)));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export {
|
|
94
|
-
ComponentNotFoundError,
|
|
95
|
-
fetchRegistryIndex,
|
|
96
|
-
fetchRegistryItem,
|
|
97
|
-
getComponent,
|
|
98
|
-
getAllComponents,
|
|
99
|
-
resolveDependencies
|
|
100
|
-
};
|
package/dist/chunk-KGMF6UW4.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/utils/format.ts
|
|
4
|
-
var BRAND = "\x1B[38;2;166;244;48m";
|
|
5
|
-
var DIM = "\x1B[2m";
|
|
6
|
-
var RESET = "\x1B[0m";
|
|
7
|
-
var enabled = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
8
|
-
var wrap = (code, text) => enabled ? `${code}${text}${RESET}` : text;
|
|
9
|
-
var brand = (text) => wrap(BRAND, text);
|
|
10
|
-
var dim = (text) => wrap(DIM, text);
|
|
11
|
-
var LOGO = brand("\u273B");
|
|
12
|
-
var CHECK = brand("\u2713");
|
|
13
|
-
var CROSS = "\u2717";
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
brand,
|
|
17
|
-
dim,
|
|
18
|
-
LOGO,
|
|
19
|
-
CHECK,
|
|
20
|
-
CROSS
|
|
21
|
-
};
|
package/dist/chunk-KKUJRJ2N.js
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
CHECK,
|
|
4
|
-
CROSS,
|
|
5
|
-
brand
|
|
6
|
-
} from "./chunk-KGMF6UW4.js";
|
|
7
|
-
|
|
8
|
-
// src/schema/index.ts
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
var registryItemTypeSchema = z.enum([
|
|
11
|
-
"registry:ui",
|
|
12
|
-
"registry:component",
|
|
13
|
-
"registry:hook",
|
|
14
|
-
"registry:lib",
|
|
15
|
-
"registry:style",
|
|
16
|
-
"registry:font"
|
|
17
|
-
]);
|
|
18
|
-
var registryItemFileSchema = z.object({
|
|
19
|
-
path: z.string(),
|
|
20
|
-
type: registryItemTypeSchema,
|
|
21
|
-
content: z.string().optional(),
|
|
22
|
-
target: z.string().optional()
|
|
23
|
-
});
|
|
24
|
-
var registryItemFontSchema = z.object({
|
|
25
|
-
family: z.string(),
|
|
26
|
-
provider: z.literal("google"),
|
|
27
|
-
import: z.string(),
|
|
28
|
-
variable: z.string(),
|
|
29
|
-
weight: z.array(z.string()).optional(),
|
|
30
|
-
subsets: z.array(z.string()).optional(),
|
|
31
|
-
selector: z.string().optional(),
|
|
32
|
-
dependency: z.string().optional()
|
|
33
|
-
});
|
|
34
|
-
var registryItemCommonSchema = z.object({
|
|
35
|
-
name: z.string(),
|
|
36
|
-
dependencies: z.array(z.string()).optional(),
|
|
37
|
-
registryDependencies: z.array(z.string()).optional(),
|
|
38
|
-
files: z.array(registryItemFileSchema).optional()
|
|
39
|
-
});
|
|
40
|
-
var registryItemSchema = z.discriminatedUnion("type", [
|
|
41
|
-
registryItemCommonSchema.extend({
|
|
42
|
-
type: z.literal("registry:font"),
|
|
43
|
-
font: registryItemFontSchema,
|
|
44
|
-
files: z.array(registryItemFileSchema).optional()
|
|
45
|
-
}),
|
|
46
|
-
registryItemCommonSchema.extend({
|
|
47
|
-
type: registryItemTypeSchema.exclude(["registry:font"]),
|
|
48
|
-
files: z.array(registryItemFileSchema)
|
|
49
|
-
})
|
|
50
|
-
]);
|
|
51
|
-
var registryIndexEntrySchema = z.object({
|
|
52
|
-
name: z.string(),
|
|
53
|
-
type: z.string(),
|
|
54
|
-
dependencies: z.array(z.string()).optional(),
|
|
55
|
-
registryDependencies: z.array(z.string()).optional()
|
|
56
|
-
});
|
|
57
|
-
var registryIndexSchema = z.object({
|
|
58
|
-
name: z.string(),
|
|
59
|
-
items: z.array(registryIndexEntrySchema)
|
|
60
|
-
});
|
|
61
|
-
var configSchema = z.object({
|
|
62
|
-
$schema: z.string().optional(),
|
|
63
|
-
version: z.literal(1),
|
|
64
|
-
css: z.string(),
|
|
65
|
-
aliases: z.object({
|
|
66
|
-
components: z.string(),
|
|
67
|
-
utils: z.string(),
|
|
68
|
-
ui: z.string(),
|
|
69
|
-
lib: z.string(),
|
|
70
|
-
hooks: z.string()
|
|
71
|
-
}),
|
|
72
|
-
fonts: z.object({
|
|
73
|
-
strategy: z.enum(["stera-default", "keep-existing", "skip"]),
|
|
74
|
-
nextFont: z.boolean().optional()
|
|
75
|
-
}).optional()
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// src/registry/index.ts
|
|
79
|
-
var REGISTRY_URL = process.env.REGISTRY_URL ?? "https://ui.stera.sh/r";
|
|
80
|
-
var FETCH_TIMEOUT_MS = 15e3;
|
|
81
|
-
var ComponentNotFoundError = class extends Error {
|
|
82
|
-
components;
|
|
83
|
-
constructor(components) {
|
|
84
|
-
super(
|
|
85
|
-
components.length === 1 ? `Component "${components[0]}" not found in registry.` : `Components not found in registry: ${components.map((c) => `"${c}"`).join(", ")}.`
|
|
86
|
-
);
|
|
87
|
-
this.name = "ComponentNotFoundError";
|
|
88
|
-
this.components = components;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
var _indexCache = null;
|
|
92
|
-
async function fetchJSON(url) {
|
|
93
|
-
let res;
|
|
94
|
-
try {
|
|
95
|
-
res = await fetch(url, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
96
|
-
} catch (err) {
|
|
97
|
-
if (err instanceof Error && err.name === "TimeoutError") {
|
|
98
|
-
throw new Error(
|
|
99
|
-
`Timed out fetching ${url} after ${FETCH_TIMEOUT_MS / 1e3}s. Check your network connection.`
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
throw new Error(
|
|
103
|
-
`Failed to fetch ${url}: ${err instanceof Error ? err.message : String(err)}`
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
if (!res.ok) {
|
|
107
|
-
throw new Error(`Failed to fetch ${url}: ${res.status} ${res.statusText}`);
|
|
108
|
-
}
|
|
109
|
-
return res.json();
|
|
110
|
-
}
|
|
111
|
-
async function fetchRegistryIndex() {
|
|
112
|
-
if (_indexCache) return _indexCache;
|
|
113
|
-
const data = await fetchJSON(`${REGISTRY_URL}/index.json`);
|
|
114
|
-
const parsed = registryIndexSchema.safeParse(data);
|
|
115
|
-
if (!parsed.success) {
|
|
116
|
-
throw new Error(
|
|
117
|
-
`Registry index at ${REGISTRY_URL}/index.json returned unexpected data.`
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
_indexCache = parsed.data.items;
|
|
121
|
-
return _indexCache;
|
|
122
|
-
}
|
|
123
|
-
async function fetchRegistryItem(name) {
|
|
124
|
-
const data = await fetchJSON(`${REGISTRY_URL}/${name}.json`);
|
|
125
|
-
const parsed = registryItemSchema.safeParse(data);
|
|
126
|
-
if (!parsed.success) {
|
|
127
|
-
throw new Error(
|
|
128
|
-
`Registry item "${name}" returned unexpected data from ${REGISTRY_URL}/${name}.json.`
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
return parsed.data;
|
|
132
|
-
}
|
|
133
|
-
async function getAllComponents() {
|
|
134
|
-
return fetchRegistryIndex();
|
|
135
|
-
}
|
|
136
|
-
async function resolveDependencies(names) {
|
|
137
|
-
const index = await fetchRegistryIndex();
|
|
138
|
-
const byName = new Map(index.map((entry) => [entry.name, entry]));
|
|
139
|
-
const needed = [];
|
|
140
|
-
const seen = /* @__PURE__ */ new Set();
|
|
141
|
-
const missing = [];
|
|
142
|
-
const queue = [...names];
|
|
143
|
-
while (queue.length > 0) {
|
|
144
|
-
const name = queue.shift();
|
|
145
|
-
if (seen.has(name)) continue;
|
|
146
|
-
seen.add(name);
|
|
147
|
-
const entry = byName.get(name);
|
|
148
|
-
if (!entry) {
|
|
149
|
-
missing.push(name);
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
needed.push(name);
|
|
153
|
-
queue.push(...entry.registryDependencies ?? []);
|
|
154
|
-
}
|
|
155
|
-
if (missing.length > 0) {
|
|
156
|
-
throw new ComponentNotFoundError(missing);
|
|
157
|
-
}
|
|
158
|
-
return Promise.all(needed.map((name) => fetchRegistryItem(name)));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// src/utils/spinner.ts
|
|
162
|
-
var FRAMES = ["\u2022", "\u2726", "\u2736", "\u273B"].map(brand);
|
|
163
|
-
var INTERVAL_MS = 150;
|
|
164
|
-
function createSpinner(text) {
|
|
165
|
-
const isTTY = process.stdout.isTTY;
|
|
166
|
-
if (!isTTY) {
|
|
167
|
-
process.stdout.write(` ${text}...
|
|
168
|
-
`);
|
|
169
|
-
return {
|
|
170
|
-
succeed(msg) {
|
|
171
|
-
process.stdout.write(` ${CHECK} ${msg}
|
|
172
|
-
`);
|
|
173
|
-
},
|
|
174
|
-
fail(msg) {
|
|
175
|
-
process.stdout.write(` ${CROSS} ${msg}
|
|
176
|
-
`);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
let frameIndex = 0;
|
|
181
|
-
const interval = setInterval(() => {
|
|
182
|
-
process.stdout.write(`\r ${FRAMES[frameIndex % FRAMES.length]} ${text}`);
|
|
183
|
-
frameIndex++;
|
|
184
|
-
}, INTERVAL_MS);
|
|
185
|
-
const clear = () => {
|
|
186
|
-
clearInterval(interval);
|
|
187
|
-
process.stdout.write("\r" + " ".repeat(text.length + 6) + "\r");
|
|
188
|
-
};
|
|
189
|
-
return {
|
|
190
|
-
succeed(msg) {
|
|
191
|
-
clear();
|
|
192
|
-
process.stdout.write(` ${CHECK} ${msg}
|
|
193
|
-
`);
|
|
194
|
-
},
|
|
195
|
-
fail(msg) {
|
|
196
|
-
clear();
|
|
197
|
-
process.stdout.write(` ${CROSS} ${msg}
|
|
198
|
-
`);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export {
|
|
204
|
-
ComponentNotFoundError,
|
|
205
|
-
fetchRegistryItem,
|
|
206
|
-
getAllComponents,
|
|
207
|
-
resolveDependencies,
|
|
208
|
-
createSpinner
|
|
209
|
-
};
|