shadcn-nuxt 0.1.0 → 0.8.6

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/README.md CHANGED
@@ -47,7 +47,18 @@ npm install --save-dev shadcn-nuxt
47
47
  export default defineNuxtConfig({
48
48
  modules: [
49
49
  'shadcn-nuxt'
50
- ]
50
+ ],
51
+ shadcn: {
52
+ /**
53
+ * Prefix for all the imported component
54
+ */
55
+ prefix: '',
56
+ /**
57
+ * Directory that the component lives in.
58
+ * @default "./components/ui"
59
+ */
60
+ componentDir: './components/ui'
61
+ }
51
62
  })
52
63
  ```
53
64
 
package/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "shadcn",
3
3
  "configKey": "shadcn",
4
- "version": "0.1.0"
4
+ "version": "0.8.6"
5
5
  }
package/dist/module.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { readdirSync } from 'node:fs';
1
+ import { readdirSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
2
3
  import { defineNuxtModule, createResolver, addComponent } from '@nuxt/kit';
3
- import { Project } from 'ts-morph';
4
+ import { parse } from 'recast';
4
5
 
5
6
  const module = defineNuxtModule({
6
7
  meta: {
@@ -11,25 +12,25 @@ const module = defineNuxtModule({
11
12
  prefix: "",
12
13
  componentDir: "./components/ui"
13
14
  },
14
- async setup(options, nuxt) {
15
- const IGNORE_DIR = "**/components/ui";
16
- const COMPONENT_DIR_PATH = options.componentDir;
15
+ async setup({ prefix, componentDir }, nuxt) {
16
+ const COMPONENT_DIR_PATH = componentDir;
17
17
  const ROOT_DIR_PATH = nuxt.options.rootDir;
18
- const { resolve } = createResolver(ROOT_DIR_PATH);
19
- nuxt.options.ignore.push(IGNORE_DIR);
20
- nuxt._ignore?.add(IGNORE_DIR);
21
- nuxt._ignorePatterns?.push(IGNORE_DIR);
18
+ const { resolve, resolvePath } = createResolver(ROOT_DIR_PATH);
19
+ nuxt.hook("components:dirs", (dirs) => {
20
+ dirs.unshift({
21
+ path: resolve(COMPONENT_DIR_PATH),
22
+ extensions: []
23
+ });
24
+ });
22
25
  try {
23
26
  readdirSync(resolve(COMPONENT_DIR_PATH)).forEach(async (dir) => {
24
- const filePath = resolve(COMPONENT_DIR_PATH, dir, "index.ts");
25
- const project = new Project();
26
- project.addSourceFileAtPath(filePath);
27
- const sourceFile = project.getSourceFileOrThrow(filePath);
28
- const exportedDeclarations = sourceFile.getExportedDeclarations();
29
- const exportedKeys = Array.from(exportedDeclarations.keys()).filter((key) => /^[A-Z]/.test(key));
27
+ const filePath = await resolvePath(join(COMPONENT_DIR_PATH, dir, "index"), { extensions: [".ts", "js"] });
28
+ const content = readFileSync(filePath, { encoding: "utf8" });
29
+ const ast = parse(content);
30
+ const exportedKeys = ast.program.body.filter((node) => node.type === "ExportNamedDeclaration").flatMap((node) => node.specifiers.map((specifier) => specifier.exported.name)).filter((key) => /^[A-Z]/.test(key));
30
31
  exportedKeys.forEach((key) => {
31
32
  addComponent({
32
- name: `${options.prefix}${key}`,
33
+ name: `${prefix}${key}`,
33
34
  // name of the component to be used in vue templates
34
35
  export: key,
35
36
  // (optional) if the component is a named (rather than default) export
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shadcn-nuxt",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.8.6",
5
5
  "description": "Add shadcn-vue module to Nuxt",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -26,6 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@nuxt/kit": "^3.8.2",
29
+ "recast": "^0.23.4",
29
30
  "ts-morph": "^19.0.0"
30
31
  },
31
32
  "devDependencies": {