@typix-editor/cli 3.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Diyorbek
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/dist/index.js ADDED
@@ -0,0 +1,238 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { Command } from "commander";
5
+
6
+ // src/commands/init.ts
7
+ import inquirer from "inquirer";
8
+
9
+ // src/utils/config.ts
10
+ import fs from "fs-extra";
11
+ import path from "path";
12
+ var CONFIG_FILE = "typix.json";
13
+ function getConfigPath() {
14
+ return path.resolve(process.cwd(), CONFIG_FILE);
15
+ }
16
+ async function readConfig() {
17
+ const configPath = getConfigPath();
18
+ if (await fs.pathExists(configPath)) {
19
+ return fs.readJson(configPath);
20
+ }
21
+ return null;
22
+ }
23
+ async function writeConfig(config) {
24
+ const configPath = getConfigPath();
25
+ await fs.writeJson(configPath, config, { spaces: 2 });
26
+ }
27
+ function getDefaultConfig() {
28
+ return {
29
+ componentDir: "src/components/typix",
30
+ typescript: true,
31
+ tailwind: true
32
+ };
33
+ }
34
+
35
+ // src/utils/logger.ts
36
+ import chalk from "chalk";
37
+ import ora from "ora";
38
+ var logger = {
39
+ info: (msg) => console.log(chalk.cyan("\u2139"), msg),
40
+ success: (msg) => console.log(chalk.green("\u2714"), msg),
41
+ warn: (msg) => console.log(chalk.yellow("\u26A0"), msg),
42
+ error: (msg) => console.log(chalk.red("\u2716"), msg),
43
+ break: () => console.log("")
44
+ };
45
+ function spinner(text) {
46
+ return ora({ text, color: "cyan" });
47
+ }
48
+
49
+ // src/commands/init.ts
50
+ async function initCommand() {
51
+ const existing = await readConfig();
52
+ if (existing) {
53
+ const { overwrite } = await inquirer.prompt([
54
+ {
55
+ type: "confirm",
56
+ name: "overwrite",
57
+ message: "typix.json already exists. Overwrite?",
58
+ default: false
59
+ }
60
+ ]);
61
+ if (!overwrite) {
62
+ logger.info("Init cancelled.");
63
+ return;
64
+ }
65
+ }
66
+ const defaults = getDefaultConfig();
67
+ const answers = await inquirer.prompt([
68
+ {
69
+ type: "input",
70
+ name: "componentDir",
71
+ message: "Component output directory:",
72
+ default: defaults.componentDir
73
+ },
74
+ {
75
+ type: "confirm",
76
+ name: "typescript",
77
+ message: "Use TypeScript?",
78
+ default: defaults.typescript
79
+ },
80
+ {
81
+ type: "confirm",
82
+ name: "tailwind",
83
+ message: "Use Tailwind CSS?",
84
+ default: defaults.tailwind
85
+ }
86
+ ]);
87
+ await writeConfig({
88
+ componentDir: answers.componentDir,
89
+ typescript: answers.typescript,
90
+ tailwind: answers.tailwind
91
+ });
92
+ logger.break();
93
+ logger.success("Created typix.json");
94
+ logger.info(`Components will be added to ${answers.componentDir}`);
95
+ }
96
+
97
+ // src/commands/add.ts
98
+ import chalk2 from "chalk";
99
+
100
+ // src/utils/registry.ts
101
+ var registry = {
102
+ "toolbar-button": {
103
+ name: "toolbar-button",
104
+ description: "Reusable toolbar button with active state styling",
105
+ files: ["toolbar-button/toolbar-button.tsx"],
106
+ dependencies: ["@typix-editor/react"],
107
+ registryDependencies: []
108
+ }
109
+ };
110
+ function getRegistryEntry(name) {
111
+ return registry[name];
112
+ }
113
+ function getAllComponents() {
114
+ return Object.values(registry);
115
+ }
116
+ function getComponentNames() {
117
+ return Object.keys(registry);
118
+ }
119
+
120
+ // src/utils/writer.ts
121
+ import fs2 from "fs-extra";
122
+ import path2 from "path";
123
+ import { fileURLToPath } from "url";
124
+ var __filename = fileURLToPath(import.meta.url);
125
+ var __dirname = path2.dirname(__filename);
126
+ function getTemplatesDir() {
127
+ return path2.resolve(__dirname, "..", "templates");
128
+ }
129
+ async function writeComponent(entry, config) {
130
+ const templatesDir = getTemplatesDir();
131
+ const outputDir = path2.resolve(process.cwd(), config.componentDir);
132
+ const written = [];
133
+ for (const file of entry.files) {
134
+ const srcPath = path2.join(templatesDir, file);
135
+ const destPath = path2.join(outputDir, file);
136
+ await fs2.ensureDir(path2.dirname(destPath));
137
+ await fs2.copyFile(srcPath, destPath);
138
+ const relativePath = path2.relative(process.cwd(), destPath);
139
+ written.push(relativePath);
140
+ }
141
+ return written;
142
+ }
143
+ function collectDependencies(entries) {
144
+ const deps = /* @__PURE__ */ new Set();
145
+ for (const entry of entries) {
146
+ for (const dep of entry.dependencies) {
147
+ deps.add(dep);
148
+ }
149
+ }
150
+ return Array.from(deps).sort();
151
+ }
152
+
153
+ // src/commands/add.ts
154
+ async function addCommand(components, options) {
155
+ const config = await readConfig();
156
+ if (!config) {
157
+ logger.error(
158
+ "No typix.json found. Run " + chalk2.cyan("typix init") + " first."
159
+ );
160
+ process.exit(1);
161
+ }
162
+ let entries;
163
+ if (options.all) {
164
+ entries = getAllComponents();
165
+ } else {
166
+ if (components.length === 0) {
167
+ logger.error("Please specify a component name or use --all.");
168
+ logger.info(
169
+ "Available: " + getComponentNames().join(", ")
170
+ );
171
+ process.exit(1);
172
+ }
173
+ entries = [];
174
+ for (const name of components) {
175
+ const entry = getRegistryEntry(name);
176
+ if (!entry) {
177
+ logger.error(
178
+ `Component "${name}" not found. Available: ${getComponentNames().join(", ")}`
179
+ );
180
+ process.exit(1);
181
+ }
182
+ entries.push(entry);
183
+ }
184
+ }
185
+ const s = spinner("Adding components...").start();
186
+ const allWritten = [];
187
+ for (const entry of entries) {
188
+ const written = await writeComponent(entry, config);
189
+ allWritten.push(...written);
190
+ }
191
+ s.succeed("Components added!");
192
+ logger.break();
193
+ for (const file of allWritten) {
194
+ logger.success(`Created ${chalk2.bold(file)}`);
195
+ }
196
+ const deps = collectDependencies(entries);
197
+ if (deps.length > 0) {
198
+ logger.break();
199
+ logger.info("Install required dependencies:");
200
+ console.log(
201
+ chalk2.cyan(` pnpm add ${deps.join(" ")}`)
202
+ );
203
+ }
204
+ }
205
+
206
+ // src/commands/list.ts
207
+ import chalk3 from "chalk";
208
+ async function listCommand() {
209
+ const components = getAllComponents();
210
+ logger.break();
211
+ console.log(chalk3.bold("Available components:"));
212
+ logger.break();
213
+ const nameWidth = 20;
214
+ const header = chalk3.gray(
215
+ " " + "Name".padEnd(nameWidth) + "Description"
216
+ );
217
+ console.log(header);
218
+ console.log(chalk3.gray(" " + "\u2500".repeat(55)));
219
+ for (const component of components) {
220
+ const name = chalk3.cyan(component.name.padEnd(nameWidth));
221
+ console.log(` ${name}${component.description}`);
222
+ }
223
+ logger.break();
224
+ logger.info(
225
+ `Add a component: ${chalk3.cyan("typix add <component>")}`
226
+ );
227
+ logger.info(
228
+ `Add all components: ${chalk3.cyan("typix add --all")}`
229
+ );
230
+ }
231
+
232
+ // src/index.ts
233
+ var program = new Command();
234
+ program.name("typix").description("CLI for adding pre-built UI components to your Typix editor").version("1.0.0");
235
+ program.command("init").description("Initialize Typix config (typix.json)").action(initCommand);
236
+ program.command("add").description("Add a component to your project").argument("[components...]", "Components to add").option("-a, --all", "Add all available components").action(addCommand);
237
+ program.command("list").description("List available components").action(listCommand);
238
+ program.parse();
@@ -0,0 +1,39 @@
1
+ "use client";
2
+
3
+ type ToolbarButtonProps = {
4
+ onClick: () => void;
5
+ active?: boolean;
6
+ title: string;
7
+ children: React.ReactNode;
8
+ size?: "sm" | "md";
9
+ };
10
+
11
+ export function ToolbarButton({
12
+ onClick,
13
+ active,
14
+ title,
15
+ children,
16
+ size = "sm",
17
+ }: ToolbarButtonProps) {
18
+ return (
19
+ <button
20
+ className={[
21
+ "inline-flex items-center justify-center rounded-md transition-all",
22
+ "hover:bg-accent",
23
+ size === "sm" ? "h-7 w-7" : "h-8 w-8",
24
+ active ? "bg-primary/10 text-primary hover:bg-primary/20" : "",
25
+ ]
26
+ .filter(Boolean)
27
+ .join(" ")}
28
+ onClick={onClick}
29
+ title={title}
30
+ type="button"
31
+ >
32
+ {children}
33
+ </button>
34
+ );
35
+ }
36
+
37
+ export function ToolbarDivider() {
38
+ return <div className="mx-1.5 h-5 w-px bg-border/60" />;
39
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@typix-editor/cli",
3
+ "version": "3.0.0",
4
+ "description": "CLI for adding pre-built UI components to your Typix editor project",
5
+ "author": "Diyorbek Juraev <mrdiyorbekjuraev@gmail.com>",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "bin": {
9
+ "typix": "./dist/index.js"
10
+ },
11
+ "main": "dist/index.js",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "dependencies": {
16
+ "chalk": "^5.4.1",
17
+ "commander": "^13.1.0",
18
+ "fs-extra": "^11.3.0",
19
+ "inquirer": "^12.6.0",
20
+ "ora": "^8.2.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/fs-extra": "^11.0.4",
24
+ "@types/node": "^24.10.1",
25
+ "tsup": "^8.0.0",
26
+ "typescript": "^5.3.0"
27
+ },
28
+ "keywords": [
29
+ "typix",
30
+ "cli",
31
+ "editor",
32
+ "ui",
33
+ "components"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/mrdiyorbek-juraev/typix.git"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
45
+ "clean": "git clean -xdf .cache .turbo dist node_modules rm -rf dist"
46
+ }
47
+ }