diff --git a/.changes/cta-update-vite-package.md b/.changes/cta-update-vite-package.md new file mode 100644 index 000000000..05597ba31 --- /dev/null +++ b/.changes/cta-update-vite-package.md @@ -0,0 +1,5 @@ +--- +"create-tauri-app": patch +--- + +Update vite recipe to use the new vite npm [package](https://github.com/vitejs/vite/tree/main/packages/create-vite). diff --git a/.github/workflows/test-cta.yml b/.github/workflows/test-cta.yml index 78c8198fb..9e723d752 100644 --- a/.github/workflows/test-cta.yml +++ b/.github/workflows/test-cta.yml @@ -26,7 +26,7 @@ jobs: matrix: node: ["14", "16"] manager: ["6", "7"] - recipe: ["vanillajs", "cra", "vite", "ngcli"] + recipe: ["vanillajs", "cra", "vite", "ngcli", "svelte"] exclude: - node: "16" manager: "6" @@ -73,7 +73,7 @@ jobs: fail-fast: false matrix: node: ["14", "16"] - recipe: ["vanillajs", "cra", "vite", "ngcli"] + recipe: ["vanillajs", "cra", "vite", "ngcli", "svelte"] steps: - uses: actions/checkout@v2 diff --git a/tooling/create-tauri-app/src/helpers/add-tauri-script.ts b/tooling/create-tauri-app/src/helpers/update-package-json.ts similarity index 68% rename from tooling/create-tauri-app/src/helpers/add-tauri-script.ts rename to tooling/create-tauri-app/src/helpers/update-package-json.ts index 7089e9289..a76a2a415 100644 --- a/tooling/create-tauri-app/src/helpers/add-tauri-script.ts +++ b/tooling/create-tauri-app/src/helpers/update-package-json.ts @@ -5,20 +5,22 @@ import { readFileSync, writeFileSync } from 'fs' import { join } from 'path' -export function addTauriScript(appDirectory: string): void { +interface Package { + name?: string + scripts?: {} +} + +export function updatePackageJson(appDirectory: string, appName: string): void { const pkgPath = join(appDirectory, 'package.json') const pkgString = readFileSync(pkgPath, 'utf8') - const pkg = JSON.parse(pkgString) as { - scripts: {} - } - - const outputPkg: { scripts: { tauri: string } } = { + const pkg = JSON.parse(pkgString) as Package + const outputPkg = { ...pkg, + name: appName, scripts: { ...pkg.scripts, tauri: 'tauri' } } - writeFileSync(pkgPath, JSON.stringify(outputPkg, undefined, 2)) } diff --git a/tooling/create-tauri-app/src/index.ts b/tooling/create-tauri-app/src/index.ts index 4eef732e1..62cce3672 100644 --- a/tooling/create-tauri-app/src/index.ts +++ b/tooling/create-tauri-app/src/index.ts @@ -15,7 +15,7 @@ import { ngcli } from './recipes/ng-cli' import { svelte } from './recipes/svelte' import { install, checkPackageManager } from './dependency-manager' import { shell } from './shell' -import { addTauriScript } from './helpers/add-tauri-script' +import { updatePackageJson } from './helpers/update-package-json' import { Recipe } from './types/recipe' import { updateTauriConf } from './helpers/update-tauri-conf' @@ -197,7 +197,7 @@ const runInit = async (argv: Argv): Promise => { { type: 'list', name: 'recipeName', - message: 'Would you like to add a UI recipe?', + message: 'What UI recipe would you like to add?', choices: recipeDescriptiveNames, default: defaults.recipeName, when: !argv.ci && !argv.r @@ -341,8 +341,8 @@ const runInit = async (argv: Argv): Promise => { packageManager }) - logStep(`Adding ${reset(yellow('"tauri"'))} script to package.json`) - addTauriScript(appDirectory) + logStep(`Updating ${reset(yellow('"package.json"'))}`) + updatePackageJson(appDirectory, appName) logStep(`Running: ${reset(yellow('tauri init'))}`) const binary = !argv.b ? packageManager : resolve(appDirectory, argv.b) diff --git a/tooling/create-tauri-app/src/recipes/ng-cli.ts b/tooling/create-tauri-app/src/recipes/ng-cli.ts index 5671792bd..d8280a92d 100644 --- a/tooling/create-tauri-app/src/recipes/ng-cli.ts +++ b/tooling/create-tauri-app/src/recipes/ng-cli.ts @@ -29,10 +29,14 @@ const ngcli: Recipe = { shortName: 'ngcli', extraNpmDependencies: [], extraNpmDevDependencies: [], - configUpdate: ({ cfg }) => ({ + configUpdate: ({ cfg, packageManager }) => ({ ...cfg, distDir: `../dist/${cfg.appName}`, - devPath: 'http://localhost:4200' + devPath: 'http://localhost:4200', + beforeDevCommand: `${packageManager === 'yarn' ? 'yarn' : 'npm run'} start`, + beforeBuildCommand: `${ + packageManager === 'yarn' ? 'yarn' : 'npm run' + } build` }), extraQuestions: ({ ci }) => { return [ @@ -96,9 +100,14 @@ const ngcli: Recipe = { } } }, - postInit: async ({ cwd }) => { + postInit: async ({ packageManager, cfg }) => { console.log(` - Your installation completed. Change directory to \`${cwd}\` and happy coding. + Your installation completed. + + $ cd ${cfg.appName} + $ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${ + packageManager === 'npm' ? '--' : '' + } dev `) return await Promise.resolve() diff --git a/tooling/create-tauri-app/src/recipes/react.ts b/tooling/create-tauri-app/src/recipes/react.ts index 9c80da859..164abf8ad 100644 --- a/tooling/create-tauri-app/src/recipes/react.ts +++ b/tooling/create-tauri-app/src/recipes/react.ts @@ -96,10 +96,14 @@ export const cra: Recipe = { } await afterCra(cwd, cfg.appName, template === 'cra.ts') }, - postInit: async ({ packageManager }) => { + postInit: async ({ packageManager, cfg }) => { console.log(` Your installation completed. - To start, run ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri dev + + $ cd ${cfg.appName} + $ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${ + packageManager === 'npm' ? '--' : '' + } dev `) return await Promise.resolve() } diff --git a/tooling/create-tauri-app/src/recipes/svelte.ts b/tooling/create-tauri-app/src/recipes/svelte.ts index 61ab93c6b..089109f52 100644 --- a/tooling/create-tauri-app/src/recipes/svelte.ts +++ b/tooling/create-tauri-app/src/recipes/svelte.ts @@ -14,14 +14,15 @@ const svelte: Recipe = { shortName: 'svelte', extraNpmDevDependencies: [], extraNpmDependencies: [], - extraQuestions: () => { + extraQuestions: ({ ci }) => { return [ { type: 'confirm', name: 'typescript', message: 'Enable Typescript?', default: true, - loop: false + loop: false, + when: !ci } ] }, @@ -53,13 +54,13 @@ const svelte: Recipe = { }, postInit: async ({ cfg, packageManager }) => { console.log(` - Your installation completed. - To start, run the dev script: + Your installation completed. + + $ cd ${cfg.appName}. + $ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${ + packageManager === 'npm' ? '--' : '' + } dev - $ cd ${cfg.appName} - $ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${ - packageManager === 'npm' ? '-- ' : '' - }dev `) return await Promise.resolve() diff --git a/tooling/create-tauri-app/src/recipes/vanilla.ts b/tooling/create-tauri-app/src/recipes/vanilla.ts index 98b6f6489..c564dcdf3 100644 --- a/tooling/create-tauri-app/src/recipes/vanilla.ts +++ b/tooling/create-tauri-app/src/recipes/vanilla.ts @@ -40,26 +40,15 @@ export const vanillajs: Recipe = { } }, postInit: async ({ cfg, packageManager }) => { - const setApp = - packageManager === 'npm' - ? ` -set tauri script once - $ npm set-script tauri tauri - ` - : '' - console.log(` -change directory: - $ cd ${cfg.appName} -${setApp} -install dependencies: - $ ${packageManager} install + Your installation completed. -run the app: + $ cd ${cfg.appName} + $ ${packageManager} install $ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${ packageManager === 'npm' ? '-- ' : '' }dev - `) + `) return await Promise.resolve() } } diff --git a/tooling/create-tauri-app/src/recipes/vite.ts b/tooling/create-tauri-app/src/recipes/vite.ts index 13f26307d..0e8ff5d08 100644 --- a/tooling/create-tauri-app/src/recipes/vite.ts +++ b/tooling/create-tauri-app/src/recipes/vite.ts @@ -26,8 +26,8 @@ const afterViteCA = async ( const vite: Recipe = { descriptiveName: { - name: '@vitejs/create-app (https://vitejs.dev/guide/#scaffolding-your-first-vite-project)', - value: 'vite-create-app' + name: 'create-vite (https://vitejs.dev/guide/#scaffolding-your-first-vite-project)', + value: 'create-vite' }, shortName: 'vite', configUpdate: ({ cfg, packageManager }) => ({ @@ -77,13 +77,7 @@ const vite: Recipe = { if (packageManager === 'yarn') { await shell( 'yarn', - [ - 'create', - '@vitejs/app', - `${cfg.appName}`, - '--template', - `${template}` - ], + ['create', 'vite', `${cfg.appName}`, '--template', `${template}`], { cwd } @@ -91,12 +85,7 @@ const vite: Recipe = { } else { await shell( 'npx', - [ - '@vitejs/create-app@latest', - `${cfg.appName}`, - '--template', - `${template}` - ], + ['create-vite@latest', `${cfg.appName}`, '--template', `${template}`], { cwd } @@ -105,7 +94,7 @@ const vite: Recipe = { await afterViteCA(cwd, cfg.appName, template) }, - postInit: async ({ cwd, packageManager }) => { + postInit: async ({ cwd, packageManager, cfg }) => { // we don't have a consistent way to rebuild and // esbuild has hit all the bugs and struggles to install on the postinstall await shell('node', ['./node_modules/esbuild/install.js'], { cwd }) @@ -115,8 +104,10 @@ const vite: Recipe = { await shell('npm', ['run', 'build'], { cwd }) } console.log(` - Your installation completed. Change directories to \`${cwd}\`. - To start, run ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${ + Your installation completed. + + $ cd ${cfg.appName}. + $ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${ packageManager === 'npm' ? '--' : '' } dev `) diff --git a/tooling/create-tauri-app/src/recipes/vue-cli.ts b/tooling/create-tauri-app/src/recipes/vue-cli.ts index a91cc9d2d..746ca2554 100644 --- a/tooling/create-tauri-app/src/recipes/vue-cli.ts +++ b/tooling/create-tauri-app/src/recipes/vue-cli.ts @@ -6,11 +6,6 @@ import { join } from 'path' import { shell } from '../shell' import { Recipe } from '../types/recipe' -const completeLogMsg = ` - Your installation completed. - To start, run yarn tauri:serve -` - const vuecli: Recipe = { descriptiveName: { name: 'Vue CLI (https://cli.vuejs.org/)', @@ -50,8 +45,13 @@ const vuecli: Recipe = { } ) }, - postInit: async () => { - console.log(completeLogMsg) + postInit: async ({ cfg, packageManager }) => { + console.log(` + Your installation completed. + + $ cd ${cfg.appName} + $ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri:serve + `) return await Promise.resolve() } } diff --git a/tooling/create-tauri-app/test/index.spec.ts b/tooling/create-tauri-app/test/index.spec.ts index 0112729a9..e05b4c55e 100644 --- a/tooling/create-tauri-app/test/index.spec.ts +++ b/tooling/create-tauri-app/test/index.spec.ts @@ -15,7 +15,7 @@ const api = path.resolve('../api/') const manager = process.env.TAURI_RUN_MANAGER ?? 'npm' const recipes = process.env.TAURI_RECIPE ? [process.env.TAURI_RECIPE] - : ['vanillajs', 'cra', 'vite', 'vuecli'] + : ['vanillajs', 'cra', 'vite', 'vuecli', 'ngcli', 'svelte'] const timeoutLong = 900000 const timeoutLittleLonger = 930000 const logOut = false ? 'inherit' : 'pipe' @@ -142,6 +142,13 @@ describe('CTA', () => { tauri: 'tauri' }) ) + }, + svelte: () => { + expect(packageFileOutput['scripts']).toEqual( + expect.objectContaining({ + tauri: 'tauri' + }) + ) } }