Skip to content

Commit a649aad

Browse files
feat(cli): check and notify about updates on tauri dev, closes #3789 (#3960)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 4a40506 commit a649aad

File tree

5 files changed

+89
-14
lines changed

5 files changed

+89
-14
lines changed

.changes/cli-dev-update.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
Notify CLI update when running `tauri dev`.

.github/workflows/publish-cli.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ jobs:
2222
target: x86_64-apple-darwin
2323
architecture: x64
2424
build: |
25-
yarn build
25+
yarn build:release
2626
strip -x *.node
2727
- host: windows-latest
28-
build: yarn build
28+
build: yarn build:release
2929
target: x86_64-pc-windows-msvc
3030
architecture: x64
3131
- host: windows-latest
32-
build: yarn build --target i686-pc-windows-msvc
32+
build: yarn build:release --target i686-pc-windows-msvc
3333
target: i686-pc-windows-msvc
3434
architecture: x64
3535
- host: ubuntu-18.04
@@ -39,16 +39,16 @@ jobs:
3939
set -e &&
4040
rustup target add x86_64-unknown-linux-gnu &&
4141
cd tooling/cli/node
42-
yarn build --target x86_64-unknown-linux-gnu --zig --zig-abi-suffix 2.12 &&
42+
yarn build:release --target x86_64-unknown-linux-gnu --zig --zig-abi-suffix 2.12 &&
4343
llvm-strip -x *.node
4444
- host: ubuntu-18.04
4545
target: x86_64-unknown-linux-musl
4646
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
47-
build: set -e && cd tooling/cli/node && yarn build && strip *.node
47+
build: set -e && cd tooling/cli/node && yarn build:release && strip *.node
4848
- host: macos-latest
4949
target: aarch64-apple-darwin
5050
build: |
51-
yarn build --target=aarch64-apple-darwin
51+
yarn build:release --target=aarch64-apple-darwin
5252
strip -x *.node
5353
- host: ubuntu-18.04
5454
architecture: x64
@@ -57,7 +57,7 @@ jobs:
5757
sudo apt-get update
5858
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
5959
build: |
60-
yarn build --target=aarch64-unknown-linux-gnu
60+
yarn build:release --target=aarch64-unknown-linux-gnu
6161
aarch64-linux-gnu-strip *.node
6262
- host: ubuntu-18.04
6363
architecture: x64
@@ -66,7 +66,7 @@ jobs:
6666
sudo apt-get update
6767
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
6868
build: |
69-
yarn build --target=armv7-unknown-linux-gnueabihf
69+
yarn build:release --target=armv7-unknown-linux-gnueabihf
7070
arm-linux-gnueabihf-strip *.node
7171
- host: ubuntu-18.04
7272
architecture: x64
@@ -76,12 +76,12 @@ jobs:
7676
set -e &&
7777
rustup target add aarch64-unknown-linux-musl &&
7878
cd tooling/cli/node &&
79-
yarn build --target aarch64-unknown-linux-musl &&
79+
yarn build:release --target aarch64-unknown-linux-musl &&
8080
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
8181
#- host: windows-latest
8282
# architecture: x64
8383
# target: aarch64-pc-windows-msvc
84-
# build: yarn build --target aarch64-pc-windows-msvc
84+
# build: yarn build:release --target aarch64-pc-windows-msvc
8585
name: stable - ${{ matrix.settings.target }} - node@16
8686
runs-on: ${{ matrix.settings.host }}
8787
steps:
@@ -173,7 +173,7 @@ jobs:
173173
# freebsd-version
174174
# cd ./tooling/cli/node/
175175
# yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
176-
# yarn build
176+
# yarn build:release
177177
# strip -x *.node
178178
# rm -rf node_modules
179179
# rm -rf ../target

tooling/cli/node/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
},
5353
"scripts": {
5454
"artifacts": "napi artifacts",
55-
"build": "napi build --platform --release",
56-
"build:debug": "napi build --platform",
55+
"build:release": "napi build --platform --release",
56+
"build": "napi build --platform",
5757
"prepublishOnly": "napi prepublish -t npm",
5858
"test": "jest --runInBand --forceExit --no-cache",
5959
"version": "napi version",

tooling/cli/src/dev.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ pub fn command(options: Options) -> Result<()> {
7878
fn command_internal(options: Options) -> Result<()> {
7979
let logger = Logger::new("tauri:dev");
8080

81+
#[cfg(not(debug_assertions))]
82+
match check_for_updates() {
83+
Ok((msg, sleep)) => {
84+
if sleep {
85+
logger.log(msg);
86+
std::thread::sleep(std::time::Duration::from_secs(3));
87+
} else {
88+
logger.log(msg);
89+
}
90+
}
91+
Err(e) => {
92+
logger.log(e.to_string());
93+
}
94+
};
95+
8196
let tauri_path = tauri_dir();
8297
set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;
8398
let merge_config = if let Some(config) = &options.config {
@@ -281,6 +296,23 @@ fn command_internal(options: Options) -> Result<()> {
281296
}
282297
}
283298

299+
#[cfg(not(debug_assertions))]
300+
fn check_for_updates() -> Result<(String, bool)> {
301+
let current_version = crate::info::cli_current_version()?;
302+
let current = semver::Version::parse(&current_version)?;
303+
304+
let upstream_version = crate::info::cli_upstream_version()?;
305+
let upstream = semver::Version::parse(&upstream_version)?;
306+
if upstream.gt(&current) {
307+
let message = format!(
308+
"🚀 A new version of Tauri CLI is avaliable! [{}]",
309+
upstream.to_string()
310+
);
311+
return Ok((message, true));
312+
}
313+
Ok(("🎉 Tauri CLI is up-to-date!".into(), false))
314+
}
315+
284316
fn lookup<F: FnMut(FileType, PathBuf)>(dir: &Path, mut f: F) {
285317
let mut default_gitignore = std::env::temp_dir();
286318
default_gitignore.push(".tauri-dev");

tooling/cli/src/info.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,43 @@ enum PackageManager {
8585
#[clap(about = "Shows information about Tauri dependencies and project configuration")]
8686
pub struct Options;
8787

88+
fn version_metadata() -> Result<VersionMetadata> {
89+
serde_json::from_str::<VersionMetadata>(include_str!("../metadata.json")).map_err(Into::into)
90+
}
91+
92+
#[cfg(not(debug_assertions))]
93+
pub(crate) fn cli_current_version() -> Result<String> {
94+
version_metadata().map(|meta| meta.js_cli.version)
95+
}
96+
97+
#[cfg(not(debug_assertions))]
98+
pub(crate) fn cli_upstream_version() -> Result<String> {
99+
let upstream_metadata = match ureq::get(
100+
"https://raw.githubusercontent.com/tauri-apps/tauri/dev/tooling/cli/metadata.json",
101+
)
102+
.call()
103+
{
104+
Ok(r) => r,
105+
Err(ureq::Error::Status(code, _response)) => {
106+
let message = format!("Unable to find updates at the moment. Code: {}", code);
107+
return Err(anyhow::Error::msg(message));
108+
}
109+
Err(ureq::Error::Transport(transport)) => {
110+
let message = format!(
111+
"Unable to find updates at the moment. Error: {:?}",
112+
transport.kind()
113+
);
114+
return Err(anyhow::Error::msg(message));
115+
}
116+
};
117+
118+
upstream_metadata
119+
.into_string()
120+
.and_then(|meta_str| Ok(serde_json::from_str::<VersionMetadata>(&meta_str)))
121+
.and_then(|json| Ok(json.unwrap().js_cli.version))
122+
.map_err(|e| anyhow::Error::new(e))
123+
}
124+
88125
fn crate_latest_version(name: &str) -> Option<String> {
89126
let url = format!("https://docs.rs/crate/{}/", name);
90127
match ureq::get(&url).call() {
@@ -582,7 +619,7 @@ pub fn command(_options: Options) -> Result<()> {
582619
.unwrap_or_default();
583620
panic::set_hook(hook);
584621

585-
let metadata = serde_json::from_str::<VersionMetadata>(include_str!("../metadata.json"))?;
622+
let metadata = version_metadata()?;
586623
VersionBlock::new(
587624
"Node.js",
588625
get_version("node", &[])

0 commit comments

Comments
 (0)