Skip to content

Commit

Permalink
feat: add Nuxt template (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: John Leider <[email protected]>
  • Loading branch information
userquin and johnleider authored Nov 12, 2024
1 parent c8ef277 commit b75e547
Show file tree
Hide file tree
Showing 20 changed files with 1,165 additions and 109 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@
"scripts": {
"build": "node ./scripts/build.js",
"start": "node ./index.js",
"lint": "eslint --fix 'src/**'",
"lint": "eslint --fix ./src/**",
"prepublishOnly": "npm run build"
},
"dependencies": {
"kolorist": "^1.5.1",
"minimist": "^1.2.6",
"magicast": "^0.3.4",
"package-manager-detector": "^0.2.2",
"prompts": "^2.4.2",
"validate-npm-package-name": "^4.0.0"
},
"devDependencies": {
"@release-it/conventional-changelog": "^8.0.1",
"@types/minimist": "^1.2.2",
"@types/node": "^20.12.8",
"@types/prompts": "^2.0.14",
"@types/validate-npm-package-name": "^4.0.0",
"@typescript-eslint/eslint-plugin": "^5.30.6",
Expand Down
49 changes: 39 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function bundleMain () {
format: 'esm',
platform: 'node',
target: 'node18',
external: ['validate-npm-package-name', 'kolorist', 'minimist', 'prompts'],
external: ['package-browser-detector', 'magicast', 'validate-npm-package-name', 'kolorist', 'minimist', 'prompts'],
})
}

Expand Down
64 changes: 47 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { mkdirSync, rmSync, writeFileSync } from 'fs'

// Types
import type { ContextState } from './utils/prompts'
import type { NuxtPresetName } from './utils/presets'

// Utils
import { initPrompts } from './utils/prompts'
import { red } from 'kolorist'
import minimist from 'minimist'
import { installDependencies, renderTemplate } from './utils'
import { renderNuxtTemplate } from './utils/nuxt/renderNuxtTemplate'

const validPresets = ['base', 'custom', 'default', 'essentials']

Expand Down Expand Up @@ -48,6 +50,12 @@ async function run () {
usePackageManager,
installDependencies: installDeps,
usePreset,
useStore,
useEslint,
useNuxtV4Compat,
useNuxtModule,
useNuxtSSR,
useNuxtSSRClientHints,
} = await initPrompts(context)

const projectRoot = join(cwd, projectName)
Expand All @@ -57,30 +65,51 @@ async function run () {
rmSync(projectRoot, { recursive: true })
}

// Create project directory
mkdirSync(projectRoot)
const preset = context.usePreset ?? usePreset

if (preset.startsWith('nuxt-')) {
const templateRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../template/typescript')
const templatePath = resolve(dirname(fileURLToPath(import.meta.url)), '../template/typescript/nuxt')
// we are going to run Nuxi CLI that will handle the creation for us
await renderNuxtTemplate({
cwd,
projectName,
projectRoot,
templateRoot,
templatePath,
nuxtPreset: preset as NuxtPresetName,
useNuxtV4Compat,
useNuxtModule,
useNuxtSSR,
useNuxtSSRClientHints,
})
}
else {
// Create project directory
mkdirSync(projectRoot)

// Create base package.json
writeFileSync(resolve(projectRoot, 'package.json'), JSON.stringify({ name: projectName }, null, 2))
// Create base package.json
writeFileSync(resolve(projectRoot, 'package.json'), JSON.stringify({ name: projectName }, null, 2))

const jsOrTs = useTypeScript ? 'typescript' : 'javascript'
let templatePath = resolve(dirname(fileURLToPath(import.meta.url)), '../template', jsOrTs)
console.log('\n◌ Generating scaffold...')

console.log('\n◌ Generating scaffold...')
const jsOrTs = useTypeScript ? 'typescript' : 'javascript'
let templatePath = resolve(dirname(fileURLToPath(import.meta.url)), '../template', jsOrTs)

renderTemplate(resolve(templatePath, 'default'), projectRoot)
renderTemplate(resolve(templatePath, 'default'), projectRoot)

if (['base', 'essentials'].includes(usePreset)) {
renderTemplate(resolve(templatePath, 'base'), projectRoot)
}
if (['base', 'essentials'].includes(usePreset)) {
renderTemplate(resolve(templatePath, 'base'), projectRoot)
}

if (['essentials', 'recommended'].includes(usePreset)) {
renderTemplate(resolve(templatePath, 'essentials'), projectRoot)
}
if (['essentials', 'recommended'].includes(usePreset)) {
renderTemplate(resolve(templatePath, 'essentials'), projectRoot)
}

if (usePackageManager && installDeps) {
console.log(`◌ Installing dependencies with ${usePackageManager}...\n`)
installDependencies(projectRoot, usePackageManager)
if (usePackageManager && installDeps) {
console.log(`◌ Installing dependencies with ${usePackageManager}...\n`)
installDependencies(projectRoot, usePackageManager)
}
}

console.log(`\n${projectName} has been generated at ${projectRoot}\n`)
Expand All @@ -91,6 +120,7 @@ run()
console.log('Discord community: https://community.vuetifyjs.com')
console.log('Github: https://github.com/vuetifyjs/vuetify')
console.log('Support Vuetify: https://github.com/sponsors/johnleider')
process.exit(0)
})
.catch((err) => {
console.error(`\n${red('✖')} ${err}\n`)
Expand Down
Loading

0 comments on commit b75e547

Please sign in to comment.