stera-ui 0.3.0 → 0.3.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/cli.js +96 -28
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -370,27 +370,39 @@ function hasGlobalsCss(config, projectRoot) {
|
|
|
370
370
|
var transforms = [transformImports];
|
|
371
371
|
async function add(components, options) {
|
|
372
372
|
const cwd = options.cwd ? path6.resolve(options.cwd) : process.cwd();
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
373
|
+
const spinner = createSpinner("Fetching registry");
|
|
374
|
+
try {
|
|
375
|
+
for (const name of components) {
|
|
376
|
+
const item = await getComponent(name);
|
|
377
|
+
if (!item) {
|
|
378
|
+
spinner.fail(`Component "${name}" not found in registry.`);
|
|
379
|
+
console.error(` Run "stera-ui list" to see available components.`);
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
379
382
|
}
|
|
383
|
+
} catch (err) {
|
|
384
|
+
spinner.fail("Failed to fetch registry");
|
|
385
|
+
throw err;
|
|
380
386
|
}
|
|
381
387
|
const configPath = findConfigPath(cwd);
|
|
382
388
|
if (!configPath) {
|
|
383
|
-
|
|
384
|
-
` Error: ${CONFIG_FILE} not found. Run "stera-ui init" first.`
|
|
385
|
-
);
|
|
389
|
+
spinner.fail(`${CONFIG_FILE} not found. Run "stera-ui init" first.`);
|
|
386
390
|
process.exit(1);
|
|
387
391
|
}
|
|
388
392
|
const config = loadConfig(cwd);
|
|
389
393
|
if (!config) {
|
|
390
|
-
|
|
394
|
+
spinner.fail(`Failed to parse ${CONFIG_FILE}.`);
|
|
391
395
|
process.exit(1);
|
|
392
396
|
}
|
|
393
397
|
const projectRoot = path6.dirname(configPath);
|
|
398
|
+
let resolved;
|
|
399
|
+
try {
|
|
400
|
+
resolved = await resolveDependencies(components);
|
|
401
|
+
} catch (err) {
|
|
402
|
+
spinner.fail("Failed to fetch registry");
|
|
403
|
+
throw err;
|
|
404
|
+
}
|
|
405
|
+
spinner.succeed("Registry resolved");
|
|
394
406
|
const isAddingGlobals = components.includes("globals");
|
|
395
407
|
if (!isAddingGlobals && !hasGlobalsCss(config, projectRoot)) {
|
|
396
408
|
console.warn(`
|
|
@@ -399,7 +411,6 @@ async function add(components, options) {
|
|
|
399
411
|
console.warn(` Run "stera-ui add globals" to install base styles.
|
|
400
412
|
`);
|
|
401
413
|
}
|
|
402
|
-
const resolved = await resolveDependencies(components);
|
|
403
414
|
for (const item of resolved) {
|
|
404
415
|
for (const file of item.files ?? []) {
|
|
405
416
|
if (file.content) {
|
|
@@ -968,11 +979,28 @@ function buildConfig(project, strategy) {
|
|
|
968
979
|
}
|
|
969
980
|
};
|
|
970
981
|
}
|
|
971
|
-
function
|
|
972
|
-
|
|
982
|
+
function stripImportLines(content) {
|
|
983
|
+
const lines = content.split("\n");
|
|
984
|
+
const imports = [];
|
|
985
|
+
const kept = [];
|
|
986
|
+
for (const line of lines) {
|
|
987
|
+
if (line.trim().match(/^@import\s+["'].+["']/)) {
|
|
988
|
+
if (!line.trim().match(/^@import\s+["']tailwindcss["']/)) {
|
|
989
|
+
imports.push(line.trim());
|
|
990
|
+
}
|
|
991
|
+
} else {
|
|
992
|
+
kept.push(line);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
return { content: kept.join("\n"), imports };
|
|
973
996
|
}
|
|
974
997
|
function insertImportLine(filePath, importStatement) {
|
|
975
998
|
const content = fs9.readFileSync(filePath, "utf-8");
|
|
999
|
+
const importPath = importStatement.match(/["']([^"']+)["']/)?.[1];
|
|
1000
|
+
if (importPath) {
|
|
1001
|
+
const escaped = importPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1002
|
+
if (new RegExp(`@import\\s+["']${escaped}["']`).test(content)) return;
|
|
1003
|
+
}
|
|
976
1004
|
const lines = content.split("\n");
|
|
977
1005
|
let lastImportIndex = -1;
|
|
978
1006
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -1028,16 +1056,23 @@ async function promptFontStrategy(detected, skipPrompts) {
|
|
|
1028
1056
|
return strategy;
|
|
1029
1057
|
}
|
|
1030
1058
|
async function fetchDefaultFonts() {
|
|
1059
|
+
const spinner = createSpinner("Fetching fonts");
|
|
1031
1060
|
const fonts = [];
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1061
|
+
try {
|
|
1062
|
+
for (const name of DEFAULT_FONT_NAMES) {
|
|
1063
|
+
try {
|
|
1064
|
+
const item = await fetchRegistryItem(name);
|
|
1065
|
+
if (item.type === "registry:font") {
|
|
1066
|
+
fonts.push(item);
|
|
1067
|
+
}
|
|
1068
|
+
} catch {
|
|
1037
1069
|
}
|
|
1038
|
-
} catch {
|
|
1039
1070
|
}
|
|
1071
|
+
} catch (err) {
|
|
1072
|
+
spinner.fail("Failed to fetch fonts");
|
|
1073
|
+
throw err;
|
|
1040
1074
|
}
|
|
1075
|
+
spinner.succeed("Fonts resolved");
|
|
1041
1076
|
return fonts;
|
|
1042
1077
|
}
|
|
1043
1078
|
async function executeFontStrategy(strategy, project, detected, config, cwd) {
|
|
@@ -1142,22 +1177,40 @@ async function init(options) {
|
|
|
1142
1177
|
` ${CHECK} Stera already initialised ${dim(`(${path10.join(path10.dirname(project.existingCssFile), "stera-ui.css")} exists)`)}`
|
|
1143
1178
|
);
|
|
1144
1179
|
} else {
|
|
1180
|
+
const fetchSpinner = createSpinner("Fetching base styles");
|
|
1181
|
+
let globalsItem;
|
|
1145
1182
|
try {
|
|
1146
|
-
|
|
1183
|
+
globalsItem = await fetchRegistryItem("globals");
|
|
1184
|
+
} catch {
|
|
1185
|
+
fetchSpinner.fail("Base styles not found \u2014 skipping");
|
|
1186
|
+
globalsItem = null;
|
|
1187
|
+
}
|
|
1188
|
+
if (globalsItem) {
|
|
1189
|
+
fetchSpinner.succeed("Base styles resolved");
|
|
1147
1190
|
const globalsContent = globalsItem.files?.[0]?.content ?? "";
|
|
1148
|
-
const steraUiContent =
|
|
1191
|
+
const { content: steraUiContent, imports } = stripImportLines(globalsContent);
|
|
1149
1192
|
const steraUiPath = path10.join(cssDir, "stera-ui.css");
|
|
1150
1193
|
fs9.mkdirSync(cssDir, { recursive: true });
|
|
1151
1194
|
fs9.writeFileSync(steraUiPath, steraUiContent, "utf-8");
|
|
1152
1195
|
console.log(` ${CHECK} Created ${path10.relative(cwd, steraUiPath)}`);
|
|
1153
1196
|
const existingCssPath = path10.resolve(cwd, project.existingCssFile);
|
|
1197
|
+
for (const imp of imports) {
|
|
1198
|
+
insertImportLine(existingCssPath, imp);
|
|
1199
|
+
}
|
|
1154
1200
|
insertImportLine(existingCssPath, "@import './stera-ui.css';");
|
|
1155
1201
|
console.log(` ${CHECK} Added @import to ${project.existingCssFile}`);
|
|
1156
|
-
} catch {
|
|
1157
1202
|
}
|
|
1158
1203
|
}
|
|
1159
1204
|
} else {
|
|
1160
|
-
const
|
|
1205
|
+
const fetchSpinner = createSpinner("Fetching base styles");
|
|
1206
|
+
let resolved;
|
|
1207
|
+
try {
|
|
1208
|
+
resolved = await resolveDependencies(["globals"]);
|
|
1209
|
+
} catch (err) {
|
|
1210
|
+
fetchSpinner.fail("Failed to fetch base styles");
|
|
1211
|
+
throw err;
|
|
1212
|
+
}
|
|
1213
|
+
fetchSpinner.succeed("Base styles resolved");
|
|
1161
1214
|
const filtered = resolved.filter((item) => item.name !== "fonts");
|
|
1162
1215
|
const { written } = await writeComponentFiles(filtered, config, cwd);
|
|
1163
1216
|
for (const file of written) {
|
|
@@ -1171,14 +1224,21 @@ async function init(options) {
|
|
|
1171
1224
|
config,
|
|
1172
1225
|
cwd
|
|
1173
1226
|
);
|
|
1227
|
+
const depsSpinner = createSpinner("Fetching package list");
|
|
1228
|
+
let globalsForDeps;
|
|
1174
1229
|
try {
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1230
|
+
globalsForDeps = await fetchRegistryItem("globals");
|
|
1231
|
+
} catch {
|
|
1232
|
+
depsSpinner.fail("Package list unavailable \u2014 skipping");
|
|
1233
|
+
globalsForDeps = null;
|
|
1234
|
+
}
|
|
1235
|
+
if (globalsForDeps) {
|
|
1236
|
+
depsSpinner.succeed("Package list resolved");
|
|
1237
|
+
if (globalsForDeps.dependencies) {
|
|
1238
|
+
const deps = [...new Set(globalsForDeps.dependencies)].sort();
|
|
1178
1239
|
console.log("");
|
|
1179
1240
|
await installDependencies(deps, cwd);
|
|
1180
1241
|
}
|
|
1181
|
-
} catch {
|
|
1182
1242
|
}
|
|
1183
1243
|
console.log("");
|
|
1184
1244
|
console.log(" Next steps:");
|
|
@@ -1192,7 +1252,15 @@ async function init(options) {
|
|
|
1192
1252
|
|
|
1193
1253
|
// src/commands/list.ts
|
|
1194
1254
|
async function list() {
|
|
1195
|
-
const
|
|
1255
|
+
const spinner = createSpinner("Fetching registry");
|
|
1256
|
+
let items;
|
|
1257
|
+
try {
|
|
1258
|
+
items = await getAllComponents();
|
|
1259
|
+
} catch (err) {
|
|
1260
|
+
spinner.fail("Failed to fetch registry");
|
|
1261
|
+
throw err;
|
|
1262
|
+
}
|
|
1263
|
+
spinner.succeed("Registry resolved");
|
|
1196
1264
|
const groups = /* @__PURE__ */ new Map();
|
|
1197
1265
|
for (const item of items) {
|
|
1198
1266
|
const type = item.type.replace("registry:", "");
|