Skip to content

Commit ea28d01

Browse files
authored
create-tauri-app welcome prompt and recipes links (#1748)
* CTA welcome prompt and recipes links * fix tests for new recipe names * check that package file exists before build * change file * turn off vuecli tests until we can get them to pass
1 parent b2a7bfd commit ea28d01

10 files changed

Lines changed: 118 additions & 63 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-tauri-app": patch
3+
---
4+
5+
Add a welcome prompt to let the user know about the process and links to more info including prerequisite setup steps. Also add links to each of the templates to give the user more context what they are getting into.

.github/workflows/test-cta.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
matrix:
2727
node: ["14", "16"]
2828
manager: ["6", "7"]
29-
recipe: ["vanillajs", "reactjs", "reactts", "vite", "vuecli"]
29+
recipe: ["vanillajs", "cra", "vite"]
3030
exclude:
3131
- node: "16"
3232
manager: "6"
@@ -66,7 +66,7 @@ jobs:
6666
fail-fast: false
6767
matrix:
6868
node: ["14", "16"]
69-
recipe: ["vanillajs", "reactjs", "reactts", "vite", "vuecli"]
69+
recipe: ["vanillajs", "cra", "vite"]
7070

7171
steps:
7272
- uses: actions/checkout@v2

tooling/create-tauri-app/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
external: [
1717
'fs',
1818
'path',
19+
'os',
1920
...Object.keys(pkg.dependencies || {}),
2021
...Object.keys(pkg.peerDependencies || {})
2122
],

tooling/create-tauri-app/src/index.ts

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import minimist from 'minimist'
66
import inquirer from 'inquirer'
77
import { bold, cyan, green, reset, yellow } from 'chalk'
8+
import { platform } from 'os'
89
import { resolve, join } from 'path'
9-
import { reactjs, reactts } from './recipes/react'
10+
import { cra } from './recipes/react'
1011
import { vuecli } from './recipes/vue-cli'
1112
import { vanillajs } from './recipes/vanilla'
1213
import { vite } from './recipes/vite'
@@ -112,19 +113,62 @@ interface Responses {
112113
recipeName: string
113114
}
114115

115-
const allRecipes: Recipe[] = [vanillajs, reactjs, reactts, vite, vuecli]
116+
const allRecipes: Recipe[] = [vanillajs, cra, vite, vuecli]
116117

117118
const recipeByShortName = (name: string): Recipe | undefined =>
118119
allRecipes.find((r) => r.shortName === name)
119120

120121
const recipeByDescriptiveName = (name: string): Recipe | undefined =>
121-
allRecipes.find((r) => r.descriptiveName === name)
122+
allRecipes.find((r) => r.descriptiveName.value === name)
122123

123124
const recipeShortNames = allRecipes.map((r) => r.shortName)
124125

125126
const recipeDescriptiveNames = allRecipes.map((r) => r.descriptiveName)
126127

128+
const keypress = async (skip: boolean): Promise<void> => {
129+
if (skip) return
130+
process.stdin.setRawMode(true)
131+
return await new Promise((resolve, reject) => {
132+
console.log('Press any key to continue...')
133+
process.stdin.once('data', (data) => {
134+
const byteArray = [...data]
135+
if (byteArray.length > 0 && byteArray[0] === 3) {
136+
console.log('^C')
137+
process.exit(1)
138+
}
139+
process.stdin.setRawMode(false)
140+
resolve()
141+
})
142+
})
143+
}
144+
127145
const runInit = async (argv: Argv): Promise<void> => {
146+
console.log(
147+
`We hope to help you create something special with ${bold(
148+
yellow('Tauri')
149+
)}!`
150+
)
151+
console.log(
152+
'You will have a choice of one of the UI frameworks supported by the greater web tech community.'
153+
)
154+
console.log(
155+
`This should get you started. See our docs at https://tauri.studio/`
156+
)
157+
158+
const setupLink =
159+
platform() === 'win32'
160+
? 'https://tauri.studio/en/docs/getting-started/setup-windows/'
161+
: platform() === 'darwin'
162+
? 'https://tauri.studio/en/docs/getting-started/setup-macos/'
163+
: 'https://tauri.studio/en/docs/getting-started/setup-linux/'
164+
165+
console.log(
166+
`If you haven't already, please take a moment to setup your system.`
167+
)
168+
console.log(`You may find the requirements here: ${setupLink}`)
169+
170+
await keypress(argv.ci)
171+
128172
const defaults = {
129173
appName: 'tauri-app',
130174
tauri: { window: { title: 'Tauri App' } },
@@ -184,15 +228,9 @@ const runInit = async (argv: Argv): Promise<void> => {
184228
recipe = recipeByDescriptiveName(recipeName)
185229
}
186230

231+
// throw if recipe is not set
187232
if (!recipe) {
188-
if (argv.ci) {
189-
recipe = recipeByShortName('vanillajs')
190-
}
191-
// throw if recipe is not set
192-
// if it fails to set in CI, throw as well
193-
if (!recipe) {
194-
throw new Error('Could not find the recipe specified.')
195-
}
233+
throw new Error('Could not find the recipe specified.')
196234
}
197235

198236
const packageManager =

tooling/create-tauri-app/src/recipes/react.ts

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ const afterCra = async (
2828
}
2929
}
3030

31-
const reactjs: Recipe = {
32-
descriptiveName: 'React.js',
33-
shortName: 'reactjs',
31+
export const cra: Recipe = {
32+
descriptiveName: {
33+
name: 'create-react-app (https://create-react-app.dev/)',
34+
value: 'create-react-app'
35+
},
36+
shortName: 'cra',
3437
configUpdate: ({ cfg, packageManager }) => ({
3538
...cfg,
3639
distDir: `../build`,
@@ -42,39 +45,37 @@ const reactjs: Recipe = {
4245
}),
4346
extraNpmDevDependencies: [],
4447
extraNpmDependencies: [],
45-
preInit: async ({ cwd, cfg, packageManager }) => {
46-
// CRA creates the folder for you
47-
if (packageManager === 'yarn') {
48-
await shell('yarn', ['create', 'react-app', `${cfg.appName}`], {
49-
cwd
50-
})
51-
} else {
52-
await shell('npx', ['create-react-app', `${cfg.appName}`, '--use-npm'], {
53-
cwd
54-
})
55-
}
56-
await afterCra(cwd, cfg.appName)
48+
extraQuestions: ({ ci }) => {
49+
return [
50+
{
51+
type: 'list',
52+
name: 'template',
53+
message: 'Which vite template would you like to use?',
54+
choices: [
55+
{ name: 'create-react-app (JavaScript)', value: 'cra.js' },
56+
{ name: 'create-react-app (Typescript)', value: 'cra.ts' }
57+
],
58+
default: 'cra.js',
59+
loop: false,
60+
when: !ci
61+
}
62+
]
5763
},
58-
postInit: async ({ packageManager }) => {
59-
console.log(`
60-
Your installation completed.
61-
To start, run ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri dev
62-
`)
63-
return await Promise.resolve()
64-
}
65-
}
66-
67-
const reactts: Recipe = {
68-
...reactjs,
69-
descriptiveName: 'React with Typescript',
70-
shortName: 'reactts',
71-
extraNpmDependencies: [],
72-
preInit: async ({ cwd, cfg, packageManager }) => {
64+
preInit: async ({ cwd, cfg, packageManager, answers }) => {
65+
let template = 'cra.js'
66+
if (answers) {
67+
template = answers.template ? (answers.template as string) : 'vue'
68+
}
7369
// CRA creates the folder for you
7470
if (packageManager === 'yarn') {
7571
await shell(
7672
'yarn',
77-
['create', 'react-app', '--template', 'typescript', `${cfg.appName}`],
73+
[
74+
'create',
75+
'react-app',
76+
...(template === 'cra.ts' ? ['--template', 'typescript'] : []),
77+
`${cfg.appName}`
78+
],
7879
{
7980
cwd
8081
}
@@ -84,17 +85,16 @@ const reactts: Recipe = {
8485
'npx',
8586
[
8687
'create-react-app',
88+
...(template === 'cra.ts' ? ['--template', 'typescript'] : []),
8789
`${cfg.appName}`,
88-
'--use-npm',
89-
'--template',
90-
'typescript'
90+
'--use-npm'
9191
],
9292
{
9393
cwd
9494
}
9595
)
9696
}
97-
await afterCra(cwd, cfg.appName, true)
97+
await afterCra(cwd, cfg.appName, template === 'cra.ts')
9898
},
9999
postInit: async ({ packageManager }) => {
100100
console.log(`
@@ -104,5 +104,3 @@ const reactts: Recipe = {
104104
return await Promise.resolve()
105105
}
106106
}
107-
108-
export { reactjs, reactts }

tooling/create-tauri-app/src/recipes/vanilla.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import scaffe from 'scaffe'
88
import { Recipe } from '../types/recipe'
99

1010
export const vanillajs: Recipe = {
11-
descriptiveName: 'Vanilla.js',
11+
descriptiveName: {
12+
name: 'Vanilla.js (html, css, and js without the bundlers)',
13+
value: 'Vanilla.js'
14+
},
1215
shortName: 'vanillajs',
1316
configUpdate: ({ cfg }) => ({
1417
...cfg,

tooling/create-tauri-app/src/recipes/vite.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ const afterViteCA = async (
2525
}
2626

2727
const vite: Recipe = {
28-
descriptiveName: 'Vite backed recipe',
28+
descriptiveName: {
29+
name:
30+
'@vitejs/create-app (https://vitejs.dev/guide/#scaffolding-your-first-vite-project)',
31+
value: 'vite-create-app'
32+
},
2933
shortName: 'vite',
3034
configUpdate: ({ cfg, packageManager }) => ({
3135
...cfg,

tooling/create-tauri-app/src/recipes/vue-cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const completeLogMsg = `
1212
`
1313

1414
const vuecli: Recipe = {
15-
descriptiveName: 'Vue CLI',
15+
descriptiveName: {
16+
name: 'Vue CLI (https://cli.vuejs.org/)',
17+
value: 'vue-cli'
18+
},
1619
shortName: 'vuecli',
1720
extraNpmDevDependencies: [],
1821
extraNpmDependencies: [],

tooling/create-tauri-app/src/types/recipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface RecipeArgs {
1212
}
1313

1414
export interface Recipe {
15-
descriptiveName: string
15+
descriptiveName: { name: string; value: string }
1616
shortName: string
1717
configUpdate?: (args: RecipeArgs) => TauriBuildConfig
1818
extraNpmDependencies: string[]

tooling/create-tauri-app/test/index.spec.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const api = path.resolve('../api/')
1515
const manager = process.env.TAURI_RUN_MANAGER ?? 'npm'
1616
const recipes = process.env.TAURI_RECIPE
1717
? [process.env.TAURI_RECIPE]
18-
: ['vanillajs', 'reactjs', 'reactts', 'vite', 'vuecli']
18+
: ['vanillajs', 'cra', 'vite', 'vuecli']
1919
const timeoutLong = 900000
2020
const timeoutLittleLonger = 930000
2121
const logOut = false ? 'inherit' : 'pipe'
@@ -96,6 +96,16 @@ describe('CTA', () => {
9696
expect(cta.killed).toBe(false)
9797
expect(cta.signal).toBe(undefined)
9898

99+
const packageFileInitial: {
100+
[k: string]: string | object
101+
} = JSON.parse(
102+
await fs.promises.readFile(
103+
path.join(appFolder, 'package.json'),
104+
'utf-8'
105+
)
106+
)
107+
expect(packageFileInitial['name']).toBe(appName)
108+
99109
// run a tauri build to check if what we produced
100110
// can actually create an app
101111
// TODO long term we will want to hook this up to a real test harness
@@ -138,14 +148,7 @@ describe('CTA', () => {
138148
tauri: 'tauri'
139149
})
140150
},
141-
reactjs: () => {
142-
expect(packageFileOutput['scripts']).toEqual(
143-
expect.objectContaining({
144-
tauri: 'tauri'
145-
})
146-
)
147-
},
148-
reactts: () => {
151+
cra: () => {
149152
expect(packageFileOutput['scripts']).toEqual(
150153
expect.objectContaining({
151154
tauri: 'tauri'

0 commit comments

Comments
 (0)