stera-ui 0.1.0 → 0.1.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/chunk-57DNZ2YS.js +46 -0
- package/dist/chunk-KEZKNZR6.js +60 -0
- package/dist/chunk-PUJGGJCB.js +362 -0
- package/dist/cli.js +664 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +63 -664
- package/dist/registry/index.js +7 -52
- package/dist/schema/index.d.ts +18 -18
- package/dist/schema/index.js +7 -38
- package/dist/utils/index.js +21 -342
- package/package.json +2 -2
package/dist/registry/index.js
CHANGED
|
@@ -1,55 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
return res.json();
|
|
10
|
-
}
|
|
11
|
-
async function fetchRegistryIndex() {
|
|
12
|
-
if (_indexCache) return _indexCache;
|
|
13
|
-
const data = await fetchJSON(
|
|
14
|
-
`${REGISTRY_URL}/index.json`
|
|
15
|
-
);
|
|
16
|
-
_indexCache = data.items;
|
|
17
|
-
return _indexCache;
|
|
18
|
-
}
|
|
19
|
-
async function fetchRegistryItem(name) {
|
|
20
|
-
return fetchJSON(`${REGISTRY_URL}/${name}.json`);
|
|
21
|
-
}
|
|
22
|
-
async function getComponent(name) {
|
|
23
|
-
const index = await fetchRegistryIndex();
|
|
24
|
-
return index.find((item) => item.name === name);
|
|
25
|
-
}
|
|
26
|
-
async function getAllComponents() {
|
|
27
|
-
return fetchRegistryIndex();
|
|
28
|
-
}
|
|
29
|
-
async function resolveDependencies(names) {
|
|
30
|
-
const resolved = /* @__PURE__ */ new Map();
|
|
31
|
-
const queue = [...names];
|
|
32
|
-
while (queue.length > 0) {
|
|
33
|
-
const name = queue.shift();
|
|
34
|
-
if (resolved.has(name)) continue;
|
|
35
|
-
let item;
|
|
36
|
-
try {
|
|
37
|
-
item = await fetchRegistryItem(name);
|
|
38
|
-
} catch {
|
|
39
|
-
console.error(`Component "${name}" not found in registry.`);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
resolved.set(name, item);
|
|
43
|
-
if (item.registryDependencies) {
|
|
44
|
-
for (const dep of item.registryDependencies) {
|
|
45
|
-
if (!resolved.has(dep)) {
|
|
46
|
-
queue.push(dep);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return Array.from(resolved.values());
|
|
52
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
fetchRegistryIndex,
|
|
3
|
+
fetchRegistryItem,
|
|
4
|
+
getAllComponents,
|
|
5
|
+
getComponent,
|
|
6
|
+
resolveDependencies
|
|
7
|
+
} from "../chunk-KEZKNZR6.js";
|
|
53
8
|
export {
|
|
54
9
|
fetchRegistryIndex,
|
|
55
10
|
fetchRegistryItem,
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -8,13 +8,13 @@ declare const registryItemFileSchema: z.ZodObject<{
|
|
|
8
8
|
content: z.ZodOptional<z.ZodString>;
|
|
9
9
|
target: z.ZodOptional<z.ZodString>;
|
|
10
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
12
11
|
path: string;
|
|
12
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
13
13
|
content?: string | undefined;
|
|
14
14
|
target?: string | undefined;
|
|
15
15
|
}, {
|
|
16
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
17
16
|
path: string;
|
|
17
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
18
18
|
content?: string | undefined;
|
|
19
19
|
target?: string | undefined;
|
|
20
20
|
}>;
|
|
@@ -30,33 +30,33 @@ declare const registryItemSchema: z.ZodObject<{
|
|
|
30
30
|
content: z.ZodOptional<z.ZodString>;
|
|
31
31
|
target: z.ZodOptional<z.ZodString>;
|
|
32
32
|
}, "strip", z.ZodTypeAny, {
|
|
33
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
34
33
|
path: string;
|
|
34
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
35
35
|
content?: string | undefined;
|
|
36
36
|
target?: string | undefined;
|
|
37
37
|
}, {
|
|
38
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
39
38
|
path: string;
|
|
39
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
40
40
|
content?: string | undefined;
|
|
41
41
|
target?: string | undefined;
|
|
42
42
|
}>, "many">;
|
|
43
43
|
}, "strip", z.ZodTypeAny, {
|
|
44
|
-
name: string;
|
|
45
44
|
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
45
|
+
name: string;
|
|
46
46
|
files: {
|
|
47
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
48
47
|
path: string;
|
|
48
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
49
49
|
content?: string | undefined;
|
|
50
50
|
target?: string | undefined;
|
|
51
51
|
}[];
|
|
52
52
|
dependencies?: string[] | undefined;
|
|
53
53
|
registryDependencies?: string[] | undefined;
|
|
54
54
|
}, {
|
|
55
|
-
name: string;
|
|
56
55
|
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
56
|
+
name: string;
|
|
57
57
|
files: {
|
|
58
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
59
58
|
path: string;
|
|
59
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
60
60
|
content?: string | undefined;
|
|
61
61
|
target?: string | undefined;
|
|
62
62
|
}[];
|
|
@@ -77,33 +77,33 @@ declare const registryIndexSchema: z.ZodObject<{
|
|
|
77
77
|
content: z.ZodOptional<z.ZodString>;
|
|
78
78
|
target: z.ZodOptional<z.ZodString>;
|
|
79
79
|
}, "strip", z.ZodTypeAny, {
|
|
80
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
81
80
|
path: string;
|
|
81
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
82
82
|
content?: string | undefined;
|
|
83
83
|
target?: string | undefined;
|
|
84
84
|
}, {
|
|
85
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
86
85
|
path: string;
|
|
86
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
87
87
|
content?: string | undefined;
|
|
88
88
|
target?: string | undefined;
|
|
89
89
|
}>, "many">;
|
|
90
90
|
}, "strip", z.ZodTypeAny, {
|
|
91
|
-
name: string;
|
|
92
91
|
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
92
|
+
name: string;
|
|
93
93
|
files: {
|
|
94
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
95
94
|
path: string;
|
|
95
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
96
96
|
content?: string | undefined;
|
|
97
97
|
target?: string | undefined;
|
|
98
98
|
}[];
|
|
99
99
|
dependencies?: string[] | undefined;
|
|
100
100
|
registryDependencies?: string[] | undefined;
|
|
101
101
|
}, {
|
|
102
|
-
name: string;
|
|
103
102
|
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
103
|
+
name: string;
|
|
104
104
|
files: {
|
|
105
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
106
105
|
path: string;
|
|
106
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
107
107
|
content?: string | undefined;
|
|
108
108
|
target?: string | undefined;
|
|
109
109
|
}[];
|
|
@@ -113,11 +113,11 @@ declare const registryIndexSchema: z.ZodObject<{
|
|
|
113
113
|
}, "strip", z.ZodTypeAny, {
|
|
114
114
|
name: string;
|
|
115
115
|
items: {
|
|
116
|
-
name: string;
|
|
117
116
|
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
117
|
+
name: string;
|
|
118
118
|
files: {
|
|
119
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
120
119
|
path: string;
|
|
120
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
121
121
|
content?: string | undefined;
|
|
122
122
|
target?: string | undefined;
|
|
123
123
|
}[];
|
|
@@ -127,11 +127,11 @@ declare const registryIndexSchema: z.ZodObject<{
|
|
|
127
127
|
}, {
|
|
128
128
|
name: string;
|
|
129
129
|
items: {
|
|
130
|
-
name: string;
|
|
131
130
|
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
131
|
+
name: string;
|
|
132
132
|
files: {
|
|
133
|
-
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
134
133
|
path: string;
|
|
134
|
+
type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
|
|
135
135
|
content?: string | undefined;
|
|
136
136
|
target?: string | undefined;
|
|
137
137
|
}[];
|
package/dist/schema/index.js
CHANGED
|
@@ -1,41 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"registry:style"
|
|
9
|
-
]);
|
|
10
|
-
var registryItemFileSchema = z.object({
|
|
11
|
-
path: z.string(),
|
|
12
|
-
type: registryItemTypeSchema,
|
|
13
|
-
content: z.string().optional(),
|
|
14
|
-
target: z.string().optional()
|
|
15
|
-
});
|
|
16
|
-
var registryItemSchema = z.object({
|
|
17
|
-
name: z.string(),
|
|
18
|
-
type: registryItemTypeSchema,
|
|
19
|
-
dependencies: z.array(z.string()).optional(),
|
|
20
|
-
registryDependencies: z.array(z.string()).optional(),
|
|
21
|
-
files: z.array(registryItemFileSchema)
|
|
22
|
-
});
|
|
23
|
-
var registryIndexSchema = z.object({
|
|
24
|
-
name: z.string(),
|
|
25
|
-
items: z.array(registryItemSchema)
|
|
26
|
-
});
|
|
27
|
-
var configSchema = z.object({
|
|
28
|
-
$schema: z.string().optional(),
|
|
29
|
-
version: z.literal(1),
|
|
30
|
-
css: z.string(),
|
|
31
|
-
aliases: z.object({
|
|
32
|
-
components: z.string(),
|
|
33
|
-
utils: z.string(),
|
|
34
|
-
ui: z.string(),
|
|
35
|
-
lib: z.string(),
|
|
36
|
-
hooks: z.string()
|
|
37
|
-
})
|
|
38
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
configSchema,
|
|
3
|
+
registryIndexSchema,
|
|
4
|
+
registryItemFileSchema,
|
|
5
|
+
registryItemSchema,
|
|
6
|
+
registryItemTypeSchema
|
|
7
|
+
} from "../chunk-57DNZ2YS.js";
|
|
39
8
|
export {
|
|
40
9
|
configSchema,
|
|
41
10
|
registryIndexSchema,
|
package/dist/utils/index.js
CHANGED
|
@@ -1,344 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
rules.push({ type: "exact", from: DEFAULT_ALIASES.utils, to: aliases.utils });
|
|
22
|
-
}
|
|
23
|
-
if (aliases.ui !== DEFAULT_ALIASES.ui) {
|
|
24
|
-
rules.push({ type: "prefix", from: DEFAULT_ALIASES.ui, to: aliases.ui });
|
|
25
|
-
}
|
|
26
|
-
if (aliases.components !== DEFAULT_ALIASES.components) {
|
|
27
|
-
rules.push({ type: "prefix", from: DEFAULT_ALIASES.components, to: aliases.components });
|
|
28
|
-
}
|
|
29
|
-
if (aliases.lib !== DEFAULT_ALIASES.lib) {
|
|
30
|
-
rules.push({ type: "prefix", from: DEFAULT_ALIASES.lib, to: aliases.lib });
|
|
31
|
-
}
|
|
32
|
-
if (aliases.hooks !== DEFAULT_ALIASES.hooks) {
|
|
33
|
-
rules.push({ type: "prefix", from: DEFAULT_ALIASES.hooks, to: aliases.hooks });
|
|
34
|
-
}
|
|
35
|
-
if (rules.length === 0) {
|
|
36
|
-
return content;
|
|
37
|
-
}
|
|
38
|
-
return content.replace(
|
|
39
|
-
/from\s+(["'])([^"']+)\1/g,
|
|
40
|
-
(match, quote, importPath) => {
|
|
41
|
-
for (const rule of rules) {
|
|
42
|
-
if (rule.type === "exact" && importPath === rule.from) {
|
|
43
|
-
return `from ${quote}${rule.to}${quote}`;
|
|
44
|
-
}
|
|
45
|
-
if (rule.type === "prefix" && importPath.startsWith(rule.from + "/")) {
|
|
46
|
-
const rest = importPath.slice(rule.from.length);
|
|
47
|
-
return `from ${quote}${rule.to}${rest}${quote}`;
|
|
48
|
-
}
|
|
49
|
-
if (rule.type === "prefix" && importPath === rule.from) {
|
|
50
|
-
return `from ${quote}${rule.to}${quote}`;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return match;
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// src/utils/resolve-paths.ts
|
|
59
|
-
import path from "path";
|
|
60
|
-
import { loadConfig, createMatchPath } from "tsconfig-paths";
|
|
61
|
-
var TYPE_TO_ALIAS = {
|
|
62
|
-
"registry:ui": "ui",
|
|
63
|
-
"registry:lib": "lib",
|
|
64
|
-
"registry:hook": "hooks",
|
|
65
|
-
"registry:component": "components"
|
|
66
|
-
};
|
|
67
|
-
function resolveAlias(alias, projectRoot) {
|
|
68
|
-
const tsConfig = loadConfig(projectRoot);
|
|
69
|
-
if (tsConfig.resultType === "success") {
|
|
70
|
-
const match = createMatchPath(tsConfig.absoluteBaseUrl, tsConfig.paths);
|
|
71
|
-
const resolved = match(alias, void 0, () => true, [".ts", ".tsx"]);
|
|
72
|
-
if (resolved) {
|
|
73
|
-
return path.relative(projectRoot, resolved);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return alias.replace(/^@\//, "");
|
|
77
|
-
}
|
|
78
|
-
function resolveOutputPath(config, projectRoot, file) {
|
|
79
|
-
const alias = TYPE_TO_ALIAS[file.type];
|
|
80
|
-
if (alias) {
|
|
81
|
-
const dir = resolveAlias(config.aliases[alias], projectRoot);
|
|
82
|
-
const filename = path.basename(file.path);
|
|
83
|
-
return path.join(projectRoot, dir, filename);
|
|
84
|
-
}
|
|
85
|
-
if (file.type === "registry:style") {
|
|
86
|
-
const cssDir = path.dirname(config.css);
|
|
87
|
-
const filename = path.basename(file.path);
|
|
88
|
-
return path.join(projectRoot, cssDir, filename);
|
|
89
|
-
}
|
|
90
|
-
return path.join(projectRoot, file.path);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/utils/resolve-config.ts
|
|
94
|
-
import fs from "fs";
|
|
95
|
-
import path2 from "path";
|
|
96
|
-
var CONFIG_FILE = "components.json";
|
|
97
|
-
function migrateConfig(raw) {
|
|
98
|
-
if (!("version" in raw) && "tailwind" in raw) {
|
|
99
|
-
const legacy = raw;
|
|
100
|
-
return {
|
|
101
|
-
version: 1,
|
|
102
|
-
css: legacy.tailwind.css || "src/styles/globals.css",
|
|
103
|
-
aliases: legacy.aliases
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
return raw;
|
|
107
|
-
}
|
|
108
|
-
function findConfigPath(cwd) {
|
|
109
|
-
let dir = path2.resolve(cwd);
|
|
110
|
-
while (true) {
|
|
111
|
-
const configPath = path2.join(dir, CONFIG_FILE);
|
|
112
|
-
if (fs.existsSync(configPath)) return configPath;
|
|
113
|
-
const parent = path2.dirname(dir);
|
|
114
|
-
if (parent === dir) return null;
|
|
115
|
-
dir = parent;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function loadConfig2(cwd) {
|
|
119
|
-
const configPath = findConfigPath(cwd);
|
|
120
|
-
if (!configPath) return null;
|
|
121
|
-
try {
|
|
122
|
-
const raw = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
123
|
-
return migrateConfig(raw);
|
|
124
|
-
} catch {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// src/utils/detect-project.ts
|
|
130
|
-
import fs2 from "fs";
|
|
131
|
-
import path3 from "path";
|
|
132
|
-
function hasFile(cwd, filenames) {
|
|
133
|
-
return filenames.some((f) => fs2.existsSync(path3.join(cwd, f)));
|
|
134
|
-
}
|
|
135
|
-
function findTailwindCssFile(cwd) {
|
|
136
|
-
const candidates = [
|
|
137
|
-
"src/app/globals.css",
|
|
138
|
-
"src/styles/globals.css",
|
|
139
|
-
"src/index.css",
|
|
140
|
-
"app/globals.css",
|
|
141
|
-
"styles/globals.css",
|
|
142
|
-
"index.css"
|
|
143
|
-
];
|
|
144
|
-
for (const candidate of candidates) {
|
|
145
|
-
const fullPath = path3.join(cwd, candidate);
|
|
146
|
-
if (!fs2.existsSync(fullPath)) continue;
|
|
147
|
-
const content = fs2.readFileSync(fullPath, "utf-8");
|
|
148
|
-
if (content.includes('@import "tailwindcss"') || content.includes("@import 'tailwindcss'") || content.includes("@tailwind base")) {
|
|
149
|
-
return candidate;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
function detectProject(cwd) {
|
|
155
|
-
const hasSrc = fs2.existsSync(path3.join(cwd, "src"));
|
|
156
|
-
let framework = "other";
|
|
157
|
-
if (hasFile(cwd, ["next.config.ts", "next.config.js", "next.config.mjs"])) {
|
|
158
|
-
framework = "next";
|
|
159
|
-
} else if (hasFile(cwd, ["vite.config.ts", "vite.config.js", "vite.config.mjs"])) {
|
|
160
|
-
framework = "vite";
|
|
161
|
-
}
|
|
162
|
-
let rsc = false;
|
|
163
|
-
if (framework === "next") {
|
|
164
|
-
const appDir = hasSrc ? "src/app" : "app";
|
|
165
|
-
rsc = fs2.existsSync(path3.join(cwd, appDir));
|
|
166
|
-
}
|
|
167
|
-
const existingCssFile = findTailwindCssFile(cwd);
|
|
168
|
-
return { hasSrc, framework, rsc, existingCssFile };
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// src/utils/detect-globals.ts
|
|
172
|
-
import fs3 from "fs";
|
|
173
|
-
import path4 from "path";
|
|
174
|
-
function hasGlobalsCss(config, projectRoot) {
|
|
175
|
-
const cssPath = path4.resolve(projectRoot, config.css);
|
|
176
|
-
if (!fs3.existsSync(cssPath)) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
const steraPath = path4.join(path4.dirname(cssPath), "stera-ui.css");
|
|
180
|
-
return fs3.existsSync(steraPath);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// src/utils/install-deps.ts
|
|
184
|
-
import fs4 from "fs";
|
|
185
|
-
import path5 from "path";
|
|
186
|
-
import { spawn } from "child_process";
|
|
187
|
-
|
|
188
|
-
// src/utils/format.ts
|
|
189
|
-
var BRAND = "\x1B[38;2;166;244;48m";
|
|
190
|
-
var DIM = "\x1B[2m";
|
|
191
|
-
var RESET = "\x1B[0m";
|
|
192
|
-
var enabled = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
193
|
-
var wrap = (code, text) => enabled ? `${code}${text}${RESET}` : text;
|
|
194
|
-
var brand = (text) => wrap(BRAND, text);
|
|
195
|
-
var dim = (text) => wrap(DIM, text);
|
|
196
|
-
var LOGO = brand("\u273B");
|
|
197
|
-
var CHECK = brand("\u2713");
|
|
198
|
-
var CROSS = "\u2717";
|
|
199
|
-
var WARN = "!";
|
|
200
|
-
|
|
201
|
-
// src/utils/spinner.ts
|
|
202
|
-
var FRAMES = ["\u2022", "\u2726", "\u2736", "\u273B"].map(brand);
|
|
203
|
-
var INTERVAL_MS = 150;
|
|
204
|
-
function createSpinner(text) {
|
|
205
|
-
const isTTY = process.stdout.isTTY;
|
|
206
|
-
if (!isTTY) {
|
|
207
|
-
process.stdout.write(` ${text}...
|
|
208
|
-
`);
|
|
209
|
-
return {
|
|
210
|
-
succeed(msg) {
|
|
211
|
-
process.stdout.write(` ${CHECK} ${msg}
|
|
212
|
-
`);
|
|
213
|
-
},
|
|
214
|
-
fail(msg) {
|
|
215
|
-
process.stdout.write(` ${CROSS} ${msg}
|
|
216
|
-
`);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
let frameIndex = 0;
|
|
221
|
-
const interval = setInterval(() => {
|
|
222
|
-
process.stdout.write(`\r ${FRAMES[frameIndex % FRAMES.length]} ${text}`);
|
|
223
|
-
frameIndex++;
|
|
224
|
-
}, INTERVAL_MS);
|
|
225
|
-
const clear = () => {
|
|
226
|
-
clearInterval(interval);
|
|
227
|
-
process.stdout.write("\r" + " ".repeat(text.length + 6) + "\r");
|
|
228
|
-
};
|
|
229
|
-
return {
|
|
230
|
-
succeed(msg) {
|
|
231
|
-
clear();
|
|
232
|
-
process.stdout.write(` ${CHECK} ${msg}
|
|
233
|
-
`);
|
|
234
|
-
},
|
|
235
|
-
fail(msg) {
|
|
236
|
-
clear();
|
|
237
|
-
process.stdout.write(` ${CROSS} ${msg}
|
|
238
|
-
`);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/utils/install-deps.ts
|
|
244
|
-
function detectPackageManager(cwd) {
|
|
245
|
-
if (fs4.existsSync(path5.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
246
|
-
if (fs4.existsSync(path5.join(cwd, "bun.lockb"))) return "bun";
|
|
247
|
-
if (fs4.existsSync(path5.join(cwd, "yarn.lock"))) return "yarn";
|
|
248
|
-
return "npm";
|
|
249
|
-
}
|
|
250
|
-
function getInstallArgs(pm, deps) {
|
|
251
|
-
switch (pm) {
|
|
252
|
-
case "pnpm":
|
|
253
|
-
return ["pnpm", ["add", ...deps]];
|
|
254
|
-
case "yarn":
|
|
255
|
-
return ["yarn", ["add", ...deps]];
|
|
256
|
-
case "bun":
|
|
257
|
-
return ["bun", ["add", ...deps]];
|
|
258
|
-
default:
|
|
259
|
-
return ["npm", ["install", ...deps]];
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
async function installDependencies(deps, cwd) {
|
|
263
|
-
if (deps.length === 0) return;
|
|
264
|
-
const pkgPath = path5.join(cwd, "package.json");
|
|
265
|
-
let existing = /* @__PURE__ */ new Set();
|
|
266
|
-
if (fs4.existsSync(pkgPath)) {
|
|
267
|
-
try {
|
|
268
|
-
const pkg = JSON.parse(fs4.readFileSync(pkgPath, "utf-8"));
|
|
269
|
-
existing = new Set(Object.keys({ ...pkg.dependencies, ...pkg.devDependencies }));
|
|
270
|
-
} catch {
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
const toInstall = deps.filter((dep) => !existing.has(dep));
|
|
274
|
-
if (toInstall.length === 0) return;
|
|
275
|
-
const pm = detectPackageManager(cwd);
|
|
276
|
-
const [cmd, args] = getInstallArgs(pm, toInstall);
|
|
277
|
-
const spinner = createSpinner(`Installing with ${pm}`);
|
|
278
|
-
await new Promise((resolve, reject) => {
|
|
279
|
-
const proc = spawn(cmd, args, { cwd, stdio: "pipe" });
|
|
280
|
-
proc.on("close", (code) => {
|
|
281
|
-
if (code === 0) {
|
|
282
|
-
spinner.succeed(`Installed with ${pm}`);
|
|
283
|
-
resolve();
|
|
284
|
-
} else {
|
|
285
|
-
spinner.fail(`Install failed (exit ${code})`);
|
|
286
|
-
reject(new Error(`${pm} exited with code ${code}`));
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
proc.on("error", (err) => {
|
|
290
|
-
spinner.fail(`Install failed`);
|
|
291
|
-
reject(err);
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/utils/write-files.ts
|
|
297
|
-
import fs5 from "fs";
|
|
298
|
-
import path6 from "path";
|
|
299
|
-
import readline from "readline/promises";
|
|
300
|
-
async function confirmOverwrite(relativePath) {
|
|
301
|
-
if (!process.stdin.isTTY) {
|
|
302
|
-
console.log(` Skipping ${relativePath} (already exists, use --overwrite to replace)`);
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
const rl = readline.createInterface({
|
|
306
|
-
input: process.stdin,
|
|
307
|
-
output: process.stdout
|
|
308
|
-
});
|
|
309
|
-
const answer = await rl.question(` ${relativePath} already exists. Overwrite? (y/N) `);
|
|
310
|
-
rl.close();
|
|
311
|
-
return answer.toLowerCase() === "y";
|
|
312
|
-
}
|
|
313
|
-
async function writeComponentFiles(items, config, projectRoot, options = {}) {
|
|
314
|
-
const written = [];
|
|
315
|
-
const skipped = [];
|
|
316
|
-
for (const item of items) {
|
|
317
|
-
for (const file of item.files) {
|
|
318
|
-
const outputPath = resolveOutputPath(config, projectRoot, file);
|
|
319
|
-
const relativePath = path6.relative(projectRoot, outputPath);
|
|
320
|
-
if (fs5.existsSync(outputPath)) {
|
|
321
|
-
const existing = fs5.readFileSync(outputPath, "utf-8");
|
|
322
|
-
if (existing === file.content) {
|
|
323
|
-
skipped.push(relativePath);
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
if (!options.overwrite) {
|
|
327
|
-
const confirmed = await confirmOverwrite(relativePath);
|
|
328
|
-
if (!confirmed) {
|
|
329
|
-
skipped.push(relativePath);
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
const dir = path6.dirname(outputPath);
|
|
335
|
-
fs5.mkdirSync(dir, { recursive: true });
|
|
336
|
-
fs5.writeFileSync(outputPath, file.content ?? "", "utf-8");
|
|
337
|
-
written.push(relativePath);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return { written, skipped };
|
|
341
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
CHECK,
|
|
3
|
+
CONFIG_FILE,
|
|
4
|
+
CROSS,
|
|
5
|
+
LOGO,
|
|
6
|
+
WARN,
|
|
7
|
+
applyTransforms,
|
|
8
|
+
brand,
|
|
9
|
+
createSpinner,
|
|
10
|
+
detectPackageManager,
|
|
11
|
+
detectProject,
|
|
12
|
+
dim,
|
|
13
|
+
findConfigPath,
|
|
14
|
+
hasGlobalsCss,
|
|
15
|
+
installDependencies,
|
|
16
|
+
loadConfig,
|
|
17
|
+
resolveOutputPath,
|
|
18
|
+
transformImports,
|
|
19
|
+
writeComponentFiles
|
|
20
|
+
} from "../chunk-PUJGGJCB.js";
|
|
342
21
|
export {
|
|
343
22
|
CHECK,
|
|
344
23
|
CONFIG_FILE,
|
|
@@ -354,7 +33,7 @@ export {
|
|
|
354
33
|
findConfigPath,
|
|
355
34
|
hasGlobalsCss,
|
|
356
35
|
installDependencies,
|
|
357
|
-
|
|
36
|
+
loadConfig,
|
|
358
37
|
resolveOutputPath,
|
|
359
38
|
transformImports,
|
|
360
39
|
writeComponentFiles
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stera-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Add Stera UI components to your project.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
23
23
|
"bin": {
|
|
24
|
-
"stera-ui": "./dist/
|
|
24
|
+
"stera-ui": "./dist/cli.js"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": "./dist/index.js",
|