stera-ui 0.5.0 → 0.6.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-JUBSRCDJ.js +304 -0
- package/dist/chunk-2Y64FOD3.js +161 -0
- package/dist/{chunk-3KADOWKC.js → chunk-4E46BULJ.js} +8 -1
- package/dist/chunk-BJNLGEZJ.js +100 -0
- package/dist/chunk-KGMF6UW4.js +21 -0
- package/dist/chunk-KKUJRJ2N.js +209 -0
- package/dist/{chunk-F4NT3JC6.js → chunk-SIXUH4HI.js} +47 -20
- package/dist/cli.js +19 -1339
- package/dist/index.d.ts +3 -3
- package/dist/index.js +14 -10
- package/dist/init-E7O5WAUI.js +796 -0
- package/dist/list-M73QTIWR.js +44 -0
- package/dist/registry/index.d.ts +16 -10
- package/dist/registry/index.js +4 -1
- package/dist/schema/index.d.ts +29 -187
- package/dist/schema/index.js +3 -1
- package/dist/utils/index.d.ts +7 -2
- package/dist/utils/index.js +3 -2
- package/package.json +2 -2
- package/dist/chunk-T3QWOVJR.js +0 -60
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
CONFIG_FILE,
|
|
4
|
+
findConfigPath,
|
|
5
|
+
installDependencies,
|
|
6
|
+
loadConfig,
|
|
7
|
+
writeSteraUiCss
|
|
8
|
+
} from "./chunk-2Y64FOD3.js";
|
|
9
|
+
import {
|
|
10
|
+
ComponentNotFoundError,
|
|
11
|
+
createSpinner,
|
|
12
|
+
resolveDependencies
|
|
13
|
+
} from "./chunk-KKUJRJ2N.js";
|
|
14
|
+
import {
|
|
15
|
+
CHECK,
|
|
16
|
+
CROSS,
|
|
17
|
+
dim
|
|
18
|
+
} from "./chunk-KGMF6UW4.js";
|
|
19
|
+
|
|
20
|
+
// src/commands/add.ts
|
|
21
|
+
import path3 from "path";
|
|
22
|
+
|
|
23
|
+
// src/utils/write-files.ts
|
|
24
|
+
import fs from "fs";
|
|
25
|
+
import path2 from "path";
|
|
26
|
+
import { confirm } from "@inquirer/prompts";
|
|
27
|
+
|
|
28
|
+
// src/utils/resolve-paths.ts
|
|
29
|
+
import path from "path";
|
|
30
|
+
import { loadConfig as loadConfig2, createMatchPath } from "tsconfig-paths";
|
|
31
|
+
var TYPE_TO_ALIAS = {
|
|
32
|
+
"registry:ui": "ui",
|
|
33
|
+
"registry:lib": "lib",
|
|
34
|
+
"registry:hook": "hooks",
|
|
35
|
+
"registry:component": "components"
|
|
36
|
+
};
|
|
37
|
+
var matcherCache = /* @__PURE__ */ new Map();
|
|
38
|
+
function getTsConfigMatcher(projectRoot) {
|
|
39
|
+
let matcher = matcherCache.get(projectRoot);
|
|
40
|
+
if (matcher !== void 0) return matcher;
|
|
41
|
+
const tsConfig = loadConfig2(projectRoot);
|
|
42
|
+
matcher = tsConfig.resultType === "success" && Object.keys(tsConfig.paths).length > 0 ? {
|
|
43
|
+
paths: tsConfig.paths,
|
|
44
|
+
match: createMatchPath(tsConfig.absoluteBaseUrl, tsConfig.paths)
|
|
45
|
+
} : null;
|
|
46
|
+
matcherCache.set(projectRoot, matcher);
|
|
47
|
+
return matcher;
|
|
48
|
+
}
|
|
49
|
+
function resolveAlias(alias, projectRoot) {
|
|
50
|
+
const matcher = getTsConfigMatcher(projectRoot);
|
|
51
|
+
if (matcher) {
|
|
52
|
+
const hasMatchingPrefix = Object.keys(matcher.paths).some((key) => {
|
|
53
|
+
const prefix = key.replace(/\/\*$/, "");
|
|
54
|
+
return alias === prefix || alias.startsWith(`${prefix}/`);
|
|
55
|
+
});
|
|
56
|
+
if (hasMatchingPrefix) {
|
|
57
|
+
const resolved = matcher.match(alias, void 0, () => true, [
|
|
58
|
+
".ts",
|
|
59
|
+
".tsx"
|
|
60
|
+
]);
|
|
61
|
+
if (resolved) {
|
|
62
|
+
return path.relative(projectRoot, resolved);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Could not resolve alias "${alias}" from tsconfig.json. Ensure compilerOptions.paths defines a mapping for it (e.g. "${alias}/*"), then re-run. See https://ui.stera.sh/docs/installation.`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
function resolveOutputPath(config, projectRoot, file) {
|
|
71
|
+
const alias = TYPE_TO_ALIAS[file.type];
|
|
72
|
+
if (alias) {
|
|
73
|
+
const dir = resolveAlias(config.aliases[alias], projectRoot);
|
|
74
|
+
const filename = path.basename(file.path);
|
|
75
|
+
return path.join(projectRoot, dir, filename);
|
|
76
|
+
}
|
|
77
|
+
if (file.type === "registry:style") {
|
|
78
|
+
const cssDir = path.dirname(config.css);
|
|
79
|
+
const filename = path.basename(file.path);
|
|
80
|
+
return path.join(projectRoot, cssDir, filename);
|
|
81
|
+
}
|
|
82
|
+
return path.join(projectRoot, file.path);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/utils/write-files.ts
|
|
86
|
+
async function confirmOverwrite(relativePath) {
|
|
87
|
+
if (!process.stdin.isTTY) {
|
|
88
|
+
console.log(
|
|
89
|
+
` Skipping ${relativePath} (already exists, use --overwrite to replace)`
|
|
90
|
+
);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return confirm({
|
|
94
|
+
message: `${relativePath} already exists. Overwrite?`,
|
|
95
|
+
default: false
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async function writeComponentFiles(items, config, projectRoot, options = {}) {
|
|
99
|
+
const written = [];
|
|
100
|
+
const skipped = [];
|
|
101
|
+
for (const item of items) {
|
|
102
|
+
for (const file of item.files ?? []) {
|
|
103
|
+
const outputPath = resolveOutputPath(config, projectRoot, file);
|
|
104
|
+
const relativePath = path2.relative(projectRoot, outputPath);
|
|
105
|
+
if (fs.existsSync(outputPath)) {
|
|
106
|
+
const existing = fs.readFileSync(outputPath, "utf-8");
|
|
107
|
+
if (existing === file.content) {
|
|
108
|
+
skipped.push({ path: relativePath, reason: "unchanged" });
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (!options.overwrite) {
|
|
112
|
+
const confirmed = await confirmOverwrite(relativePath);
|
|
113
|
+
if (!confirmed) {
|
|
114
|
+
skipped.push({ path: relativePath, reason: "declined" });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const dir = path2.dirname(outputPath);
|
|
120
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
121
|
+
fs.writeFileSync(outputPath, file.content ?? "", "utf-8");
|
|
122
|
+
written.push(relativePath);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { written, skipped };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/utils/transform.ts
|
|
129
|
+
function applyTransforms(content, ctx, transforms2) {
|
|
130
|
+
return transforms2.reduce((acc, fn) => fn(acc, ctx), content);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/utils/transform-imports.ts
|
|
134
|
+
var DEFAULT_ALIASES = {
|
|
135
|
+
utils: "@/lib/utils",
|
|
136
|
+
ui: "@/components/ui",
|
|
137
|
+
components: "@/components",
|
|
138
|
+
lib: "@/lib",
|
|
139
|
+
hooks: "@/hooks"
|
|
140
|
+
};
|
|
141
|
+
var transformImports = (content, ctx) => {
|
|
142
|
+
if (!ctx.filename.endsWith(".ts") && !ctx.filename.endsWith(".tsx")) {
|
|
143
|
+
return content;
|
|
144
|
+
}
|
|
145
|
+
const { aliases } = ctx.config;
|
|
146
|
+
const rules = [];
|
|
147
|
+
if (aliases.utils !== DEFAULT_ALIASES.utils) {
|
|
148
|
+
rules.push({
|
|
149
|
+
type: "exact",
|
|
150
|
+
from: DEFAULT_ALIASES.utils,
|
|
151
|
+
to: aliases.utils
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (aliases.ui !== DEFAULT_ALIASES.ui) {
|
|
155
|
+
rules.push({ type: "prefix", from: DEFAULT_ALIASES.ui, to: aliases.ui });
|
|
156
|
+
}
|
|
157
|
+
if (aliases.components !== DEFAULT_ALIASES.components) {
|
|
158
|
+
rules.push({
|
|
159
|
+
type: "prefix",
|
|
160
|
+
from: DEFAULT_ALIASES.components,
|
|
161
|
+
to: aliases.components
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (aliases.lib !== DEFAULT_ALIASES.lib) {
|
|
165
|
+
rules.push({ type: "prefix", from: DEFAULT_ALIASES.lib, to: aliases.lib });
|
|
166
|
+
}
|
|
167
|
+
if (aliases.hooks !== DEFAULT_ALIASES.hooks) {
|
|
168
|
+
rules.push({
|
|
169
|
+
type: "prefix",
|
|
170
|
+
from: DEFAULT_ALIASES.hooks,
|
|
171
|
+
to: aliases.hooks
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (rules.length === 0) {
|
|
175
|
+
return content;
|
|
176
|
+
}
|
|
177
|
+
return content.replace(
|
|
178
|
+
/from\s+(["'])([^"']+)\1/g,
|
|
179
|
+
(match, quote, importPath) => {
|
|
180
|
+
for (const rule of rules) {
|
|
181
|
+
if (rule.type === "exact" && importPath === rule.from) {
|
|
182
|
+
return `from ${quote}${rule.to}${quote}`;
|
|
183
|
+
}
|
|
184
|
+
if (rule.type === "prefix" && importPath.startsWith(rule.from + "/")) {
|
|
185
|
+
const rest = importPath.slice(rule.from.length);
|
|
186
|
+
return `from ${quote}${rule.to}${rest}${quote}`;
|
|
187
|
+
}
|
|
188
|
+
if (rule.type === "prefix" && importPath === rule.from) {
|
|
189
|
+
return `from ${quote}${rule.to}${quote}`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return match;
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/commands/add.ts
|
|
198
|
+
var transforms = [transformImports];
|
|
199
|
+
async function add(components, options) {
|
|
200
|
+
const cwd = options.cwd ? path3.resolve(options.cwd) : process.cwd();
|
|
201
|
+
const configPath = findConfigPath(cwd);
|
|
202
|
+
if (!configPath) {
|
|
203
|
+
console.error(
|
|
204
|
+
` ${CROSS} ${CONFIG_FILE} not found. Run "stera-ui init" first.`
|
|
205
|
+
);
|
|
206
|
+
process.exit(1);
|
|
207
|
+
}
|
|
208
|
+
const config = loadConfig(cwd);
|
|
209
|
+
if (!config) {
|
|
210
|
+
console.error(` ${CROSS} Failed to parse ${CONFIG_FILE}.`);
|
|
211
|
+
process.exit(1);
|
|
212
|
+
}
|
|
213
|
+
const projectRoot = path3.dirname(configPath);
|
|
214
|
+
if (components.includes("globals")) {
|
|
215
|
+
if (components.length > 1) {
|
|
216
|
+
console.error(
|
|
217
|
+
` ${CROSS} "stera-ui add globals" refreshes design tokens and cannot be combined with other components.`
|
|
218
|
+
);
|
|
219
|
+
console.error(
|
|
220
|
+
` Run "stera-ui add globals" and "stera-ui add ${components.filter((c) => c !== "globals").join(" ")}" separately.`
|
|
221
|
+
);
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
const spinner2 = createSpinner("Refreshing base styles");
|
|
225
|
+
let result;
|
|
226
|
+
try {
|
|
227
|
+
result = await writeSteraUiCss(config, projectRoot);
|
|
228
|
+
} catch (err) {
|
|
229
|
+
spinner2.fail("Failed to refresh base styles");
|
|
230
|
+
throw err;
|
|
231
|
+
}
|
|
232
|
+
spinner2.succeed(
|
|
233
|
+
`Refreshed ${path3.relative(projectRoot, result.steraUiPath)}`
|
|
234
|
+
);
|
|
235
|
+
console.log("");
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const spinner = createSpinner("Fetching registry");
|
|
239
|
+
let resolved;
|
|
240
|
+
try {
|
|
241
|
+
resolved = await resolveDependencies(components);
|
|
242
|
+
} catch (err) {
|
|
243
|
+
if (err instanceof ComponentNotFoundError) {
|
|
244
|
+
spinner.fail(err.message);
|
|
245
|
+
console.error(` Run "stera-ui list" to see available components.`);
|
|
246
|
+
process.exit(1);
|
|
247
|
+
}
|
|
248
|
+
spinner.fail("Failed to fetch registry");
|
|
249
|
+
throw err;
|
|
250
|
+
}
|
|
251
|
+
spinner.succeed("Registry resolved");
|
|
252
|
+
for (const item of resolved) {
|
|
253
|
+
for (const file of item.files ?? []) {
|
|
254
|
+
if (file.content) {
|
|
255
|
+
file.content = applyTransforms(
|
|
256
|
+
file.content,
|
|
257
|
+
{ config, filename: file.path },
|
|
258
|
+
transforms
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const requested = new Set(components);
|
|
264
|
+
console.log("\n Installing components\n");
|
|
265
|
+
for (const item of resolved) {
|
|
266
|
+
const tag = requested.has(item.name) ? "" : dim(" (dependency)");
|
|
267
|
+
console.log(` \u2192 ${item.name}${tag}`);
|
|
268
|
+
}
|
|
269
|
+
const allNpmDeps = [];
|
|
270
|
+
for (const item of resolved) {
|
|
271
|
+
if (item.dependencies) {
|
|
272
|
+
allNpmDeps.push(...item.dependencies);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const uniqueNpmDeps = [...new Set(allNpmDeps)].sort();
|
|
276
|
+
if (uniqueNpmDeps.length > 0) {
|
|
277
|
+
console.log("\n npm packages\n");
|
|
278
|
+
for (const dep of uniqueNpmDeps) {
|
|
279
|
+
console.log(` \u2192 ${dep}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
console.log("");
|
|
283
|
+
const { written, skipped } = await writeComponentFiles(
|
|
284
|
+
resolved,
|
|
285
|
+
config,
|
|
286
|
+
projectRoot,
|
|
287
|
+
{ overwrite: options.overwrite }
|
|
288
|
+
);
|
|
289
|
+
for (const file of written) {
|
|
290
|
+
console.log(` ${CHECK} ${file}`);
|
|
291
|
+
}
|
|
292
|
+
for (const file of skipped) {
|
|
293
|
+
const label = file.reason === "unchanged" ? "(unchanged)" : "(skipped)";
|
|
294
|
+
console.log(` ${dim(`\xB7 ${file.path} ${label}`)}`);
|
|
295
|
+
}
|
|
296
|
+
if (uniqueNpmDeps.length > 0) {
|
|
297
|
+
console.log("");
|
|
298
|
+
await installDependencies(uniqueNpmDeps, projectRoot);
|
|
299
|
+
}
|
|
300
|
+
console.log("");
|
|
301
|
+
}
|
|
302
|
+
export {
|
|
303
|
+
add
|
|
304
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
createSpinner,
|
|
4
|
+
fetchRegistryItem
|
|
5
|
+
} from "./chunk-KKUJRJ2N.js";
|
|
6
|
+
|
|
7
|
+
// src/utils/resolve-config.ts
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
var CONFIG_FILE = "stera.config.json";
|
|
11
|
+
var LEGACY_CONFIG_FILE = "components.json";
|
|
12
|
+
function migrateConfig(raw) {
|
|
13
|
+
if (!("version" in raw) && "tailwind" in raw) {
|
|
14
|
+
const legacy = raw;
|
|
15
|
+
return {
|
|
16
|
+
version: 1,
|
|
17
|
+
css: legacy.tailwind.css || "src/styles/globals.css",
|
|
18
|
+
aliases: legacy.aliases
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return raw;
|
|
22
|
+
}
|
|
23
|
+
var warnedLegacyFilename = false;
|
|
24
|
+
function warnLegacyFilenameOnce(legacyPath) {
|
|
25
|
+
if (warnedLegacyFilename) return;
|
|
26
|
+
warnedLegacyFilename = true;
|
|
27
|
+
console.warn(
|
|
28
|
+
` \u26A0 Found ${LEGACY_CONFIG_FILE}. Rename to ${CONFIG_FILE} \u2014 legacy filename support will be removed in a future release.
|
|
29
|
+
(${legacyPath})`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function findConfigPath(cwd) {
|
|
33
|
+
let dir = path.resolve(cwd);
|
|
34
|
+
while (true) {
|
|
35
|
+
const configPath = path.join(dir, CONFIG_FILE);
|
|
36
|
+
if (fs.existsSync(configPath)) return configPath;
|
|
37
|
+
const legacyPath = path.join(dir, LEGACY_CONFIG_FILE);
|
|
38
|
+
if (fs.existsSync(legacyPath)) return legacyPath;
|
|
39
|
+
const parent = path.dirname(dir);
|
|
40
|
+
if (parent === dir) return null;
|
|
41
|
+
dir = parent;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function loadConfig(cwd) {
|
|
45
|
+
const configPath = findConfigPath(cwd);
|
|
46
|
+
if (!configPath) return null;
|
|
47
|
+
if (path.basename(configPath) === LEGACY_CONFIG_FILE) {
|
|
48
|
+
warnLegacyFilenameOnce(configPath);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const raw = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
52
|
+
return migrateConfig(raw);
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/utils/install-deps.ts
|
|
59
|
+
import fs2 from "fs";
|
|
60
|
+
import path2 from "path";
|
|
61
|
+
import { detect } from "@antfu/ni";
|
|
62
|
+
import { execa } from "execa";
|
|
63
|
+
async function detectPackageManager(cwd) {
|
|
64
|
+
const detected = await detect({ programmatic: true, cwd });
|
|
65
|
+
if (detected === "pnpm@6" || detected === "pnpm") return "pnpm";
|
|
66
|
+
if (detected === "yarn@berry" || detected === "yarn") return "yarn";
|
|
67
|
+
if (detected === "bun") return "bun";
|
|
68
|
+
if (detected === "npm") return "npm";
|
|
69
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
70
|
+
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
71
|
+
if (userAgent.startsWith("yarn")) return "yarn";
|
|
72
|
+
if (userAgent.startsWith("bun")) return "bun";
|
|
73
|
+
return "npm";
|
|
74
|
+
}
|
|
75
|
+
function getInstallArgs(pm, deps) {
|
|
76
|
+
switch (pm) {
|
|
77
|
+
case "pnpm":
|
|
78
|
+
return ["pnpm", ["add", ...deps]];
|
|
79
|
+
case "yarn":
|
|
80
|
+
return ["yarn", ["add", ...deps]];
|
|
81
|
+
case "bun":
|
|
82
|
+
return ["bun", ["add", ...deps]];
|
|
83
|
+
default:
|
|
84
|
+
return ["npm", ["install", ...deps]];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function installDependencies(deps, cwd) {
|
|
88
|
+
if (deps.length === 0) return;
|
|
89
|
+
const pkgPath = path2.join(cwd, "package.json");
|
|
90
|
+
let existing = /* @__PURE__ */ new Set();
|
|
91
|
+
if (fs2.existsSync(pkgPath)) {
|
|
92
|
+
try {
|
|
93
|
+
const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf-8"));
|
|
94
|
+
existing = new Set(
|
|
95
|
+
Object.keys({ ...pkg.dependencies, ...pkg.devDependencies })
|
|
96
|
+
);
|
|
97
|
+
} catch {
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const toInstall = deps.filter((dep) => !existing.has(dep));
|
|
101
|
+
if (toInstall.length === 0) return;
|
|
102
|
+
const pm = await detectPackageManager(cwd);
|
|
103
|
+
const [cmd, args] = getInstallArgs(pm, toInstall);
|
|
104
|
+
const spinner = createSpinner(`Installing with ${pm}`);
|
|
105
|
+
try {
|
|
106
|
+
await execa(cmd, args, { cwd });
|
|
107
|
+
spinner.succeed(`Installed with ${pm}`);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
spinner.fail(`Install failed`);
|
|
110
|
+
if (error instanceof Error && "stdout" in error && typeof error.stdout === "string" && error.stdout.includes("ERR_PNPM_ADDING_TO_ROOT")) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`Cannot install dependencies at a pnpm workspace root.
|
|
113
|
+
Run stera-ui init from within a specific workspace package instead,
|
|
114
|
+
or use "pnpm add -w <package>" manually to install at the root.`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/utils/write-stera-css.ts
|
|
122
|
+
import fs3 from "fs/promises";
|
|
123
|
+
import path3 from "path";
|
|
124
|
+
function stripImportLines(content) {
|
|
125
|
+
const lines = content.split("\n");
|
|
126
|
+
const imports = [];
|
|
127
|
+
const kept = [];
|
|
128
|
+
for (const line of lines) {
|
|
129
|
+
if (line.trim().match(/^@import\s+["'].+["']/)) {
|
|
130
|
+
if (!line.trim().match(/^@import\s+["']tailwindcss["']/)) {
|
|
131
|
+
imports.push(line.trim());
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
kept.push(line);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { content: kept.join("\n"), imports };
|
|
138
|
+
}
|
|
139
|
+
async function writeSteraUiCss(config, cwd) {
|
|
140
|
+
const item = await fetchRegistryItem("globals");
|
|
141
|
+
const rawContent = item.files?.[0]?.content ?? "";
|
|
142
|
+
const { content, imports } = stripImportLines(rawContent);
|
|
143
|
+
const cssDir = path3.dirname(path3.resolve(cwd, config.css));
|
|
144
|
+
const steraUiPath = path3.join(cssDir, "stera-ui.css");
|
|
145
|
+
await fs3.mkdir(cssDir, { recursive: true });
|
|
146
|
+
await fs3.writeFile(steraUiPath, content, "utf-8");
|
|
147
|
+
return {
|
|
148
|
+
steraUiPath,
|
|
149
|
+
extraImports: imports,
|
|
150
|
+
dependencies: item.dependencies ?? []
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export {
|
|
155
|
+
CONFIG_FILE,
|
|
156
|
+
LEGACY_CONFIG_FILE,
|
|
157
|
+
findConfigPath,
|
|
158
|
+
loadConfig,
|
|
159
|
+
installDependencies,
|
|
160
|
+
writeSteraUiCss
|
|
161
|
+
};
|
|
@@ -41,9 +41,15 @@ var registryItemSchema = z.discriminatedUnion("type", [
|
|
|
41
41
|
files: z.array(registryItemFileSchema)
|
|
42
42
|
})
|
|
43
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
|
+
});
|
|
44
50
|
var registryIndexSchema = z.object({
|
|
45
51
|
name: z.string(),
|
|
46
|
-
items: z.array(
|
|
52
|
+
items: z.array(registryIndexEntrySchema)
|
|
47
53
|
});
|
|
48
54
|
var configSchema = z.object({
|
|
49
55
|
$schema: z.string().optional(),
|
|
@@ -67,6 +73,7 @@ export {
|
|
|
67
73
|
registryItemFileSchema,
|
|
68
74
|
registryItemFontSchema,
|
|
69
75
|
registryItemSchema,
|
|
76
|
+
registryIndexEntrySchema,
|
|
70
77
|
registryIndexSchema,
|
|
71
78
|
configSchema
|
|
72
79
|
};
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
};
|