@nuxt/cli-nightly 3.29.4-20251009-171833-0915ec9 → 3.29.4-20251021-190716-bbf70fc
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/dist/_shared-C3vB2YLc.mjs +42 -0
- package/dist/_utils-DTrPahho.mjs +29 -0
- package/dist/add-BGMHIn5L.mjs +333 -0
- package/dist/add-CRBwIlDF.mjs +298 -0
- package/dist/add-hFFIzkcy.mjs +10 -0
- package/dist/analyze-CUKAi_IN.mjs +115 -0
- package/dist/banner-CqfM_0Qo.mjs +55 -0
- package/dist/build-BSxJLNs_.mjs +78 -0
- package/dist/build-KNIBU0AI.mjs +9 -0
- package/dist/cleanup-8GRakeLu.mjs +31 -0
- package/dist/dev/index.d.mts +87 -83
- package/dist/dev/index.mjs +7 -23
- package/dist/dev-Bs_0dzlh.mjs +591 -0
- package/dist/dev-CnQwDUaD.mjs +7 -0
- package/dist/dev-L7lhoThJ.mjs +438 -0
- package/dist/dev-child-CSiX6Uyv.mjs +37 -0
- package/dist/devtools-BLGzUSNU.mjs +44 -0
- package/dist/env-Dz4K_NkM.mjs +12 -0
- package/dist/fs-ewAp6tjM.mjs +40 -0
- package/dist/generate-CGy3-x2K.mjs +35 -0
- package/dist/index.d.mts +9 -18
- package/dist/index.mjs +129 -8
- package/dist/info-BDdsghj1.mjs +120 -0
- package/dist/init-_n9DXzzY.mjs +336 -0
- package/dist/kit-xFxVGu6d.mjs +37 -0
- package/dist/logger-Dk0gkCkX.mjs +7 -0
- package/dist/module-CqBrGD-s.mjs +17 -0
- package/dist/nuxt-Cc9ZTk7m.mjs +44 -0
- package/dist/packageManagers-DbVB5cXf.mjs +9 -0
- package/dist/prepare-B0KOhO-L.mjs +7 -0
- package/dist/prepare-xI978yFg.mjs +49 -0
- package/dist/preview-C5fNqrC6.mjs +109 -0
- package/dist/search-DCyXfxzn.mjs +113 -0
- package/dist/test-CBt1emEB.mjs +55 -0
- package/dist/typecheck-DCWe7Iej.mjs +102 -0
- package/dist/upgrade-BMSFcUWJ.mjs +184 -0
- package/dist/versions-CSy_3o_-.mjs +18 -0
- package/package.json +13 -13
- package/dist/chunks/add.mjs +0 -381
- package/dist/chunks/add2.mjs +0 -319
- package/dist/chunks/analyze.mjs +0 -139
- package/dist/chunks/build.mjs +0 -94
- package/dist/chunks/cleanup.mjs +0 -34
- package/dist/chunks/dev-child.mjs +0 -38
- package/dist/chunks/dev.mjs +0 -709
- package/dist/chunks/devtools.mjs +0 -46
- package/dist/chunks/generate.mjs +0 -45
- package/dist/chunks/index.mjs +0 -507
- package/dist/chunks/index2.mjs +0 -15
- package/dist/chunks/info.mjs +0 -150
- package/dist/chunks/init.mjs +0 -413
- package/dist/chunks/prepare.mjs +0 -57
- package/dist/chunks/preview.mjs +0 -131
- package/dist/chunks/search.mjs +0 -114
- package/dist/chunks/test.mjs +0 -62
- package/dist/chunks/typecheck.mjs +0 -85
- package/dist/chunks/upgrade.mjs +0 -214
- package/dist/dev/index.d.ts +0 -94
- package/dist/index.d.ts +0 -23
- package/dist/shared/cli-nightly.B9AmABr3.mjs +0 -5
- package/dist/shared/cli-nightly.BRlCc6aT.mjs +0 -204
- package/dist/shared/cli-nightly.BSm0_9Hr.mjs +0 -7
- package/dist/shared/cli-nightly.Bu_9IHj2.mjs +0 -51
- package/dist/shared/cli-nightly.Cr-OCgdO.mjs +0 -37
- package/dist/shared/cli-nightly.DHenkA1C.mjs +0 -14
- package/dist/shared/cli-nightly.DPmMxQ6h.mjs +0 -33
- package/dist/shared/cli-nightly.DS8guhZv.mjs +0 -52
- package/dist/shared/cli-nightly.DkO5RR_e.mjs +0 -14
- package/dist/shared/cli-nightly.qKvs7FJ2.mjs +0 -36
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region ../nuxi/src/commands/_shared.ts
|
|
2
|
+
const cwdArgs = { cwd: {
|
|
3
|
+
type: "string",
|
|
4
|
+
description: "Specify the working directory",
|
|
5
|
+
valueHint: "directory",
|
|
6
|
+
default: "."
|
|
7
|
+
} };
|
|
8
|
+
const logLevelArgs = { logLevel: {
|
|
9
|
+
type: "string",
|
|
10
|
+
description: "Specify build-time log level",
|
|
11
|
+
valueHint: "silent|info|verbose"
|
|
12
|
+
} };
|
|
13
|
+
const envNameArgs = { envName: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "The environment to use when resolving configuration overrides (default is `production` when building, and `development` when running the dev server)"
|
|
16
|
+
} };
|
|
17
|
+
const dotEnvArgs = { dotenv: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Path to `.env` file to load, relative to the root directory"
|
|
20
|
+
} };
|
|
21
|
+
const extendsArgs = { extends: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "Extend from a Nuxt layer",
|
|
24
|
+
valueHint: "layer-name",
|
|
25
|
+
alias: ["e"]
|
|
26
|
+
} };
|
|
27
|
+
const legacyRootDirArgs = {
|
|
28
|
+
cwd: {
|
|
29
|
+
...cwdArgs.cwd,
|
|
30
|
+
description: "Specify the working directory, this takes precedence over ROOTDIR (default: `.`)",
|
|
31
|
+
default: void 0
|
|
32
|
+
},
|
|
33
|
+
rootDir: {
|
|
34
|
+
type: "positional",
|
|
35
|
+
description: "Specifies the working directory (default: `.`)",
|
|
36
|
+
required: false,
|
|
37
|
+
default: "."
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { legacyRootDirArgs as a, extendsArgs as i, dotEnvArgs as n, logLevelArgs as o, envNameArgs as r, cwdArgs as t };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { satisfies } from "semver";
|
|
2
|
+
import { $fetch } from "ofetch";
|
|
3
|
+
import { parseINI } from "confbox";
|
|
4
|
+
|
|
5
|
+
//#region ../nuxi/src/commands/module/_utils.ts
|
|
6
|
+
async function fetchModules() {
|
|
7
|
+
const { modules } = await $fetch(`https://api.nuxt.com/modules?version=all`);
|
|
8
|
+
return modules;
|
|
9
|
+
}
|
|
10
|
+
function checkNuxtCompatibility(module, nuxtVersion) {
|
|
11
|
+
if (!module.compatibility?.nuxt) return true;
|
|
12
|
+
return satisfies(nuxtVersion, module.compatibility.nuxt, { includePrerelease: true });
|
|
13
|
+
}
|
|
14
|
+
function getRegistryFromContent(content, scope) {
|
|
15
|
+
try {
|
|
16
|
+
const npmConfig = parseINI(content);
|
|
17
|
+
if (scope) {
|
|
18
|
+
const scopeKey = `${scope}:registry`;
|
|
19
|
+
if (npmConfig[scopeKey]) return npmConfig[scopeKey].trim();
|
|
20
|
+
}
|
|
21
|
+
if (npmConfig.registry) return npmConfig.registry.trim();
|
|
22
|
+
return null;
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { fetchModules as n, getRegistryFromContent as r, checkNuxtCompatibility as t };
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { o as logLevelArgs, t as cwdArgs } from "./_shared-C3vB2YLc.mjs";
|
|
2
|
+
import { t as logger } from "./logger-Dk0gkCkX.mjs";
|
|
3
|
+
import { t as loadKit } from "./kit-xFxVGu6d.mjs";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { defineCommand } from "citty";
|
|
6
|
+
import { existsSync, promises } from "node:fs";
|
|
7
|
+
import { dirname, extname, resolve } from "pathe";
|
|
8
|
+
import { camelCase, pascalCase } from "scule";
|
|
9
|
+
|
|
10
|
+
//#region ../nuxi/src/utils/templates/api.ts
|
|
11
|
+
const httpMethods = [
|
|
12
|
+
"connect",
|
|
13
|
+
"delete",
|
|
14
|
+
"get",
|
|
15
|
+
"head",
|
|
16
|
+
"options",
|
|
17
|
+
"post",
|
|
18
|
+
"put",
|
|
19
|
+
"trace",
|
|
20
|
+
"patch"
|
|
21
|
+
];
|
|
22
|
+
const api = ({ name, args, nuxtOptions }) => {
|
|
23
|
+
return {
|
|
24
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, `api/${name}${applySuffix(args, httpMethods, "method")}.ts`),
|
|
25
|
+
contents: `
|
|
26
|
+
export default defineEventHandler(event => {
|
|
27
|
+
return 'Hello ${name}'
|
|
28
|
+
})
|
|
29
|
+
`
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region ../nuxi/src/utils/templates/app.ts
|
|
35
|
+
const app = ({ args, nuxtOptions }) => ({
|
|
36
|
+
path: resolve(nuxtOptions.srcDir, "app.vue"),
|
|
37
|
+
contents: args.pages ? `
|
|
38
|
+
<script setup lang="ts"><\/script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<div>
|
|
42
|
+
<NuxtLayout>
|
|
43
|
+
<NuxtPage/>
|
|
44
|
+
</NuxtLayout>
|
|
45
|
+
</div>
|
|
46
|
+
</template>
|
|
47
|
+
|
|
48
|
+
<style scoped></style>
|
|
49
|
+
` : `
|
|
50
|
+
<script setup lang="ts"><\/script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<div>
|
|
54
|
+
<h1>Hello World!</h1>
|
|
55
|
+
</div>
|
|
56
|
+
</template>
|
|
57
|
+
|
|
58
|
+
<style scoped></style>
|
|
59
|
+
`
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region ../nuxi/src/utils/templates/app-config.ts
|
|
64
|
+
const appConfig = ({ nuxtOptions }) => ({
|
|
65
|
+
path: resolve(nuxtOptions.srcDir, "app.config.ts"),
|
|
66
|
+
contents: `
|
|
67
|
+
export default defineAppConfig({})
|
|
68
|
+
`
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region ../nuxi/src/utils/templates/component.ts
|
|
73
|
+
const component = ({ name, args, nuxtOptions }) => ({
|
|
74
|
+
path: resolve(nuxtOptions.srcDir, `components/${name}${applySuffix(args, ["client", "server"], "mode")}.vue`),
|
|
75
|
+
contents: `
|
|
76
|
+
<script setup lang="ts"><\/script>
|
|
77
|
+
|
|
78
|
+
<template>
|
|
79
|
+
<div>
|
|
80
|
+
Component: ${name}
|
|
81
|
+
</div>
|
|
82
|
+
</template>
|
|
83
|
+
|
|
84
|
+
<style scoped></style>
|
|
85
|
+
`
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region ../nuxi/src/utils/templates/composable.ts
|
|
90
|
+
const composable = ({ name, nuxtOptions }) => {
|
|
91
|
+
const nameWithUsePrefix = `use${pascalCase(name.replace(/^use-?/, ""))}`;
|
|
92
|
+
return {
|
|
93
|
+
path: resolve(nuxtOptions.srcDir, `composables/${name}.ts`),
|
|
94
|
+
contents: `
|
|
95
|
+
export const ${nameWithUsePrefix} = () => {
|
|
96
|
+
return ref()
|
|
97
|
+
}
|
|
98
|
+
`
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region ../nuxi/src/utils/templates/error.ts
|
|
104
|
+
const error = ({ nuxtOptions }) => ({
|
|
105
|
+
path: resolve(nuxtOptions.srcDir, "error.vue"),
|
|
106
|
+
contents: `
|
|
107
|
+
<script setup lang="ts">
|
|
108
|
+
import type { NuxtError } from '#app'
|
|
109
|
+
|
|
110
|
+
const props = defineProps({
|
|
111
|
+
error: Object as () => NuxtError
|
|
112
|
+
})
|
|
113
|
+
<\/script>
|
|
114
|
+
|
|
115
|
+
<template>
|
|
116
|
+
<div>
|
|
117
|
+
<h1>{{ error.statusCode }}</h1>
|
|
118
|
+
<NuxtLink to="/">Go back home</NuxtLink>
|
|
119
|
+
</div>
|
|
120
|
+
</template>
|
|
121
|
+
|
|
122
|
+
<style scoped></style>
|
|
123
|
+
`
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region ../nuxi/src/utils/templates/layer.ts
|
|
128
|
+
const layer = ({ name, nuxtOptions }) => {
|
|
129
|
+
return {
|
|
130
|
+
path: resolve(nuxtOptions.rootDir, `layers/${name}/nuxt.config.ts`),
|
|
131
|
+
contents: `
|
|
132
|
+
export default defineNuxtConfig({})
|
|
133
|
+
`
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region ../nuxi/src/utils/templates/layout.ts
|
|
139
|
+
const layout = ({ name, nuxtOptions }) => ({
|
|
140
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.layouts, `${name}.vue`),
|
|
141
|
+
contents: `
|
|
142
|
+
<script setup lang="ts"><\/script>
|
|
143
|
+
|
|
144
|
+
<template>
|
|
145
|
+
<div>
|
|
146
|
+
Layout: ${name}
|
|
147
|
+
<slot />
|
|
148
|
+
</div>
|
|
149
|
+
</template>
|
|
150
|
+
|
|
151
|
+
<style scoped></style>
|
|
152
|
+
`
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region ../nuxi/src/utils/templates/middleware.ts
|
|
157
|
+
const middleware = ({ name, args, nuxtOptions }) => ({
|
|
158
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.middleware, `${name}${applySuffix(args, ["global"])}.ts`),
|
|
159
|
+
contents: `
|
|
160
|
+
export default defineNuxtRouteMiddleware((to, from) => {})
|
|
161
|
+
`
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region ../nuxi/src/utils/templates/module.ts
|
|
166
|
+
const module = ({ name, nuxtOptions }) => ({
|
|
167
|
+
path: resolve(nuxtOptions.rootDir, "modules", `${name}.ts`),
|
|
168
|
+
contents: `
|
|
169
|
+
import { defineNuxtModule } from 'nuxt/kit'
|
|
170
|
+
|
|
171
|
+
export default defineNuxtModule({
|
|
172
|
+
meta: {
|
|
173
|
+
name: '${name}'
|
|
174
|
+
},
|
|
175
|
+
setup () {}
|
|
176
|
+
})
|
|
177
|
+
`
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region ../nuxi/src/utils/templates/page.ts
|
|
182
|
+
const page = ({ name, nuxtOptions }) => ({
|
|
183
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.pages, `${name}.vue`),
|
|
184
|
+
contents: `
|
|
185
|
+
<script setup lang="ts"><\/script>
|
|
186
|
+
|
|
187
|
+
<template>
|
|
188
|
+
<div>
|
|
189
|
+
Page: ${name}
|
|
190
|
+
</div>
|
|
191
|
+
</template>
|
|
192
|
+
|
|
193
|
+
<style scoped></style>
|
|
194
|
+
`
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region ../nuxi/src/utils/templates/plugin.ts
|
|
199
|
+
const plugin = ({ name, args, nuxtOptions }) => ({
|
|
200
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.plugins, `${name}${applySuffix(args, ["client", "server"], "mode")}.ts`),
|
|
201
|
+
contents: `
|
|
202
|
+
export default defineNuxtPlugin(nuxtApp => {})
|
|
203
|
+
`
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region ../nuxi/src/utils/templates/server-middleware.ts
|
|
208
|
+
const serverMiddleware = ({ name, nuxtOptions }) => ({
|
|
209
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, "middleware", `${name}.ts`),
|
|
210
|
+
contents: `
|
|
211
|
+
export default defineEventHandler(event => {})
|
|
212
|
+
`
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region ../nuxi/src/utils/templates/server-plugin.ts
|
|
217
|
+
const serverPlugin = ({ name, nuxtOptions }) => ({
|
|
218
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, "plugins", `${name}.ts`),
|
|
219
|
+
contents: `
|
|
220
|
+
export default defineNitroPlugin(nitroApp => {})
|
|
221
|
+
`
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region ../nuxi/src/utils/templates/server-route.ts
|
|
226
|
+
const serverRoute = ({ name, args, nuxtOptions }) => ({
|
|
227
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, args.api ? "api" : "routes", `${name}.ts`),
|
|
228
|
+
contents: `
|
|
229
|
+
export default defineEventHandler(event => {})
|
|
230
|
+
`
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region ../nuxi/src/utils/templates/server-util.ts
|
|
235
|
+
const serverUtil = ({ name, nuxtOptions }) => ({
|
|
236
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, "utils", `${name}.ts`),
|
|
237
|
+
contents: `
|
|
238
|
+
export function ${camelCase(name)}() {}
|
|
239
|
+
`
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region ../nuxi/src/utils/templates/index.ts
|
|
244
|
+
const templates = {
|
|
245
|
+
"api": api,
|
|
246
|
+
"app": app,
|
|
247
|
+
"app-config": appConfig,
|
|
248
|
+
"component": component,
|
|
249
|
+
"composable": composable,
|
|
250
|
+
"error": error,
|
|
251
|
+
"layer": layer,
|
|
252
|
+
"layout": layout,
|
|
253
|
+
"middleware": middleware,
|
|
254
|
+
"module": module,
|
|
255
|
+
"page": page,
|
|
256
|
+
"plugin": plugin,
|
|
257
|
+
"server-middleware": serverMiddleware,
|
|
258
|
+
"server-plugin": serverPlugin,
|
|
259
|
+
"server-route": serverRoute,
|
|
260
|
+
"server-util": serverUtil
|
|
261
|
+
};
|
|
262
|
+
function applySuffix(args, suffixes, unwrapFrom) {
|
|
263
|
+
let suffix = "";
|
|
264
|
+
for (const s of suffixes) if (args[s]) suffix += `.${s}`;
|
|
265
|
+
if (unwrapFrom && args[unwrapFrom] && suffixes.includes(args[unwrapFrom])) suffix += `.${args[unwrapFrom]}`;
|
|
266
|
+
return suffix;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region ../nuxi/src/commands/add.ts
|
|
271
|
+
const templateNames = Object.keys(templates);
|
|
272
|
+
var add_default = defineCommand({
|
|
273
|
+
meta: {
|
|
274
|
+
name: "add",
|
|
275
|
+
description: "Create a new template file."
|
|
276
|
+
},
|
|
277
|
+
args: {
|
|
278
|
+
...cwdArgs,
|
|
279
|
+
...logLevelArgs,
|
|
280
|
+
force: {
|
|
281
|
+
type: "boolean",
|
|
282
|
+
description: "Force override file if it already exists",
|
|
283
|
+
default: false
|
|
284
|
+
},
|
|
285
|
+
template: {
|
|
286
|
+
type: "positional",
|
|
287
|
+
required: true,
|
|
288
|
+
valueHint: templateNames.join("|"),
|
|
289
|
+
description: `Specify which template to generate`
|
|
290
|
+
},
|
|
291
|
+
name: {
|
|
292
|
+
type: "positional",
|
|
293
|
+
required: true,
|
|
294
|
+
description: "Specify name of the generated file"
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
async run(ctx) {
|
|
298
|
+
const cwd = resolve(ctx.args.cwd);
|
|
299
|
+
const templateName = ctx.args.template;
|
|
300
|
+
if (!templateNames.includes(templateName)) {
|
|
301
|
+
logger.error(`Template ${templateName} is not supported. Possible values: ${Object.keys(templates).join(", ")}`);
|
|
302
|
+
process.exit(1);
|
|
303
|
+
}
|
|
304
|
+
const ext = extname(ctx.args.name);
|
|
305
|
+
const name = ext === ".vue" || ext === ".ts" ? ctx.args.name.replace(ext, "") : ctx.args.name;
|
|
306
|
+
if (!name) {
|
|
307
|
+
logger.error("name argument is missing!");
|
|
308
|
+
process.exit(1);
|
|
309
|
+
}
|
|
310
|
+
const config = await (await loadKit(cwd)).loadNuxtConfig({ cwd });
|
|
311
|
+
const template = templates[templateName];
|
|
312
|
+
const res = template({
|
|
313
|
+
name,
|
|
314
|
+
args: ctx.args,
|
|
315
|
+
nuxtOptions: config
|
|
316
|
+
});
|
|
317
|
+
if (!ctx.args.force && existsSync(res.path)) {
|
|
318
|
+
logger.error(`File exists: ${res.path} . Use --force to override or use a different name.`);
|
|
319
|
+
process.exit(1);
|
|
320
|
+
}
|
|
321
|
+
const parentDir = dirname(res.path);
|
|
322
|
+
if (!existsSync(parentDir)) {
|
|
323
|
+
logger.info("Creating directory", parentDir);
|
|
324
|
+
if (templateName === "page") logger.info("This enables vue-router functionality!");
|
|
325
|
+
await promises.mkdir(parentDir, { recursive: true });
|
|
326
|
+
}
|
|
327
|
+
await promises.writeFile(res.path, `${res.contents.trim()}\n`);
|
|
328
|
+
logger.info(`🪄 Generated a new ${templateName} in ${res.path}`);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
//#endregion
|
|
333
|
+
export { add_default as default };
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { o as logLevelArgs, t as cwdArgs } from "./_shared-C3vB2YLc.mjs";
|
|
2
|
+
import { t as logger } from "./logger-Dk0gkCkX.mjs";
|
|
3
|
+
import { t as getNuxtVersion } from "./versions-CSy_3o_-.mjs";
|
|
4
|
+
import { t as prepare_default } from "./prepare-xI978yFg.mjs";
|
|
5
|
+
import { n as fetchModules, r as getRegistryFromContent, t as checkNuxtCompatibility } from "./_utils-DTrPahho.mjs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import { defineCommand, runCommand } from "citty";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import * as fs from "node:fs";
|
|
11
|
+
import { resolve as resolve$1 } from "pathe";
|
|
12
|
+
import { joinURL } from "ufo";
|
|
13
|
+
import { colors } from "consola/utils";
|
|
14
|
+
import { satisfies } from "semver";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { addDependency } from "nypm";
|
|
17
|
+
import { readPackageJSON } from "pkg-types";
|
|
18
|
+
import { $fetch } from "ofetch";
|
|
19
|
+
import { updateConfig } from "c12/update";
|
|
20
|
+
|
|
21
|
+
//#region ../nuxi/src/commands/_utils.ts
|
|
22
|
+
const nuxiCommands = [
|
|
23
|
+
"add",
|
|
24
|
+
"analyze",
|
|
25
|
+
"build",
|
|
26
|
+
"cleanup",
|
|
27
|
+
"_dev",
|
|
28
|
+
"dev",
|
|
29
|
+
"devtools",
|
|
30
|
+
"generate",
|
|
31
|
+
"info",
|
|
32
|
+
"init",
|
|
33
|
+
"module",
|
|
34
|
+
"prepare",
|
|
35
|
+
"preview",
|
|
36
|
+
"start",
|
|
37
|
+
"test",
|
|
38
|
+
"typecheck",
|
|
39
|
+
"upgrade"
|
|
40
|
+
];
|
|
41
|
+
function isNuxiCommand(command) {
|
|
42
|
+
return nuxiCommands.includes(command);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../nuxi/src/run.ts
|
|
47
|
+
globalThis.__nuxt_cli__ = globalThis.__nuxt_cli__ || {
|
|
48
|
+
startTime: Date.now(),
|
|
49
|
+
entry: fileURLToPath(new URL("../../bin/nuxi.mjs", import.meta.url)),
|
|
50
|
+
devEntry: fileURLToPath(new URL("../dev/index.mjs", import.meta.url))
|
|
51
|
+
};
|
|
52
|
+
async function runCommand$1(command, argv = process.argv.slice(2), data = {}) {
|
|
53
|
+
argv.push("--no-clear");
|
|
54
|
+
if (command.meta && "name" in command.meta && typeof command.meta.name === "string") {
|
|
55
|
+
const name = command.meta.name;
|
|
56
|
+
if (!isNuxiCommand(name)) throw new Error(`Invalid command ${name}`);
|
|
57
|
+
} else throw new Error(`Invalid command, must be named`);
|
|
58
|
+
return await runCommand(command, {
|
|
59
|
+
rawArgs: argv,
|
|
60
|
+
data: { overrides: data.overrides || {} }
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region ../nuxi/src/commands/module/add.ts
|
|
66
|
+
var add_default = defineCommand({
|
|
67
|
+
meta: {
|
|
68
|
+
name: "add",
|
|
69
|
+
description: "Add Nuxt modules"
|
|
70
|
+
},
|
|
71
|
+
args: {
|
|
72
|
+
...cwdArgs,
|
|
73
|
+
...logLevelArgs,
|
|
74
|
+
moduleName: {
|
|
75
|
+
type: "positional",
|
|
76
|
+
description: "Specify one or more modules to install by name, separated by spaces"
|
|
77
|
+
},
|
|
78
|
+
skipInstall: {
|
|
79
|
+
type: "boolean",
|
|
80
|
+
description: "Skip npm install"
|
|
81
|
+
},
|
|
82
|
+
skipConfig: {
|
|
83
|
+
type: "boolean",
|
|
84
|
+
description: "Skip nuxt.config.ts update"
|
|
85
|
+
},
|
|
86
|
+
dev: {
|
|
87
|
+
type: "boolean",
|
|
88
|
+
description: "Install modules as dev dependencies"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
async setup(ctx) {
|
|
92
|
+
const cwd = resolve$1(ctx.args.cwd);
|
|
93
|
+
const modules = ctx.args._.map((e) => e.trim()).filter(Boolean);
|
|
94
|
+
const projectPkg = await readPackageJSON(cwd).catch(() => ({}));
|
|
95
|
+
if (!projectPkg.dependencies?.nuxt && !projectPkg.devDependencies?.nuxt) {
|
|
96
|
+
logger.warn(`No \`nuxt\` dependency detected in \`${cwd}\`.`);
|
|
97
|
+
if (await logger.prompt(`Do you want to continue anyway?`, {
|
|
98
|
+
type: "confirm",
|
|
99
|
+
initial: false,
|
|
100
|
+
cancel: "default"
|
|
101
|
+
}) !== true) process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
const resolvedModules = (await Promise.all(modules.map((moduleName) => resolveModule(moduleName, cwd)))).filter((x) => x != null);
|
|
104
|
+
logger.info(`Resolved \`${resolvedModules.map((x) => x.pkgName).join("`, `")}\`, adding module${resolvedModules.length > 1 ? "s" : ""}...`);
|
|
105
|
+
await addModules(resolvedModules, {
|
|
106
|
+
...ctx.args,
|
|
107
|
+
cwd
|
|
108
|
+
}, projectPkg);
|
|
109
|
+
if (!ctx.args.skipInstall) await runCommand$1(prepare_default, Object.entries(ctx.args).filter(([k]) => k in cwdArgs || k in logLevelArgs).map(([k, v]) => `--${k}=${v}`));
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
async function addModules(modules, { skipInstall, skipConfig, cwd, dev }, projectPkg) {
|
|
113
|
+
if (!skipInstall) {
|
|
114
|
+
const installedModules = [];
|
|
115
|
+
const notInstalledModules = [];
|
|
116
|
+
const dependencies = new Set([...Object.keys(projectPkg.dependencies || {}), ...Object.keys(projectPkg.devDependencies || {})]);
|
|
117
|
+
for (const module of modules) if (dependencies.has(module.pkgName)) installedModules.push(module);
|
|
118
|
+
else notInstalledModules.push(module);
|
|
119
|
+
if (installedModules.length > 0) {
|
|
120
|
+
const installedModulesList = installedModules.map((module) => module.pkgName).join("`, `");
|
|
121
|
+
const are = installedModules.length > 1 ? "are" : "is";
|
|
122
|
+
logger.info(`\`${installedModulesList}\` ${are} already installed`);
|
|
123
|
+
}
|
|
124
|
+
if (notInstalledModules.length > 0) {
|
|
125
|
+
const isDev = Boolean(projectPkg.devDependencies?.nuxt) || dev;
|
|
126
|
+
const notInstalledModulesList = notInstalledModules.map((module) => module.pkg).join("`, `");
|
|
127
|
+
const dependency = notInstalledModules.length > 1 ? "dependencies" : "dependency";
|
|
128
|
+
const a = notInstalledModules.length > 1 ? "" : " a";
|
|
129
|
+
logger.info(`Installing \`${notInstalledModulesList}\` as${a}${isDev ? " development" : ""} ${dependency}`);
|
|
130
|
+
if (await addDependency(notInstalledModules.map((module) => module.pkg), {
|
|
131
|
+
cwd,
|
|
132
|
+
dev: isDev,
|
|
133
|
+
installPeerDependencies: true
|
|
134
|
+
}).then(() => true).catch((error) => {
|
|
135
|
+
logger.error(error);
|
|
136
|
+
const failedModulesList = notInstalledModules.map((module) => colors.cyan(module.pkg)).join("`, `");
|
|
137
|
+
const s = notInstalledModules.length > 1 ? "s" : "";
|
|
138
|
+
return logger.prompt(`Install failed for \`${failedModulesList}\`. Do you want to continue adding the module${s} to ${colors.cyan("nuxt.config")}?`, {
|
|
139
|
+
type: "confirm",
|
|
140
|
+
initial: false,
|
|
141
|
+
cancel: "default"
|
|
142
|
+
});
|
|
143
|
+
}) !== true) return;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (!skipConfig) await updateConfig({
|
|
147
|
+
cwd,
|
|
148
|
+
configFile: "nuxt.config",
|
|
149
|
+
async onCreate() {
|
|
150
|
+
logger.info(`Creating \`nuxt.config.ts\``);
|
|
151
|
+
return getDefaultNuxtConfig();
|
|
152
|
+
},
|
|
153
|
+
async onUpdate(config) {
|
|
154
|
+
if (!config.modules) config.modules = [];
|
|
155
|
+
for (const resolved of modules) {
|
|
156
|
+
if (config.modules.includes(resolved.pkgName)) {
|
|
157
|
+
logger.info(`\`${resolved.pkgName}\` is already in the \`modules\``);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
logger.info(`Adding \`${resolved.pkgName}\` to the \`modules\``);
|
|
161
|
+
config.modules.push(resolved.pkgName);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}).catch((error) => {
|
|
165
|
+
logger.error(`Failed to update \`nuxt.config\`: ${error.message}`);
|
|
166
|
+
logger.error(`Please manually add \`${modules.map((module) => module.pkgName).join("`, `")}\` to the \`modules\` in \`nuxt.config.ts\``);
|
|
167
|
+
return null;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function getDefaultNuxtConfig() {
|
|
171
|
+
return `
|
|
172
|
+
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
173
|
+
export default defineNuxtConfig({
|
|
174
|
+
modules: []
|
|
175
|
+
})`;
|
|
176
|
+
}
|
|
177
|
+
const packageRegex = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?([a-z0-9-~][a-z0-9-._~]*)(@[^@]+)?$/;
|
|
178
|
+
async function resolveModule(moduleName, cwd) {
|
|
179
|
+
let pkgName = moduleName;
|
|
180
|
+
let pkgVersion;
|
|
181
|
+
const reMatch = moduleName.match(packageRegex);
|
|
182
|
+
if (reMatch) {
|
|
183
|
+
if (reMatch[3]) {
|
|
184
|
+
pkgName = `${reMatch[1] || ""}${reMatch[2] || ""}`;
|
|
185
|
+
pkgVersion = reMatch[3].slice(1);
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
logger.error(`Invalid package name \`${pkgName}\`.`);
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
const matchedModule = (await fetchModules().catch((err) => {
|
|
192
|
+
logger.warn(`Cannot search in the Nuxt Modules database: ${err}`);
|
|
193
|
+
return [];
|
|
194
|
+
})).find((module) => module.name === moduleName || pkgVersion && module.name === pkgName || module.npm === pkgName || module.aliases?.includes(pkgName));
|
|
195
|
+
if (matchedModule?.npm) pkgName = matchedModule.npm;
|
|
196
|
+
if (matchedModule && matchedModule.compatibility.nuxt) {
|
|
197
|
+
const nuxtVersion = await getNuxtVersion(cwd);
|
|
198
|
+
if (!checkNuxtCompatibility(matchedModule, nuxtVersion)) {
|
|
199
|
+
logger.warn(`The module \`${pkgName}\` is not compatible with Nuxt \`${nuxtVersion}\` (requires \`${matchedModule.compatibility.nuxt}\`)`);
|
|
200
|
+
if (!await logger.prompt("Do you want to continue installing incompatible version?", {
|
|
201
|
+
type: "confirm",
|
|
202
|
+
initial: false,
|
|
203
|
+
cancel: "default"
|
|
204
|
+
})) return false;
|
|
205
|
+
}
|
|
206
|
+
const versionMap = matchedModule.compatibility.versionMap;
|
|
207
|
+
if (versionMap) {
|
|
208
|
+
for (const [_nuxtVersion, _moduleVersion] of Object.entries(versionMap)) if (satisfies(nuxtVersion, _nuxtVersion)) {
|
|
209
|
+
if (!pkgVersion) pkgVersion = _moduleVersion;
|
|
210
|
+
else {
|
|
211
|
+
logger.warn(`Recommended version of \`${pkgName}\` for Nuxt \`${nuxtVersion}\` is \`${_moduleVersion}\` but you have requested \`${pkgVersion}\``);
|
|
212
|
+
pkgVersion = await logger.prompt("Choose a version:", {
|
|
213
|
+
type: "select",
|
|
214
|
+
options: [_moduleVersion, pkgVersion],
|
|
215
|
+
cancel: "undefined"
|
|
216
|
+
});
|
|
217
|
+
if (!pkgVersion) return false;
|
|
218
|
+
}
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
let version = pkgVersion || "latest";
|
|
224
|
+
const meta = await detectNpmRegistry(pkgName.startsWith("@") ? pkgName.split("/")[0] : null);
|
|
225
|
+
const headers = {};
|
|
226
|
+
if (meta.authToken) headers.Authorization = `Bearer ${meta.authToken}`;
|
|
227
|
+
const pkgDetails = await $fetch(joinURL(meta.registry, `${pkgName}`), { headers });
|
|
228
|
+
if (pkgDetails["dist-tags"]?.[version]) version = pkgDetails["dist-tags"][version];
|
|
229
|
+
else version = Object.keys(pkgDetails.versions)?.findLast((v) => satisfies(v, version)) || version;
|
|
230
|
+
const pkg = pkgDetails.versions[version];
|
|
231
|
+
const pkgDependencies = Object.assign(pkg.dependencies || {}, pkg.devDependencies || {});
|
|
232
|
+
if (!pkgDependencies.nuxt && !pkgDependencies["nuxt-edge"] && !pkgDependencies["@nuxt/kit"]) {
|
|
233
|
+
logger.warn(`It seems that \`${pkgName}\` is not a Nuxt module.`);
|
|
234
|
+
if (!await logger.prompt(`Do you want to continue installing ${colors.cyan(pkgName)} anyway?`, {
|
|
235
|
+
type: "confirm",
|
|
236
|
+
initial: false,
|
|
237
|
+
cancel: "default"
|
|
238
|
+
})) return false;
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
nuxtModule: matchedModule,
|
|
242
|
+
pkg: `${pkgName}@${version}`,
|
|
243
|
+
pkgName,
|
|
244
|
+
pkgVersion: version
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function getNpmrcPaths() {
|
|
248
|
+
const userNpmrcPath = join(homedir(), ".npmrc");
|
|
249
|
+
return [join(process.cwd(), ".npmrc"), userNpmrcPath];
|
|
250
|
+
}
|
|
251
|
+
async function getAuthToken(registry) {
|
|
252
|
+
const paths = getNpmrcPaths();
|
|
253
|
+
const authTokenRegex = new RegExp(`^//${registry.replace(/^https?:\/\//, "").replace(/\/$/, "")}/:_authToken=(.+)$`, "m");
|
|
254
|
+
for (const npmrcPath of paths) {
|
|
255
|
+
let fd;
|
|
256
|
+
try {
|
|
257
|
+
fd = await fs.promises.open(npmrcPath, "r");
|
|
258
|
+
if (await fd.stat().then((r) => r.isFile())) {
|
|
259
|
+
const authTokenMatch = (await fd.readFile("utf-8")).match(authTokenRegex)?.[1];
|
|
260
|
+
if (authTokenMatch) return authTokenMatch.trim();
|
|
261
|
+
}
|
|
262
|
+
} catch {} finally {
|
|
263
|
+
await fd?.close();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
async function detectNpmRegistry(scope) {
|
|
269
|
+
const registry = await getRegistry(scope);
|
|
270
|
+
return {
|
|
271
|
+
registry,
|
|
272
|
+
authToken: await getAuthToken(registry)
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
async function getRegistry(scope) {
|
|
276
|
+
if (process.env.COREPACK_NPM_REGISTRY) return process.env.COREPACK_NPM_REGISTRY;
|
|
277
|
+
const registry = await getRegistryFromFile(getNpmrcPaths(), scope);
|
|
278
|
+
if (registry) process.env.COREPACK_NPM_REGISTRY = registry;
|
|
279
|
+
return registry || "https://registry.npmjs.org";
|
|
280
|
+
}
|
|
281
|
+
async function getRegistryFromFile(paths, scope) {
|
|
282
|
+
for (const npmrcPath of paths) {
|
|
283
|
+
let fd;
|
|
284
|
+
try {
|
|
285
|
+
fd = await fs.promises.open(npmrcPath, "r");
|
|
286
|
+
if (await fd.stat().then((r) => r.isFile())) {
|
|
287
|
+
const registry = getRegistryFromContent(await fd.readFile("utf-8"), scope);
|
|
288
|
+
if (registry) return registry;
|
|
289
|
+
}
|
|
290
|
+
} catch {} finally {
|
|
291
|
+
await fd?.close();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
//#endregion
|
|
298
|
+
export { runCommand$1 as n, add_default as t };
|