vue-ready-modular 1.0.0 → 1.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.
package/lib/generator.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import path from "path";
2
2
  import fs from "fs";
3
+ import { plural, capitalize } from "./utils/string.js";
3
4
 
4
5
  import { createDir, createFile } from "./utils/file.js";
5
- import { capitalize } from "./utils/string.js";
6
6
 
7
7
  // Templates
8
8
  import indexTemplate from "./templates/index.template.js";
@@ -60,17 +60,35 @@ export function createModule(name) {
60
60
  createFile(`${basePath}/stores/${module}Store.js`, storeTemplate(ctx));
61
61
  createFile(`${basePath}/data/${module}Data.js`, dataTemplate(ctx));
62
62
  createFile(`${basePath}/services/${module}Service.js`, serviceTemplate(ctx));
63
- createFile(`${basePath}/queries/use${Module}sQuery.js`, queryTemplate(ctx));
64
- createFile(`${basePath}/queries/use${Module}Mutations.js`, mutationTemplate(ctx));
63
+ createFile(
64
+ `${basePath}/queries/use${capitalize(plural(Module))}Query.js`,
65
+ queryTemplate(ctx)
66
+ );
67
+ createFile(
68
+ `${basePath}/queries/use${Module}Mutations.js`,
69
+ mutationTemplate(ctx)
70
+ );
65
71
 
66
72
  // -----------------------------
67
73
  // 4. Create page & modal components
68
74
  // -----------------------------
69
75
  createFile(`${basePath}/pages/${Module}Page.vue`, pageTemplate(ctx));
70
- createFile(`${basePath}/pages/components/AddModal.vue`, addModalTemplate(ctx));
71
- createFile(`${basePath}/pages/components/EditModal.vue`, editModalTemplate(ctx));
72
- createFile(`${basePath}/pages/components/ViewModal.vue`, viewModalTemplate(ctx));
73
- createFile(`${basePath}/pages/components/DeleteModal.vue`, deleteModalTemplate(ctx));
76
+ createFile(
77
+ `${basePath}/pages/components/AddModal.vue`,
78
+ addModalTemplate(ctx)
79
+ );
80
+ createFile(
81
+ `${basePath}/pages/components/EditModal.vue`,
82
+ editModalTemplate(ctx)
83
+ );
84
+ createFile(
85
+ `${basePath}/pages/components/ViewModal.vue`,
86
+ viewModalTemplate(ctx)
87
+ );
88
+ createFile(
89
+ `${basePath}/pages/components/DeleteModal.vue`,
90
+ deleteModalTemplate(ctx)
91
+ );
74
92
 
75
93
  console.log(`✅ Module "${module}" created successfully`);
76
94
  }
@@ -1,4 +1,10 @@
1
- export default ({ name, Name }) => `<template>
1
+ // lib/templates/page.template.js
2
+ import { plural, capitalize } from "../utils/string.js";
3
+
4
+ export default ({ name, Name }) => {
5
+ const pluralName = capitalize(plural(Name)); // Country -> Countries
6
+
7
+ return `<template>
2
8
  <div class="min-h-screen bg-gray-50">
3
9
  <div class="mb-6 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
4
10
  <PageTitle>{{ store.moduleName }} List</PageTitle>
@@ -28,7 +34,7 @@ export default ({ name, Name }) => `<template>
28
34
 
29
35
  <script setup>
30
36
  import { computed, defineAsyncComponent } from 'vue'
31
- import { use${Name}sQuery } from '../queries/use${Name}sQuery'
37
+ import { use${pluralName}Query } from '../queries/use${pluralName}Query'
32
38
  import { use${Name}Store } from '../stores/${name}Store'
33
39
 
34
40
  const ViewModal = defineAsyncComponent(() => import('./components/ViewModal.vue'))
@@ -37,7 +43,7 @@ const EditModal = defineAsyncComponent(() => import('./components/EditModal.vue'
37
43
  const DeleteModal = defineAsyncComponent(() => import('./components/DeleteModal.vue'))
38
44
 
39
45
  const store = use${Name}Store()
40
- const { data, isLoading } = use${Name}sQuery()
46
+ const { data, isLoading } = use${pluralName}Query()
41
47
 
42
48
  const columns = [
43
49
  { key: 'sl', label: 'SL' },
@@ -59,3 +65,4 @@ function onDelete(row) {
59
65
  }
60
66
  </script>
61
67
  `;
68
+ };
@@ -1,19 +1,24 @@
1
- export default ({
2
- name,
3
- Name,
4
- }) => `import { useQuery } from '@tanstack/vue-query'
1
+ import { plural, capitalize } from "../utils/string.js";
2
+
3
+ export default ({ name, Name }) => {
4
+ const pluralName = plural(name); // country countries, city cities
5
+
6
+ return `import { useQuery } from '@tanstack/vue-query'
5
7
  import { fetchAll } from '../services/${name}Service'
6
8
 
7
- export function use${Name}sQuery(params = {}) {
9
+ export function use${capitalize(
10
+ pluralName
11
+ )}Query(params = {}) { // ✅ function name dynamically pluralized
8
12
  return useQuery({
9
- queryKey: ['${name}s', params],
13
+ queryKey: ['${pluralName}', params], // ✅ query key dynamically pluralized
10
14
  queryFn: () => fetchAll(params),
11
- staleTime: 5 * 60 * 1000, // 5 minutes
12
- cacheTime: 1000 * 60 * 60, // 1 hour
15
+ staleTime: 5 * 60 * 1000,
16
+ cacheTime: 1000 * 60 * 60,
13
17
  keepPreviousData: true,
14
18
  meta: {
15
- persist: true, // ✅ persisted
19
+ persist: true,
16
20
  },
17
21
  })
18
22
  }
19
23
  `;
24
+ };
@@ -1,21 +1,26 @@
1
- export default ({
2
- name,
3
- Name,
4
- }) => `import ${Name}Page from './pages/${Name}Page.vue'
1
+ // lib/templates/routes.template.js
2
+ import { plural } from "../utils/string.js";
3
+
4
+ export default ({ name, Name }) => {
5
+ const pathName = plural(name);
6
+ const routeName = `${Name}List`;
7
+
8
+ return `import ${Name}Page from './pages/${Name}Page.vue'
5
9
  import DashboardLayout from '@/shared/layouts/DashboardLayout.vue'
6
10
 
7
11
  export default [
8
12
  {
9
- path: '/${name}s',
13
+ path: '/${pathName}',
10
14
  component: DashboardLayout,
11
15
  meta: { requiresAuth: true },
12
16
  children: [
13
17
  {
14
18
  path: '',
15
- name: '${Name}List',
19
+ name: '${routeName}',
16
20
  component: ${Name}Page,
17
21
  },
18
22
  ],
19
23
  },
20
24
  ]
21
25
  `;
26
+ };
@@ -1,9 +1,11 @@
1
- export default ({
2
- name,
3
- Name,
4
- }) => `import { useApi } from '@/shared/composables/useApi'
1
+ import { plural } from '../utils/string.js'
5
2
 
6
- const BASE_URL = '/${name}s'
3
+ export default ({ name, Name }) => {
4
+ const baseUrl = `/${plural(name)}`
5
+
6
+ return `import { useApi } from '@/shared/composables/useApi'
7
+
8
+ const BASE_URL = '${baseUrl}'
7
9
 
8
10
  const response = (api) => ({
9
11
  data: api.data.value,
@@ -40,4 +42,5 @@ export async function deleteItem(id) {
40
42
  if (api.error.value) throw api.error.value
41
43
  return api.data.value
42
44
  }
43
- `;
45
+ `
46
+ }
@@ -1,3 +1,7 @@
1
- export function capitalize(str) {
2
- return str.charAt(0).toUpperCase() + str.slice(1);
3
- }
1
+ // lib/utils/string.js
2
+ import pluralize from 'pluralize'
3
+
4
+ export const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1)
5
+
6
+ // pluralize dynamically
7
+ export const plural = (str) => pluralize(str.toLowerCase())
package/package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
- "name": "vue-ready-modular",
3
- "version": "1.0.0",
2
+ "name": "vue-ready-modular",
3
+ "version": "1.0.1",
4
4
  "description": "Vue.js module generator",
5
- "main": "lib/generator.js",
5
+ "main": "lib/generator.js",
6
6
  "bin": {
7
- "vue-modular": "./bin/cli.js"
7
+ "vue-modular": "./bin/cli.js"
8
8
  },
9
- "type": "module",
9
+ "type": "module",
10
10
  "scripts": {
11
11
  "test": "echo \"No tests yet\""
12
12
  },
13
- "keywords": ["vue", "generator", "module", "cli"],
13
+ "keywords": [
14
+ "vue",
15
+ "generator",
16
+ "module",
17
+ "cli"
18
+ ],
14
19
  "author": "Your Name",
15
20
  "license": "MIT",
16
- "dependencies": {
17
- "path": "^0.12.7"
21
+ "dependencies": {
22
+ "path": "^0.12.7",
23
+ "pluralize": "^8.0.0"
18
24
  }
19
25
  }