Replace wasm-run by xtask-wasm (#138)

This commit is contained in:
Yohan Boogaert 2022-05-09 19:20:26 +02:00 committed by GitHub
parent 28f879a9a4
commit 25be039090
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 352 additions and 1549 deletions

2
.cargo/config.toml Normal file
View file

@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --"

View file

@ -15,22 +15,22 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: cargo test --all-features --verbose
- run: cargo test --workspace --all-features --verbose
site:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
steps:
- uses: actions/checkout@v2
- run: cargo doc --verbose --all-features --no-deps
- run: cargo doc --verbose --workspace --all-features --no-deps
- name: Build (Release)
run: "cargo run -- build"
run: "cargo xtask dist --release"
- name: Move doc to build/api
run: mv ./target/doc ./build/api
run: mv ./target/doc ./target/release/dist/api
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v1.1
with:
publish-dir: './build'
publish-dir: './target/release/dist'
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: ${{ github.event.head_commit.message }}
production-deploy: true

View file

@ -16,14 +16,14 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: cargo test --all-features --verbose
- run: cargo test --workspace --all-features --verbose
- name: Build (Release)
id: build
run: "cargo run -- build && echo ::set-output name=size::`cat build/wasm_bg.wasm | wc -c`"
run: "cargo xtask dist --release && echo ::set-output name=size::`cat target/release/dist/app.wasm | wc -c`"
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v1.1
with:
publish-dir: './build'
publish-dir: 'target/release/dist'
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: ${{ github.event.pull_request.title }}
env:
@ -41,5 +41,5 @@ jobs:
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --workspace -- -D warnings
args: --all --all-features --tests -- -D warnings
- run: cargo +nightly fmt -- --check

1649
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,13 +1,32 @@
[package]
name = "run"
version = "0.0.0"
name = "yewprint"
version = "0.1.1"
authors = ["Cecile Tonglet <cecile.tonglet@cecton.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
description = "Port of blueprintjs.com to Yew"
repository = "https://github.com/yewprint/yewprint"
homepage = "https://github.com/yewprint/yewprint"
documentation = "https://docs.rs/yewprint"
readme = "README.md"
include = ["src/**/*.rs", "README.md", "LICENSE.Apache-2.0", "LICENSE.MIT", "iconSvgPaths.js", "build.rs"]
keywords = ["blueprint", "yew", "ui"]
categories = ["gui"]
[features]
default = ["tree"]
tree = ["id_tree"]
[dependencies]
log = "0.4"
structopt = "0.3"
wasm-run = "0.9"
yewprint-css = { path = "./yewprint-css" }
web-sys = { version = "0.3", features = ["DomRect", "Element"] }
yew = "0.18"
id_tree = { version = "1.7", optional = true }
yewtil = { version = "0.4", features = ["pure"] }
wasm-bindgen = "0.2"
[build-dependencies]
regex = { version = "1", default-features = false, features = ["std", "unicode-perl"] }
heck = "0.3"
[workspace]
members = ["yewprint", "yewprint-css", "yewprint-doc"]
members = ["yewprint-css", "yewprint-doc", "xtask"]

View file

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Copyright 2020 Cecile Tonglet
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 Cecile Tonglet
Copyright (c) 2020 Cecile Tonglet
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -29,15 +29,15 @@ cargo generate --git https://github.com/yewprint/yewprint-template.git
## Development Environment
```
cargo run -- serve
cargo xtask start
```
You can now go to http://localhost:3000
You can now go to http://localhost:8000
### Blueprint CSS update
```
cargo run -- update-css
cargo xtask update-css
```
Roadmap

View file

@ -1,63 +0,0 @@
#![allow(clippy::unnecessary_wraps)]
use anyhow::{Context, Result};
use std::fs;
use std::path::Path;
use std::process::Command;
use structopt::StructOpt;
use wasm_run::prelude::*;
#[wasm_run::main("yewprint-doc", pre_build, other_cli_commands)]
#[derive(StructOpt, Debug)]
enum Cli {
/// Update Blueprint CSS and docs-theme CSS.
UpdateCss,
}
fn pre_build(args: &DefaultBuildArgs, profile: BuildProfile, cargo: &mut Command) -> Result<()> {
let package = args.frontend_package();
download_css(package, false)?;
match profile {
BuildProfile::Profiling | BuildProfile::Release => {
cargo.args(&["--features", "wee_alloc"]);
}
BuildProfile::Dev => {
cargo.args(&["--features", "console_error_panic_hook"]);
}
}
fs::copy("yewprint-doc/src/logo.svg", "build/favicon.svg")?;
Ok(())
}
fn other_cli_commands(cli: Cli, _metadata: &Metadata, package: &Package) -> Result<()> {
match cli {
Cli::UpdateCss => {
download_css(package, true)?;
}
}
Ok(())
}
fn download_css(package: &Package, force: bool) -> Result<()> {
let static_path = package.manifest_path.parent().unwrap().join("static");
let css_path = static_path.join("blueprint.css");
if force || !css_path.exists() {
yewprint_css::download_css(&css_path)?;
let version = yewprint_css::download_from_npm_package(
"@blueprintjs/docs-theme",
"3.11.1",
Path::new("package/lib/css/docs-theme.css"),
&static_path.join("docs-theme.css"),
)
.context("while downloading CSS of @blueprintjs/docs-theme")?;
log::info!("Docs Theme CSS updated to: {}", version);
}
Ok(())
}

12
xtask/Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
env_logger = "0.9"
log = "0.4"
xtask-wasm = "0.1.3"
yewprint-css = { path = "../yewprint-css" }

76
xtask/src/main.rs Normal file
View file

@ -0,0 +1,76 @@
use std::{
fs,
path::{Path, PathBuf},
process,
};
use xtask_wasm::{
anyhow::{Context, Result},
clap,
};
#[derive(clap::Parser)]
enum Cli {
Dist(xtask_wasm::Dist),
Watch(xtask_wasm::Watch),
Start(xtask_wasm::DevServer),
/// Update Blueprint CSS and docs-theme CSS.
UpdateCSS,
}
fn main() -> Result<()> {
env_logger::builder()
.filter_module("xtask", log::LevelFilter::Info)
.filter_module("yewprint", log::LevelFilter::Info)
.init();
let cli: Cli = clap::Parser::parse();
match cli {
Cli::Dist(arg) => {
log::info!("Generating package...");
download_css(false)?;
let result = arg
.static_dir_path("yewprint-doc/static")
.run("yewprint-doc")?;
fs::copy(
"yewprint-doc/src/logo.svg",
result.dist_dir.join("favicon.svg"),
)?;
}
Cli::Watch(arg) => {
let mut command = process::Command::new("cargo");
command.args(["xtask", "dist"]);
arg.run(command)?;
}
Cli::Start(arg) => {
arg.arg("dist").start(xtask_wasm::default_dist_dir(false))?;
}
Cli::UpdateCSS => download_css(true)?,
}
Ok(())
}
fn download_css(force: bool) -> Result<()> {
let static_path = PathBuf::from("yewprint-doc/static");
let css_path = static_path.join("blueprint.css");
if force || !css_path.exists() {
yewprint_css::download_css(&css_path)?;
let version = yewprint_css::download_from_npm_package(
"@blueprintjs/docs-theme",
"3.11.1",
Path::new("package/lib/css/docs-theme.css"),
&static_path.join("docs-theme.css"),
)
.context("while downloading CSS of @blueprintjs/docs-theme")?;
log::info!("Docs Theme CSS updated to: {}", version);
}
Ok(())
}

View file

@ -13,7 +13,7 @@ crate-type = ["cdylib"]
wasm-bindgen = "=0.2"
yew = "0.18"
web-sys = { version = "0.3", features = ["Window", "MediaQueryList"] }
yewprint = { path = "../yewprint" }
yewprint = { path = ".." }
yew-router = "0.15"
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size

View file

@ -78,7 +78,7 @@ macro_rules! build_source_code_component {
format!(
"https://github.com/yewprint/yewprint/blob/{}\
/yewprint/src/{}.rs",
/src/{}.rs",
branch, component_name,
)
}

View file

@ -13,7 +13,7 @@
<title>Yewprint</title>
<script type="module">
import init from "/app.js";
init(new URL('app_bg.wasm', import.meta.url));
init(new URL('app.wasm', import.meta.url));
</script>
<link rel="icon" href="/favicon.svg">
<link rel="stylesheet" href="/blueprint.css">

View file

@ -1,29 +0,0 @@
[package]
name = "yewprint"
version = "0.1.1"
authors = ["Cecile Tonglet <cecile.tonglet@cecton.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
description = "Port of blueprintjs.com to Yew"
repository = "https://github.com/yewprint/yewprint"
homepage = "https://github.com/yewprint/yewprint"
documentation = "https://docs.rs/yewprint"
readme = "README.md"
include = ["src/**/*.rs", "README.md", "LICENSE.Apache-2.0", "LICENSE.MIT", "iconSvgPaths.js", "build.rs"]
keywords = ["blueprint", "yew", "ui"]
categories = ["gui"]
[features]
default = ["tree"]
tree = ["id_tree"]
[dependencies]
web-sys = { version = "0.3", features = ["DomRect", "Element"] }
yew = "0.18"
id_tree = { version = "1.7", optional = true }
yewtil = { version = "0.4", features = ["pure"] }
wasm-bindgen = "0.2"
[build-dependencies]
regex = { version = "1", default-features = false, features = ["std", "unicode-perl"] }
heck = "0.3"

View file

@ -1 +0,0 @@
../LICENSE.Apache-2.0

View file

@ -1 +0,0 @@
../LICENSE.MIT

View file

@ -1 +0,0 @@
../README.md