@nyanxx/sui 0.1.0 → 0.2.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/index.cjs +115 -30
- package/dist/index.js +115 -30
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -26,36 +26,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
// src/index.ts
|
|
27
27
|
var import_commander = require("commander");
|
|
28
28
|
|
|
29
|
-
// src/add.ts
|
|
30
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
31
|
-
var import_path = __toESM(require("path"), 1);
|
|
32
|
-
var import_chalk = __toESM(require("chalk"), 1);
|
|
33
|
-
var COMPONENTS = {
|
|
34
|
-
lead: `export function Lead({ children }: { children: React.ReactNode }) {
|
|
35
|
-
return <p className="text-xl text-muted-foreground">{children}</p>;
|
|
36
|
-
}`,
|
|
37
|
-
h1: `export function H1({ children }: { children: React.ReactNode }) {
|
|
38
|
-
return <h1 className="text-4xl font-bold">{children}</h1>;
|
|
39
|
-
}`
|
|
40
|
-
};
|
|
41
|
-
async function addComponents(names) {
|
|
42
|
-
const outDir = import_path.default.resolve(process.cwd(), "components/ui");
|
|
43
|
-
await import_fs_extra.default.ensureDir(outDir);
|
|
44
|
-
for (const name of names) {
|
|
45
|
-
if (!COMPONENTS[name]) {
|
|
46
|
-
console.log(import_chalk.default.red(`\u2716 Unknown component: ${name}`));
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const filePath = import_path.default.join(outDir, `${name}.tsx`);
|
|
50
|
-
await import_fs_extra.default.writeFile(filePath, COMPONENTS[name]);
|
|
51
|
-
console.log(import_chalk.default.green(`\u2714 Added ${name} \u2192 ${filePath}`));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
29
|
// package.json
|
|
56
30
|
var package_default = {
|
|
57
31
|
name: "@nyanxx/sui",
|
|
58
|
-
version: "0.
|
|
32
|
+
version: "0.2.0",
|
|
59
33
|
description: "Add UI components to your project",
|
|
60
34
|
type: "module",
|
|
61
35
|
main: "./dist/index.js",
|
|
@@ -106,10 +80,121 @@ var package_default = {
|
|
|
106
80
|
}
|
|
107
81
|
};
|
|
108
82
|
|
|
83
|
+
// src/constants.ts
|
|
84
|
+
var NAME = package_default.name;
|
|
85
|
+
var VERSION = package_default.version;
|
|
86
|
+
var DESCRIPTION = package_default.description;
|
|
87
|
+
var REGISTRY_BASE = "https://raw.githubusercontent.com/nyanxx/sui-registry/main";
|
|
88
|
+
var REGISTRY_URL = `${REGISTRY_BASE}/registry.json`;
|
|
89
|
+
|
|
90
|
+
// src/add.ts
|
|
91
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
92
|
+
var import_path = __toESM(require("path"), 1);
|
|
93
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
94
|
+
|
|
95
|
+
// src/registry.ts
|
|
96
|
+
async function fetchRegistry(url) {
|
|
97
|
+
const res = await fetch(url);
|
|
98
|
+
if (!res.ok) throw new Error(`Failed to fetch registry: ${res.status}`);
|
|
99
|
+
return res.json();
|
|
100
|
+
}
|
|
101
|
+
function findItem(registry, category, name) {
|
|
102
|
+
return registry.categories[category]?.[name] ?? null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/add.ts
|
|
106
|
+
async function fetchFile(url) {
|
|
107
|
+
const res = await fetch(url);
|
|
108
|
+
if (!res.ok) throw new Error(`Failed to fetch file: ${url} (${res.status})`);
|
|
109
|
+
return res.text();
|
|
110
|
+
}
|
|
111
|
+
async function addItems(category, names) {
|
|
112
|
+
let registry;
|
|
113
|
+
try {
|
|
114
|
+
registry = await fetchRegistry(REGISTRY_URL);
|
|
115
|
+
} catch {
|
|
116
|
+
console.log(
|
|
117
|
+
import_chalk.default.red(
|
|
118
|
+
"\u2716 Could not reach the registry. Check your internet connection."
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
const outDir = import_path.default.resolve(
|
|
124
|
+
process.cwd(),
|
|
125
|
+
category === "components" ? "components/ui" : category
|
|
126
|
+
);
|
|
127
|
+
await import_fs_extra.default.ensureDir(outDir);
|
|
128
|
+
for (const name of names) {
|
|
129
|
+
const item = findItem(registry, category, name);
|
|
130
|
+
if (!item) {
|
|
131
|
+
console.log(import_chalk.default.red(`\u2716 "${name}" not found in ${category}`));
|
|
132
|
+
console.log(import_chalk.default.dim(` Run: @nyanxx/sui list ${category}`));
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (item.requires.length > 0) {
|
|
136
|
+
console.log(
|
|
137
|
+
import_chalk.default.yellow(` \u26A0 ${name} requires: ${item.requires.join(", ")}`)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
for (const file of item.files) {
|
|
141
|
+
const url = `${REGISTRY_BASE}/${file}`;
|
|
142
|
+
try {
|
|
143
|
+
const content = await fetchFile(url);
|
|
144
|
+
const fileName = import_path.default.basename(file);
|
|
145
|
+
const filePath = import_path.default.join(outDir, fileName);
|
|
146
|
+
await import_fs_extra.default.outputFile(filePath, content);
|
|
147
|
+
console.log(import_chalk.default.green(`\u2714 Added ${name} \u2192 ${filePath}`));
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.log(import_chalk.default.red(`\u2716 Failed to download ${file}`));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
109
155
|
// src/index.ts
|
|
156
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
110
157
|
var program = new import_commander.Command();
|
|
111
|
-
program.name(
|
|
112
|
-
program.command("add [
|
|
113
|
-
|
|
158
|
+
program.name(NAME).description(DESCRIPTION).version(VERSION);
|
|
159
|
+
program.command("add <category> [names...]").description("Add components or sections to your project").action(async (category, names) => {
|
|
160
|
+
if (!["components", "sections"].includes(category)) {
|
|
161
|
+
console.log(import_chalk2.default.red(`\u2716 Unknown category: "${category}"`));
|
|
162
|
+
console.log(import_chalk2.default.dim(" Available: components, sections"));
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
await addItems(category, names);
|
|
166
|
+
});
|
|
167
|
+
program.command("list [category]").description("List available categories").action(async (category) => {
|
|
168
|
+
let registry;
|
|
169
|
+
try {
|
|
170
|
+
registry = await fetchRegistry(REGISTRY_URL);
|
|
171
|
+
} catch {
|
|
172
|
+
console.log(import_chalk2.default.red("\u2716 Could not reach the registry."));
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|
|
175
|
+
const categories = category ? [category] : Object.keys(registry.categories);
|
|
176
|
+
for (const cat of categories) {
|
|
177
|
+
const items = registry.categories[cat];
|
|
178
|
+
if (!items) {
|
|
179
|
+
console.log(import_chalk2.default.red(`\u2716 Unknown category: "${cat}"`));
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
console.log(import_chalk2.default.bold(`
|
|
183
|
+
${cat}`));
|
|
184
|
+
const groups = {};
|
|
185
|
+
for (const [name, item] of Object.entries(items)) {
|
|
186
|
+
const g = item.group ?? "other";
|
|
187
|
+
if (!groups[g]) groups[g] = [];
|
|
188
|
+
groups[g].push(name);
|
|
189
|
+
}
|
|
190
|
+
for (const [group, names] of Object.entries(groups)) {
|
|
191
|
+
console.log(import_chalk2.default.dim(` ${group}`));
|
|
192
|
+
for (const name of names) {
|
|
193
|
+
console.log(
|
|
194
|
+
` ${import_chalk2.default.cyan(name)} ${import_chalk2.default.dim(items[name].description)}`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
114
199
|
});
|
|
115
200
|
program.parse();
|
package/dist/index.js
CHANGED
|
@@ -3,36 +3,10 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
|
|
6
|
-
// src/add.ts
|
|
7
|
-
import fs from "fs-extra";
|
|
8
|
-
import path from "path";
|
|
9
|
-
import chalk from "chalk";
|
|
10
|
-
var COMPONENTS = {
|
|
11
|
-
lead: `export function Lead({ children }: { children: React.ReactNode }) {
|
|
12
|
-
return <p className="text-xl text-muted-foreground">{children}</p>;
|
|
13
|
-
}`,
|
|
14
|
-
h1: `export function H1({ children }: { children: React.ReactNode }) {
|
|
15
|
-
return <h1 className="text-4xl font-bold">{children}</h1>;
|
|
16
|
-
}`
|
|
17
|
-
};
|
|
18
|
-
async function addComponents(names) {
|
|
19
|
-
const outDir = path.resolve(process.cwd(), "components/ui");
|
|
20
|
-
await fs.ensureDir(outDir);
|
|
21
|
-
for (const name of names) {
|
|
22
|
-
if (!COMPONENTS[name]) {
|
|
23
|
-
console.log(chalk.red(`\u2716 Unknown component: ${name}`));
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
const filePath = path.join(outDir, `${name}.tsx`);
|
|
27
|
-
await fs.writeFile(filePath, COMPONENTS[name]);
|
|
28
|
-
console.log(chalk.green(`\u2714 Added ${name} \u2192 ${filePath}`));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
6
|
// package.json
|
|
33
7
|
var package_default = {
|
|
34
8
|
name: "@nyanxx/sui",
|
|
35
|
-
version: "0.
|
|
9
|
+
version: "0.2.0",
|
|
36
10
|
description: "Add UI components to your project",
|
|
37
11
|
type: "module",
|
|
38
12
|
main: "./dist/index.js",
|
|
@@ -83,10 +57,121 @@ var package_default = {
|
|
|
83
57
|
}
|
|
84
58
|
};
|
|
85
59
|
|
|
60
|
+
// src/constants.ts
|
|
61
|
+
var NAME = package_default.name;
|
|
62
|
+
var VERSION = package_default.version;
|
|
63
|
+
var DESCRIPTION = package_default.description;
|
|
64
|
+
var REGISTRY_BASE = "https://raw.githubusercontent.com/nyanxx/sui-registry/main";
|
|
65
|
+
var REGISTRY_URL = `${REGISTRY_BASE}/registry.json`;
|
|
66
|
+
|
|
67
|
+
// src/add.ts
|
|
68
|
+
import fs from "fs-extra";
|
|
69
|
+
import path from "path";
|
|
70
|
+
import chalk from "chalk";
|
|
71
|
+
|
|
72
|
+
// src/registry.ts
|
|
73
|
+
async function fetchRegistry(url) {
|
|
74
|
+
const res = await fetch(url);
|
|
75
|
+
if (!res.ok) throw new Error(`Failed to fetch registry: ${res.status}`);
|
|
76
|
+
return res.json();
|
|
77
|
+
}
|
|
78
|
+
function findItem(registry, category, name) {
|
|
79
|
+
return registry.categories[category]?.[name] ?? null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/add.ts
|
|
83
|
+
async function fetchFile(url) {
|
|
84
|
+
const res = await fetch(url);
|
|
85
|
+
if (!res.ok) throw new Error(`Failed to fetch file: ${url} (${res.status})`);
|
|
86
|
+
return res.text();
|
|
87
|
+
}
|
|
88
|
+
async function addItems(category, names) {
|
|
89
|
+
let registry;
|
|
90
|
+
try {
|
|
91
|
+
registry = await fetchRegistry(REGISTRY_URL);
|
|
92
|
+
} catch {
|
|
93
|
+
console.log(
|
|
94
|
+
chalk.red(
|
|
95
|
+
"\u2716 Could not reach the registry. Check your internet connection."
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
const outDir = path.resolve(
|
|
101
|
+
process.cwd(),
|
|
102
|
+
category === "components" ? "components/ui" : category
|
|
103
|
+
);
|
|
104
|
+
await fs.ensureDir(outDir);
|
|
105
|
+
for (const name of names) {
|
|
106
|
+
const item = findItem(registry, category, name);
|
|
107
|
+
if (!item) {
|
|
108
|
+
console.log(chalk.red(`\u2716 "${name}" not found in ${category}`));
|
|
109
|
+
console.log(chalk.dim(` Run: @nyanxx/sui list ${category}`));
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (item.requires.length > 0) {
|
|
113
|
+
console.log(
|
|
114
|
+
chalk.yellow(` \u26A0 ${name} requires: ${item.requires.join(", ")}`)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
for (const file of item.files) {
|
|
118
|
+
const url = `${REGISTRY_BASE}/${file}`;
|
|
119
|
+
try {
|
|
120
|
+
const content = await fetchFile(url);
|
|
121
|
+
const fileName = path.basename(file);
|
|
122
|
+
const filePath = path.join(outDir, fileName);
|
|
123
|
+
await fs.outputFile(filePath, content);
|
|
124
|
+
console.log(chalk.green(`\u2714 Added ${name} \u2192 ${filePath}`));
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.log(chalk.red(`\u2716 Failed to download ${file}`));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
86
132
|
// src/index.ts
|
|
133
|
+
import chalk2 from "chalk";
|
|
87
134
|
var program = new Command();
|
|
88
|
-
program.name(
|
|
89
|
-
program.command("add [
|
|
90
|
-
|
|
135
|
+
program.name(NAME).description(DESCRIPTION).version(VERSION);
|
|
136
|
+
program.command("add <category> [names...]").description("Add components or sections to your project").action(async (category, names) => {
|
|
137
|
+
if (!["components", "sections"].includes(category)) {
|
|
138
|
+
console.log(chalk2.red(`\u2716 Unknown category: "${category}"`));
|
|
139
|
+
console.log(chalk2.dim(" Available: components, sections"));
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
await addItems(category, names);
|
|
143
|
+
});
|
|
144
|
+
program.command("list [category]").description("List available categories").action(async (category) => {
|
|
145
|
+
let registry;
|
|
146
|
+
try {
|
|
147
|
+
registry = await fetchRegistry(REGISTRY_URL);
|
|
148
|
+
} catch {
|
|
149
|
+
console.log(chalk2.red("\u2716 Could not reach the registry."));
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
const categories = category ? [category] : Object.keys(registry.categories);
|
|
153
|
+
for (const cat of categories) {
|
|
154
|
+
const items = registry.categories[cat];
|
|
155
|
+
if (!items) {
|
|
156
|
+
console.log(chalk2.red(`\u2716 Unknown category: "${cat}"`));
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
console.log(chalk2.bold(`
|
|
160
|
+
${cat}`));
|
|
161
|
+
const groups = {};
|
|
162
|
+
for (const [name, item] of Object.entries(items)) {
|
|
163
|
+
const g = item.group ?? "other";
|
|
164
|
+
if (!groups[g]) groups[g] = [];
|
|
165
|
+
groups[g].push(name);
|
|
166
|
+
}
|
|
167
|
+
for (const [group, names] of Object.entries(groups)) {
|
|
168
|
+
console.log(chalk2.dim(` ${group}`));
|
|
169
|
+
for (const name of names) {
|
|
170
|
+
console.log(
|
|
171
|
+
` ${chalk2.cyan(name)} ${chalk2.dim(items[name].description)}`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
91
176
|
});
|
|
92
177
|
program.parse();
|