@suryaravikumar/mdx-ui 0.0.2 → 0.0.4

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.
@@ -4,15 +4,23 @@ import chalk from "chalk";
4
4
  import ora from "ora";
5
5
  import fs from "fs-extra";
6
6
  import path from "path";
7
+ import { detectProjectStructure } from "../utils/detect-structure.js";
7
8
  const init = new Command().name("init").description("Initialize your project for mdx-ui").action(async () => {
8
9
  console.log(chalk.bold("\n\u2728 Welcome to mdx-ui!\n"));
9
10
  const cwd = process.cwd();
11
+ const structure = await detectProjectStructure(cwd);
12
+ console.log(
13
+ chalk.dim(
14
+ `Detected ${structure.hasSrc ? "src/" : "root-level"} project structure
15
+ `
16
+ )
17
+ );
10
18
  const config = await prompts([
11
19
  {
12
20
  type: "text",
13
21
  name: "componentsDir",
14
22
  message: "Where should we put the components?",
15
- initial: "components/mdx"
23
+ initial: structure.componentsDir
16
24
  },
17
25
  {
18
26
  type: "confirm",
@@ -31,7 +39,7 @@ const init = new Command().name("init").description("Initialize your project for
31
39
  try {
32
40
  const componentsPath = path.join(cwd, config.componentsDir);
33
41
  await fs.ensureDir(componentsPath);
34
- const libPath = path.join(cwd, path.dirname(config.componentsDir), "lib");
42
+ const libPath = path.join(cwd, structure.libDir);
35
43
  await fs.ensureDir(libPath);
36
44
  const utilsContent = config.typescript ? `import { clsx, type ClassValue } from "clsx"
37
45
  import { twMerge } from "tailwind-merge"
@@ -64,7 +72,7 @@ export function cn(...inputs) {
64
72
  console.log(chalk.green(`\u2713 Created ${config.componentsDir}/`));
65
73
  console.log(
66
74
  chalk.green(
67
- `\u2713 Created ${path.dirname(config.componentsDir)}/lib/utils.${config.typescript ? "ts" : "js"}`
75
+ `\u2713 Created ${structure.libDir}/utils.${config.typescript ? "ts" : "js"}`
68
76
  )
69
77
  );
70
78
  console.log(chalk.bold("\n\u{1F389} You're all set!\n"));
@@ -21,17 +21,20 @@ async function loadRegistry() {
21
21
  return {
22
22
  components: [
23
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: [] },
24
+ { name: "callout", type: "mdx", description: "Alert boxes for important information", files: [], registryDependencies: ["utils"] },
25
+ { name: "code-block", type: "mdx", description: "Syntax highlighted code blocks", files: [], registryDependencies: ["utils"] },
26
+ { name: "emphasis", type: "mdx", description: "Text emphasis (bold/italic)", files: [], registryDependencies: ["utils"] },
27
+ { name: "file-tree", type: "mdx", description: "Simple string-based file/folder tree", files: [], registryDependencies: ["utils"] },
28
+ { name: "heading", type: "mdx", description: "Flexible heading component with variant support", files: [], registryDependencies: ["utils"] },
29
+ { name: "headings", type: "mdx", description: "Headings with anchor links", files: [], registryDependencies: ["utils"] },
28
30
  { name: "horizontal-rule", type: "mdx", description: "Divider lines with multiple styles", files: [] },
29
31
  { name: "image", type: "mdx", description: "Images with optional captions", files: [] },
30
- { name: "inline-code", type: "mdx", description: "Inline code snippets", files: [] },
32
+ { name: "inline-code", type: "mdx", description: "Inline code snippets", files: [], registryDependencies: ["utils"] },
31
33
  { 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: [] },
34
+ { name: "paragraph", type: "mdx", description: "Text paragraphs", files: [], registryDependencies: ["utils"] },
35
+ { name: "steps", type: "mdx", description: "Numbered step-by-step guides", files: [], registryDependencies: ["utils"] },
36
+ { name: "tabs", type: "mdx", description: "Tabbed content sections", files: [], registryDependencies: ["utils"] },
37
+ { name: "tree", type: "mdx", description: "Interactive file/folder tree structure", files: [], registryDependencies: ["utils"] },
35
38
  { name: "utils", type: "utility", description: "Utility functions (cn)", files: [] }
36
39
  ]
37
40
  };
package/dist/index.js CHANGED
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from "commander";
3
+ import { readFileSync } from "fs";
4
+ import { fileURLToPath } from "url";
5
+ import { dirname, join } from "path";
3
6
  import { add } from "./commands/add.js";
4
7
  import { init } from "./commands/init.js";
5
8
  import { list } from "./commands/list.js";
6
- const packageJson = {
7
- name: "mdx-ui",
8
- version: "0.0.1"
9
- };
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+ const packageJson = JSON.parse(
12
+ readFileSync(join(__dirname, "..", "package.json"), "utf-8")
13
+ );
10
14
  process.on("SIGINT", () => process.exit(0));
11
15
  process.on("SIGTERM", () => process.exit(0));
12
16
  async function main() {
@@ -0,0 +1,8 @@
1
+ interface ProjectStructure {
2
+ hasSrc: boolean;
3
+ componentsDir: string;
4
+ libDir: string;
5
+ }
6
+ declare function detectProjectStructure(cwd?: string): Promise<ProjectStructure>;
7
+
8
+ export { type ProjectStructure, detectProjectStructure };
@@ -0,0 +1,20 @@
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+ async function detectProjectStructure(cwd = process.cwd()) {
4
+ const srcExists = await fs.pathExists(path.join(cwd, "src"));
5
+ if (srcExists) {
6
+ return {
7
+ hasSrc: true,
8
+ componentsDir: "src/components/mdx-ui",
9
+ libDir: "src/lib"
10
+ };
11
+ }
12
+ return {
13
+ hasSrc: false,
14
+ componentsDir: "components/mdx-ui",
15
+ libDir: "lib"
16
+ };
17
+ }
18
+ export {
19
+ detectProjectStructure
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suryaravikumar/mdx-ui",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Add MDX components to your project",
5
5
  "license": "MIT",
6
6
  "type": "module",