tauri/cli/tauri.js/src/api/dependency-manager/rust.ts
nothingismagick bf82136466
feat(license): SPDX Headers (#1449)
* 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>
2021-04-11 00:09:09 +02:00

70 lines
1.8 KiB
TypeScript

// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { ManagementType } from './types'
import { spawnSync } from '../../helpers/spawn'
import getScriptVersion from '../../helpers/get-script-version'
import logger from '../../helpers/logger'
import { createWriteStream, unlinkSync } from 'fs'
import { resolve } from 'path'
import { platform } from 'os'
import https from 'https'
const log = logger('dependency:rust')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function download(url: string, dest: string): Promise<void> {
const file = createWriteStream(dest)
return await new Promise((resolve, reject) => {
https
.get(url, (response) => {
response.pipe(file)
file.on('finish', function () {
file.close()
resolve()
})
})
.on('error', function (err) {
unlinkSync(dest)
reject(err.message)
})
})
}
function installRustup(): void {
if (platform() === 'win32') {
return spawnSync(
'powershell',
[resolve(__dirname, '../../scripts/rustup-init.exe')],
process.cwd()
)
}
return spawnSync(
'/bin/sh',
[resolve(__dirname, '../../scripts/rustup-init.sh')],
process.cwd()
)
}
function manageDependencies(managementType: ManagementType): void {
if (getScriptVersion('rustup') === null) {
log('Installing rustup...')
installRustup()
}
if (managementType === ManagementType.Update) {
spawnSync('rustup', ['update'], process.cwd())
}
}
function install(): void {
return manageDependencies(ManagementType.Install)
}
function update(): void {
return manageDependencies(ManagementType.Update)
}
export { install, update }