Skip to content

Commit 718d951

Browse files
authored
refactor(cta): update vite recipe to use their new npm package (#2220)
1 parent aa498e7 commit 718d951

11 files changed

Lines changed: 75 additions & 67 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+
Update vite recipe to use the new vite npm [package](https://github.com/vitejs/vite/tree/main/packages/create-vite).

.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", "cra", "vite", "ngcli"]
29+
recipe: ["vanillajs", "cra", "vite", "ngcli", "svelte"]
3030
exclude:
3131
- node: "16"
3232
manager: "6"
@@ -73,7 +73,7 @@ jobs:
7373
fail-fast: false
7474
matrix:
7575
node: ["14", "16"]
76-
recipe: ["vanillajs", "cra", "vite", "ngcli"]
76+
recipe: ["vanillajs", "cra", "vite", "ngcli", "svelte"]
7777

7878
steps:
7979
- uses: actions/checkout@v2

tooling/create-tauri-app/src/helpers/add-tauri-script.ts renamed to tooling/create-tauri-app/src/helpers/update-package-json.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
import { readFileSync, writeFileSync } from 'fs'
66
import { join } from 'path'
77

8-
export function addTauriScript(appDirectory: string): void {
8+
interface Package {
9+
name?: string
10+
scripts?: {}
11+
}
12+
13+
export function updatePackageJson(appDirectory: string, appName: string): void {
914
const pkgPath = join(appDirectory, 'package.json')
1015
const pkgString = readFileSync(pkgPath, 'utf8')
11-
const pkg = JSON.parse(pkgString) as {
12-
scripts: {}
13-
}
14-
15-
const outputPkg: { scripts: { tauri: string } } = {
16+
const pkg = JSON.parse(pkgString) as Package
17+
const outputPkg = {
1618
...pkg,
19+
name: appName,
1720
scripts: {
1821
...pkg.scripts,
1922
tauri: 'tauri'
2023
}
2124
}
22-
2325
writeFileSync(pkgPath, JSON.stringify(outputPkg, undefined, 2))
2426
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ngcli } from './recipes/ng-cli'
1515
import { svelte } from './recipes/svelte'
1616
import { install, checkPackageManager } from './dependency-manager'
1717
import { shell } from './shell'
18-
import { addTauriScript } from './helpers/add-tauri-script'
18+
import { updatePackageJson } from './helpers/update-package-json'
1919
import { Recipe } from './types/recipe'
2020
import { updateTauriConf } from './helpers/update-tauri-conf'
2121

@@ -197,7 +197,7 @@ const runInit = async (argv: Argv): Promise<void> => {
197197
{
198198
type: 'list',
199199
name: 'recipeName',
200-
message: 'Would you like to add a UI recipe?',
200+
message: 'What UI recipe would you like to add?',
201201
choices: recipeDescriptiveNames,
202202
default: defaults.recipeName,
203203
when: !argv.ci && !argv.r
@@ -341,8 +341,8 @@ const runInit = async (argv: Argv): Promise<void> => {
341341
packageManager
342342
})
343343

344-
logStep(`Adding ${reset(yellow('"tauri"'))} script to package.json`)
345-
addTauriScript(appDirectory)
344+
logStep(`Updating ${reset(yellow('"package.json"'))}`)
345+
updatePackageJson(appDirectory, appName)
346346

347347
logStep(`Running: ${reset(yellow('tauri init'))}`)
348348
const binary = !argv.b ? packageManager : resolve(appDirectory, argv.b)

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ const ngcli: Recipe = {
2929
shortName: 'ngcli',
3030
extraNpmDependencies: [],
3131
extraNpmDevDependencies: [],
32-
configUpdate: ({ cfg }) => ({
32+
configUpdate: ({ cfg, packageManager }) => ({
3333
...cfg,
3434
distDir: `../dist/${cfg.appName}`,
35-
devPath: 'http://localhost:4200'
35+
devPath: 'http://localhost:4200',
36+
beforeDevCommand: `${packageManager === 'yarn' ? 'yarn' : 'npm run'} start`,
37+
beforeBuildCommand: `${
38+
packageManager === 'yarn' ? 'yarn' : 'npm run'
39+
} build`
3640
}),
3741
extraQuestions: ({ ci }) => {
3842
return [
@@ -96,9 +100,14 @@ const ngcli: Recipe = {
96100
}
97101
}
98102
},
99-
postInit: async ({ cwd }) => {
103+
postInit: async ({ packageManager, cfg }) => {
100104
console.log(`
101-
Your installation completed. Change directory to \`${cwd}\` and happy coding.
105+
Your installation completed.
106+
107+
$ cd ${cfg.appName}
108+
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
109+
packageManager === 'npm' ? '--' : ''
110+
} dev
102111
`)
103112

104113
return await Promise.resolve()

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ export const cra: Recipe = {
9696
}
9797
await afterCra(cwd, cfg.appName, template === 'cra.ts')
9898
},
99-
postInit: async ({ packageManager }) => {
99+
postInit: async ({ packageManager, cfg }) => {
100100
console.log(`
101101
Your installation completed.
102-
To start, run ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri dev
102+
103+
$ cd ${cfg.appName}
104+
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
105+
packageManager === 'npm' ? '--' : ''
106+
} dev
103107
`)
104108
return await Promise.resolve()
105109
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ const svelte: Recipe = {
1414
shortName: 'svelte',
1515
extraNpmDevDependencies: [],
1616
extraNpmDependencies: [],
17-
extraQuestions: () => {
17+
extraQuestions: ({ ci }) => {
1818
return [
1919
{
2020
type: 'confirm',
2121
name: 'typescript',
2222
message: 'Enable Typescript?',
2323
default: true,
24-
loop: false
24+
loop: false,
25+
when: !ci
2526
}
2627
]
2728
},
@@ -53,13 +54,13 @@ const svelte: Recipe = {
5354
},
5455
postInit: async ({ cfg, packageManager }) => {
5556
console.log(`
56-
Your installation completed.
57-
To start, run the dev script:
57+
Your installation completed.
58+
59+
$ cd ${cfg.appName}.
60+
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
61+
packageManager === 'npm' ? '--' : ''
62+
} dev
5863
59-
$ cd ${cfg.appName}
60-
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
61-
packageManager === 'npm' ? '-- ' : ''
62-
}dev
6364
`)
6465

6566
return await Promise.resolve()

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,15 @@ export const vanillajs: Recipe = {
4040
}
4141
},
4242
postInit: async ({ cfg, packageManager }) => {
43-
const setApp =
44-
packageManager === 'npm'
45-
? `
46-
set tauri script once
47-
$ npm set-script tauri tauri
48-
`
49-
: ''
50-
5143
console.log(`
52-
change directory:
44+
Your installation completed.
45+
5346
$ cd ${cfg.appName}
54-
${setApp}
55-
install dependencies:
5647
$ ${packageManager} install
57-
58-
run the app:
5948
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
6049
packageManager === 'npm' ? '-- ' : ''
6150
}dev
62-
`)
51+
`)
6352
return await Promise.resolve()
6453
}
6554
}

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const afterViteCA = async (
2626

2727
const vite: Recipe = {
2828
descriptiveName: {
29-
name: '@vitejs/create-app (https://vitejs.dev/guide/#scaffolding-your-first-vite-project)',
30-
value: 'vite-create-app'
29+
name: 'create-vite (https://vitejs.dev/guide/#scaffolding-your-first-vite-project)',
30+
value: 'create-vite'
3131
},
3232
shortName: 'vite',
3333
configUpdate: ({ cfg, packageManager }) => ({
@@ -77,26 +77,15 @@ const vite: Recipe = {
7777
if (packageManager === 'yarn') {
7878
await shell(
7979
'yarn',
80-
[
81-
'create',
82-
'@vitejs/app',
83-
`${cfg.appName}`,
84-
'--template',
85-
`${template}`
86-
],
80+
['create', 'vite', `${cfg.appName}`, '--template', `${template}`],
8781
{
8882
cwd
8983
}
9084
)
9185
} else {
9286
await shell(
9387
'npx',
94-
[
95-
'@vitejs/create-app@latest',
96-
`${cfg.appName}`,
97-
'--template',
98-
`${template}`
99-
],
88+
['create-vite@latest', `${cfg.appName}`, '--template', `${template}`],
10089
{
10190
cwd
10291
}
@@ -105,7 +94,7 @@ const vite: Recipe = {
10594

10695
await afterViteCA(cwd, cfg.appName, template)
10796
},
108-
postInit: async ({ cwd, packageManager }) => {
97+
postInit: async ({ cwd, packageManager, cfg }) => {
10998
// we don't have a consistent way to rebuild and
11099
// esbuild has hit all the bugs and struggles to install on the postinstall
111100
await shell('node', ['./node_modules/esbuild/install.js'], { cwd })
@@ -115,8 +104,10 @@ const vite: Recipe = {
115104
await shell('npm', ['run', 'build'], { cwd })
116105
}
117106
console.log(`
118-
Your installation completed. Change directories to \`${cwd}\`.
119-
To start, run ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
107+
Your installation completed.
108+
109+
$ cd ${cfg.appName}.
110+
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
120111
packageManager === 'npm' ? '--' : ''
121112
} dev
122113
`)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import { join } from 'path'
66
import { shell } from '../shell'
77
import { Recipe } from '../types/recipe'
88

9-
const completeLogMsg = `
10-
Your installation completed.
11-
To start, run yarn tauri:serve
12-
`
13-
149
const vuecli: Recipe = {
1510
descriptiveName: {
1611
name: 'Vue CLI (https://cli.vuejs.org/)',
@@ -50,8 +45,13 @@ const vuecli: Recipe = {
5045
}
5146
)
5247
},
53-
postInit: async () => {
54-
console.log(completeLogMsg)
48+
postInit: async ({ cfg, packageManager }) => {
49+
console.log(`
50+
Your installation completed.
51+
52+
$ cd ${cfg.appName}
53+
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri:serve
54+
`)
5555
return await Promise.resolve()
5656
}
5757
}

0 commit comments

Comments
 (0)