Skip to content

Commit

Permalink
Reorganize examples and general repo layout (#1092)
Browse files Browse the repository at this point in the history
* Reorganize crates

* Remove symlink

* Check examples

* Cleanup CI scripts

* nits

* cleanup

* cargo fmt

* Fix yew-stdweb

* cargo clippy --all

* stdweb-examples

* run_emscripten_checks.sh

* Fix typo

* fix typo

* yew-stdweb

* Run tests from yew-stdweb

* fix webgl script
  • Loading branch information
jstarry authored Apr 20, 2020
1 parent 6c16c8c commit fa8a1d9
Show file tree
Hide file tree
Showing 271 changed files with 1,070 additions and 2,012 deletions.
2 changes: 0 additions & 2 deletions .rustfmt.toml

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ install:
- ./ci/install_cargo_web.sh

script:
- ./ci/run_checks.sh
- ./ci/run_stable_checks.sh
- GECKODRIVER=$(pwd)/geckodriver ./ci/run_tests.sh
- ./ci/check_examples.sh
- ./ci/run_emscripten_checks.sh
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ cloned is when a wrapper component re-renders nested children components.

- #### ⚡️ Features

- `Future` support :tada: A `Component` can update following the completion of a `Future`. Check out [this example](https://github.com/yewstack/yew/tree/master/examples/futures) to see how it works. This approach was borrowed from a fork of Yew called [`plaster`](https://github.com/carlosdp/plaster) created by [@carlosdp]. [[@hgzimmerman], [#717](https://github.com/yewstack/yew/pull/717)]
- `Future` support :tada: A `Component` can update following the completion of a `Future`. Check out [this example](https://github.com/yewstack/yew/tree/v0.14.0/examples/futures) to see how it works. This approach was borrowed from a fork of Yew called [`plaster`](https://github.com/carlosdp/plaster) created by [@carlosdp]. [[@hgzimmerman], [#717](https://github.com/yewstack/yew/pull/717)]
- Added the `agent` and `services` features so that this functionality can be disabled (useful if you are switching to using `Future`s). [[@hgzimmerman], [#684](https://github.com/yewstack/yew/pull/684)]
- Add `ref` keyword for allowing a `Component` to have a direct reference to its rendered elements. For example, you can now easily focus an `<input>` element after mounting. [[@jstarry], [#715](https://github.com/yewstack/yew/pull/715)]

Expand Down
33 changes: 11 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@
rustup target add wasm32-unknown-unknown
```

#### Install [cargo-web]

This is an optional tool that simplifies running the examples:
#### Build

```bash
cargo install cargo-web
cargo build --target wasm32-unknown-unknown
```

> Add `--force` option to ensure you install the latest version.
#### Examples

[cargo-web]: https://github.com/koute/cargo-web
TODO: Add more info

#### Build
##### stdweb
In order to run the examples in `./yew-stdweb`, you may wish to install [cargo-web]:

Either
```bash
cargo build --target wasm32-unknown-unknown --features web_sys
```
or
```bash
cargo build --target wasm32-unknown-unknown --features std_web
cargo install cargo-web
```
See more about features [here](https://docs.rs/yew/0.14.0/yew/#important-notes)

[cargo-web]: https://github.com/koute/cargo-web

#### Test

Expand All @@ -48,9 +42,9 @@ although more driver support may be added! You can download these at:
* safaridriver - should be preinstalled on OSX

##### Macro Tests
When adding or updating tests, please make sure you have updated the appropriate `stderr` file, which you can find [here](https://github.com/yewstack/yew/tree/master/crates/macro/tests/macro) for the `html!` macro. These files ensure that macro compilation errors are correct and easy to understand.
When adding or updating tests, please make sure you have updated the appropriate `stderr` file, which you can find [here](https://github.com/yewstack/yew/tree/master/yew-macro/tests/macro) for the `html!` macro. These files ensure that macro compilation errors are correct and easy to understand.

To update or generate a new `stderr` file you can run `TRYBUILD=overwrite cargo test --test macro_test` or `TRYBUILD=overwrite cargo test --test derive_props_test` from the `crates/macro` directory.
To update or generate a new `stderr` file you can run `TRYBUILD=overwrite cargo test --test macro_test` or `TRYBUILD=overwrite cargo test --test derive_props_test` from the `yew-macro` directory.

##### Running Tests

Expand All @@ -60,10 +54,5 @@ To update or generate a new `stderr` file you can run `TRYBUILD=overwrite cargo
or

```bash
cargo test --target wasm32-unknown-unknown --features wasm_test --features web_sys
```
or

```bash
cargo test --target wasm32-unknown-unknown --features wasm_test --features std_web
cargo test --target wasm32-unknown-unknown --features wasm_test
```
168 changes: 29 additions & 139 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,142 +1,32 @@
[package]
name = "yew"
version = "0.14.3"
edition = "2018"
authors = [
"Denis Kolodin <deniskolodin@gmail.com>",
"Justin Starry <justin@yew.rs>",
]
repository = "https://github.com/yewstack/yew"
homepage = "https://github.com/yewstack/yew"
documentation = "https://docs.rs/yew/"
license = "MIT/Apache-2.0"
readme = "README.md"
keywords = ["web", "asmjs", "webasm", "javascript"]
categories = ["gui", "web-programming"]
description = "A framework for making client-side single-page apps"

[badges]
travis-ci = { repository = "yewstack/yew" }

[dependencies]
anyhow = "1"
anymap = "0.12"
bincode = { version = "~1.2.1", optional = true }
cfg-if = "0.1"
cfg-match = "0.2"
console_error_panic_hook = { version = "0.1", optional = true }
futures = { version = "0.3", optional = true }
gloo = { version = "0.2.1", optional = true }
http = "0.2"
indexmap = "1.0.2"
js-sys = { version = "0.3", optional = true }
log = "0.4"
proc-macro-hack = "0.5"
proc-macro-nested = "0.1"
rmp-serde = { version = "0.14.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_cbor = { version = "0.11.1", optional = true }
serde_json = "1.0"
serde_yaml = { version = "0.8.3", optional = true }
slab = "0.4"
stdweb = { version = "0.4.20", optional = true }
thiserror = "1"
toml = { version = "0.5", optional = true }
wasm-bindgen = { version = "0.2.60", optional = true }
wasm-bindgen-futures = { version = "0.4", optional = true }
yew-macro = { version = "0.14.1", path = "crates/macro" }

[dependencies.web-sys]
version = "0.3"
optional = true
features = [
"AbortController",
"AbortSignal",
"BinaryType",
"Blob",
"BlobPropertyBag",
"console",
"DedicatedWorkerGlobalScope",
"Document",
"DomTokenList",
"DragEvent",
"Element",
"Event",
"EventTarget",
"File",
"FileList",
"FileReader",
"FocusEvent",
"Headers",
"HtmlElement",
"HtmlInputElement",
"HtmlSelectElement",
"HtmlTextAreaElement",
"KeyboardEvent",
"Location",
"MessageEvent",
"MouseEvent",
"Node",
"ObserverCallback",
"PointerEvent",
"ReferrerPolicy",
"Request",
"RequestCache",
"RequestCredentials",
"RequestInit",
"RequestMode",
"RequestRedirect",
"Response",
"Storage",
"Text",
"TouchEvent",
"UiEvent",
"Url",
"WebSocket",
"WheelEvent",
"Window",
"Worker",
"WorkerGlobalScope",
"WorkerOptions",
]

# Changes here must be reflected in `build.rs`
[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies]
wasm-bindgen = "0.2.60"

# Changes here must be reflected in `build.rs`
[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dev-dependencies]
wasm-bindgen-test = "0.3.4"
base64 = "0.12.0"
ssri = "5.0.0"

[target.'cfg(target_os = "emscripten")'.dependencies]
ryu = "1.0.2" # 1.0.1 breaks emscripten

[dev-dependencies]
serde_derive = "1"
trybuild = "1.0"
rustversion = "1.0"
rmp-serde = "0.14.0"
bincode = "~1.2.1"

[features]
default = ["services", "agent"]
std_web = ["stdweb"]
web_sys = ["console_error_panic_hook", "futures", "gloo", "js-sys", "web-sys", "wasm-bindgen", "wasm-bindgen-futures"]
doc_test = []
wasm_test = []
services = []
agent = ["bincode"]
yaml = ["serde_yaml"]
msgpack = ["rmp-serde"]
cbor = ["serde_cbor"]

[package.metadata.docs.rs]
features = ["web_sys", "agent", "services", "yaml", "cbor", "toml", "msgpack", "doc_test"]

[workspace]
members = [
"crates/macro",
"crates/functional",
"yew",
"yew-functional",
"yew-macro",

# Examples
"examples/counter",
"examples/crm",
"examples/custom_components",
"examples/dashboard",
"examples/file_upload",
"examples/fragments",
"examples/futures",
"examples/game_of_life",
"examples/inner_html",
"examples/js_callback",
"examples/large_table",
"examples/minimal",
"examples/mount_point",
"examples/multi_thread",
"examples/nested_list",
"examples/node_refs",
"examples/npm_and_rest",
"examples/pub_sub",
"examples/server",
"examples/textarea",
"examples/timer",
"examples/todomvc",
"examples/two_apps",
"examples/webgl",
]
38 changes: 0 additions & 38 deletions ci/check_examples.sh

This file was deleted.

12 changes: 0 additions & 12 deletions ci/run_checks.sh

This file was deleted.

12 changes: 12 additions & 0 deletions ci/run_emscripten_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
echo "$(rustup default)" | grep -q "1.39.0"
emscripten_supported=$?
set -euxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/

pushd yew-stdweb
if [ "$emscripten_supported" == "0" ]; then
# TODO - Emscripten builds are broken on rustc > 1.39.0
cargo check --all --target asmjs-unknown-emscripten
cargo check --all --target wasm32-unknown-emscripten
fi
popd
28 changes: 28 additions & 0 deletions ci/run_stable_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

echo "$(rustup default)" | grep -q "stable"
if [ "$?" != "0" ]; then
# only run checks on stable
exit 0
fi

set -euxo pipefail

cargo fmt --all -- --check
cargo clippy --all -- --deny=warnings
cargo check --all

# Enable all optional features
(cd yew \
&& cargo check --features cbor,msgpack,toml,yaml \
&& cargo clippy --features cbor,msgpack,toml,yaml -- --deny=warnings)

# Check stdweb
pushd yew-stdweb
cargo fmt --all -- --check
cargo clippy --all -- --deny=warnings
cargo check --all --target wasm32-unknown-unknown

# webgl_stdweb doesn't play nice with wasm-bindgen
(cd examples/webgl && cargo web check --target wasm32-unknown-unknown)
popd
29 changes: 16 additions & 13 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ echo "$(rustup default)" | grep -q "1.39.0"
emscripten_supported=$?
set -euxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/

cargo test --target wasm32-unknown-unknown --features wasm_test,std_web
cargo test --target wasm32-unknown-unknown --features wasm_test,web_sys
(cd yew \
&& cargo test --target wasm32-unknown-unknown --features wasm_test \
&& cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,toml \
&& cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,toml \
--features std_web,agent,services --no-default-features)

if [ "$emscripten_supported" == "0" ]; then
# TODO - Emscripten builds are broken on rustc > 1.39.0
cargo web test --target asmjs-unknown-emscripten --features std_web
cargo web test --target wasm32-unknown-emscripten --features std_web
fi

cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,std_web
cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,web_sys
(cd yew-functional \
&& cargo test --target wasm32-unknown-unknown)

(cd crates/macro \
(cd yew-macro \
&& cargo test --test macro_test \
&& cargo test --test derive_props_test \
&& cargo test --doc)

(cd crates/functional \
&& cargo test --features wasm_test --target wasm32-unknown-unknown)
(cd yew-stdweb && cargo test --target wasm32-unknown-unknown --features wasm_test)

# TODO - Emscripten builds are broken on rustc > 1.39.0
if [ "$emscripten_supported" == "0" ]; then
(cd yew-stdweb \
&& cargo web test --target asmjs-unknown-emscripten \
&& cargo web test --target wasm32-unknown-emscripten)
fi
Loading

0 comments on commit fa8a1d9

Please sign in to comment.