@suryaravikumar/mdx-ui 0.0.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.
@@ -0,0 +1,5 @@
1
+ import { Command } from 'commander';
2
+
3
+ declare const add: Command;
4
+
5
+ export { add };
@@ -0,0 +1,119 @@
1
+ import { Command } from "commander";
2
+ import prompts from "prompts";
3
+ import chalk from "chalk";
4
+ import ora from "ora";
5
+ import fs from "fs-extra";
6
+ import path from "path";
7
+ import { fileURLToPath } from "url";
8
+ import { getConfig } from "../utils/get-config.js";
9
+ import { fetchComponent } from "../utils/fetch-component.js";
10
+ import { installDependencies } from "../utils/install-deps.js";
11
+ import { writeComponent } from "../utils/write-component.js";
12
+ async function loadRegistry() {
13
+ try {
14
+ const __dirname2 = path.dirname(fileURLToPath(import.meta.url));
15
+ const possiblePaths = [
16
+ path.join(__dirname2, "../../../../registry/registry.json"),
17
+ path.join(__dirname2, "../../../registry/registry.json"),
18
+ path.join(__dirname2, "../../registry/registry.json")
19
+ ];
20
+ for (const registryPath of possiblePaths) {
21
+ if (await fs.pathExists(registryPath)) {
22
+ return await fs.readJSON(registryPath);
23
+ }
24
+ }
25
+ } catch (error) {
26
+ }
27
+ return {
28
+ components: [
29
+ { name: "blockquote", type: "mdx", description: "Styled quote blocks", files: [] },
30
+ { name: "callout", type: "mdx", description: "Alert boxes", files: [] },
31
+ { name: "code-block", type: "mdx", description: "Code blocks", files: [] },
32
+ { name: "emphasis", type: "mdx", description: "Bold/italic", files: [] },
33
+ { name: "headings", type: "mdx", description: "Headings", files: [] },
34
+ { name: "horizontal-rule", type: "mdx", description: "Dividers", files: [] },
35
+ { name: "image", type: "mdx", description: "Images", files: [] },
36
+ { name: "inline-code", type: "mdx", description: "Inline code", files: [] },
37
+ { name: "list", type: "mdx", description: "Lists", files: [] },
38
+ { name: "paragraph", type: "mdx", description: "Paragraphs", files: [] },
39
+ { name: "steps", type: "mdx", description: "Step guides", files: [] },
40
+ { name: "tabs", type: "mdx", description: "Tabs", files: [] }
41
+ ]
42
+ };
43
+ }
44
+ const add = new Command().name("add").description("Add components to your project").argument("[components...]", "components to add").action(async (components) => {
45
+ console.log();
46
+ const config = await getConfig();
47
+ if (!config) {
48
+ console.log(chalk.red("\u2717 No mdx-ui.json found"));
49
+ console.log(chalk.yellow("Run 'npx mdx-ui init' first"));
50
+ process.exit(1);
51
+ }
52
+ if (components.length === 0) {
53
+ const registry = await loadRegistry();
54
+ const mdxComponents = registry.components.filter((c) => c.type === "mdx");
55
+ const { selected } = await prompts({
56
+ type: "multiselect",
57
+ name: "selected",
58
+ message: "Which components would you like to add?",
59
+ choices: mdxComponents.map((c) => ({
60
+ title: c.name.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" "),
61
+ value: c.name,
62
+ description: c.description
63
+ }))
64
+ });
65
+ components = selected;
66
+ }
67
+ if (!components || components.length === 0) {
68
+ console.log(chalk.yellow("No components selected"));
69
+ process.exit(0);
70
+ }
71
+ const spinner = ora("Fetching components...").start();
72
+ try {
73
+ const componentsData = [];
74
+ const processedComponents = /* @__PURE__ */ new Set();
75
+ async function fetchComponentRecursive(componentName) {
76
+ if (processedComponents.has(componentName)) {
77
+ return;
78
+ }
79
+ processedComponents.add(componentName);
80
+ const data = await fetchComponent(componentName);
81
+ if (data.registryDependencies && data.registryDependencies.length > 0) {
82
+ for (const depName of data.registryDependencies) {
83
+ await fetchComponentRecursive(depName);
84
+ }
85
+ }
86
+ componentsData.push(data);
87
+ }
88
+ for (const component of components) {
89
+ await fetchComponentRecursive(component);
90
+ }
91
+ spinner.text = "Installing dependencies...";
92
+ const allDeps = /* @__PURE__ */ new Set();
93
+ for (const data of componentsData) {
94
+ data.dependencies?.forEach((dep) => allDeps.add(dep));
95
+ }
96
+ if (allDeps.size > 0) {
97
+ await installDependencies(Array.from(allDeps));
98
+ }
99
+ spinner.text = "Writing components...";
100
+ for (const data of componentsData) {
101
+ await writeComponent(data, config);
102
+ }
103
+ spinner.succeed("Components added successfully!");
104
+ console.log();
105
+ for (const component of components) {
106
+ console.log(chalk.green(`\u2713 ${component}`));
107
+ }
108
+ console.log();
109
+ console.log(chalk.bold("Done! \u{1F389}"));
110
+ console.log();
111
+ } catch (error) {
112
+ spinner.fail("Failed to add components");
113
+ console.error(chalk.red(error.message));
114
+ process.exit(1);
115
+ }
116
+ });
117
+ export {
118
+ add
119
+ };
@@ -0,0 +1,5 @@
1
+ import { Command } from 'commander';
2
+
3
+ declare const init: Command;
4
+
5
+ export { init };
@@ -0,0 +1,83 @@
1
+ import { Command } from "commander";
2
+ import prompts from "prompts";
3
+ import chalk from "chalk";
4
+ import ora from "ora";
5
+ import fs from "fs-extra";
6
+ import path from "path";
7
+ const init = new Command().name("init").description("Initialize your project for mdx-ui").action(async () => {
8
+ console.log(chalk.bold("\n\u2728 Welcome to mdx-ui!\n"));
9
+ const cwd = process.cwd();
10
+ const config = await prompts([
11
+ {
12
+ type: "text",
13
+ name: "componentsDir",
14
+ message: "Where should we put the components?",
15
+ initial: "components/mdx"
16
+ },
17
+ {
18
+ type: "confirm",
19
+ name: "typescript",
20
+ message: "Are you using TypeScript?",
21
+ initial: true
22
+ },
23
+ {
24
+ type: "confirm",
25
+ name: "tailwind",
26
+ message: "Are you using Tailwind CSS?",
27
+ initial: true
28
+ }
29
+ ]);
30
+ const spinner = ora("Initializing project...").start();
31
+ try {
32
+ const componentsPath = path.join(cwd, config.componentsDir);
33
+ await fs.ensureDir(componentsPath);
34
+ const libPath = path.join(cwd, path.dirname(config.componentsDir), "lib");
35
+ await fs.ensureDir(libPath);
36
+ const utilsContent = config.typescript ? `import { clsx, type ClassValue } from "clsx"
37
+ import { twMerge } from "tailwind-merge"
38
+
39
+ export function cn(...inputs: ClassValue[]) {
40
+ return twMerge(clsx(inputs))
41
+ }
42
+ ` : `import { clsx } from "clsx"
43
+ import { twMerge } from "tailwind-merge"
44
+
45
+ export function cn(...inputs) {
46
+ return twMerge(clsx(inputs))
47
+ }
48
+ `;
49
+ await fs.writeFile(
50
+ path.join(libPath, config.typescript ? "utils.ts" : "utils.js"),
51
+ utilsContent
52
+ );
53
+ const configFile = {
54
+ $schema: "https://mdx-ui.com/schema.json",
55
+ componentsDir: config.componentsDir,
56
+ typescript: config.typescript,
57
+ tailwind: config.tailwind
58
+ };
59
+ await fs.writeJSON(path.join(cwd, "mdx-ui.json"), configFile, {
60
+ spaces: 2
61
+ });
62
+ spinner.succeed("Project initialized!");
63
+ console.log(chalk.green("\n\u2713 Created mdx-ui.json"));
64
+ console.log(chalk.green(`\u2713 Created ${config.componentsDir}/`));
65
+ console.log(
66
+ chalk.green(
67
+ `\u2713 Created ${path.dirname(config.componentsDir)}/lib/utils.${config.typescript ? "ts" : "js"}`
68
+ )
69
+ );
70
+ console.log(chalk.bold("\n\u{1F389} You're all set!\n"));
71
+ console.log("Next steps:");
72
+ console.log(chalk.cyan(" npx mdx-ui add callout"));
73
+ console.log(chalk.cyan(" npx mdx-ui list"));
74
+ console.log();
75
+ } catch (error) {
76
+ spinner.fail("Failed to initialize project");
77
+ console.error(error);
78
+ process.exit(1);
79
+ }
80
+ });
81
+ export {
82
+ init
83
+ };
@@ -0,0 +1,5 @@
1
+ import { Command } from 'commander';
2
+
3
+ declare const list: Command;
4
+
5
+ export { list };
@@ -0,0 +1,66 @@
1
+ import { Command } from "commander";
2
+ import chalk from "chalk";
3
+ import fs from "fs-extra";
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ async function loadRegistry() {
7
+ try {
8
+ const __dirname2 = path.dirname(fileURLToPath(import.meta.url));
9
+ const possiblePaths = [
10
+ path.join(__dirname2, "../../../../registry/registry.json"),
11
+ path.join(__dirname2, "../../../registry/registry.json"),
12
+ path.join(__dirname2, "../../registry/registry.json")
13
+ ];
14
+ for (const registryPath of possiblePaths) {
15
+ if (await fs.pathExists(registryPath)) {
16
+ return await fs.readJSON(registryPath);
17
+ }
18
+ }
19
+ } catch (error) {
20
+ }
21
+ return {
22
+ components: [
23
+ { name: "blockquote", type: "mdx", description: "Styled quote blocks with optional citation", files: [] },
24
+ { name: "callout", type: "mdx", description: "Alert boxes for important information", files: [] },
25
+ { name: "code-block", type: "mdx", description: "Syntax highlighted code blocks", files: [] },
26
+ { name: "emphasis", type: "mdx", description: "Text emphasis (bold/italic)", files: [] },
27
+ { name: "headings", type: "mdx", description: "Headings with anchor links", files: [] },
28
+ { name: "horizontal-rule", type: "mdx", description: "Divider lines with multiple styles", files: [] },
29
+ { name: "image", type: "mdx", description: "Images with optional captions", files: [] },
30
+ { name: "inline-code", type: "mdx", description: "Inline code snippets", files: [] },
31
+ { name: "list", type: "mdx", description: "Styled ordered and unordered lists", files: [] },
32
+ { name: "paragraph", type: "mdx", description: "Text paragraphs", files: [] },
33
+ { name: "steps", type: "mdx", description: "Numbered step-by-step guides", files: [] },
34
+ { name: "tabs", type: "mdx", description: "Tabbed content sections", files: [] },
35
+ { name: "utils", type: "utility", description: "Utility functions (cn)", files: [] }
36
+ ]
37
+ };
38
+ }
39
+ const list = new Command().name("list").description("List all available components").action(async () => {
40
+ console.log();
41
+ console.log(chalk.bold("Available components:\n"));
42
+ const registry = await loadRegistry();
43
+ const mdxComponents = registry.components.filter((c) => c.type === "mdx");
44
+ const utilityComponents = registry.components.filter((c) => c.type === "utility");
45
+ if (mdxComponents.length > 0) {
46
+ console.log(chalk.bold(" MDX Components:"));
47
+ for (const component of mdxComponents) {
48
+ const deps = component.registryDependencies?.length ? chalk.dim(` (requires: ${component.registryDependencies.join(", ")})`) : "";
49
+ console.log(chalk.cyan(` ${component.name.padEnd(18)}`), component.description + deps);
50
+ }
51
+ console.log();
52
+ }
53
+ if (utilityComponents.length > 0) {
54
+ console.log(chalk.bold(" Utilities:"));
55
+ for (const component of utilityComponents) {
56
+ console.log(chalk.cyan(` ${component.name.padEnd(18)}`), component.description);
57
+ }
58
+ console.log();
59
+ }
60
+ console.log(chalk.dim("Usage:"));
61
+ console.log(chalk.dim(" npx mdx-ui add <component>"));
62
+ console.log();
63
+ });
64
+ export {
65
+ list
66
+ };
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { add } from "./commands/add.js";
4
+ import { init } from "./commands/init.js";
5
+ import { list } from "./commands/list.js";
6
+ const packageJson = {
7
+ name: "mdx-ui",
8
+ version: "0.0.1"
9
+ };
10
+ process.on("SIGINT", () => process.exit(0));
11
+ process.on("SIGTERM", () => process.exit(0));
12
+ async function main() {
13
+ const program = new Command().name("mdx-ui").description("Add beautiful MDX components to your project").version(
14
+ packageJson.version || "0.0.1",
15
+ "-v, --version",
16
+ "display the version number"
17
+ );
18
+ program.addCommand(init).addCommand(add).addCommand(list);
19
+ program.parse();
20
+ }
21
+ main();
@@ -0,0 +1,12 @@
1
+ interface ComponentData {
2
+ name: string;
3
+ files: Array<{
4
+ path: string;
5
+ content: string;
6
+ }>;
7
+ dependencies?: string[];
8
+ registryDependencies?: string[];
9
+ }
10
+ declare function fetchComponent(name: string): Promise<ComponentData>;
11
+
12
+ export { type ComponentData, fetchComponent };
@@ -0,0 +1,35 @@
1
+ import axios from "axios";
2
+ import fs from "fs-extra";
3
+ import path from "path";
4
+ import { fileURLToPath } from "url";
5
+ const REGISTRY_URL = "https://raw.githubusercontent.com/yourusername/mdx-ui/main/registry/mdx";
6
+ async function fetchComponent(name) {
7
+ try {
8
+ const __dirname2 = path.dirname(fileURLToPath(import.meta.url));
9
+ const possiblePaths = [
10
+ path.join(__dirname2, "../../../../registry/mdx", `${name}.json`),
11
+ path.join(__dirname2, "../../../registry/mdx", `${name}.json`),
12
+ path.join(__dirname2, "../../registry/mdx", `${name}.json`)
13
+ ];
14
+ for (const registryPath of possiblePaths) {
15
+ if (await fs.pathExists(registryPath)) {
16
+ const data = await fs.readJSON(registryPath);
17
+ return data;
18
+ }
19
+ }
20
+ } catch (error) {
21
+ }
22
+ try {
23
+ const url = `${REGISTRY_URL}/${name}.json`;
24
+ const response = await axios.get(url);
25
+ return response.data;
26
+ } catch (error) {
27
+ if (error.response?.status === 404) {
28
+ throw new Error(`Component "${name}" not found`);
29
+ }
30
+ throw new Error(`Failed to fetch component: ${error.message}`);
31
+ }
32
+ }
33
+ export {
34
+ fetchComponent
35
+ };
@@ -0,0 +1,8 @@
1
+ interface Config {
2
+ componentsDir: string;
3
+ typescript: boolean;
4
+ tailwind: boolean;
5
+ }
6
+ declare function getConfig(): Promise<Config | null>;
7
+
8
+ export { type Config, getConfig };
@@ -0,0 +1,19 @@
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+ async function getConfig() {
4
+ const cwd = process.cwd();
5
+ const configPath = path.join(cwd, "mdx-ui.json");
6
+ try {
7
+ const exists = await fs.pathExists(configPath);
8
+ if (!exists) {
9
+ return null;
10
+ }
11
+ const config = await fs.readJSON(configPath);
12
+ return config;
13
+ } catch (error) {
14
+ return null;
15
+ }
16
+ }
17
+ export {
18
+ getConfig
19
+ };
@@ -0,0 +1,3 @@
1
+ declare function installDependencies(deps: string[]): Promise<void>;
2
+
3
+ export { installDependencies };
@@ -0,0 +1,23 @@
1
+ import { execa } from "execa";
2
+ async function installDependencies(deps) {
3
+ if (deps.length === 0) return;
4
+ const packageManager = await detectPackageManager();
5
+ const args = packageManager === "npm" ? ["install", ...deps] : ["add", ...deps];
6
+ await execa(packageManager, args, {
7
+ cwd: process.cwd()
8
+ });
9
+ }
10
+ async function detectPackageManager() {
11
+ const { stdout } = await execa("which", ["pnpm"], {
12
+ reject: false
13
+ });
14
+ if (stdout) return "pnpm";
15
+ const { stdout: yarnStdout } = await execa("which", ["yarn"], {
16
+ reject: false
17
+ });
18
+ if (yarnStdout) return "yarn";
19
+ return "npm";
20
+ }
21
+ export {
22
+ installDependencies
23
+ };
@@ -0,0 +1,6 @@
1
+ import { Config } from './get-config.js';
2
+ import { ComponentData } from './fetch-component.js';
3
+
4
+ declare function writeComponent(component: ComponentData, config: Config): Promise<void>;
5
+
6
+ export { writeComponent };
@@ -0,0 +1,13 @@
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+ async function writeComponent(component, config) {
4
+ const cwd = process.cwd();
5
+ for (const file of component.files) {
6
+ const filePath = path.join(cwd, config.componentsDir, file.path);
7
+ await fs.ensureDir(path.dirname(filePath));
8
+ await fs.writeFile(filePath, file.content, "utf-8");
9
+ }
10
+ }
11
+ export {
12
+ writeComponent
13
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@suryaravikumar/mdx-ui",
3
+ "version": "0.0.1",
4
+ "description": "Add MDX components to your project",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "author": {
8
+ "name": "ida02pingala06",
9
+ "url": "https://github.com/ida02pingala06"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/ida02pingala06/mdx-ui.git",
14
+ "directory": "packages/cli"
15
+ },
16
+ "homepage": "https://github.com/ida02pingala06/mdx-ui#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/ida02pingala06/mdx-ui/issues"
19
+ },
20
+ "exports": "./dist/index.js",
21
+ "bin": {
22
+ "mdx-ui": "./dist/index.js"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "dev": "tsup --watch",
29
+ "build": "tsup",
30
+ "typecheck": "tsc --noEmit",
31
+ "clean": "rm -rf dist"
32
+ },
33
+ "dependencies": {
34
+ "commander": "^11.1.0",
35
+ "prompts": "^2.4.2",
36
+ "chalk": "^5.3.0",
37
+ "ora": "^8.0.1",
38
+ "execa": "^8.0.1",
39
+ "fs-extra": "^11.2.0",
40
+ "axios": "^1.6.7",
41
+ "zod": "^3.22.4",
42
+ "cosmiconfig": "^9.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/fs-extra": "^11.0.4",
46
+ "@types/prompts": "^2.4.9",
47
+ "tsup": "^8.0.2",
48
+ "typescript": "^5.5.3"
49
+ }
50
+ }