@tryelements/cli 0.1.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.js +183 -0
- package/package.json +36 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands/add.ts
|
|
4
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
|
|
7
|
+
// src/utils.ts
|
|
8
|
+
var REGISTRY_BASE = process.env.TRYELEMENTS_REGISTRY || "https://tryelements.dev/r";
|
|
9
|
+
function normalizeName(input) {
|
|
10
|
+
const name = input.toLowerCase().trim();
|
|
11
|
+
return name.endsWith("-logo") ? name : `${name}-logo`;
|
|
12
|
+
}
|
|
13
|
+
function svgUrl(logoName) {
|
|
14
|
+
return `${REGISTRY_BASE}/svg/${normalizeName(logoName)}.svg`;
|
|
15
|
+
}
|
|
16
|
+
function logosIndexUrl() {
|
|
17
|
+
return `${REGISTRY_BASE}/logos-index.json`;
|
|
18
|
+
}
|
|
19
|
+
async function fetchSvg(logoName) {
|
|
20
|
+
const url = svgUrl(logoName);
|
|
21
|
+
const res = await fetch(url);
|
|
22
|
+
if (!res.ok) {
|
|
23
|
+
if (res.status === 404) {
|
|
24
|
+
throw new Error(`Logo "${logoName}" not found in registry`);
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`Failed to fetch ${logoName}: ${res.statusText}`);
|
|
27
|
+
}
|
|
28
|
+
return res.text();
|
|
29
|
+
}
|
|
30
|
+
async function fetchLogosList() {
|
|
31
|
+
const res = await fetch(logosIndexUrl());
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
throw new Error(`Failed to fetch logos list: ${res.statusText}`);
|
|
34
|
+
}
|
|
35
|
+
return res.json();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/commands/add.ts
|
|
39
|
+
async function addCommand(logos, options) {
|
|
40
|
+
if (!logos.length) {
|
|
41
|
+
console.error("Error: No logos specified");
|
|
42
|
+
console.log(`
|
|
43
|
+
Usage: tryelements add-logo <logos...> [--output-dir=public/]`);
|
|
44
|
+
console.log("Example: tryelements add-logo apple clerk astro");
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
const outputDir = resolve(options.outputDir);
|
|
48
|
+
mkdirSync(outputDir, { recursive: true });
|
|
49
|
+
const results = [];
|
|
50
|
+
for (const logo of logos) {
|
|
51
|
+
const name = normalizeName(logo);
|
|
52
|
+
const outputPath = join(outputDir, `${name}.svg`);
|
|
53
|
+
if (existsSync(outputPath) && !options.overwrite) {
|
|
54
|
+
results.push({
|
|
55
|
+
name,
|
|
56
|
+
status: "err",
|
|
57
|
+
detail: "Already exists (use --overwrite)"
|
|
58
|
+
});
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const svg = await fetchSvg(logo);
|
|
63
|
+
writeFileSync(outputPath, svg);
|
|
64
|
+
results.push({ name, status: "ok", detail: outputPath });
|
|
65
|
+
} catch (error) {
|
|
66
|
+
results.push({
|
|
67
|
+
name,
|
|
68
|
+
status: "err",
|
|
69
|
+
detail: error instanceof Error ? error.message : "Unknown error"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
console.log();
|
|
74
|
+
for (const r of results) {
|
|
75
|
+
const icon = r.status === "ok" ? "+" : "x";
|
|
76
|
+
const detail = r.status === "ok" ? r.detail : r.detail;
|
|
77
|
+
console.log(` ${icon} ${r.name} -> ${detail}`);
|
|
78
|
+
}
|
|
79
|
+
const ok = results.filter((r) => r.status === "ok").length;
|
|
80
|
+
console.log(`
|
|
81
|
+
${ok}/${logos.length} logos installed.`);
|
|
82
|
+
if (ok < logos.length) {
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/commands/list.ts
|
|
88
|
+
async function listCommand(options) {
|
|
89
|
+
try {
|
|
90
|
+
const logos = await fetchLogosList();
|
|
91
|
+
if (options.json) {
|
|
92
|
+
console.log(JSON.stringify(logos, null, 2));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
console.log(`
|
|
96
|
+
Available logos (${logos.length}):
|
|
97
|
+
`);
|
|
98
|
+
const cols = 4;
|
|
99
|
+
for (let i = 0;i < logos.length; i += cols) {
|
|
100
|
+
const row = logos.slice(i, i + cols);
|
|
101
|
+
console.log(" " + row.map((n) => n.padEnd(22)).join(""));
|
|
102
|
+
}
|
|
103
|
+
console.log(`
|
|
104
|
+
Install: tryelements add <name> [--output-dir=public/]`);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error("Error:", error instanceof Error ? error.message : error);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/index.ts
|
|
112
|
+
var VERSION = "0.1.0";
|
|
113
|
+
function printHelp() {
|
|
114
|
+
console.log(`
|
|
115
|
+
tryelements v${VERSION}
|
|
116
|
+
|
|
117
|
+
Install SVG logos from tryelements.dev
|
|
118
|
+
|
|
119
|
+
Usage:
|
|
120
|
+
tryelements add-logo <logos...> [options]
|
|
121
|
+
tryelements list [options]
|
|
122
|
+
|
|
123
|
+
Commands:
|
|
124
|
+
add-logo <logos...> Install logo SVGs to your project
|
|
125
|
+
list List all available logos
|
|
126
|
+
|
|
127
|
+
Options:
|
|
128
|
+
-o, --output-dir Output directory (default: public/)
|
|
129
|
+
--overwrite Overwrite existing files
|
|
130
|
+
--json Output list as JSON
|
|
131
|
+
-h, --help Show this help
|
|
132
|
+
-v, --version Show version
|
|
133
|
+
|
|
134
|
+
Examples:
|
|
135
|
+
tryelements add-logo apple clerk astro
|
|
136
|
+
tryelements add-logo github --output-dir=src/assets
|
|
137
|
+
tryelements list
|
|
138
|
+
`);
|
|
139
|
+
}
|
|
140
|
+
async function main() {
|
|
141
|
+
const args = process.argv.slice(2);
|
|
142
|
+
if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
|
|
143
|
+
printHelp();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (args.includes("-v") || args.includes("--version")) {
|
|
147
|
+
console.log(VERSION);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const command = args[0];
|
|
151
|
+
const rest = args.slice(1);
|
|
152
|
+
if (command === "add-logo") {
|
|
153
|
+
const logos = [];
|
|
154
|
+
let outputDir = "public/";
|
|
155
|
+
let overwrite = false;
|
|
156
|
+
for (const arg of rest) {
|
|
157
|
+
if (arg === "--overwrite") {
|
|
158
|
+
overwrite = true;
|
|
159
|
+
} else if (arg.startsWith("-o=") || arg.startsWith("--output-dir=")) {
|
|
160
|
+
outputDir = arg.split("=")[1];
|
|
161
|
+
} else if (arg === "-o" || arg === "--output-dir") {
|
|
162
|
+
const idx = rest.indexOf(arg);
|
|
163
|
+
if (idx + 1 < rest.length) {
|
|
164
|
+
outputDir = rest[idx + 1];
|
|
165
|
+
}
|
|
166
|
+
} else if (!arg.startsWith("-")) {
|
|
167
|
+
logos.push(arg);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
await addCommand(logos, { outputDir, overwrite });
|
|
171
|
+
} else if (command === "list") {
|
|
172
|
+
const json = rest.includes("--json");
|
|
173
|
+
await listCommand({ json });
|
|
174
|
+
} else {
|
|
175
|
+
console.error(`Unknown command: ${command}`);
|
|
176
|
+
printHelp();
|
|
177
|
+
process.exit(1);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
main().catch((error) => {
|
|
181
|
+
console.error("Fatal:", error.message || error);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tryelements/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Install SVG logos from tryelements.dev",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"tryelements": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"dev": "bun run src/index.ts",
|
|
15
|
+
"build": "bun build src/index.ts --outdir dist --target node --format esm",
|
|
16
|
+
"prepublishOnly": "bun run build"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"cli",
|
|
20
|
+
"svg",
|
|
21
|
+
"logos",
|
|
22
|
+
"icons",
|
|
23
|
+
"tryelements",
|
|
24
|
+
"shadcn"
|
|
25
|
+
],
|
|
26
|
+
"author": "Railly Hugo <the.crafter.station@gmail.com>",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/crafter-station/elements",
|
|
31
|
+
"directory": "packages/tryelements"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|