Skip to content

Commit

Permalink
feat(action) add option to run custom package.json script (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Jul 12, 2020
1 parent af79aee commit f91ad8d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/custom-script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"action": patch
---

Adds an option to run a custom package.json script with the `npmScript` input.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
| `releaseCommitish` | false | Any branch or commit SHA the Git tag is created from, unused if the Git tag already exists | string | SHA of current commit |
| `iconPath` | false | path to the PNG icon to use as app icon, relative to the projectPath | string | |
| `includeDebug` | false | whether to include a debug build or not | bool | |
| `npmScript` | false | the package.json script to run to build the Tauri app | string | |

## Outputs

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ inputs:
description: 'path to the PNG icon to use as app icon, relative to the projectPath'
includeDebug:
description: 'whether to include a debug build or not'
npmScript:
description: 'the package.json script to run to build the Tauri app'
outputs:
releaseId:
description: 'The ID of the created release'
Expand Down
13 changes: 9 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ interface BuildOptions {
configPath: string | null
distPath: string | null
iconPath: string | null
npmScript: string | null
}

async function buildProject(root: string, debug: boolean, { configPath, distPath, iconPath }: BuildOptions): Promise<string[]> {
async function buildProject(root: string, debug: boolean, { configPath, distPath, iconPath, npmScript }: BuildOptions): Promise<string[]> {
return new Promise<string>((resolve) => {
if (hasTauriDependency(root)) {
const runner = usesYarn(root) ? 'yarn tauri' : 'npx tauri'
resolve(runner)
if (npmScript) {
resolve(usesYarn(root) ? `yarn ${npmScript}` : `npm run ${npmScript}`)
} else {
resolve(usesYarn(root) ? 'yarn tauri' : 'npx tauri')
}
} else {
execCommand('npm install -g tauri', { cwd: undefined }).then(() => resolve('tauri'))
}
Expand Down Expand Up @@ -151,6 +155,7 @@ async function run(): Promise<void> {
const distPath = core.getInput('distPath')
const iconPath = core.getInput('iconPath')
const includeDebug = core.getInput('includeDebug') === 'true'
const npmScript = core.getInput('npmScript')

let tagName = core.getInput('tagName').replace('refs/tags/', '')
let releaseName = core.getInput('releaseName').replace('refs/tags/', '')
Expand All @@ -163,7 +168,7 @@ async function run(): Promise<void> {
throw new Error('`tag` is required along with `releaseName` when creating a release.')
}

const options = { configPath: existsSync(configPath) ? configPath : null, distPath, iconPath }
const options: BuildOptions = { configPath: existsSync(configPath) ? configPath : null, distPath, iconPath, npmScript }
const artifacts = await buildProject(projectPath, false, options)
if (includeDebug) {
const debugArtifacts = await buildProject(projectPath, true, options)
Expand Down

0 comments on commit f91ad8d

Please sign in to comment.