create-bearnie 0.5.0 → 0.6.1
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/index.js +87 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13,6 +13,26 @@ var link = (text, url) => `\x1B]8;;${url}\x07${pc.cyan(text)}\x1B]8;;\x07`;
|
|
|
13
13
|
function parseFullArg() {
|
|
14
14
|
return process.argv.includes("--full");
|
|
15
15
|
}
|
|
16
|
+
function parseThemeArg() {
|
|
17
|
+
const argv = process.argv;
|
|
18
|
+
for (let i = 2; i < argv.length; i++) {
|
|
19
|
+
if (argv[i].startsWith("--theme=")) {
|
|
20
|
+
return argv[i].slice("--theme=".length) || null;
|
|
21
|
+
}
|
|
22
|
+
if (argv[i] === "--theme") {
|
|
23
|
+
return argv[i + 1] && !argv[i + 1].startsWith("--") ? argv[i + 1] : null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function isThemeEntry(name) {
|
|
29
|
+
return name === "styles" || name.startsWith("styles-");
|
|
30
|
+
}
|
|
31
|
+
function composeThemeName(base, accent) {
|
|
32
|
+
if (base === "neutral") return accent;
|
|
33
|
+
if (accent === "default") return base;
|
|
34
|
+
return `${base}-${accent}`;
|
|
35
|
+
}
|
|
16
36
|
function detectPackageManager() {
|
|
17
37
|
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
18
38
|
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
@@ -39,7 +59,6 @@ var FALLBACK_UTILITY_NAMES = [
|
|
|
39
59
|
"cn",
|
|
40
60
|
"focus-trap",
|
|
41
61
|
"ui-runtime-loader",
|
|
42
|
-
"ui-runtime-boot",
|
|
43
62
|
"ui-runtime-dialog",
|
|
44
63
|
"ui-runtime-disclosure-triggers",
|
|
45
64
|
"ui-runtime-dropdown-menu",
|
|
@@ -93,10 +112,12 @@ async function fetchRegistryIndex() {
|
|
|
93
112
|
}
|
|
94
113
|
return await response.json();
|
|
95
114
|
}
|
|
96
|
-
async function writeBearnieConfig(targetDir) {
|
|
97
|
-
await fs.writeJson(
|
|
98
|
-
|
|
99
|
-
|
|
115
|
+
async function writeBearnieConfig(targetDir, theme) {
|
|
116
|
+
await fs.writeJson(
|
|
117
|
+
path.join(targetDir, "bearnie.json"),
|
|
118
|
+
{ ...BEARNIE_CONFIG, theme },
|
|
119
|
+
{ spaces: 2 }
|
|
120
|
+
);
|
|
100
121
|
}
|
|
101
122
|
async function writeRegistryFiles(targetDir, entry) {
|
|
102
123
|
for (const file of entry.files) {
|
|
@@ -140,6 +161,54 @@ ${fullInstall ? ` ${pc.dim("Full install: including all components")}
|
|
|
140
161
|
}
|
|
141
162
|
const finalName = projectName;
|
|
142
163
|
const targetDir = path.resolve(process.cwd(), finalName);
|
|
164
|
+
let availableThemes = ["default"];
|
|
165
|
+
let themeBases = ["neutral"];
|
|
166
|
+
let themeAccents = ["default"];
|
|
167
|
+
try {
|
|
168
|
+
const index = await fetchRegistryIndex();
|
|
169
|
+
if (index.themes?.length) availableThemes = index.themes;
|
|
170
|
+
if (index.themeBases?.length) themeBases = index.themeBases;
|
|
171
|
+
if (index.themeAccents?.length) themeAccents = index.themeAccents;
|
|
172
|
+
} catch {
|
|
173
|
+
}
|
|
174
|
+
let theme = parseThemeArg();
|
|
175
|
+
if (theme && !availableThemes.includes(theme)) {
|
|
176
|
+
console.log(
|
|
177
|
+
`
|
|
178
|
+
${pc.red("Unknown theme:")} ${theme}
|
|
179
|
+
Themes combine a base and an accent, e.g. ${pc.cyan("slate-blue")}.
|
|
180
|
+
Bases: ${themeBases.join(", ")}
|
|
181
|
+
Accents: ${themeAccents.join(", ")}
|
|
182
|
+
`
|
|
183
|
+
);
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
if (!theme && (themeBases.length > 1 || themeAccents.length > 1) && process.stdin.isTTY) {
|
|
187
|
+
const response = await prompts([
|
|
188
|
+
{
|
|
189
|
+
type: "select",
|
|
190
|
+
name: "base",
|
|
191
|
+
message: "Base color (grays and surfaces)",
|
|
192
|
+
choices: themeBases.map((name) => ({ title: name, value: name })),
|
|
193
|
+
initial: 0
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
type: "select",
|
|
197
|
+
name: "accent",
|
|
198
|
+
message: "Accent color (buttons, focus rings)",
|
|
199
|
+
choices: themeAccents.map((name) => ({
|
|
200
|
+
title: name === "default" ? "default (neutral)" : name,
|
|
201
|
+
value: name
|
|
202
|
+
})),
|
|
203
|
+
initial: 0
|
|
204
|
+
}
|
|
205
|
+
]);
|
|
206
|
+
theme = composeThemeName(
|
|
207
|
+
response.base ?? "neutral",
|
|
208
|
+
response.accent ?? "default"
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
theme = theme ?? "default";
|
|
143
212
|
if (fs.existsSync(targetDir)) {
|
|
144
213
|
const { overwrite } = await prompts({
|
|
145
214
|
type: "confirm",
|
|
@@ -164,7 +233,18 @@ ${fullInstall ? ` ${pc.dim("Full install: including all components")}
|
|
|
164
233
|
const pkg = await fs.readJson(pkgPath);
|
|
165
234
|
pkg.name = finalName;
|
|
166
235
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
167
|
-
await writeBearnieConfig(targetDir);
|
|
236
|
+
await writeBearnieConfig(targetDir, theme);
|
|
237
|
+
if (theme !== "default") {
|
|
238
|
+
const themeEntry = await fetchRegistryEntry(`styles-${theme}`);
|
|
239
|
+
if (themeEntry?.files) {
|
|
240
|
+
await writeRegistryFiles(targetDir, themeEntry);
|
|
241
|
+
console.log(` ${pc.green("\u2713")} Applied ${theme} theme`);
|
|
242
|
+
} else {
|
|
243
|
+
console.log(
|
|
244
|
+
` ${pc.yellow("!")} Couldn't fetch the ${theme} theme \u2014 using default`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
168
248
|
if (fullInstall) {
|
|
169
249
|
console.log(`
|
|
170
250
|
${pc.dim("Fetching components from registry...")}
|
|
@@ -184,7 +264,7 @@ ${fullInstall ? ` ${pc.dim("Full install: including all components")}
|
|
|
184
264
|
console.log(` ${pc.yellow("!")} Failed to fetch ${utilityName} utility`);
|
|
185
265
|
}
|
|
186
266
|
}
|
|
187
|
-
const componentNames = registryIndex.components.map((component) => component.name).filter((name) => name
|
|
267
|
+
const componentNames = registryIndex.components.map((component) => component.name).filter((name) => !isThemeEntry(name) && name !== "barrel");
|
|
188
268
|
let installed = 0;
|
|
189
269
|
let failed = 0;
|
|
190
270
|
for (const componentName of componentNames) {
|