@beaket/ui 1.5.0 → 1.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/LICENSE +21 -0
- package/package.json +1 -1
- package/src/commands/add.ts +1 -1
- package/src/commands/init.ts +102 -21
- package/src/utils/config.ts +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Beaket
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -14,7 +14,7 @@ export async function add(componentName: string, options: AddOptions) {
|
|
|
14
14
|
// Read config
|
|
15
15
|
const config = await getConfig();
|
|
16
16
|
if (!config) {
|
|
17
|
-
console.log(pc.red("Error:"), "beaket.json not found.");
|
|
17
|
+
console.log(pc.red("Error:"), "beaket.ui.json not found.");
|
|
18
18
|
console.log("Run", pc.cyan("npx @beaket/ui init"), "first.");
|
|
19
19
|
process.exit(1);
|
|
20
20
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -4,28 +4,105 @@ import pc from "picocolors";
|
|
|
4
4
|
import prompts from "prompts";
|
|
5
5
|
import { writeConfig, type BeaketConfig } from "../utils/config.ts";
|
|
6
6
|
|
|
7
|
+
interface TsConfig {
|
|
8
|
+
compilerOptions?: {
|
|
9
|
+
paths?: Record<string, string[]>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function detectAliasPath(): Promise<string> {
|
|
14
|
+
const cwd = process.cwd();
|
|
15
|
+
|
|
16
|
+
// Try to read tsconfig.json or tsconfig.app.json
|
|
17
|
+
for (const configFile of ["tsconfig.json", "tsconfig.app.json"]) {
|
|
18
|
+
const configPath = path.join(cwd, configFile);
|
|
19
|
+
if (await fs.pathExists(configPath)) {
|
|
20
|
+
try {
|
|
21
|
+
const content = await fs.readFile(configPath, "utf-8");
|
|
22
|
+
const tsconfig: TsConfig = JSON.parse(content);
|
|
23
|
+
const paths = tsconfig.compilerOptions?.paths;
|
|
24
|
+
if (paths?.["@/*"]) {
|
|
25
|
+
const aliasPath = paths["@/*"][0];
|
|
26
|
+
// "./src/*" -> "src", "./*" -> ""
|
|
27
|
+
const prefix = aliasPath.replace(/^\.\/|\/?\*$/g, "");
|
|
28
|
+
return prefix ? `${prefix}/components/ui` : "components/ui";
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
// Ignore parse errors
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Fallback: detect from package.json
|
|
37
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
38
|
+
if (await fs.pathExists(pkgPath)) {
|
|
39
|
+
try {
|
|
40
|
+
const content = await fs.readFile(pkgPath, "utf-8");
|
|
41
|
+
const pkg = JSON.parse(content);
|
|
42
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
43
|
+
// Next.js uses root alias by default
|
|
44
|
+
if (deps.next) {
|
|
45
|
+
return "components/ui";
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
// Ignore parse errors
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Default to src/components/ui (Vite style)
|
|
53
|
+
return "src/components/ui";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function detectCssPath(): Promise<string> {
|
|
57
|
+
const cwd = process.cwd();
|
|
58
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
59
|
+
|
|
60
|
+
if (await fs.pathExists(pkgPath)) {
|
|
61
|
+
try {
|
|
62
|
+
const content = await fs.readFile(pkgPath, "utf-8");
|
|
63
|
+
const pkg = JSON.parse(content);
|
|
64
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
65
|
+
if (deps.next) {
|
|
66
|
+
return "app/globals.css";
|
|
67
|
+
}
|
|
68
|
+
} catch {
|
|
69
|
+
// Ignore parse errors
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return "src/index.css";
|
|
74
|
+
}
|
|
75
|
+
|
|
7
76
|
const CSS_VARIABLES = `
|
|
8
77
|
/* Beaket UI Design System */
|
|
78
|
+
@theme {
|
|
79
|
+
--color-inverse: var(--paper);
|
|
80
|
+
--shadow-offset: 2px 2px 0px 0px var(--chrome);
|
|
81
|
+
--shadow-offset-dark: 2px 2px 0px 0px var(--aluminum);
|
|
82
|
+
--shadow-offset-hover: 3px 3px 0px 0px var(--chrome);
|
|
83
|
+
--shadow-offset-active: 1px 1px 0px 0px var(--chrome);
|
|
84
|
+
}
|
|
85
|
+
|
|
9
86
|
:root {
|
|
10
|
-
--
|
|
11
|
-
--ink: #
|
|
12
|
-
--
|
|
13
|
-
--
|
|
14
|
-
--chrome: #C8C8C8;
|
|
15
|
-
--graphite: #1A1A1A;
|
|
16
|
-
--iron: #2D2D2D;
|
|
87
|
+
--graphite: #0d0d0d;
|
|
88
|
+
--ink: #1a1a1a;
|
|
89
|
+
--branch: #1c1f24;
|
|
90
|
+
--iron: #2d2d2d;
|
|
17
91
|
--slate: #404040;
|
|
18
92
|
--zinc: #525252;
|
|
19
|
-
--
|
|
20
|
-
--
|
|
21
|
-
--
|
|
22
|
-
--
|
|
23
|
-
--
|
|
24
|
-
--
|
|
25
|
-
--
|
|
26
|
-
--signal-
|
|
27
|
-
--signal-
|
|
28
|
-
--signal-
|
|
93
|
+
--steel: #595959;
|
|
94
|
+
--aluminum: #9e9e9e;
|
|
95
|
+
--chrome: #d0d0d0;
|
|
96
|
+
--silver: #dedede;
|
|
97
|
+
--platinum: #e8e8e8;
|
|
98
|
+
--frost: #f5f5f5;
|
|
99
|
+
--paper: #fafafa;
|
|
100
|
+
--signal-blue: #00449e;
|
|
101
|
+
--signal-red: #c41e1e;
|
|
102
|
+
--signal-green: #00794c;
|
|
103
|
+
--signal-amber: #b8860b;
|
|
104
|
+
--signal-purple: #6f2da8;
|
|
105
|
+
--signal-cyan: #1a6b7c;
|
|
29
106
|
}
|
|
30
107
|
`;
|
|
31
108
|
|
|
@@ -34,18 +111,22 @@ export async function init() {
|
|
|
34
111
|
console.log(pc.bold("Initializing Beaket UI..."));
|
|
35
112
|
console.log();
|
|
36
113
|
|
|
114
|
+
// Auto-detect defaults based on project structure
|
|
115
|
+
const detectedComponentsPath = await detectAliasPath();
|
|
116
|
+
const detectedCssPath = await detectCssPath();
|
|
117
|
+
|
|
37
118
|
const response = await prompts([
|
|
38
119
|
{
|
|
39
120
|
type: "text",
|
|
40
121
|
name: "components",
|
|
41
122
|
message: "Where should components be installed?",
|
|
42
|
-
initial:
|
|
123
|
+
initial: detectedComponentsPath,
|
|
43
124
|
},
|
|
44
125
|
{
|
|
45
126
|
type: "text",
|
|
46
127
|
name: "css",
|
|
47
128
|
message: "Where is your Tailwind CSS file?",
|
|
48
|
-
initial:
|
|
129
|
+
initial: detectedCssPath,
|
|
49
130
|
},
|
|
50
131
|
]);
|
|
51
132
|
|
|
@@ -54,14 +135,14 @@ export async function init() {
|
|
|
54
135
|
process.exit(1);
|
|
55
136
|
}
|
|
56
137
|
|
|
57
|
-
// Write beaket.json (only components path)
|
|
138
|
+
// Write beaket.ui.json (only components path)
|
|
58
139
|
const config: BeaketConfig = {
|
|
59
140
|
$schema: "https://beaket.dev/schema.json",
|
|
60
141
|
components: response.components,
|
|
61
142
|
};
|
|
62
143
|
|
|
63
144
|
await writeConfig(config);
|
|
64
|
-
console.log(pc.green("✔"), "Created beaket.json");
|
|
145
|
+
console.log(pc.green("✔"), "Created beaket.ui.json");
|
|
65
146
|
|
|
66
147
|
// Inject CSS variables into Tailwind CSS file
|
|
67
148
|
if (response.css) {
|
package/src/utils/config.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface BeaketConfig {
|
|
|
6
6
|
components: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const CONFIG_FILE = "beaket.json";
|
|
9
|
+
const CONFIG_FILE = "beaket.ui.json";
|
|
10
10
|
|
|
11
11
|
export async function getConfig(): Promise<BeaketConfig | null> {
|
|
12
12
|
const configPath = path.join(process.cwd(), CONFIG_FILE);
|