@nuxt/cli-nightly 0.0.0 → 3.20.0-20250109-193455-6ea36ef
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/LICENSE +21 -0
- package/README.md +27 -0
- package/bin/nuxi.mjs +11 -0
- package/dist/chunks/add.mjs +317 -0
- package/dist/chunks/add2.mjs +320 -0
- package/dist/chunks/analyze.mjs +134 -0
- package/dist/chunks/build.mjs +90 -0
- package/dist/chunks/cleanup.mjs +33 -0
- package/dist/chunks/dev-child.mjs +81 -0
- package/dist/chunks/dev.mjs +224 -0
- package/dist/chunks/dev2.mjs +250 -0
- package/dist/chunks/devtools.mjs +44 -0
- package/dist/chunks/generate.mjs +40 -0
- package/dist/chunks/index.mjs +15 -0
- package/dist/chunks/info.mjs +146 -0
- package/dist/chunks/init.mjs +189 -0
- package/dist/chunks/prepare.mjs +54 -0
- package/dist/chunks/preview.mjs +102 -0
- package/dist/chunks/search.mjs +110 -0
- package/dist/chunks/test.mjs +61 -0
- package/dist/chunks/typecheck.mjs +73 -0
- package/dist/chunks/upgrade.mjs +187 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.mjs +7 -0
- package/dist/shared/cli-nightly.7lipAIIb.mjs +49 -0
- package/dist/shared/cli-nightly.BSm0_9Hr.mjs +7 -0
- package/dist/shared/cli-nightly.C935N1ss.mjs +29 -0
- package/dist/shared/cli-nightly.CGRrR0sp.mjs +26 -0
- package/dist/shared/cli-nightly.CPUttwQp.mjs +52 -0
- package/dist/shared/cli-nightly.CnY_9Zvw.mjs +307 -0
- package/dist/shared/cli-nightly.DlcAx0De.mjs +38 -0
- package/dist/shared/cli-nightly.cDY7IcTr.mjs +14 -0
- package/package.json +91 -2
- package/dist/.gitkeep +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Nuxt Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Nuxt CLI (nuxi)
|
|
2
|
+
|
|
3
|
+
⚡️ [Nuxt](https://nuxt.com/) Generation CLI Experience.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
All commands are listed on https://nuxt.com/docs/api/commands
|
|
8
|
+
|
|
9
|
+
## Contributing
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Install dependencies
|
|
13
|
+
pnpm i
|
|
14
|
+
|
|
15
|
+
# Generate type stubs
|
|
16
|
+
pnpm dev:prepare
|
|
17
|
+
|
|
18
|
+
# Go to the playground directory
|
|
19
|
+
cd playground
|
|
20
|
+
|
|
21
|
+
# And run any commands
|
|
22
|
+
pnpm nuxi <command>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
[MIT](./LICENSE)
|
package/bin/nuxi.mjs
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { existsSync, promises } from 'node:fs';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { defineCommand } from 'citty';
|
|
4
|
+
import { resolve, extname, dirname } from 'pathe';
|
|
5
|
+
import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
|
|
6
|
+
import { c as cwdArgs, l as logLevelArgs, a as logger } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
7
|
+
import { pascalCase, camelCase } from 'scule';
|
|
8
|
+
import 'jiti';
|
|
9
|
+
import 'node:path';
|
|
10
|
+
import 'std-env';
|
|
11
|
+
import 'consola';
|
|
12
|
+
import 'node:url';
|
|
13
|
+
|
|
14
|
+
const httpMethods = [
|
|
15
|
+
"connect",
|
|
16
|
+
"delete",
|
|
17
|
+
"get",
|
|
18
|
+
"head",
|
|
19
|
+
"options",
|
|
20
|
+
"post",
|
|
21
|
+
"put",
|
|
22
|
+
"trace",
|
|
23
|
+
"patch"
|
|
24
|
+
];
|
|
25
|
+
const api = ({ name, args, nuxtOptions }) => {
|
|
26
|
+
return {
|
|
27
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, `api/${name}${applySuffix(args, httpMethods, "method")}.ts`),
|
|
28
|
+
contents: `
|
|
29
|
+
export default defineEventHandler(event => {
|
|
30
|
+
return 'Hello ${name}'
|
|
31
|
+
})
|
|
32
|
+
`
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const app = ({ args, nuxtOptions }) => ({
|
|
37
|
+
path: resolve(nuxtOptions.srcDir, "app.vue"),
|
|
38
|
+
contents: args.pages ? `
|
|
39
|
+
<script setup lang="ts"><\/script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<div>
|
|
43
|
+
<NuxtLayout>
|
|
44
|
+
<NuxtPage/>
|
|
45
|
+
</NuxtLayout>
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<style scoped></style>
|
|
50
|
+
` : `
|
|
51
|
+
<script setup lang="ts"><\/script>
|
|
52
|
+
|
|
53
|
+
<template>
|
|
54
|
+
<div>
|
|
55
|
+
<h1>Hello World!</h1>
|
|
56
|
+
</div>
|
|
57
|
+
</template>
|
|
58
|
+
|
|
59
|
+
<style scoped></style>
|
|
60
|
+
`
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const appConfig = ({ nuxtOptions }) => ({
|
|
64
|
+
path: resolve(nuxtOptions.srcDir, "app.config.ts"),
|
|
65
|
+
contents: `
|
|
66
|
+
export default defineAppConfig({})
|
|
67
|
+
`
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const component = ({ name, args, nuxtOptions }) => ({
|
|
71
|
+
path: resolve(nuxtOptions.srcDir, `components/${name}${applySuffix(
|
|
72
|
+
args,
|
|
73
|
+
["client", "server"],
|
|
74
|
+
"mode"
|
|
75
|
+
)}.vue`),
|
|
76
|
+
contents: `
|
|
77
|
+
<script setup lang="ts"><\/script>
|
|
78
|
+
|
|
79
|
+
<template>
|
|
80
|
+
<div>
|
|
81
|
+
Component: ${name}
|
|
82
|
+
</div>
|
|
83
|
+
</template>
|
|
84
|
+
|
|
85
|
+
<style scoped></style>
|
|
86
|
+
`
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const composable = ({ name, nuxtOptions }) => {
|
|
90
|
+
const nameWithoutUsePrefix = name.replace(/^use-?/, "");
|
|
91
|
+
const nameWithUsePrefix = `use${pascalCase(nameWithoutUsePrefix)}`;
|
|
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
|
+
const error = ({ nuxtOptions }) => ({
|
|
103
|
+
path: resolve(nuxtOptions.srcDir, "error.vue"),
|
|
104
|
+
contents: `
|
|
105
|
+
<script setup lang="ts">
|
|
106
|
+
import type { NuxtError } from '#app'
|
|
107
|
+
|
|
108
|
+
const props = defineProps({
|
|
109
|
+
error: Object as () => NuxtError
|
|
110
|
+
})
|
|
111
|
+
<\/script>
|
|
112
|
+
|
|
113
|
+
<template>
|
|
114
|
+
<div>
|
|
115
|
+
<h1>{{ error.statusCode }}</h1>
|
|
116
|
+
<NuxtLink to="/">Go back home</NuxtLink>
|
|
117
|
+
</div>
|
|
118
|
+
</template>
|
|
119
|
+
|
|
120
|
+
<style scoped></style>
|
|
121
|
+
`
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const layer = ({ name, nuxtOptions }) => {
|
|
125
|
+
return {
|
|
126
|
+
path: resolve(nuxtOptions.srcDir, `layers/${name}/nuxt.config.ts`),
|
|
127
|
+
contents: `
|
|
128
|
+
export default defineNuxtConfig({})
|
|
129
|
+
`
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const layout = ({ name, nuxtOptions }) => ({
|
|
134
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.layouts, `${name}.vue`),
|
|
135
|
+
contents: `
|
|
136
|
+
<script setup lang="ts"><\/script>
|
|
137
|
+
|
|
138
|
+
<template>
|
|
139
|
+
<div>
|
|
140
|
+
Layout: ${name}
|
|
141
|
+
<slot />
|
|
142
|
+
</div>
|
|
143
|
+
</template>
|
|
144
|
+
|
|
145
|
+
<style scoped></style>
|
|
146
|
+
`
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const middleware = ({ name, args, nuxtOptions }) => ({
|
|
150
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.middleware, `${name}${applySuffix(args, ["global"])}.ts`),
|
|
151
|
+
contents: `
|
|
152
|
+
export default defineNuxtRouteMiddleware((to, from) => {})
|
|
153
|
+
`
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const module = ({ name, nuxtOptions }) => ({
|
|
157
|
+
path: resolve(nuxtOptions.rootDir, "modules", `${name}.vue`),
|
|
158
|
+
contents: `
|
|
159
|
+
import { defineNuxtModule } from 'nuxt/kit'
|
|
160
|
+
|
|
161
|
+
export default defineNuxtModule({
|
|
162
|
+
meta: {
|
|
163
|
+
name: '${name}'
|
|
164
|
+
},
|
|
165
|
+
setup () {}
|
|
166
|
+
})
|
|
167
|
+
`
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const page = ({ name, nuxtOptions }) => ({
|
|
171
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.pages, `${name}.vue`),
|
|
172
|
+
contents: `
|
|
173
|
+
<script setup lang="ts"><\/script>
|
|
174
|
+
|
|
175
|
+
<template>
|
|
176
|
+
<div>
|
|
177
|
+
Page: ${name}
|
|
178
|
+
</div>
|
|
179
|
+
</template>
|
|
180
|
+
|
|
181
|
+
<style scoped></style>
|
|
182
|
+
`
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const plugin = ({ name, args, nuxtOptions }) => ({
|
|
186
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.plugins, `${name}${applySuffix(args, ["client", "server"], "mode")}.ts`),
|
|
187
|
+
contents: `
|
|
188
|
+
export default defineNuxtPlugin(nuxtApp => {})
|
|
189
|
+
`
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const serverMiddleware = ({ name, nuxtOptions }) => ({
|
|
193
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, "middleware", `${name}.ts`),
|
|
194
|
+
contents: `
|
|
195
|
+
export default defineEventHandler(event => {})
|
|
196
|
+
`
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const serverPlugin = ({ name, nuxtOptions }) => ({
|
|
200
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, "plugins", `${name}.ts`),
|
|
201
|
+
contents: `
|
|
202
|
+
export default defineNitroPlugin(nitroApp => {})
|
|
203
|
+
`
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const serverRoute = ({ name, args, nuxtOptions }) => ({
|
|
207
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, args.api ? "api" : "routes", `${name}.ts`),
|
|
208
|
+
contents: `
|
|
209
|
+
export default defineEventHandler(event => {})
|
|
210
|
+
`
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const serverUtil = ({ name, nuxtOptions }) => ({
|
|
214
|
+
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, "utils", `${name}.ts`),
|
|
215
|
+
contents: `
|
|
216
|
+
export function ${camelCase(name)}() {}
|
|
217
|
+
`
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const templates = {
|
|
221
|
+
"api": api,
|
|
222
|
+
"app": app,
|
|
223
|
+
"app-config": appConfig,
|
|
224
|
+
"component": component,
|
|
225
|
+
"composable": composable,
|
|
226
|
+
"error": error,
|
|
227
|
+
"layer": layer,
|
|
228
|
+
"layout": layout,
|
|
229
|
+
"middleware": middleware,
|
|
230
|
+
"module": module,
|
|
231
|
+
"page": page,
|
|
232
|
+
"plugin": plugin,
|
|
233
|
+
"server-middleware": serverMiddleware,
|
|
234
|
+
"server-plugin": serverPlugin,
|
|
235
|
+
"server-route": serverRoute,
|
|
236
|
+
"server-util": serverUtil
|
|
237
|
+
};
|
|
238
|
+
function applySuffix(args, suffixes, unwrapFrom) {
|
|
239
|
+
let suffix = "";
|
|
240
|
+
for (const s of suffixes) {
|
|
241
|
+
if (args[s]) {
|
|
242
|
+
suffix += `.${s}`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (unwrapFrom && args[unwrapFrom] && suffixes.includes(args[unwrapFrom])) {
|
|
246
|
+
suffix += `.${args[unwrapFrom]}`;
|
|
247
|
+
}
|
|
248
|
+
return suffix;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const templateNames = Object.keys(templates);
|
|
252
|
+
const add = defineCommand({
|
|
253
|
+
meta: {
|
|
254
|
+
name: "add",
|
|
255
|
+
description: "Create a new template file."
|
|
256
|
+
},
|
|
257
|
+
args: {
|
|
258
|
+
...cwdArgs,
|
|
259
|
+
...logLevelArgs,
|
|
260
|
+
force: {
|
|
261
|
+
type: "boolean",
|
|
262
|
+
description: "Override existing file"
|
|
263
|
+
},
|
|
264
|
+
template: {
|
|
265
|
+
type: "positional",
|
|
266
|
+
required: true,
|
|
267
|
+
valueHint: templateNames.join("|"),
|
|
268
|
+
description: `Template type to scaffold`
|
|
269
|
+
},
|
|
270
|
+
name: {
|
|
271
|
+
type: "positional",
|
|
272
|
+
required: true,
|
|
273
|
+
description: "Generated file name"
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
async run(ctx) {
|
|
277
|
+
const cwd = resolve(ctx.args.cwd);
|
|
278
|
+
const templateName = ctx.args.template;
|
|
279
|
+
if (!templateNames.includes(templateName)) {
|
|
280
|
+
logger.error(
|
|
281
|
+
`Template ${templateName} is not supported. Possible values: ${Object.keys(
|
|
282
|
+
templates
|
|
283
|
+
).join(", ")}`
|
|
284
|
+
);
|
|
285
|
+
process.exit(1);
|
|
286
|
+
}
|
|
287
|
+
const ext = extname(ctx.args.name);
|
|
288
|
+
const name = ext === ".vue" || ext === ".ts" ? ctx.args.name.replace(ext, "") : ctx.args.name;
|
|
289
|
+
if (!name) {
|
|
290
|
+
logger.error("name argument is missing!");
|
|
291
|
+
process.exit(1);
|
|
292
|
+
}
|
|
293
|
+
const kit = await loadKit(cwd);
|
|
294
|
+
const config = await kit.loadNuxtConfig({ cwd });
|
|
295
|
+
const template = templates[templateName];
|
|
296
|
+
const res = template({ name, args: ctx.args, nuxtOptions: config });
|
|
297
|
+
if (!ctx.args.force && existsSync(res.path)) {
|
|
298
|
+
logger.error(
|
|
299
|
+
`File exists: ${res.path} . Use --force to override or use a different name.`
|
|
300
|
+
);
|
|
301
|
+
process.exit(1);
|
|
302
|
+
}
|
|
303
|
+
const parentDir = dirname(res.path);
|
|
304
|
+
if (!existsSync(parentDir)) {
|
|
305
|
+
logger.info("Creating directory", parentDir);
|
|
306
|
+
if (templateName === "page") {
|
|
307
|
+
logger.info("This enables vue-router functionality!");
|
|
308
|
+
}
|
|
309
|
+
await promises.mkdir(parentDir, { recursive: true });
|
|
310
|
+
}
|
|
311
|
+
await promises.writeFile(res.path, `${res.contents.trim()}
|
|
312
|
+
`);
|
|
313
|
+
logger.info(`\u{1FA84} Generated a new ${templateName} in ${res.path}`);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
export { add as default };
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import { updateConfig } from 'c12/update';
|
|
6
|
+
import { defineCommand } from 'citty';
|
|
7
|
+
import { colors } from 'consola/utils';
|
|
8
|
+
import { addDependency } from 'nypm';
|
|
9
|
+
import { $fetch } from 'ofetch';
|
|
10
|
+
import { resolve } from 'pathe';
|
|
11
|
+
import { readPackageJSON } from 'pkg-types';
|
|
12
|
+
import { satisfies } from 'semver';
|
|
13
|
+
import { joinURL } from 'ufo';
|
|
14
|
+
import { c as cwdArgs, l as logLevelArgs, a as logger, r as runCommand } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
15
|
+
import { f as fetchModules, g as getNuxtVersion, c as checkNuxtCompatibility } from '../shared/cli-nightly.C935N1ss.mjs';
|
|
16
|
+
import 'std-env';
|
|
17
|
+
import 'consola';
|
|
18
|
+
import 'node:url';
|
|
19
|
+
|
|
20
|
+
const add = defineCommand({
|
|
21
|
+
meta: {
|
|
22
|
+
name: "add",
|
|
23
|
+
description: "Add Nuxt modules"
|
|
24
|
+
},
|
|
25
|
+
args: {
|
|
26
|
+
...cwdArgs,
|
|
27
|
+
...logLevelArgs,
|
|
28
|
+
moduleName: {
|
|
29
|
+
type: "positional",
|
|
30
|
+
description: "Specify one or more modules to install by name, separated by spaces"
|
|
31
|
+
},
|
|
32
|
+
skipInstall: {
|
|
33
|
+
type: "boolean",
|
|
34
|
+
description: "Skip npm install"
|
|
35
|
+
},
|
|
36
|
+
skipConfig: {
|
|
37
|
+
type: "boolean",
|
|
38
|
+
description: "Skip nuxt.config.ts update"
|
|
39
|
+
},
|
|
40
|
+
dev: {
|
|
41
|
+
type: "boolean",
|
|
42
|
+
description: "Install modules as dev dependencies"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
async setup(ctx) {
|
|
46
|
+
const cwd = resolve(ctx.args.cwd);
|
|
47
|
+
const modules = ctx.args._.map((e) => e.trim()).filter(Boolean);
|
|
48
|
+
const projectPkg = await readPackageJSON(cwd).catch(() => ({}));
|
|
49
|
+
if (!projectPkg.dependencies?.nuxt && !projectPkg.devDependencies?.nuxt) {
|
|
50
|
+
logger.warn(`No \`nuxt\` dependency detected in \`${cwd}\`.`);
|
|
51
|
+
const shouldContinue = await logger.prompt(
|
|
52
|
+
`Do you want to continue anyway?`,
|
|
53
|
+
{
|
|
54
|
+
type: "confirm",
|
|
55
|
+
initial: false
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
if (shouldContinue !== true) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const maybeResolvedModules = await Promise.all(modules.map((moduleName) => resolveModule(moduleName, cwd)));
|
|
63
|
+
const resolvedModules = maybeResolvedModules.filter((x) => x != null);
|
|
64
|
+
logger.info(`Resolved \`${resolvedModules.map((x) => x.pkgName).join("`, `")}\`, adding module${resolvedModules.length > 1 ? "s" : ""}...`);
|
|
65
|
+
await addModules(resolvedModules, { ...ctx.args, cwd }, projectPkg);
|
|
66
|
+
const args = Object.entries(ctx.args).filter(([k]) => k in cwdArgs || k in logLevelArgs).map(([k, v]) => `--${k}=${v}`);
|
|
67
|
+
await runCommand("prepare", args);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
async function addModules(modules, { skipInstall, skipConfig, cwd, dev }, projectPkg) {
|
|
71
|
+
if (!skipInstall) {
|
|
72
|
+
const installedModules = [];
|
|
73
|
+
const notInstalledModules = [];
|
|
74
|
+
const dependencies = /* @__PURE__ */ new Set([
|
|
75
|
+
...Object.keys(projectPkg.dependencies || {}),
|
|
76
|
+
...Object.keys(projectPkg.devDependencies || {})
|
|
77
|
+
]);
|
|
78
|
+
for (const module of modules) {
|
|
79
|
+
if (dependencies.has(module.pkgName)) {
|
|
80
|
+
installedModules.push(module);
|
|
81
|
+
} else {
|
|
82
|
+
notInstalledModules.push(module);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (installedModules.length > 0) {
|
|
86
|
+
const installedModulesList = installedModules.map((module) => module.pkgName).join("`, `");
|
|
87
|
+
const are = installedModules.length > 1 ? "are" : "is";
|
|
88
|
+
logger.info(`\`${installedModulesList}\` ${are} already installed`);
|
|
89
|
+
}
|
|
90
|
+
if (notInstalledModules.length > 0) {
|
|
91
|
+
const isDev = Boolean(projectPkg.devDependencies?.nuxt) || dev;
|
|
92
|
+
const notInstalledModulesList = notInstalledModules.map((module) => module.pkg).join("`, `");
|
|
93
|
+
const dependency = notInstalledModules.length > 1 ? "dependencies" : "dependency";
|
|
94
|
+
const a = notInstalledModules.length > 1 ? "" : " a";
|
|
95
|
+
logger.info(`Installing \`${notInstalledModulesList} as${a}\`${isDev ? " development" : ""} ${dependency}`);
|
|
96
|
+
const res = await addDependency(notInstalledModules.map((module) => module.pkg), {
|
|
97
|
+
cwd,
|
|
98
|
+
dev: isDev,
|
|
99
|
+
installPeerDependencies: true
|
|
100
|
+
}).catch(
|
|
101
|
+
(error) => {
|
|
102
|
+
logger.error(error);
|
|
103
|
+
const failedModulesList = notInstalledModules.map((module) => colors.cyan(module.pkg)).join("`, `");
|
|
104
|
+
const s = notInstalledModules.length > 1 ? "s" : "";
|
|
105
|
+
return logger.prompt(`Install failed for \`${failedModulesList}\`. Do you want to continue adding the module${s} to ${colors.cyan("nuxt.config")}?`, {
|
|
106
|
+
type: "confirm",
|
|
107
|
+
initial: false
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
if (res === false) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!skipConfig) {
|
|
117
|
+
await updateConfig({
|
|
118
|
+
cwd,
|
|
119
|
+
configFile: "nuxt.config",
|
|
120
|
+
async onCreate() {
|
|
121
|
+
logger.info(`Creating \`nuxt.config.ts\``);
|
|
122
|
+
return getDefaultNuxtConfig();
|
|
123
|
+
},
|
|
124
|
+
async onUpdate(config) {
|
|
125
|
+
if (!config.modules) {
|
|
126
|
+
config.modules = [];
|
|
127
|
+
}
|
|
128
|
+
for (const resolved of modules) {
|
|
129
|
+
if (config.modules.includes(resolved.pkgName)) {
|
|
130
|
+
logger.info(`\`${resolved.pkgName}\` is already in the \`modules\``);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
logger.info(`Adding \`${resolved.pkgName}\` to the \`modules\``);
|
|
134
|
+
config.modules.push(resolved.pkgName);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}).catch((error) => {
|
|
138
|
+
logger.error(`Failed to update \`nuxt.config\`: ${error.message}`);
|
|
139
|
+
logger.error(`Please manually add \`${modules.map((module) => module.pkgName).join("`, `")}\` to the \`modules\` in \`nuxt.config.ts\``);
|
|
140
|
+
return null;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function getDefaultNuxtConfig() {
|
|
145
|
+
return `
|
|
146
|
+
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
147
|
+
export default defineNuxtConfig({
|
|
148
|
+
modules: []
|
|
149
|
+
})`;
|
|
150
|
+
}
|
|
151
|
+
const packageRegex = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?([a-z0-9-~][a-z0-9-._~]*)(@[^@]+)?$/;
|
|
152
|
+
async function resolveModule(moduleName, cwd) {
|
|
153
|
+
let pkgName = moduleName;
|
|
154
|
+
let pkgVersion;
|
|
155
|
+
const reMatch = moduleName.match(packageRegex);
|
|
156
|
+
if (reMatch) {
|
|
157
|
+
if (reMatch[3]) {
|
|
158
|
+
pkgName = `${reMatch[1] || ""}${reMatch[2] || ""}`;
|
|
159
|
+
pkgVersion = reMatch[3].slice(1);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
logger.error(`Invalid package name \`${pkgName}\`.`);
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
const modulesDB = await fetchModules().catch((err) => {
|
|
166
|
+
logger.warn(`Cannot search in the Nuxt Modules database: ${err}`);
|
|
167
|
+
return [];
|
|
168
|
+
});
|
|
169
|
+
const matchedModule = modulesDB.find(
|
|
170
|
+
(module) => module.name === moduleName || module.npm === pkgName || module.aliases?.includes(pkgName)
|
|
171
|
+
);
|
|
172
|
+
if (matchedModule?.npm) {
|
|
173
|
+
pkgName = matchedModule.npm;
|
|
174
|
+
}
|
|
175
|
+
if (matchedModule && matchedModule.compatibility.nuxt) {
|
|
176
|
+
const nuxtVersion = await getNuxtVersion(cwd);
|
|
177
|
+
if (!checkNuxtCompatibility(matchedModule, nuxtVersion)) {
|
|
178
|
+
logger.warn(
|
|
179
|
+
`The module \`${pkgName}\` is not compatible with Nuxt \`${nuxtVersion}\` (requires \`${matchedModule.compatibility.nuxt}\`)`
|
|
180
|
+
);
|
|
181
|
+
const shouldContinue = await logger.prompt(
|
|
182
|
+
"Do you want to continue installing incompatible version?",
|
|
183
|
+
{
|
|
184
|
+
type: "confirm",
|
|
185
|
+
initial: false
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
if (shouldContinue !== true) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const versionMap = matchedModule.compatibility.versionMap;
|
|
193
|
+
if (versionMap) {
|
|
194
|
+
for (const [_nuxtVersion, _moduleVersion] of Object.entries(versionMap)) {
|
|
195
|
+
if (satisfies(nuxtVersion, _nuxtVersion)) {
|
|
196
|
+
if (!pkgVersion) {
|
|
197
|
+
pkgVersion = _moduleVersion;
|
|
198
|
+
} else {
|
|
199
|
+
logger.warn(
|
|
200
|
+
`Recommended version of \`${pkgName}\` for Nuxt \`${nuxtVersion}\` is \`${_moduleVersion}\` but you have requested \`${pkgVersion}\``
|
|
201
|
+
);
|
|
202
|
+
pkgVersion = await logger.prompt("Choose a version:", {
|
|
203
|
+
type: "select",
|
|
204
|
+
options: [_moduleVersion, pkgVersion]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
pkgVersion = pkgVersion || "latest";
|
|
213
|
+
const pkgScope = pkgName.startsWith("@") ? pkgName.split("/")[0] : null;
|
|
214
|
+
const meta = await detectNpmRegistry(pkgScope);
|
|
215
|
+
const headers = {};
|
|
216
|
+
if (meta.authToken) {
|
|
217
|
+
headers.Authorization = `Bearer ${meta.authToken}`;
|
|
218
|
+
}
|
|
219
|
+
const pkgDetails = await $fetch(joinURL(meta.registry, `${pkgName}`), {
|
|
220
|
+
headers
|
|
221
|
+
});
|
|
222
|
+
pkgVersion = pkgDetails["dist-tags"]?.[pkgVersion] || pkgVersion;
|
|
223
|
+
const pkg = pkgDetails.versions[pkgVersion];
|
|
224
|
+
const pkgDependencies = Object.assign(
|
|
225
|
+
pkg.dependencies || {},
|
|
226
|
+
pkg.devDependencies || {}
|
|
227
|
+
);
|
|
228
|
+
if (!pkgDependencies.nuxt && !pkgDependencies["nuxt-edge"] && !pkgDependencies["@nuxt/kit"]) {
|
|
229
|
+
logger.warn(`It seems that \`${pkgName}\` is not a Nuxt module.`);
|
|
230
|
+
const shouldContinue = await logger.prompt(
|
|
231
|
+
`Do you want to continue installing \`${pkgName}\` anyway?`,
|
|
232
|
+
{
|
|
233
|
+
type: "confirm",
|
|
234
|
+
initial: false
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
if (shouldContinue !== true) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
nuxtModule: matchedModule,
|
|
243
|
+
pkg: `${pkgName}@${pkgVersion}`,
|
|
244
|
+
pkgName,
|
|
245
|
+
pkgVersion
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function getNpmrcPaths() {
|
|
249
|
+
const userNpmrcPath = join(homedir(), ".npmrc");
|
|
250
|
+
const cwdNpmrcPath = join(process.cwd(), ".npmrc");
|
|
251
|
+
return [cwdNpmrcPath, userNpmrcPath];
|
|
252
|
+
}
|
|
253
|
+
async function getAuthToken(registry) {
|
|
254
|
+
const paths = getNpmrcPaths();
|
|
255
|
+
const authTokenRegex = new RegExp(`^//${registry.replace(/^https?:\/\//, "").replace(/\/$/, "")}/:_authToken=(.+)$`, "m");
|
|
256
|
+
for (const npmrcPath of paths) {
|
|
257
|
+
let fd;
|
|
258
|
+
try {
|
|
259
|
+
fd = await fs.promises.open(npmrcPath, "r");
|
|
260
|
+
if (await fd.stat().then((r) => r.isFile())) {
|
|
261
|
+
const npmrcContent = await fd.readFile("utf-8");
|
|
262
|
+
const authTokenMatch = npmrcContent.match(authTokenRegex)?.[1];
|
|
263
|
+
if (authTokenMatch) {
|
|
264
|
+
return authTokenMatch.trim();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
} catch {
|
|
268
|
+
} finally {
|
|
269
|
+
await fd?.close();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
async function detectNpmRegistry(scope) {
|
|
275
|
+
const registry = await getRegistry(scope);
|
|
276
|
+
const authToken = await getAuthToken(registry);
|
|
277
|
+
return {
|
|
278
|
+
registry,
|
|
279
|
+
authToken
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
async function getRegistry(scope) {
|
|
283
|
+
if (process.env.COREPACK_NPM_REGISTRY) {
|
|
284
|
+
return process.env.COREPACK_NPM_REGISTRY;
|
|
285
|
+
}
|
|
286
|
+
const registry = await getRegistryFromFile(getNpmrcPaths(), scope);
|
|
287
|
+
if (registry) {
|
|
288
|
+
process.env.COREPACK_NPM_REGISTRY = registry;
|
|
289
|
+
}
|
|
290
|
+
return registry || "https://registry.npmjs.org";
|
|
291
|
+
}
|
|
292
|
+
async function getRegistryFromFile(paths, scope) {
|
|
293
|
+
for (const npmrcPath of paths) {
|
|
294
|
+
let fd;
|
|
295
|
+
try {
|
|
296
|
+
fd = await fs.promises.open(npmrcPath, "r");
|
|
297
|
+
if (await fd.stat().then((r) => r.isFile())) {
|
|
298
|
+
const npmrcContent = await fd.readFile("utf-8");
|
|
299
|
+
if (scope) {
|
|
300
|
+
const scopedRegex = new RegExp(`^${scope}:registry=(.+)$`, "m");
|
|
301
|
+
const scopedMatch = npmrcContent.match(scopedRegex)?.[1];
|
|
302
|
+
if (scopedMatch) {
|
|
303
|
+
return scopedMatch.trim();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const defaultRegex = /^\s*registry=(.+)$/m;
|
|
307
|
+
const defaultMatch = npmrcContent.match(defaultRegex)?.[1];
|
|
308
|
+
if (defaultMatch) {
|
|
309
|
+
return defaultMatch.trim();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
} catch {
|
|
313
|
+
} finally {
|
|
314
|
+
await fd?.close();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export { add as default };
|