mirror of
https://github.com/tauri-apps/tauri-action.git
synced 2026-01-31 00:35:20 +01:00
* fix: switch from `npx` to `npm run`, closes #367 * fix command options if runner doesnt use npm run * don't append `--` if there are no args * further explain projectPath usage * Update README.md
This commit is contained in:
5
.changes/fix-npx-workspace.md
Normal file
5
.changes/fix-npx-workspace.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'action': patch
|
||||
---
|
||||
|
||||
The action will now use `npm run tauri` instead of `npx tauri` to prevent issues in npm workspaces.
|
||||
18
README.md
18
README.md
@@ -202,12 +202,12 @@ These inputs are _typically_ only used if your GitHub repo does not contain an e
|
||||
|
||||
These inputs allow you to change how your Tauri project will be build.
|
||||
|
||||
| Name | Required | Description | Type | Default |
|
||||
| ---------------- | :------: | ------------------------------------------------------------------------------------------ | ------ | ----------------- |
|
||||
| `includeDebug` | false | whether to include a debug build or not | bool | false |
|
||||
| `includeRelease` | false | whether to include a release build or not | bool | true |
|
||||
| `tauriScript` | false | the script to execute the Tauri CLI. It must not include any args or commands like `build` | string | `yarn\|npx tauri` |
|
||||
| `args` | false | Additional arguments to the current build command | string | |
|
||||
| Name | Required | Description | Type | Default |
|
||||
| ---------------- | :------: | ------------------------------------------------------------------------------------------ | ------ | --------------------------- |
|
||||
| `includeDebug` | false | whether to include a debug build or not | bool | false |
|
||||
| `includeRelease` | false | whether to include a release build or not | bool | true |
|
||||
| `tauriScript` | false | the script to execute the Tauri CLI. It must not include any args or commands like `build` | string | `npm run\|pnpm\|yarn tauri` |
|
||||
| `args` | false | Additional arguments to the current build command | string | |
|
||||
|
||||
### Release Configuration
|
||||
|
||||
@@ -236,8 +236,10 @@ These inputs allow you to modify the GitHub release.
|
||||
|
||||
- You can use this Action on a repo that doesn't have Tauri configured. We automatically initialize Tauri before building, and configure it to use your Web artifacts.
|
||||
- You can configure Tauri with the `configPath`, `distPath` and `iconPath` options.
|
||||
- You can run custom Tauri CLI scripts with the `tauriScript` option. So instead of running `yarn tauri <COMMAND> <ARGS>` or `npx tauri <COMMAND> <ARGS>`, we'll execute `${tauriScript} <COMMAND> <ARGS>`.
|
||||
- You can run custom Tauri CLI scripts with the `tauriScript` option. So instead of running `yarn tauri <COMMAND> <ARGS>` or `npm run tauri <COMMAND> <ARGS>`, we'll execute `${tauriScript} <COMMAND> <ARGS>`.
|
||||
- Useful when you need custom build functionality when creating Tauri apps e.g. a `desktop:build` script.
|
||||
- `tauriScript` can also be an absolute file path pointing to a `tauri-cli` binary. The path currently cannot contain spaces.
|
||||
- If you want to add additional arguments to the build command, you can use the `args` option. For example, if you're setting a specific target for your build, you can specify `args: --target your-target-arch`.
|
||||
- When your app isn't on the root of the repo, use the `projectPath` input.
|
||||
- When your Tauri app is not in the root of the repo, use the `projectPath` input.
|
||||
- Usually it will work without it, but the action will install and use a global `@tauri-apps/cli` installation instead of your project's CLI which can cause issues if you also configured `tauriScript` or if you have multiple `tauri.conf.json` files in your repo.
|
||||
- If you create the release yourself and provide a `releaseId` but do not set `tagName`, the download url for updater bundles in `latest.json` will point to `releases/latest/download/<bundle>` which can cause issues if your repo contains releases that do not include updater bundles.
|
||||
|
||||
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
61
src/build.ts
61
src/build.ts
@@ -3,43 +3,10 @@ import { readFileSync, existsSync, copyFileSync, writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { initProject } from './init-project';
|
||||
import {
|
||||
execCommand,
|
||||
getInfo,
|
||||
getTargetDir,
|
||||
getWorkspaceDir,
|
||||
hasDependency,
|
||||
usesPnpm,
|
||||
usesYarn,
|
||||
} from './utils';
|
||||
import { getRunner } from './runner';
|
||||
import { getInfo, getTargetDir, getWorkspaceDir, hasDependency } from './utils';
|
||||
|
||||
import type { Artifact, BuildOptions, Runner } from './types';
|
||||
|
||||
async function getRunner(
|
||||
root: string,
|
||||
tauriScript: string | null
|
||||
): Promise<Runner> {
|
||||
if (tauriScript) {
|
||||
const [runnerCommand, ...runnerArgs] = tauriScript.split(' ');
|
||||
return { runnerCommand, runnerArgs };
|
||||
}
|
||||
|
||||
if (
|
||||
hasDependency('@tauri-apps/cli', root) ||
|
||||
hasDependency('vue-cli-plugin-tauri', root)
|
||||
) {
|
||||
if (usesYarn(root)) return { runnerCommand: 'yarn', runnerArgs: ['tauri'] };
|
||||
if (usesPnpm(root)) return { runnerCommand: 'pnpm', runnerArgs: ['tauri'] };
|
||||
// FIXME: This can trigger a download of the tauri alpha package. Likely when the tauri frontend is part of a workspace and projectPath is undefined.
|
||||
return { runnerCommand: 'npx', runnerArgs: ['tauri'] };
|
||||
}
|
||||
|
||||
await execCommand('npm', ['install', '-g', '@tauri-apps/cli'], {
|
||||
cwd: undefined,
|
||||
});
|
||||
|
||||
return { runnerCommand: 'tauri', runnerArgs: [] };
|
||||
}
|
||||
import type { Artifact, BuildOptions } from './types';
|
||||
|
||||
export async function buildProject(
|
||||
root: string,
|
||||
@@ -74,29 +41,15 @@ export async function buildProject(
|
||||
const tauriArgs = debug
|
||||
? ['--debug', ...(buildOpts.args ?? [])]
|
||||
: buildOpts.args ?? [];
|
||||
let buildCommand;
|
||||
let buildArgs: string[] = [];
|
||||
|
||||
let buildCommand;
|
||||
if (hasDependency('vue-cli-plugin-tauri', root)) {
|
||||
if (usesYarn(root)) {
|
||||
buildCommand = 'yarn';
|
||||
buildArgs = ['tauri:build'];
|
||||
}
|
||||
if (usesPnpm(root)) {
|
||||
buildCommand = 'pnpm';
|
||||
buildArgs = ['tauri:build'];
|
||||
} else {
|
||||
buildCommand = 'npm';
|
||||
buildArgs = ['run', 'tauri:build'];
|
||||
}
|
||||
buildCommand = 'tauri:build';
|
||||
} else {
|
||||
buildCommand = app.runner.runnerCommand;
|
||||
buildArgs = [...app.runner.runnerArgs, 'build'];
|
||||
buildCommand = 'build';
|
||||
}
|
||||
|
||||
await execCommand(buildCommand, [...buildArgs, ...tauriArgs], {
|
||||
cwd: root,
|
||||
});
|
||||
await runner.execTauriCommand([buildCommand], [...tauriArgs], root);
|
||||
|
||||
let fileAppName = app.name;
|
||||
// on Linux, the app product name is converted to kebab-case
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { execCommand, getConfig, getPackageJson, getTauriDir } from './utils';
|
||||
import { Runner } from './runner';
|
||||
import { getConfig, getPackageJson, getTauriDir } from './utils';
|
||||
|
||||
import type { Application, BuildOptions, Info, Runner } from './types';
|
||||
import type { Application, BuildOptions, Info } from './types';
|
||||
|
||||
export async function initProject(
|
||||
root: string,
|
||||
@@ -14,12 +15,10 @@ export async function initProject(
|
||||
const packageJson = getPackageJson(root);
|
||||
const tauriPath = getTauriDir(root);
|
||||
|
||||
await execCommand(
|
||||
runner.runnerCommand,
|
||||
[...runner.runnerArgs, 'init', '--ci', '--app-name', info.name],
|
||||
{
|
||||
cwd: root,
|
||||
}
|
||||
await runner.execTauriCommand(
|
||||
['init'],
|
||||
['--ci', '--app-name', info.name],
|
||||
root
|
||||
);
|
||||
|
||||
if (tauriPath === null) {
|
||||
@@ -68,13 +67,7 @@ export async function initProject(
|
||||
};
|
||||
|
||||
if (iconPath) {
|
||||
await execCommand(
|
||||
runner.runnerCommand,
|
||||
[...runner.runnerArgs, 'icon', join(root, iconPath)],
|
||||
{
|
||||
cwd: root,
|
||||
}
|
||||
);
|
||||
await runner.execTauriCommand(['icon', join(root, iconPath)], [], root);
|
||||
}
|
||||
|
||||
return app;
|
||||
|
||||
68
src/runner.ts
Normal file
68
src/runner.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { execCommand, hasDependency, usesPnpm, usesYarn } from './utils';
|
||||
|
||||
class Runner {
|
||||
// Could be "npm", "yarn", "pnpm", "cargo", "path/to/tauri-cli/binary" or "tauri"
|
||||
bin: string;
|
||||
// could be ["tauri"], ["run", "tauri"], ["some package.json script"], ["run", "some package.json script"] or []
|
||||
tauriScript: string[];
|
||||
// vue-cli-plugin-tauri uses `tauri:build` instead of `tauri build`
|
||||
vueCli: boolean;
|
||||
|
||||
constructor(bin: string, tauriScript?: string[], vueCli?: boolean) {
|
||||
this.bin = bin;
|
||||
this.tauriScript = tauriScript || [];
|
||||
this.vueCli = !!vueCli;
|
||||
}
|
||||
|
||||
async execTauriCommand(
|
||||
command: string[],
|
||||
commandOptions: string[],
|
||||
cwd?: string
|
||||
): Promise<void> {
|
||||
const args: string[] = [];
|
||||
|
||||
if (this.bin === 'npm' && this.tauriScript[0] !== 'run') {
|
||||
args.push('run');
|
||||
}
|
||||
|
||||
if (!(this.vueCli && command[0] === 'tauri:build')) {
|
||||
args.push(...this.tauriScript);
|
||||
}
|
||||
|
||||
args.push(...command);
|
||||
|
||||
if (this.bin === 'npm' && commandOptions.length) {
|
||||
args.push('--');
|
||||
}
|
||||
|
||||
args.push(...commandOptions);
|
||||
|
||||
return execCommand(this.bin, args, { cwd });
|
||||
}
|
||||
}
|
||||
|
||||
async function getRunner(
|
||||
root: string,
|
||||
tauriScript: string | null
|
||||
): Promise<Runner> {
|
||||
if (tauriScript) {
|
||||
// FIXME: This will also split file paths with spaces.
|
||||
const [runnerCommand, ...runnerArgs] = tauriScript.split(' ');
|
||||
return new Runner(runnerCommand, runnerArgs);
|
||||
}
|
||||
|
||||
const vueCli = hasDependency('vue-cli-plugin-tauri', root);
|
||||
if (hasDependency('@tauri-apps/cli', root) || vueCli) {
|
||||
if (usesYarn(root)) return new Runner('yarn', ['tauri'], vueCli);
|
||||
if (usesPnpm(root)) return new Runner('pnpm', ['tauri'], vueCli);
|
||||
return new Runner('npm', ['run', 'tauri'], vueCli);
|
||||
}
|
||||
|
||||
await execCommand('npm', ['install', '-g', '@tauri-apps/cli'], {
|
||||
cwd: undefined,
|
||||
});
|
||||
|
||||
return new Runner('tauri');
|
||||
}
|
||||
|
||||
export { Runner, getRunner };
|
||||
7
src/types.d.ts
vendored
7
src/types.d.ts
vendored
@@ -1,3 +1,5 @@
|
||||
import { Runner } from './runner';
|
||||
|
||||
export interface Application {
|
||||
tauriPath: string;
|
||||
runner: Runner;
|
||||
@@ -36,11 +38,6 @@ export interface Info {
|
||||
wixLanguage: string | string[] | { [language: string]: unknown };
|
||||
}
|
||||
|
||||
export interface Runner {
|
||||
runnerCommand: string;
|
||||
runnerArgs: string[];
|
||||
}
|
||||
|
||||
export interface TauriConfig {
|
||||
package?: {
|
||||
productName?: string;
|
||||
|
||||
Reference in New Issue
Block a user