Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(template): support pug template #960

Merged
merged 7 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -50,6 +50,9 @@ yarn create nuxt-app <my-project>
- [Vant](https://github.com/youzan/vant)
- [View UI](https://www.iviewui.com/)
- [Vuetify](https://github.com/vuetifyjs/vuetify)
1. Template engine
- HTML
- Pug
1. Nuxt.js modules:
- [Axios - Promise based HTTP client](https://github.com/nuxt-community/axios-module)
- [Progressive Web App (PWA)](https://github.com/nuxt-community/pwa-module)
Expand Down
6 changes: 6 additions & 0 deletions packages/cna-template/template/frameworks/pug/package.json
@@ -0,0 +1,6 @@
{
"dependencies": {
"pug": "^3.0.2",
"pug-plain-loader": "^1.1.0"
}
}
10 changes: 10 additions & 0 deletions packages/cna-template/template/frameworks/pug/pages/index.vue
@@ -0,0 +1,10 @@
<template lang="pug">
tutorial
</template>

<script>
import Vue from 'vue'

export default Vue.extend({
name: 'IndexPage'
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the end tag

3 changes: 2 additions & 1 deletion packages/create-nuxt-app/lib/package.js
Expand Up @@ -22,9 +22,10 @@ module.exports = {
},
load (generator) {
const nuxtPkg = this.loadPackage('nuxt', generator)
const templatePkg = this.loadPackage(generator.answers.template, generator)
const uiPkg = this.loadPackage(generator.answers.ui, generator)
const testPkg = this.loadPackage(generator.answers.test, generator)
const pkg = merge(nuxtPkg, uiPkg, testPkg)
const pkg = merge(nuxtPkg, templatePkg, uiPkg, testPkg)
pkg.dependencies = sortByKey(pkg.dependencies)
pkg.devDependencies = sortByKey(pkg.devDependencies)
return pkg
Expand Down
10 changes: 10 additions & 0 deletions packages/create-nuxt-app/lib/prompts.js
Expand Up @@ -48,6 +48,16 @@ module.exports = [
],
default: 'none'
},
{
name: 'template',
message: 'Template engine:',
type: 'list',
choices: [
{ name: 'HTML', value: 'html' },
{ name: 'Pug', value: 'pug' }
],
default: 'html'
},
{
name: 'features',
message: 'Nuxt.js modules:',
Expand Down
8 changes: 8 additions & 0 deletions packages/create-nuxt-app/lib/saofile.js
Expand Up @@ -74,6 +74,14 @@ module.exports = {
}
}]

if (this.answers.template !== 'html') {
actions.push({
type: 'add',
files: '**',
templateDir: join(frameworksDir, this.answers.template)
})
}

if (this.answers.ui !== 'none') {
actions.push({
type: 'add',
Expand Down
166 changes: 166 additions & 0 deletions packages/create-nuxt-app/test/snapshots/index.test.js.md
Expand Up @@ -1746,6 +1746,172 @@ Generated by [AVA](https://avajs.dev).
}␊
`

## verify template: HTML

> Generated files

[
'.editorconfig',
'.gitignore',
'README.md',
'components/NuxtLogo.vue',
'components/Tutorial.vue',
'nuxt.config.js',
'package.json',
'pages/index.vue',
'static/favicon.ico',
'store/README.md',
]

> package.json

{
dependencies: {
'core-js': '^3.25.0',
nuxt: '^2.15.8',
vue: '^2.7.10',
'vue-server-renderer': '^2.7.10',
'vue-template-compiler': '^2.7.10',
},
devDependencies: {},
private: true,
scripts: {
build: 'nuxt build',
dev: 'nuxt',
generate: 'nuxt generate',
start: 'nuxt start',
},
}

> Generated nuxt.config.js

`export default {␊
// Global page headers: https://go.nuxtjs.dev/config-head␊
head: {␊
title: 'output',␊
htmlAttrs: {␊
lang: 'en'␊
},␊
meta: [␊
{ charset: 'utf-8' },␊
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
{ hid: 'description', name: 'description', content: '' },␊
{ name: 'format-detection', content: 'telephone=no' }␊
],␊
link: [␊
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
]␊
},␊
// Global CSS: https://go.nuxtjs.dev/config-css␊
css: [␊
],␊
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins␊
plugins: [␊
],␊
// Auto import components: https://go.nuxtjs.dev/config-components␊
components: true,␊
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules␊
buildModules: [␊
],␊
// Modules: https://go.nuxtjs.dev/config-modules␊
modules: [␊
],␊
// Build Configuration: https://go.nuxtjs.dev/config-build␊
build: {␊
}␊
}␊
`

## verify template: Pug

> Generated files

[
'.editorconfig',
'.gitignore',
'README.md',
'components/NuxtLogo.vue',
'components/Tutorial.vue',
'nuxt.config.js',
'package.json',
'pages/index.vue',
'static/favicon.ico',
'store/README.md',
]

> package.json

{
dependencies: {
'core-js': '^3.25.0',
nuxt: '^2.15.8',
pug: '^3.0.2',
'pug-plain-loader': '^1.1.0',
vue: '^2.7.10',
'vue-server-renderer': '^2.7.10',
'vue-template-compiler': '^2.7.10',
},
devDependencies: {},
private: true,
scripts: {
build: 'nuxt build',
dev: 'nuxt',
generate: 'nuxt generate',
start: 'nuxt start',
},
}

> Generated nuxt.config.js

`export default {␊
// Global page headers: https://go.nuxtjs.dev/config-head␊
head: {␊
title: 'output',␊
htmlAttrs: {␊
lang: 'en'␊
},␊
meta: [␊
{ charset: 'utf-8' },␊
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
{ hid: 'description', name: 'description', content: '' },␊
{ name: 'format-detection', content: 'telephone=no' }␊
],␊
link: [␊
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
]␊
},␊
// Global CSS: https://go.nuxtjs.dev/config-css␊
css: [␊
],␊
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins␊
plugins: [␊
],␊
// Auto import components: https://go.nuxtjs.dev/config-components␊
components: true,␊
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules␊
buildModules: [␊
],␊
// Modules: https://go.nuxtjs.dev/config-modules␊
modules: [␊
],␊
// Build Configuration: https://go.nuxtjs.dev/config-build␊
build: {␊
}␊
}␊
`

## verify features: Axios - Promise based HTTP client, Progressive Web App (PWA), Content - Git-based headless CMS

> Generated files
Expand Down
Binary file modified packages/create-nuxt-app/test/snapshots/index.test.js.snap
Binary file not shown.