Skip to content

Commit 397b7af

Browse files
jboldaamrbashir
andauthored
chore: CTA defaults in CI mode (#1671)
* better defaults in CI mode * chalk should be a dep since it needs to be installed by user * always install webkit2gtk * avoid installing `cli.js` from npm in `--dev` mode * use correct path for `api` linking in tests * update `tauri.conf.json` after init * remove `beforeBuild/DevCommand` from vanilla recipe * explicitly install `vite` deps * change file Co-authored-by: amrbashir <48618675+amrbashir@users.noreply.github.com>
1 parent e393059 commit 397b7af

9 files changed

Lines changed: 66 additions & 20 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+
Explicitly install deps after a vite recipe.

.github/workflows/test-cta.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ jobs:
4444
node-version: ${{ matrix.node }}
4545
npm-version: ${{ matrix.manager }}
4646
yarn-version: 1.22.5
47-
- name: install webkit2gtk (ubuntu only)
48-
if: matrix.platform == 'ubuntu-latest'
47+
- name: install webkit2gtk
4948
run: |
5049
sudo apt-get update
5150
sudo apt-get install -y webkit2gtk-4.0
@@ -81,8 +80,7 @@ jobs:
8180
with:
8281
node-version: ${{ matrix.node }}
8382
yarn-version: 1.22.5
84-
- name: install webkit2gtk (ubuntu only)
85-
if: matrix.platform == 'ubuntu-latest'
83+
- name: install webkit2gtk
8684
run: |
8785
sudo apt-get update
8886
sudo apt-get install -y webkit2gtk-4.0

tooling/create-tauri-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"test": "jest --runInBand"
3434
},
3535
"dependencies": {
36+
"chalk": "4.1.1",
3637
"execa": "^5.0.0",
3738
"inquirer": "^8.0.0",
3839
"minimist": "^1.2.5",
@@ -49,7 +50,6 @@
4950
"@types/semver": "7.3.5",
5051
"@typescript-eslint/eslint-plugin": "4.22.0",
5152
"@typescript-eslint/parser": "4.22.0",
52-
"chalk": "4.1.1",
5353
"eslint": "7.25.0",
5454
"eslint-config-prettier": "8.3.0",
5555
"eslint-config-standard-with-typescript": "20.0.0",

tooling/create-tauri-app/src/helpers/add-tauri-script.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ export function addTauriScript(appDirectory: string): void {
99
const pkgPath = join(appDirectory, 'package.json')
1010
const pkgString = readFileSync(pkgPath, 'utf8')
1111
const pkg = JSON.parse(pkgString) as {
12-
scripts: {
13-
tauri: string
14-
}
12+
scripts: {}
1513
}
1614

17-
const outputPkg = {
15+
const outputPkg: { scripts: { tauri: string } } = {
1816
...pkg,
1917
scripts: {
2018
...pkg.scripts,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
import { readFileSync, writeFileSync } from 'fs'
6+
import { join } from 'path'
7+
import { TauriBuildConfig } from '../types/config'
8+
9+
export function updateTauriConf(
10+
appDirectory: string,
11+
cfg: TauriBuildConfig
12+
): void {
13+
const tauriConfPath = join(appDirectory, 'src-tauri', 'tauri.conf.json')
14+
const tauriConfString = readFileSync(tauriConfPath, 'utf8')
15+
const tauriConf = JSON.parse(tauriConfString) as {
16+
build: TauriBuildConfig
17+
}
18+
19+
const outputPkg: { build: TauriBuildConfig } = {
20+
...tauriConf,
21+
build: {
22+
...tauriConf.build,
23+
beforeBuildCommand: cfg.beforeBuildCommand,
24+
beforeDevCommand: cfg.beforeDevCommand
25+
}
26+
}
27+
28+
writeFileSync(tauriConfPath, JSON.stringify(outputPkg, undefined, 2))
29+
}

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { install, checkPackageManager } from './dependency-manager'
1414
import { shell } from './shell'
1515
import { addTauriScript } from './helpers/add-tauri-script'
1616
import { Recipe } from './types/recipe'
17+
import { updateTauriConf } from './helpers/update-tauri-conf'
1718

1819
interface Argv {
1920
h: boolean
@@ -183,7 +184,16 @@ const runInit = async (argv: Argv): Promise<void> => {
183184
recipe = recipeByDescriptiveName(recipeName)
184185
}
185186

186-
if (!recipe) throw new Error('Could not find the recipe specified.')
187+
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+
}
196+
}
187197

188198
const packageManager =
189199
argv.m === 'yarn' || argv.m === 'npm'
@@ -279,10 +289,10 @@ const runInit = async (argv: Argv): Promise<void> => {
279289
if (recipe.shortName !== 'vuecli') {
280290
logStep('Installing any additional needed dependencies')
281291
if (argv.dev) {
282-
await shell('yarn', ['link', '@tauri-apps/cli'], {
292+
await shell(packageManager, ['link', '@tauri-apps/cli'], {
283293
cwd: appDirectory
284294
})
285-
await shell('yarn', ['link', '@tauri-apps/api'], {
295+
await shell(packageManager, ['link', '@tauri-apps/api'], {
286296
cwd: appDirectory
287297
})
288298
}
@@ -292,13 +302,16 @@ const runInit = async (argv: Argv): Promise<void> => {
292302
dependencies: recipe.extraNpmDependencies,
293303
devDependencies: argv.dev
294304
? [...recipe.extraNpmDevDependencies]
295-
: ['@tauri-apps/cli'].concat(recipe.extraNpmDevDependencies),
305+
: [argv.dev ? '@tauri-apps/cli' : ''].concat(
306+
recipe.extraNpmDevDependencies
307+
),
296308
packageManager
297309
})
298310

299-
logStep(`Running: ${reset(yellow('tauri init'))}`)
311+
logStep('Adding `tauri` script to package.json')
300312
addTauriScript(appDirectory)
301313

314+
logStep(`Running: ${reset(yellow('tauri init'))}`)
302315
const binary = !argv.b ? packageManager : resolve(appDirectory, argv.b)
303316
const runTauriArgs =
304317
packageManager === 'npm' && !argv.b
@@ -307,6 +320,9 @@ const runInit = async (argv: Argv): Promise<void> => {
307320
await shell(binary, [...runTauriArgs, ...initArgs, '--ci'], {
308321
cwd: appDirectory
309322
})
323+
324+
logStep('Updating `tauri.conf.json`')
325+
updateTauriConf(appDirectory, cfg)
310326
}
311327

312328
if (recipe.postInit) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ import { Recipe } from '../types/recipe'
1010
export const vanillajs: Recipe = {
1111
descriptiveName: 'Vanilla.js',
1212
shortName: 'vanillajs',
13-
configUpdate: ({ cfg, packageManager }) => ({
13+
configUpdate: ({ cfg }) => ({
1414
...cfg,
1515
distDir: `../dist`,
1616
devPath: `../dist`,
17-
beforeDevCommand: `${packageManager === 'yarn' ? 'yarn' : 'npm run'} start`,
18-
beforeBuildCommand: `${
19-
packageManager === 'yarn' ? 'yarn' : 'npm run'
20-
} build`
17+
beforeDevCommand: '',
18+
beforeBuildCommand: ''
2119
}),
2220
extraNpmDevDependencies: [],
2321
extraNpmDependencies: [],

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const vite: Recipe = {
7373
cwd
7474
}
7575
)
76+
await shell('yarn', ['install'], { cwd })
7677
} else {
7778
await shell(
7879
'npx',
@@ -81,6 +82,7 @@ const vite: Recipe = {
8182
cwd
8283
}
8384
)
85+
await shell('npm', ['install'], { cwd })
8486
}
8587

8688
await afterViteCA(cwd, cfg.appName, template)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ beforeAll(async () => {
5353

5454
const linkAPI = await execa('yarn', ['link'], {
5555
stdio: logOut,
56-
cwd: api,
56+
cwd: path.join(api, 'dist'),
5757
timeout: timeoutLong
5858
})
5959
}, timeoutLittleLonger)

0 commit comments

Comments
 (0)