Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 47e3ba0

Browse files
committed
refactor: improve choices output
1 parent c13a140 commit 47e3ba0

File tree

4 files changed

+2486
-227
lines changed

4 files changed

+2486
-227
lines changed

saofile.js

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ module.exports = {
2828
{
2929
name: 'pm',
3030
message: 'Choose a package manager',
31-
choices: ['yarn', 'npm'],
31+
choices: [
32+
{ name: 'Yarn', value: 'yarn' },
33+
{ name: 'Npm', value: 'npm' }
34+
],
3235
type: 'list',
3336
default: 'yarn'
3437
},
@@ -37,16 +40,16 @@ module.exports = {
3740
message: 'Use a custom UI framework',
3841
type: 'list',
3942
choices: [
40-
'none',
41-
'bootstrap',
42-
'vuetify',
43-
'bulma',
44-
'tailwind',
45-
'element-ui',
46-
'buefy',
47-
'ant-design-vue',
48-
'iview',
49-
'tachyons'
43+
{ name: 'None', value: 'none' },
44+
{ name: 'Ant Design Vue', value: 'ant-design-vue' },
45+
{ name: 'Bootstrap Vue', value: 'bootstrap' },
46+
{ name: 'Buefy', value: 'buefy' },
47+
{ name: 'Bulma', value: 'bulma' },
48+
{ name: 'Element', value: 'element-ui' },
49+
{ name: 'iView', value: 'iview' },
50+
{ name: 'Tachyons', value: 'tachyons' },
51+
{ name: 'Tailwind CSS', value: 'tailwind' },
52+
{ name: 'Vuetify.js', value: 'vuetify' }
5053
],
5154
default: 'none'
5255
},
@@ -55,14 +58,14 @@ module.exports = {
5558
message: 'Use a custom server framework',
5659
type: 'list',
5760
choices: [
58-
'none',
59-
'express',
60-
'koa',
61-
'adonis',
62-
'hapi',
63-
'feathers',
64-
'micro',
65-
'fastify'
61+
{ name: 'none', value: 'none' },
62+
{ name: 'AdonisJs', value: 'adonis' },
63+
{ name: 'Express', value: 'express' },
64+
{ name: 'Fastify', value: 'fastify' },
65+
{ name: 'Feathers', value: 'feathers' },
66+
{ name: 'hapi', value: 'hapi' },
67+
{ name: 'Koa', value: 'koa' },
68+
{ name: 'Micro', value: 'micro' }
6669
],
6770
default: 'none'
6871
},
@@ -71,22 +74,10 @@ module.exports = {
7174
message: 'Choose features to install',
7275
type: 'checkbox',
7376
choices: [
74-
{
75-
name: 'Progressive Web App (PWA) Support',
76-
value: 'pwa'
77-
},
78-
{
79-
name: 'Linter / Formatter',
80-
value: 'linter'
81-
},
82-
{
83-
name: 'Prettier',
84-
value: 'prettier'
85-
},
86-
{
87-
name: 'Axios',
88-
value: 'axios'
89-
}
77+
{ name: 'Axios', value: 'axios' },
78+
{ name: 'ESLint', value: 'linter' },
79+
{ name: 'Prettier', value: 'prettier' },
80+
{ name: 'Progressive Web App (PWA) Support', value: 'pwa' },
9081
],
9182
default: []
9283
},
@@ -95,9 +86,9 @@ module.exports = {
9586
message: 'Use a custom test framework',
9687
type: 'list',
9788
choices: [
98-
'none',
99-
'jest',
100-
'ava'
89+
{ name: 'none', value: 'none' },
90+
{ name: 'Jest', value: 'jest' },
91+
{ name: 'AVA', value: 'ava' }
10192
],
10293
default: 'none'
10394
},
@@ -106,7 +97,7 @@ module.exports = {
10697
message: 'Choose rendering mode',
10798
type: 'list',
10899
choices: [
109-
{ name: 'Universal', value: 'universal' },
100+
{ name: 'Universal (SSR)', value: 'universal' },
110101
{ name: 'Single Page App', value: 'spa' }
111102
],
112103
default: 'universal'

test/index.test.js

Lines changed: 24 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path'
22
import test from 'ava'
33
import sao from 'sao'
4+
import saoConfig from '../saofile'
45

56
const generator = path.join(__dirname, '..')
67

@@ -17,88 +18,30 @@ const verifyPkg = async (t, answers) => {
1718
const stream = await sao.mock({ generator }, answers)
1819

1920
const pkg = await stream.readFile('package.json')
20-
t.snapshot(stream.fileList, 'Generated files')
21+
t.snapshot(stream.fileList, 'Generated package.json')
2122
t.snapshot(getPkgFields(pkg), 'package.json')
2223
}
2324

24-
test('defaults', async (t) => {
25-
await verifyPkg(t)
26-
})
27-
28-
test('use express', async (t) => {
29-
await verifyPkg(t, {
30-
server: 'express'
31-
})
32-
})
33-
34-
test('use koa', async (t) => {
35-
await verifyPkg(t, {
36-
server: 'koa'
37-
})
38-
})
39-
40-
test('use hapi', async (t) => {
41-
await verifyPkg(t, {
42-
server: 'hapi'
43-
})
44-
})
45-
46-
test('use feathers', async (t) => {
47-
await verifyPkg(t, {
48-
server: 'feathers'
49-
})
50-
})
51-
52-
test('use micro', async (t) => {
53-
await verifyPkg(t, {
54-
server: 'micro'
55-
})
56-
})
57-
58-
test('use fastify', async (t) => {
59-
await verifyPkg(t, {
60-
server: 'fastify'
61-
})
62-
})
63-
64-
test('use axios', async (t) => {
65-
await verifyPkg(t, {
66-
features: ['axios']
67-
})
68-
})
69-
70-
test('use jest', async (t) => {
71-
await verifyPkg(t, {
72-
test: 'jest'
73-
})
74-
})
75-
76-
test('use ava', async (t) => {
77-
await verifyPkg(t, {
78-
test: 'ava'
79-
})
80-
})
81-
82-
test('use eslint', async (t) => {
83-
await verifyPkg(t, {
84-
features: ['linter']
85-
})
86-
})
87-
88-
test('use yarn', async (t) => {
89-
await verifyPkg(t, {
90-
pm: 'yarn'
91-
})
92-
})
93-
94-
test('use prettier', async (t) => {
95-
await verifyPkg(t, {
96-
features: ['prettier']
97-
})
98-
})
25+
const verifyNuxtConfig = async (t, answers = {}) => {
26+
const stream = await sao.mock({ generator }, answers)
27+
const configFile = answers.server === 'adonis' ? 'config/nuxt.js' : 'nuxt.config.js'
28+
const config = await stream.readFile(configFile)
29+
t.snapshot(config, `Generated ${configFile}`)
30+
}
9931

100-
test('use pwa', async (t) => {
101-
await verifyPkg(t, {
102-
features: ['pwa']
103-
})
104-
})
32+
test('verify default answers', async (t) => {
33+
await verifyPkg(t)
34+
await verifyNuxtConfig(t)
35+
})
36+
37+
for (const prompt of saoConfig.prompts) {
38+
if (Array.isArray(prompt.choices)) {
39+
for (const choice of prompt.choices) {
40+
test(`verify ${prompt.name}: ${choice.name}`, async (t) => {
41+
const answer = { [prompt.name]: prompt.type === 'list' ? choice.value : [choice.value] }
42+
await verifyPkg(t, answer)
43+
await verifyNuxtConfig(t, answer)
44+
})
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)