mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
feat(cli)!: use giget 0.1x with template registry for nuxi init
(#7404)
This commit is contained in:
parent
9abc7a2122
commit
270055b86d
@ -4,13 +4,19 @@
|
||||
npx nuxi init|create [--verbose|-v] [--template,-t] [dir]
|
||||
```
|
||||
|
||||
The `init` command initializes a fresh Nuxt project.
|
||||
The `init` command initializes a fresh Nuxt project using [unjs/giget](https://github.com/unjs/giget).
|
||||
|
||||
## Options
|
||||
|
||||
Option | Default | Description
|
||||
-------------------------|-----------------|------------------
|
||||
`--template, -t` | `nuxt/starter#v3` | Specify a Git repository to use as a template.
|
||||
`--template, -t` | `v3` | Specify template name or git repository to use as a template. Format is `gh:org/name` to use a custom github template.
|
||||
`--force` | `false` | Force clone to any existing directory.
|
||||
`--offline` | `false` | Do not attempt to download from github and only use local cache.
|
||||
`--prefer-offline` | `false` | Try local cache first. (might be outdated)
|
||||
`--shell` | `false` | (experimental) Open shell in cloned directory.
|
||||
`dir` | `nuxt-app` | Name of the install directory.
|
||||
`--prefer-offline` | `false` | Try local cache first to download templates.
|
||||
`--shell` | `false` | Open shell in cloned directory (experimental).
|
||||
|
||||
## Environment variables
|
||||
|
||||
- `NUXI_INIT_REGISTRY`: Set to a custom template registry. ([learn more](https://github.com/unjs/giget#custom-registry)).
|
||||
- Default registry is loaded from [nuxt/starter/templates](https://github.com/nuxt/starter/tree/templates/templates)
|
||||
|
@ -34,7 +34,7 @@
|
||||
"destr": "^1.1.1",
|
||||
"execa": "^6.1.0",
|
||||
"flat": "^5.0.2",
|
||||
"giget": "^0.0.4",
|
||||
"giget": "^0.1.5",
|
||||
"jiti": "^1.15.0",
|
||||
"listhen": "^0.2.15",
|
||||
"mlly": "^0.5.14",
|
||||
@ -44,7 +44,6 @@
|
||||
"pkg-types": "^0.3.5",
|
||||
"scule": "^0.3.2",
|
||||
"semver": "^7.3.7",
|
||||
"superb": "^4.0.0",
|
||||
"unbuild": "latest"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
@ -1,27 +1,11 @@
|
||||
import { downloadRepo, startShell } from 'giget'
|
||||
import { relative, resolve } from 'pathe'
|
||||
import superb from 'superb'
|
||||
import { downloadTemplate, startShell } from 'giget'
|
||||
import { relative } from 'pathe'
|
||||
import consola from 'consola'
|
||||
import { defineNuxtCommand } from './index'
|
||||
|
||||
const rpath = (p: string) => relative(process.cwd(), p)
|
||||
|
||||
const resolveTemplate = (template: string | boolean) => {
|
||||
if (typeof template === 'boolean') {
|
||||
consola.error('Please specify a template!')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!template) {
|
||||
template = 'v3'
|
||||
}
|
||||
|
||||
if (template.includes('/')) {
|
||||
return template
|
||||
}
|
||||
|
||||
return `nuxt/starter#${template}`
|
||||
}
|
||||
const DEFAULT_REGISTRY = 'https://raw.githubusercontent.com/nuxt/starter/templates/templates'
|
||||
|
||||
export default defineNuxtCommand({
|
||||
meta: {
|
||||
@ -31,32 +15,31 @@ export default defineNuxtCommand({
|
||||
},
|
||||
async invoke (args) {
|
||||
// Clone template
|
||||
const src = resolveTemplate(args.template || args.t)
|
||||
const dstDir = resolve(process.cwd(), args._[0] || 'nuxt-app')
|
||||
if (args.verbose || args.v) {
|
||||
process.env.DEBUG = process.env.DEBUG || 'true'
|
||||
}
|
||||
await downloadRepo(src, dstDir, {
|
||||
const template = args.template || args.t || 'v3'
|
||||
|
||||
const t = await downloadTemplate(template, {
|
||||
dir: args._[0] as string,
|
||||
force: args.force,
|
||||
offline: args.offline,
|
||||
preferOffline: args['prefer-offline']
|
||||
preferOffline: args['prefer-offline'],
|
||||
registry: process.env.NUXI_INIT_REGISTRY || DEFAULT_REGISTRY
|
||||
})
|
||||
|
||||
// Show next steps
|
||||
const relativeDist = rpath(dstDir)
|
||||
const relativeDist = rpath(t.dir)
|
||||
const nextSteps = [
|
||||
relativeDist.length > 1 && `📁 \`cd ${relativeDist}\``,
|
||||
'💿 Install dependencies with `npm install` or `yarn install` or `pnpm install --shamefully-hoist`',
|
||||
'🚀 Start development server with `npm run dev` or `yarn dev` or `pnpm run dev`'
|
||||
!args.shell && relativeDist.length > 1 && `\`cd ${relativeDist}\``,
|
||||
'Install dependencies with `npm install` or `yarn install` or `pnpm install --shamefully-hoist`',
|
||||
'Start development server with `npm run dev` or `yarn dev` or `pnpm run dev`'
|
||||
].filter(Boolean)
|
||||
|
||||
consola.log(`\n ✨ Your ${superb.random()} Nuxt project is just created! Next steps:\n`)
|
||||
consola.log(`✨ Nuxt project is created with \`${t.name}\` template. Next steps:`)
|
||||
for (const step of nextSteps) {
|
||||
consola.log(` ${step}\n`)
|
||||
consola.log(` › ${step}`)
|
||||
}
|
||||
|
||||
if (args.shell) {
|
||||
startShell(dstDir)
|
||||
startShell(t.dir)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
36
yarn.lock
36
yarn.lock
@ -7442,9 +7442,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"giget@npm:^0.0.4":
|
||||
version: 0.0.4
|
||||
resolution: "giget@npm:0.0.4"
|
||||
"giget@npm:^0.1.5":
|
||||
version: 0.1.5
|
||||
resolution: "giget@npm:0.1.5"
|
||||
dependencies:
|
||||
colorette: ^2.0.19
|
||||
mri: ^1.2.0
|
||||
@ -7453,7 +7453,7 @@ __metadata:
|
||||
tar: ^6.1.11
|
||||
bin:
|
||||
giget: dist/cli.mjs
|
||||
checksum: 6e6f86c125c477d47133ddc8768bcb5e4d91d9ada6f372174e2b56d1d854cefdc1e7b5e64884e618126dcc147cfc1448f661698cd6ddc6fce29703fa1a50dea9
|
||||
checksum: 3f9e50f3bd4f9109c7cb511427449daa66c54f466a7e3169bd2475984b60b83e5e840dc35b71373ee137be22458ad1a31564fa2f99e9fc50ec760849d4d30e62
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -10151,7 +10151,7 @@ __metadata:
|
||||
execa: ^6.1.0
|
||||
flat: ^5.0.2
|
||||
fsevents: ~2.3.2
|
||||
giget: ^0.0.4
|
||||
giget: ^0.1.5
|
||||
jiti: ^1.15.0
|
||||
listhen: ^0.2.15
|
||||
mlly: ^0.5.14
|
||||
@ -10161,7 +10161,6 @@ __metadata:
|
||||
pkg-types: ^0.3.5
|
||||
scule: ^0.3.2
|
||||
semver: ^7.3.7
|
||||
superb: ^4.0.0
|
||||
unbuild: latest
|
||||
dependenciesMeta:
|
||||
fsevents:
|
||||
@ -12621,15 +12620,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"superb@npm:^4.0.0":
|
||||
version: 4.0.0
|
||||
resolution: "superb@npm:4.0.0"
|
||||
dependencies:
|
||||
unique-random-array: ^2.0.0
|
||||
checksum: b80b4d347954ac994863386f6f6ebe176b93ebe8a14258191c118d92ab78296095b8195ae23f4b21e83519ac7eec36cc553fc2672914dd5d3ee98418e93a6bdc
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"supports-color@npm:^5.3.0":
|
||||
version: 5.5.0
|
||||
resolution: "supports-color@npm:5.5.0"
|
||||
@ -13267,22 +13257,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"unique-random-array@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "unique-random-array@npm:2.0.0"
|
||||
dependencies:
|
||||
unique-random: ^2.1.0
|
||||
checksum: c983e511fe6f45b9ee9b78d26a78e94ba798a4afaa2ca289948e694bc6ad75efca0dd1944e94a010ab56dd574daf4ebcf72727c6d581693610d3b0a8192ef2e5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"unique-random@npm:^2.1.0":
|
||||
version: 2.1.0
|
||||
resolution: "unique-random@npm:2.1.0"
|
||||
checksum: 7bc33f364f288172a948c82c0bbb7393fd175f3a78932aa3a77f070d786d5e86db869dc72f7cb9e0a26e5d3142bfd5c3c9d134a68473a3b1f4e2300d84dbf39d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"unique-slug@npm:^3.0.0":
|
||||
version: 3.0.0
|
||||
resolution: "unique-slug@npm:3.0.0"
|
||||
|
Loading…
Reference in New Issue
Block a user