create-vuetify 2.3.1 → 2.4.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.
Files changed (39) hide show
  1. package/dist/index.mjs +1110 -127
  2. package/package.json +26 -29
  3. package/template/javascript/base/eslint.config.js +1 -23
  4. package/template/javascript/base/package.json +5 -9
  5. package/template/javascript/base/src/components/HelloWorld.vue +42 -109
  6. package/template/javascript/base/src/router/index.js +0 -1
  7. package/template/javascript/base/vite.config.mjs +14 -2
  8. package/template/javascript/default/package.json +10 -10
  9. package/template/javascript/default/src/components/AppFooter.vue +6 -3
  10. package/template/javascript/default/src/components/HelloWorld.vue +41 -108
  11. package/template/javascript/default/vite.config.mjs +8 -2
  12. package/template/javascript/essentials/_eslintrc-auto-import.json +11 -1
  13. package/template/javascript/essentials/package.json +3 -3
  14. package/template/javascript/essentials/src/layouts/README.md +1 -1
  15. package/template/javascript/essentials/vite.config.mjs +20 -4
  16. package/template/typescript/base/eslint.config.js +1 -36
  17. package/template/typescript/base/package.json +4 -9
  18. package/template/typescript/base/src/components/HelloWorld.vue +42 -109
  19. package/template/typescript/base/vite.config.mts +13 -1
  20. package/template/typescript/default/README.md +1 -1
  21. package/template/typescript/default/package.json +12 -14
  22. package/template/typescript/default/src/components/HelloWorld.vue +41 -108
  23. package/template/typescript/default/vite.config.mts +6 -0
  24. package/template/typescript/essentials/_eslintrc-auto-import.json +13 -0
  25. package/template/typescript/essentials/env.d.ts +1 -1
  26. package/template/typescript/essentials/package.json +3 -3
  27. package/template/typescript/essentials/src/auto-imports.d.ts +16 -66
  28. package/template/typescript/essentials/src/components/AppFooter.vue +6 -3
  29. package/template/typescript/essentials/src/layouts/README.md +1 -1
  30. package/template/typescript/essentials/vite.config.mts +18 -4
  31. package/template/typescript/nuxt/assets/logo.png +0 -0
  32. package/template/typescript/nuxt/assets/logo.svg +6 -0
  33. package/template/typescript/nuxt/components/AppFooter.vue +38 -35
  34. package/template/typescript/nuxt/components/HelloWorld.vue +44 -107
  35. package/template/typescript/nuxt/modules/vuetify.ts +35 -10
  36. package/template/typescript/nuxt/pages/index.vue +0 -1
  37. package/template/typescript/nuxt/plugins/vuetify-nuxt.ts +2 -2
  38. package/template/typescript/nuxt/plugins/vuetify.ts +1 -1
  39. package/dist/output.cjs +0 -303
@@ -2,8 +2,10 @@ import { defineNuxtModule } from '@nuxt/kit'
2
2
  import type { Options as ModuleOptions } from '@vuetify/loader-shared'
3
3
  import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
4
4
  import path from 'upath'
5
- import { resolveVuetifyBase, isObject } from '@vuetify/loader-shared'
5
+ import { isObject, resolveVuetifyBase } from '@vuetify/loader-shared'
6
6
  import { pathToFileURL } from 'node:url'
7
+ import fs from 'node:fs'
8
+ import fsp from 'node:fs/promises'
7
9
 
8
10
  export type { ModuleOptions }
9
11
 
@@ -14,7 +16,7 @@ export default defineNuxtModule<ModuleOptions>({
14
16
  configKey: 'vuetify',
15
17
  },
16
18
  defaults: () => ({ styles: true }),
17
- setup(options, nuxt) {
19
+ setup (options, nuxt) {
18
20
  let configFile: string | undefined
19
21
  const vuetifyBase = resolveVuetifyBase()
20
22
  const noneFiles = new Set<string>()
@@ -22,8 +24,9 @@ export default defineNuxtModule<ModuleOptions>({
22
24
  let sassVariables = false
23
25
  const PREFIX = 'vuetify-styles/'
24
26
  const SSR_PREFIX = `/@${PREFIX}`
27
+ const resolveCss = resolveCssFactory()
25
28
 
26
- nuxt.hook('vite:extendConfig', (viteInlineConfig) => {
29
+ nuxt.hook('vite:extendConfig', viteInlineConfig => {
27
30
  // add vuetify transformAssetUrls
28
31
  viteInlineConfig.vue ??= {}
29
32
  viteInlineConfig.vue.template ??= {}
@@ -39,6 +42,8 @@ export default defineNuxtModule<ModuleOptions>({
39
42
  viteInlineConfig.css.preprocessorOptions ??= {}
40
43
  viteInlineConfig.css.preprocessorOptions.sass ??= {}
41
44
  viteInlineConfig.css.preprocessorOptions.sass.api = 'modern-compiler'
45
+ viteInlineConfig.css.preprocessorOptions.scss ??= {}
46
+ viteInlineConfig.css.preprocessorOptions.scss.api = 'modern-compiler'
42
47
 
43
48
  viteInlineConfig.plugins.push({
44
49
  name: 'vuetify:nuxt:styles',
@@ -59,7 +64,7 @@ export default defineNuxtModule<ModuleOptions>({
59
64
  },
60
65
  async resolveId (source, importer, { custom, ssr }) {
61
66
  if (source.startsWith(PREFIX) || source.startsWith(SSR_PREFIX)) {
62
- if (source.endsWith('.sass')) {
67
+ if (source.match(/\.s[ca]ss$/)) {
63
68
  return source
64
69
  }
65
70
 
@@ -74,8 +79,7 @@ export default defineNuxtModule<ModuleOptions>({
74
79
  )
75
80
  ) {
76
81
  if (options.styles === 'sass') {
77
- const target = source.replace(/\.css$/, '.sass')
78
- return this.resolve(target, importer, { skipSelf: true, custom })
82
+ return this.resolve(await resolveCss(source), importer, { skipSelf: true, custom })
79
83
  }
80
84
 
81
85
  const resolution = await this.resolve(source, importer, { skipSelf: true, custom })
@@ -83,7 +87,7 @@ export default defineNuxtModule<ModuleOptions>({
83
87
  if (!resolution)
84
88
  return undefined
85
89
 
86
- const target = resolution.id.replace(/\.css$/, '.sass')
90
+ const target = await resolveCss(resolution.id)
87
91
  if (isNone) {
88
92
  noneFiles.add(target)
89
93
  return target
@@ -94,7 +98,7 @@ export default defineNuxtModule<ModuleOptions>({
94
98
 
95
99
  return undefined
96
100
  },
97
- load(id){
101
+ load (id){
98
102
  if (sassVariables) {
99
103
  const target = id.startsWith(PREFIX)
100
104
  ? path.resolve(vuetifyBase, id.slice(PREFIX.length))
@@ -103,8 +107,9 @@ export default defineNuxtModule<ModuleOptions>({
103
107
  : undefined
104
108
 
105
109
  if (target) {
110
+ const suffix = target.match(/\.scss/) ? ';\n' : '\n'
106
111
  return {
107
- code: `@use "${configFile}"\n@use "${pathToFileURL(target).href}"`,
112
+ code: `@use "${configFile}"${suffix}@use "${pathToFileURL(target).href}"${suffix}`,
108
113
  map: {
109
114
  mappings: '',
110
115
  },
@@ -116,9 +121,29 @@ export default defineNuxtModule<ModuleOptions>({
116
121
  },
117
122
  })
118
123
  })
119
- }
124
+ },
120
125
  })
121
126
 
127
+ function resolveCssFactory () {
128
+ const mappings = new Map<string, string>()
129
+ return async (source: string) => {
130
+ let mapping = mappings.get(source)
131
+ if (!mapping) {
132
+ try {
133
+ mapping = source.replace(/\.css$/, '.sass')
134
+ await fsp.access(mapping, fs.constants.R_OK)
135
+ }
136
+ catch (err) {
137
+ if (!(err instanceof Error && 'code' in err && err.code === 'ENOENT'))
138
+ throw err
139
+ mapping = source.replace(/\.css$/, '.scss')
140
+ }
141
+ mappings.set(source, mapping)
142
+ }
143
+ return mapping
144
+ }
145
+ }
146
+
122
147
  function isSubdir (root: string, test: string) {
123
148
  const relative = path.relative(root, test)
124
149
  return relative && !relative.startsWith('..') && !path.isAbsolute(relative)
@@ -5,4 +5,3 @@
5
5
  <template>
6
6
  <HelloWorld />
7
7
  </template>
8
-
@@ -1,6 +1,6 @@
1
- export default defineNuxtPlugin((nuxtApp) => {
1
+ export default defineNuxtPlugin(nuxtApp => {
2
2
  // check https://vuetify-nuxt-module.netlify.app/guide/nuxt-runtime-hooks.html
3
- nuxtApp.hook('vuetify:before-create', (options) => {
3
+ nuxtApp.hook('vuetify:before-create', options => {
4
4
  if (import.meta.client) {
5
5
  console.log('vuetify:before-create', options)
6
6
  }
@@ -1,6 +1,6 @@
1
1
  import { createVuetify } from 'vuetify'
2
2
 
3
- export default defineNuxtPlugin((nuxtApp) => {
3
+ export default defineNuxtPlugin(nuxtApp => {
4
4
  const vuetify = createVuetify({
5
5
  // WARNING: when switching ssr option in nuxt.config.ts file you need to manually change it here
6
6
  ssr: true,
package/dist/output.cjs DELETED
@@ -1,303 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
18
-
19
- // src/index.ts
20
- var import_path3 = require("path");
21
- var import_fs3 = require("fs");
22
-
23
- // src/utils/prompts.ts
24
- var import_path = require("path");
25
- var import_fs = require("fs");
26
-
27
- // src/utils/presets.ts
28
- var defaultContext = {
29
- useEslint: false,
30
- useRouter: false,
31
- useStore: false
32
- };
33
- var baseContext = {
34
- ...defaultContext,
35
- useEslint: true,
36
- useRouter: true
37
- };
38
- var essentialsContext = {
39
- ...baseContext,
40
- useStore: true
41
- };
42
- var presets = {
43
- base: baseContext,
44
- default: defaultContext,
45
- essentials: essentialsContext
46
- };
47
-
48
- // src/utils/prompts.ts
49
- var import_kolorist = require("kolorist");
50
- var import_prompts = __toESM(require("prompts"), 1);
51
- var import_validate_npm_package_name = __toESM(require("validate-npm-package-name"), 1);
52
- var promptQuestions = (context) => [
53
- {
54
- name: "projectName",
55
- type: "text",
56
- message: "Project name:",
57
- initial: "vuetify-project",
58
- validate: (v) => {
59
- const { errors } = (0, import_validate_npm_package_name.default)(String(v).trim());
60
- return !(errors && errors.length) || `Package ${errors[0]}`;
61
- }
62
- },
63
- {
64
- name: "canOverwrite",
65
- active: "Yes",
66
- inactive: "No",
67
- initial: false,
68
- type: (_, { projectName }) => {
69
- const projectPath = (0, import_path.join)(context.cwd, projectName);
70
- return !(0, import_fs.existsSync)(projectPath) || (0, import_fs.readdirSync)(projectPath).length === 0 ? null : "toggle";
71
- },
72
- message: (prev) => `The project path: ${(0, import_path.resolve)(context.cwd, prev)} already exists, would you like to overwrite this directory?`
73
- },
74
- {
75
- name: "usePreset",
76
- type: context.usePreset ? null : "select",
77
- message: "Which preset would you like to install?",
78
- initial: 1,
79
- choices: [
80
- { title: "Default (Vuetify)", value: "default" },
81
- { title: "Base (Vuetify, VueRouter)", value: "base" },
82
- { title: "Essentials (Vuetify, VueRouter, Pinia)", value: "essentials" },
83
- { title: "Custom (Choose your features)", value: "custom" }
84
- ]
85
- },
86
- {
87
- name: "useTypeScript",
88
- type: context.useTypeScript ? null : "toggle",
89
- message: "Use TypeScript?",
90
- active: "Yes",
91
- inactive: "No",
92
- initial: false
93
- },
94
- {
95
- name: "useRouter",
96
- type: (_, { usePreset }) => usePreset !== "custom" && context.usePreset !== "custom" ? null : "toggle",
97
- message: "Use Vue Router?",
98
- active: "Yes",
99
- inactive: "No",
100
- initial: false
101
- },
102
- {
103
- name: "useStore",
104
- type: (_, { usePreset }) => usePreset !== "custom" && context.usePreset !== "custom" ? null : "toggle",
105
- message: "Use Pinia?",
106
- active: "Yes",
107
- inactive: "No",
108
- initial: false
109
- },
110
- {
111
- name: "useEslint",
112
- type: (_, { usePreset }) => usePreset !== "custom" && context.usePreset !== "custom" ? null : "toggle",
113
- message: "Use ESLint?",
114
- active: "Yes",
115
- inactive: "No",
116
- initial: false
117
- },
118
- {
119
- name: "usePackageManager",
120
- type: "select",
121
- message: "Would you like to install dependencies with yarn, npm, pnpm, or bun?",
122
- initial: 0,
123
- choices: [
124
- { title: "yarn", value: "yarn" },
125
- { title: "npm", value: "npm" },
126
- { title: "pnpm", value: "pnpm" },
127
- { title: "bun", value: "bun" },
128
- { title: "none", value: null }
129
- ]
130
- }
131
- ];
132
- var promptOptions = {
133
- onCancel: () => {
134
- throw new Error((0, import_kolorist.red)("\u2716") + " Operation cancelled");
135
- }
136
- };
137
- var initPrompts = async (context) => {
138
- if (context.usePreset && context.usePreset !== "custom") {
139
- context = {
140
- ...context,
141
- ...presets[context.usePreset]
142
- };
143
- }
144
- const answers = await (0, import_prompts.default)(promptQuestions(context), promptOptions);
145
- return {
146
- ...context,
147
- ...answers
148
- };
149
- };
150
-
151
- // src/index.ts
152
- var import_kolorist2 = require("kolorist");
153
- var import_minimist = __toESM(require("minimist"), 1);
154
-
155
- // src/utils/installDependencies.ts
156
- var import_child_process = require("child_process");
157
- function installDependencies(projectRoot, packageManager) {
158
- const cmd = packageManager === "npm" ? "npm install" : packageManager === "yarn" ? "yarn" : packageManager === "bun" ? "bun install" : "pnpm install";
159
- const spawn = (0, import_child_process.spawnSync)(cmd, {
160
- cwd: projectRoot,
161
- stdio: ["inherit", "inherit", "pipe"],
162
- shell: true
163
- });
164
- if (spawn.error) {
165
- throw spawn.error;
166
- }
167
- }
168
-
169
- // src/utils/renderTemplate.ts
170
- var import_fs2 = require("fs");
171
- var import_path2 = require("path");
172
-
173
- // src/utils/deepMerge.ts
174
- var isObject = (v) => {
175
- return v === Object(v) && v !== null && !Array.isArray(v);
176
- };
177
- var deepMerge = (...sources) => sources.reduce((acc, curr) => {
178
- Object.keys(curr).forEach((key) => {
179
- if (Array.isArray(acc[key]) && Array.isArray(curr[key])) {
180
- acc[key] = Array.from(new Set(acc[key].concat(curr[key])));
181
- } else if (isObject(acc[key]) && isObject(curr[key])) {
182
- acc[key] = deepMerge(acc[key], curr[key]);
183
- } else {
184
- acc[key] = curr[key];
185
- }
186
- });
187
- return acc;
188
- }, {});
189
-
190
- // src/utils/renderTemplate.ts
191
- function mergePkg(source, destination) {
192
- const target = JSON.parse((0, import_fs2.readFileSync)(destination, "utf8"));
193
- const src = JSON.parse((0, import_fs2.readFileSync)(source, "utf8"));
194
- const mergedPkg = deepMerge(target, src);
195
- const keysToSort = ["devDependencies", "dependencies"];
196
- keysToSort.forEach((k) => {
197
- mergedPkg[k] = Object.keys(mergedPkg[k]).sort().reduce((a, c) => (a[c] = mergedPkg[k][c], a), {});
198
- });
199
- (0, import_fs2.writeFileSync)(destination, JSON.stringify(mergedPkg, null, 2) + "\n");
200
- }
201
- function renderDirectory(source, destination) {
202
- (0, import_fs2.mkdirSync)(destination, { recursive: true });
203
- (0, import_fs2.readdirSync)(source).forEach((path) => renderTemplate((0, import_path2.resolve)(source, path), (0, import_path2.resolve)(destination, path)));
204
- }
205
- function renderFile(source, destination) {
206
- const filename = (0, import_path2.basename)(source);
207
- if (filename.startsWith("_"))
208
- destination = (0, import_path2.resolve)((0, import_path2.dirname)(destination), filename.replace("_", "."));
209
- if (filename === "package.json")
210
- mergePkg(source, destination);
211
- else
212
- (0, import_fs2.copyFileSync)(source, destination);
213
- }
214
- function renderTemplate(source, destination) {
215
- if ((0, import_fs2.statSync)(source).isDirectory()) {
216
- renderDirectory(source, destination);
217
- } else {
218
- renderFile(source, destination);
219
- }
220
- }
221
-
222
- // src/index.ts
223
- var validPresets = ["base", "custom", "default", "essentials"];
224
- async function run() {
225
- const argv = (0, import_minimist.default)(process.argv.slice(2), {
226
- alias: {
227
- "typescript": ["ts"]
228
- }
229
- });
230
- if (argv.preset && !validPresets.includes(argv.preset)) {
231
- throw new Error(`'${argv.preset}' is not a valid preset. Valid presets are: ${validPresets.join(", ")}.`);
232
- }
233
- const banner = "\x1B[38;2;22;151;246mV\x1B[39m\x1B[38;2;22;147;242mu\x1B[39m\x1B[38;2;22;144;238me\x1B[39m\x1B[38;2;22;140;234mt\x1B[39m\x1B[38;2;23;136;229mi\x1B[39m\x1B[38;2;23;133;225mf\x1B[39m\x1B[38;2;23;129;221my\x1B[39m\x1B[38;2;23;125;217m.\x1B[39m\x1B[38;2;23;121;213mj\x1B[39m\x1B[38;2;23;118;209ms\x1B[39m \x1B[38;2;24;114;204m-\x1B[39m \x1B[38;2;24;110;200mM\x1B[39m\x1B[38;2;24;107;196ma\x1B[39m\x1B[38;2;24;103;192mt\x1B[39m\x1B[38;2;32;110;197me\x1B[39m\x1B[38;2;39;118;202mr\x1B[39m\x1B[38;2;47;125;207mi\x1B[39m\x1B[38;2;54;132;211ma\x1B[39m\x1B[38;2;62;140;216ml\x1B[39m \x1B[38;2;70;147;221mC\x1B[39m\x1B[38;2;77;154;226mo\x1B[39m\x1B[38;2;85;161;231mm\x1B[39m\x1B[38;2;93;169;236mp\x1B[39m\x1B[38;2;100;176;240mo\x1B[39m\x1B[38;2;108;183;245mn\x1B[39m\x1B[38;2;115;191;250me\x1B[39m\x1B[38;2;123;198;255mn\x1B[39m\x1B[38;2;126;199;255mt\x1B[39m \x1B[38;2;129;201;255mF\x1B[39m\x1B[38;2;133;202;255mr\x1B[39m\x1B[38;2;136;204;255ma\x1B[39m\x1B[38;2;139;205;255mm\x1B[39m\x1B[38;2;142;207;255me\x1B[39m\x1B[38;2;145;208;255mw\x1B[39m\x1B[38;2;149;210;255mo\x1B[39m\x1B[38;2;152;211;255mr\x1B[39m\x1B[38;2;155;212;255mk\x1B[39m \x1B[38;2;158;214;255mf\x1B[39m\x1B[38;2;161;215;255mo\x1B[39m\x1B[38;2;164;217;255mr\x1B[39m \x1B[38;2;168;218;255mV\x1B[39m\x1B[38;2;171;220;255mu\x1B[39m\x1B[38;2;174;221;255me\x1B[39m";
234
- console.log(`
235
- ${banner}
236
- `);
237
- const context = {
238
- canOverwrite: false,
239
- cwd: process.cwd(),
240
- projectName: "vuetify-project",
241
- useRouter: false,
242
- useTypeScript: argv.typescript,
243
- usePreset: argv.preset,
244
- useStore: void 0,
245
- usePackageManager: void 0
246
- };
247
- const {
248
- canOverwrite,
249
- cwd,
250
- projectName,
251
- useTypeScript,
252
- usePackageManager,
253
- usePreset,
254
- useStore,
255
- useEslint,
256
- useRouter
257
- } = await initPrompts(context);
258
- const projectRoot = (0, import_path3.join)(cwd, projectName);
259
- if (canOverwrite) {
260
- (0, import_fs3.rmSync)(projectRoot, { recursive: true });
261
- }
262
- (0, import_fs3.mkdirSync)(projectRoot);
263
- (0, import_fs3.writeFileSync)((0, import_path3.resolve)(projectRoot, "package.json"), JSON.stringify({ name: projectName }, null, 2));
264
- const jsOrTs = useTypeScript ? "typescript" : "javascript";
265
- let templatePath = (0, import_path3.resolve)(__dirname, "../template", jsOrTs);
266
- console.log("\n\u25CC Generating scaffold...");
267
- if (usePreset !== "custom") {
268
- renderTemplate((0, import_path3.resolve)(templatePath, usePreset), projectRoot);
269
- } else {
270
- renderTemplate((0, import_path3.resolve)(templatePath, "default"), projectRoot);
271
- templatePath = (0, import_path3.resolve)(templatePath, usePreset);
272
- if (useEslint) {
273
- renderTemplate((0, import_path3.resolve)(templatePath, "eslint"), projectRoot);
274
- }
275
- if (useRouter) {
276
- renderTemplate((0, import_path3.resolve)(templatePath, "router"), projectRoot);
277
- }
278
- if (useStore) {
279
- renderTemplate((0, import_path3.resolve)(templatePath, "store"), projectRoot);
280
- if (useRouter) {
281
- renderTemplate((0, import_path3.resolve)(templatePath, "router-pinia"), projectRoot);
282
- }
283
- }
284
- }
285
- if (usePackageManager) {
286
- console.log(`\u25CC Installing dependencies with ${usePackageManager}...
287
- `);
288
- installDependencies(projectRoot, usePackageManager);
289
- }
290
- console.log(`
291
- ${projectName} has been generated at ${projectRoot}
292
- `);
293
- }
294
- run().then(() => {
295
- console.log("Discord community: https://community.vuetifyjs.com");
296
- console.log("Github: https://github.com/vuetifyjs/vuetify");
297
- console.log("Support Vuetify: https://github.com/sponsors/johnleider");
298
- }).catch((err) => {
299
- console.error(`
300
- ${(0, import_kolorist2.red)("\u2716")} ${err}
301
- `);
302
- process.exit(1);
303
- });