mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-11 07:55:34 +03:00
fix(ci): update getPublishedVersion script
This commit is contained in:
parent
1cc51a2195
commit
1023326269
@ -5,7 +5,7 @@
|
|||||||
"rust": {
|
"rust": {
|
||||||
"errorOnVersionRange": "^2.0.0-0",
|
"errorOnVersionRange": "^2.0.0-0",
|
||||||
"version": true,
|
"version": true,
|
||||||
"getPublishedVersion": "cargo search ${ pkgFile.pkg.package.name } --limit 1 | sed -nE \"s/^[^\\\"]*\\\"//; s/\\\".*//1p\"",
|
"getPublishedVersion": "node ../../.scripts/covector/package-latest-version.js cargo ${ pkgFile.pkg.package.name } ${ pkgFile.pkg.package.version }",
|
||||||
"prepublish": [
|
"prepublish": [
|
||||||
"sudo apt-get update",
|
"sudo apt-get update",
|
||||||
"sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libayatana-appindicator3-dev librsvg2-dev patchelf",
|
"sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libayatana-appindicator3-dev librsvg2-dev patchelf",
|
||||||
@ -69,7 +69,7 @@
|
|||||||
"javascript": {
|
"javascript": {
|
||||||
"errorOnVersionRange": "^2.0.0-0",
|
"errorOnVersionRange": "^2.0.0-0",
|
||||||
"version": true,
|
"version": true,
|
||||||
"getPublishedVersion": "npm view ${ pkgFile.pkg.name } version",
|
"getPublishedVersion": "node ../../.scripts/covector/package-latest-version.js npm ${ pkgFile.pkg.name } ${ pkgFile.pkg.version }",
|
||||||
"prepublish": [
|
"prepublish": [
|
||||||
{
|
{
|
||||||
"command": "yarn",
|
"command": "yarn",
|
||||||
@ -229,7 +229,7 @@
|
|||||||
"cli.js": {
|
"cli.js": {
|
||||||
"path": "./tooling/cli/node",
|
"path": "./tooling/cli/node",
|
||||||
"manager": "javascript",
|
"manager": "javascript",
|
||||||
"dependencies": ["cli.rs"],
|
"getPublishedVersion": "node ../../../.scripts/covector/package-latest-version.js npm ${ pkgFile.pkg.name } ${ pkgFile.pkg.version }",
|
||||||
"postversion": "node ../../../.scripts/covector/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
|
"postversion": "node ../../../.scripts/covector/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
|
||||||
"prepublish": [],
|
"prepublish": [],
|
||||||
"publish": [],
|
"publish": [],
|
||||||
|
54
.scripts/covector/package-latest-version.js
Normal file
54
.scripts/covector/package-latest-version.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/*
|
||||||
|
This script is solely intended to be run as part of the `covector publish` step to
|
||||||
|
check the latest version of a crate, considering the current minor version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const https = require('https')
|
||||||
|
|
||||||
|
const kind = process.argv[2]
|
||||||
|
const packageName = process.argv[3]
|
||||||
|
const packageVersion = process.argv[4]
|
||||||
|
const target = packageVersion.substring(0, packageVersion.lastIndexOf('.'))
|
||||||
|
|
||||||
|
let url = null
|
||||||
|
switch (kind) {
|
||||||
|
case 'cargo':
|
||||||
|
url = `https://crates.io/api/v1/crates/${packageName}`
|
||||||
|
break;
|
||||||
|
case 'npm':
|
||||||
|
url = `https://registry.npmjs.org/${packageName}`
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error('unexpected kind ' + kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'User-Agent': 'tauri (https://github.com/tauri-apps/tauri)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
https.get(url, options, (response) => {
|
||||||
|
let chunks = []
|
||||||
|
response.on('data', function (chunk) {
|
||||||
|
chunks.push(chunk)
|
||||||
|
})
|
||||||
|
|
||||||
|
response.on('end', function () {
|
||||||
|
const data = JSON.parse(chunks.join(''))
|
||||||
|
if (kind === 'cargo') {
|
||||||
|
const versions = data.versions.filter(v => v.num.startsWith(target))
|
||||||
|
console.log(versions.length ? versions[0].num : '0.0.0')
|
||||||
|
} else if (kind === 'npm') {
|
||||||
|
const versions = Object.keys(data.versions).filter(v => v.startsWith(target))
|
||||||
|
console.log(versions[versions.length - 1] || '0.0.0')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user