From 7d1705fc0031740cf2afec2997c812d6d09b8048 Mon Sep 17 00:00:00 2001 From: Jonas Kruckenberg Date: Thu, 16 Jun 2022 12:32:03 +0200 Subject: [PATCH] fmt & lint --- .eslintrc.json | 5 ++-- src/build-project.ts | 62 +++++++++++++++++++++++++++++++++----------- src/main.ts | 2 +- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 71ee545..fc638b4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,5 @@ { - "plugins": ["jest", "@typescript-eslint"], + "plugins": ["@typescript-eslint"], "extends": ["plugin:github/recommended"], "parser": "@typescript-eslint/parser", "parserOptions": { @@ -49,7 +49,6 @@ }, "env": { "node": true, - "es6": true, - "jest/globals": true + "es6": true } } \ No newline at end of file diff --git a/src/build-project.ts b/src/build-project.ts index 2db5dfb..9336d13 100644 --- a/src/build-project.ts +++ b/src/build-project.ts @@ -1,5 +1,5 @@ import {run} from '@tauri-apps/cli' -import {basename, dirname, join, posix, resolve, sep} from 'path' +import {basename, dirname, join, resolve} from 'path' import glob from 'tiny-glob' import * as core from '@actions/core' import { @@ -19,7 +19,7 @@ interface BuildOptions { } export async function buildProject(options: BuildOptions): Promise { - let args: string[] = options.args || [] + const args: string[] = options.args || [] if (options.configPath) { args.push('--config', options.configPath) @@ -43,11 +43,17 @@ export async function buildProject(options: BuildOptions): Promise { await run(['build', ...args], '') } - const crateDir = await glob(`./**/Cargo.toml`).then(([manifest]) => join(process.cwd(), dirname(manifest))) - const metaRaw = await execCmd('cargo', ['metadata', '--no-deps', '--format-version', '1'], { cwd: crateDir }) + const crateDir = await glob(`./**/Cargo.toml`).then(([manifest]) => + join(process.cwd(), dirname(manifest)) + ) + const metaRaw = await execCmd( + 'cargo', + ['metadata', '--no-deps', '--format-version', '1'], + {cwd: crateDir} + ) const meta = JSON.parse(metaRaw) const targetDir = meta.target_directory - + const profile = options.debug ? 'debug' : 'release' const bundleDir = options.target ? join(targetDir, options.target, profile, 'bundle') @@ -62,20 +68,38 @@ export async function buildProject(options: BuildOptions): Promise { ] const windowsExts = ['msi', 'msi.zip', 'msi.zip.sig'] - const artifactsLookupPattern = `${bundleDir}/*/!(linuxdeploy)*.{${[...macOSExts, linuxExts, windowsExts].join(',')}}` + const artifactsLookupPattern = `${bundleDir}/*/!(linuxdeploy)*.{${[ + ...macOSExts, + linuxExts, + windowsExts + ].join(',')}}` - core.debug(`Looking for artifacts using this pattern: ${artifactsLookupPattern}`) + core.debug( + `Looking for artifacts using this pattern: ${artifactsLookupPattern}` + ) - const artifacts = await glob(artifactsLookupPattern, { absolute: true, filesOnly: false }) + const artifacts = await glob(artifactsLookupPattern, { + absolute: true, + filesOnly: false + }) - let i = 0; + let i = 0 for (const artifact of artifacts) { - if (artifact.endsWith('.app') && !artifacts.some(a => a.endsWith('.app.tar.gz'))) { - await execCmd('tar', ['czf', `${artifact}.tar.gz`, '-C', dirname(artifact), basename(artifact)]) + if ( + artifact.endsWith('.app') && + !artifacts.some(a => a.endsWith('.app.tar.gz')) + ) { + await execCmd('tar', [ + 'czf', + `${artifact}.tar.gz`, + '-C', + dirname(artifact), + basename(artifact) + ]) artifacts[i] += '.tar.gz' } else if (artifact.endsWith('.app')) { // we can't upload a directory - artifacts.splice(i, 1); + artifacts.splice(i, 1) } i++ @@ -88,9 +112,13 @@ async function spawnCmd( cmd: string, args: string[], options: SpawnOptionsWithoutStdio = {} -) { +): Promise { return new Promise((resolve, reject) => { - const child = spawn(cmd, args, {...options, stdio: ['pipe', 'inherit', 'inherit'], shell: true}) + const child = spawn(cmd, args, { + ...options, + stdio: ['pipe', 'inherit', 'inherit'], + shell: true + }) child.on('exit', () => resolve) @@ -117,7 +145,11 @@ async function execCmd( {...options, encoding: 'utf-8'}, (error, stdout, stderr) => { if (error) { - console.error(`Failed to execute cmd ${cmd} with args: ${args.join(' ')}. reason: ${error}`); + console.error( + `Failed to execute cmd ${cmd} with args: ${args.join( + ' ' + )}. reason: ${error}` + ) reject(stderr) } else { resolve(stdout) diff --git a/src/main.ts b/src/main.ts index 79ed207..5b1a794 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' import {buildProject} from './build-project' -import stringArgv from 'string-argv'; +import stringArgv from 'string-argv' async function run(): Promise { try {