mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 11:22:04 +00:00
* chore(licenses): api Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(licenses): scripts Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): cli/core Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): cli/tauri-bundler Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): workflows Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): require license_template in rust Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-api Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-build Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-codegen Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-macros Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-updater Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-utils Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): examples Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): cli/tauri.js Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): changefile Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): place both licenses in root Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): package.json SPDX Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): SPDX everywhere Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * fix(tauri.js): tests more time for ubuntu Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): commons conservancy language Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): add spdx file Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * fix(license): clippy Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): language Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com>
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import { ManagementType, Result } from './types'
|
|
import { getCrateLatestVersion, semverLt } from './util'
|
|
import getScriptVersion from '../../helpers/get-script-version'
|
|
import logger from '../../helpers/logger'
|
|
import { sync as spawnSync } from 'cross-spawn'
|
|
import inquirer from 'inquirer'
|
|
|
|
const log = logger('dependency:cargo-commands')
|
|
|
|
const dependencies = ['tauri-bundler']
|
|
|
|
async function manageDependencies(
|
|
managementType: ManagementType
|
|
): Promise<Result> {
|
|
const installedDeps = []
|
|
const updatedDeps = []
|
|
|
|
for (const dependency of dependencies) {
|
|
const currentVersion = getScriptVersion('cargo', [dependency])
|
|
if (currentVersion === null) {
|
|
log(`Installing ${dependency}...`)
|
|
spawnSync('cargo', ['install', dependency])
|
|
installedDeps.push(dependency)
|
|
} else if (managementType === ManagementType.Update) {
|
|
const latestVersion = await getCrateLatestVersion(dependency)
|
|
if (semverLt(currentVersion, latestVersion)) {
|
|
const inquired = (await inquirer.prompt([
|
|
{
|
|
type: 'confirm',
|
|
name: 'answer',
|
|
message: `[CARGO COMMANDS] "${dependency}" latest version is ${latestVersion}. Do you want to update?`,
|
|
default: false
|
|
}
|
|
])) as { answer: boolean }
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
if (inquired.answer) {
|
|
spawnSync('cargo', ['install', dependency, '--force'])
|
|
updatedDeps.push(dependency)
|
|
}
|
|
} else {
|
|
log(`"${dependency}" is up to date`)
|
|
}
|
|
} else {
|
|
log(`"${dependency}" is already installed`)
|
|
}
|
|
}
|
|
|
|
const result: Result = new Map<ManagementType, string[]>()
|
|
result.set(ManagementType.Install, installedDeps)
|
|
result.set(ManagementType.Update, updatedDeps)
|
|
|
|
return result
|
|
}
|
|
|
|
async function install(): Promise<Result> {
|
|
return await manageDependencies(ManagementType.Install)
|
|
}
|
|
|
|
async function update(): Promise<Result> {
|
|
return await manageDependencies(ManagementType.Update)
|
|
}
|
|
|
|
export { install, update }
|