Merge branch 'master' into cli-serde-default
This commit is contained in:
159 files changed
+2545
-6250
No files matched your search
-31
@@ -1,31 +0,0 @@
|
||||
# .github/workflows/build.yml
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: release ${{ matrix.target }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- target: x86_64-unknown-linux-gnu
|
||||
archive: tar.gz tar.xz
|
||||
- target: x86_64-unknown-linux-musl
|
||||
archive: tar.gz tar.xz
|
||||
- target: x86_64-apple-darwin
|
||||
archive: tar.gz tar.xz
|
||||
- target: x86_64-pc-windows-gnu
|
||||
archive: zip
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Compile and release
|
||||
uses: rust-build/rust-build.action@latest
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
RUSTTARGET: ${{ matrix.target }}
|
||||
ARCHIVE_TYPES: ${{ matrix.archive }}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
name: github pages
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- docs/**
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-20.04
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup mdBook
|
||||
uses: peaceiris/actions-mdbook@v1
|
||||
with:
|
||||
mdbook-version: '0.4.10'
|
||||
# mdbook-version: 'latest'
|
||||
|
||||
- run: cd docs && mdbook build
|
||||
|
||||
- name: Deploy 🚀
|
||||
uses: JamesIves/github-pages-deploy-action@v4.2.3
|
||||
with:
|
||||
branch: gh-pages # The branch the action should deploy to.
|
||||
folder: docs/book # The folder the action should deploy.
|
||||
target-folder: docs/nightly/cli
|
||||
repository-name: dioxuslabs/docsite
|
||||
clean: false
|
||||
token: ${{ secrets.DEPLOY_KEY }} # let's pretend I don't need it for now
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
on: [push, pull_request]
|
||||
|
||||
name: Rust CI
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- run: cargo check
|
||||
|
||||
test:
|
||||
name: Test Suite
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- run: cargo test
|
||||
|
||||
fmt:
|
||||
name: Rustfmt
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- run: rustup component add rustfmt
|
||||
- run: cargo fmt --all -- --check
|
||||
|
||||
# clippy:
|
||||
# name: Clippy
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@v2
|
||||
# - uses: actions-rs/toolchain@v1
|
||||
# with:
|
||||
# profile: minimal
|
||||
# toolchain: stable
|
||||
# override: true
|
||||
# - uses: Swatinem/rust-cache@v1
|
||||
# - run: rustup component add clippy
|
||||
# - uses: actions-rs/cargo@v1
|
||||
# with:
|
||||
# command: clippy
|
||||
# args: -- -D warnings
|
||||
Generated
-4778
File diff suppressed because it is too large.
Load diff
@@ -22,16 +22,13 @@ serde = { version = "1.0.136", features = ["derive"] }
|
||||
serde_json = "1.0.79"
|
||||
toml = "0.5.8"
|
||||
fs_extra = "1.2.0"
|
||||
cargo_toml = "0.11.4"
|
||||
cargo_toml = "0.16.0"
|
||||
futures = "0.3.21"
|
||||
notify = { version = "5.0.0-pre.16", features = ["serde"] }
|
||||
html_parser = { workspace = true }
|
||||
binary-install = "0.0.2"
|
||||
convert_case = "0.5.0"
|
||||
cargo_metadata = "0.15.0"
|
||||
tokio = { version = "1.16.1", features = ["full"] }
|
||||
tokio = { version = "1.16.1", features = ["fs", "sync", "rt", "macros"] }
|
||||
atty = "0.2.14"
|
||||
regex = "1.5.4"
|
||||
chrono = "0.4.19"
|
||||
anyhow = "1.0.53"
|
||||
hyper = "0.14.17"
|
||||
@@ -59,7 +56,6 @@ tar = "0.4.38"
|
||||
zip = "0.6.2"
|
||||
tower = "0.4.12"
|
||||
syn = { version = "2.0", features = ["full", "extra-traits"] }
|
||||
proc-macro2 = { version = "1.0", features = ["span-locations"] }
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
# plugin packages
|
||||
@@ -71,7 +67,6 @@ mlua = { version = "0.8.1", features = [
|
||||
"macros",
|
||||
], optional = true }
|
||||
ctrlc = "3.2.3"
|
||||
gitignore = "1.0.7"
|
||||
open = "4.1.0"
|
||||
cargo-generate = "0.18"
|
||||
toml_edit = "0.19.11"
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
</div>
|
||||
|
||||
The **dioxus-cli** (inspired by wasm-pack and webpack) is a tool for getting Dioxus projects up and running.
|
||||
It handles all building, bundling, development and publishing to simplify development.
|
||||
It handles building, bundling, development and publishing to simplify development.
|
||||
|
||||
## Installation
|
||||
|
||||
### Install the stable version (recommended)
|
||||
|
||||
```
|
||||
cargo install dioxus-cli --locked
|
||||
cargo install dioxus-cli
|
||||
```
|
||||
|
||||
### Install the latest development build through git
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
book
|
||||
@@ -1,6 +0,0 @@
|
||||
[book]
|
||||
authors = ["YuKun Liu"]
|
||||
language = "en"
|
||||
multilingual = false
|
||||
src = "src"
|
||||
title = "Dioxus CLI"
|
||||
@@ -1,13 +0,0 @@
|
||||
# Summary
|
||||
|
||||
- [Introduction](./introduction.md)
|
||||
- [Installation](./installation.md)
|
||||
- [Create a project](./creating.md)
|
||||
- [Configure a project](./configure.md)
|
||||
- [Plugin development](./plugin/README.md)
|
||||
- [API.Log](plugin/interface/log.md)
|
||||
- [API.Command](plugin/interface/command.md)
|
||||
- [API.OS](plugin/interface/os.md)
|
||||
- [API.Directories](plugin/interface/dirs.md)
|
||||
- [API.Network](plugin/interface/network.md)
|
||||
- [API.Path](plugin/interface/path.md)
|
||||
@@ -1,197 +0,0 @@
|
||||
# Configure Project
|
||||
|
||||
This chapter will teach you how to configure the CLI with the `Dioxus.toml` file.
|
||||
There's an [example](#config-example) which has comments to describe individual keys.
|
||||
You can copy that or view this documentation for a more complete learning experience.
|
||||
|
||||
"🔒" indicates a mandatory item. Some headers are mandatory, but none of the keys inside them are. It might look weird, but it's normal. Simply don't include any keys.
|
||||
|
||||
## Structure
|
||||
|
||||
Each header has it's TOML form directly under it.
|
||||
|
||||
### Application 🔒
|
||||
|
||||
```toml
|
||||
[application]
|
||||
```
|
||||
|
||||
Application-wide configuration. Applies to both web and desktop.
|
||||
|
||||
1. **name** 🔒 - Project name & title.
|
||||
```toml
|
||||
name = "my_project"
|
||||
```
|
||||
|
||||
2. **default_platform** 🔒 - The platform this project targets
|
||||
```toml
|
||||
# Currently supported platforms: web, desktop
|
||||
default_platform = "web"
|
||||
```
|
||||
|
||||
3. **out_dir** - The directory to place the build artifacts from `dx build` or `dx serve` into. This is also where the `assets` directory will be copied into.
|
||||
```toml
|
||||
out_dir = "dist"
|
||||
```
|
||||
|
||||
4. **asset_dir** - The directory with your static assets. The CLI will automatically copy these assets into the **out_dir** after a build/serve.
|
||||
```toml
|
||||
asset_dir = "public"
|
||||
```
|
||||
|
||||
5. **sub_package** - The sub package in the workspace to build by default.
|
||||
```toml
|
||||
sub_package = "my-crate"
|
||||
```
|
||||
|
||||
### Web.App 🔒
|
||||
|
||||
```toml
|
||||
[web.app]
|
||||
```
|
||||
|
||||
Web-specific configuration.
|
||||
|
||||
1. **title** - The title of the web page.
|
||||
```toml
|
||||
# HTML title tag content
|
||||
title = "project_name"
|
||||
```
|
||||
|
||||
2. **base_path** - The base path to build the application for serving at. This can be useful when serving your application in a subdirectory under a domain. For example when building a site to be served on GitHub Pages.
|
||||
```toml
|
||||
# The application will be served at domain.com/my_application/, so we need to modify the base_path to the path where the application will be served
|
||||
base_path = "my_application"
|
||||
```
|
||||
|
||||
### Web.Watcher ✍
|
||||
|
||||
```toml
|
||||
[web.watcher]
|
||||
```
|
||||
|
||||
Development server configuration.
|
||||
|
||||
1. **reload_html** - If this is true, the cli will rebuild the index.html file every time the application is rebuilt
|
||||
```toml
|
||||
reload_html = true
|
||||
```
|
||||
|
||||
2. **watch_path** - The files & directories to monitor for changes
|
||||
```toml
|
||||
watch_path = ["src", "public"]
|
||||
```
|
||||
|
||||
3. **index_on_404** - If enabled, Dioxus will serve the root page when a route is not found.
|
||||
*This is needed when serving an application that uses the router*.
|
||||
However, when serving your app using something else than Dioxus (e.g. GitHub Pages), you will have to check how to configure it on that platform.
|
||||
In GitHub Pages, you can make a copy of `index.html` named `404.html` in the same directory.
|
||||
```toml
|
||||
index_on_404 = true
|
||||
```
|
||||
|
||||
### Web.Resource 🔒
|
||||
|
||||
```toml
|
||||
[web.resource]
|
||||
```
|
||||
|
||||
Static resource configuration.
|
||||
|
||||
1. **style** - CSS files to include in your application.
|
||||
```toml
|
||||
style = [
|
||||
# Include from public_dir.
|
||||
"./assets/style.css",
|
||||
# Or some asset from online cdn.
|
||||
"https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.css"
|
||||
]
|
||||
```
|
||||
|
||||
2. **script** - JavaScript files to include in your application.
|
||||
```toml
|
||||
script = [
|
||||
# Include from asset_dir.
|
||||
"./public/index.js",
|
||||
# Or from an online CDN.
|
||||
"https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.js"
|
||||
]
|
||||
```
|
||||
|
||||
### Web.Resource.Dev 🔒
|
||||
|
||||
```toml
|
||||
[web.resource.dev]
|
||||
```
|
||||
|
||||
This is the same as [`[web.resource]`](#webresource-), but it only works in development servers.
|
||||
For example, if you want to include a file in a `dx serve` server, but not a `dx serve --release` server, put it here.
|
||||
|
||||
### Web.Proxy
|
||||
|
||||
```toml
|
||||
[[web.proxy]]
|
||||
```
|
||||
|
||||
Configuration related to any proxies your application requires during development. Proxies will forward requests to a new service.
|
||||
|
||||
1. **backend** - The URL to the server to proxy. The CLI will forward any requests under the backend relative route to the backend instead of returning 404
|
||||
```toml
|
||||
backend = "http://localhost:8000/api/"
|
||||
```
|
||||
This will cause any requests made to the dev server with prefix /api/ to be redirected to the backend server at http://localhost:8000. The path and query parameters will be passed on as-is (path rewriting is currently not supported).
|
||||
|
||||
## Config example
|
||||
|
||||
This includes all fields, mandatory or not.
|
||||
|
||||
```toml
|
||||
[application]
|
||||
|
||||
# App name
|
||||
name = "project_name"
|
||||
|
||||
# The Dioxus platform to default to
|
||||
default_platform = "web"
|
||||
|
||||
# `build` & `serve` output path
|
||||
out_dir = "dist"
|
||||
|
||||
# The static resource path
|
||||
asset_dir = "public"
|
||||
|
||||
[web.app]
|
||||
|
||||
# HTML title tag content
|
||||
title = "project_name"
|
||||
|
||||
[web.watcher]
|
||||
|
||||
# When watcher is triggered, regenerate the `index.html`
|
||||
reload_html = true
|
||||
|
||||
# Which files or dirs will be monitored
|
||||
watch_path = ["src", "public"]
|
||||
|
||||
# Include style or script assets
|
||||
[web.resource]
|
||||
|
||||
# CSS style file
|
||||
style = []
|
||||
|
||||
# Javascript code file
|
||||
script = []
|
||||
|
||||
[web.resource.dev]
|
||||
|
||||
# Same as [web.resource], but for development servers
|
||||
|
||||
# CSS style file
|
||||
style = []
|
||||
|
||||
# JavaScript files
|
||||
script = []
|
||||
|
||||
[[web.proxy]]
|
||||
backend = "http://localhost:8000/api/"
|
||||
```
|
||||
@@ -1,37 +0,0 @@
|
||||
# Create a Project
|
||||
|
||||
Once you have the Dioxus CLI installed, you can use it to create your own project!
|
||||
|
||||
## Initializing a default project
|
||||
|
||||
First, run the `dx create` command to create a new project:
|
||||
```
|
||||
dx create hello-dioxus
|
||||
```
|
||||
|
||||
> It will clone this [template](https://github.com/DioxusLabs/dioxus-template).
|
||||
> This default template is used for `web` platform application.
|
||||
>
|
||||
> You can choose to create your project from a different template by passing the `template` argument:
|
||||
> ```
|
||||
> dx init hello-dioxus --template=gh:dioxuslabs/dioxus-template
|
||||
> ```
|
||||
|
||||
Next, navigate into your new project:
|
||||
|
||||
```
|
||||
cd hello-dioxus
|
||||
```
|
||||
|
||||
> Make sure the WASM target is installed before running the projects.
|
||||
> You can install the WASM target for rust using rustup:
|
||||
> ```
|
||||
> rustup target add wasm32-unknown-unknown
|
||||
> ```
|
||||
|
||||
Finally, serve your project:
|
||||
```
|
||||
dx serve
|
||||
```
|
||||
|
||||
By default, the CLI serves your website at [`http://127.0.0.1:8080/`](http://127.0.0.1:8080/).
|
||||
@@ -1,23 +0,0 @@
|
||||
# Installation
|
||||
|
||||
## Install the latest development build through git
|
||||
|
||||
To get the latest bug fixes and features, you can install the development version from git.
|
||||
|
||||
```
|
||||
cargo install --git https://github.com/Dioxuslabs/cli
|
||||
```
|
||||
|
||||
This will download `Dioxus-CLI` source from GitHub master branch,
|
||||
and install it in Cargo's global binary directory (`~/.cargo/bin/` by default).
|
||||
|
||||
## Install stable through `crates.io`
|
||||
|
||||
The published version of the Dioxus CLI is updated less often, but is more stable than the git version.
|
||||
|
||||
```
|
||||
cargo install dioxus-cli --locked
|
||||
```
|
||||
|
||||
Run `dx --help` for a list of all the available commands.
|
||||
Furthermore, you can run `dx <COMMAND> --help` to get help with a specific command.
|
||||
@@ -1,18 +0,0 @@
|
||||
# Introduction
|
||||
|
||||
The 📦✨ **Dioxus CLI** is a tool to help get Dioxus projects off the ground.
|
||||
|
||||
## Features
|
||||
|
||||
* Build and pack a Dioxus project
|
||||
* `html` to `rsx` conversion tool
|
||||
* Hot Reload for `web` platform
|
||||
* Create a Dioxus project from `git` repo
|
||||
* And more!
|
||||
<!-- Checkmarks don't render on the website, so I've just made a normal list. You can uncomment this if the website rendering is fixed.
|
||||
- [x] `html` to `rsx` conversion tool
|
||||
- [x] Hot Reload for `web` platform
|
||||
- [x] Create a Dioxus project from `git` repo
|
||||
- [x] Build & pack Dioxus project
|
||||
- [ ] Automatically format Dioxus `rsx` code
|
||||
-->
|
||||
@@ -1,140 +0,0 @@
|
||||
# CLI Plugin development
|
||||
|
||||
**IMPORTANT: Ignore this documentation. Plugins are yet to be released and chances are it won't work for you. This is just what plugins *could* look like.**
|
||||
|
||||
In the past we used `dx tool` to use and install tools, but it was a flawed system.
|
||||
Tools were hard-coded by us, but people want more tools than we could code, so this plugin system was made to let
|
||||
anyone develop plugins and use them in Dioxus projects.
|
||||
|
||||
Plugin resources:
|
||||
* [Source code](https://github.com/DioxusLabs/dioxus/tree/master/packages/cli/src/plugin)
|
||||
* [Unofficial Dioxus plugin community](https://github.com/DioxusPluginCommunity). Contains certain plugins you can use right now.
|
||||
|
||||
### Why Lua?
|
||||
|
||||
We chose Lua `5.4` to be the plugin developing language,
|
||||
because it's extremely lightweight, embeddable and easy to learn.
|
||||
We installed Lua into the CLI, so you don't need to do it yourself.
|
||||
|
||||
Lua resources:
|
||||
* [Official website](https://www.lua.org/). You can basically find everything here.
|
||||
* [Awesome Lua](https://github.com/LewisJEllis/awesome-lua). Additional resources (such as Lua plugins for your favorite IDE), and other *awesome* tools!
|
||||
|
||||
|
||||
## Creating a plugin
|
||||
|
||||
A plugin is just an `init.lua` file.
|
||||
You can include other files using `dofile(path)`.
|
||||
You need to have a plugin and a manager instance, which you can get using `require`:
|
||||
```lua
|
||||
local plugin = require("plugin")
|
||||
local manager = require("manager")
|
||||
```
|
||||
|
||||
You need to set some `manager` fields and then initialize the plugin:
|
||||
```lua
|
||||
manager.name = "My first plugin"
|
||||
manager.repository = "https://github.com/john-doe/my-first-plugin" -- The repository URL.
|
||||
manager.author = "John Doe <john.doe@example.com>"
|
||||
manager.version = "0.1.0"
|
||||
plugin.init(manager)
|
||||
```
|
||||
|
||||
You also need to return the `manager`, which basically represents your plugin:
|
||||
```lua
|
||||
-- Your code here.
|
||||
-- End of file.
|
||||
|
||||
manager.serve.interval = 1000
|
||||
return manager
|
||||
```
|
||||
|
||||
And you're ready to go. Now, go and have a look at the stuff below and the API documentation.
|
||||
|
||||
### Plugin info
|
||||
|
||||
You will encounter this type in the events below. The keys are as follows:
|
||||
* `name: string` - The name of the plugin.
|
||||
* `repository: string` - The plugin repository URL.
|
||||
* `author: string` - The author of the plugin.
|
||||
* `version: string` - The plugin version.
|
||||
|
||||
### Event management
|
||||
|
||||
The plugin library has certain events that you can subscribe to.
|
||||
|
||||
* `manager.on_init` - Triggers the first time the plugin is loaded.
|
||||
* `manager.build.on_start(info)` - Triggers before the build process. E.g., before `dx build`.
|
||||
* `manager.build.on_finish(info)` - Triggers after the build process. E.g., after `dx build`.
|
||||
* `manager.serve.on_start(info)` - Triggers before the serving process. E.g., before `dx serve`.
|
||||
* `manager.serve.on_rebuild_start(info)` - Triggers before the server rebuilds the web with hot reload.
|
||||
* `manager.serve.on_rebuild_end(info)` - Triggers after the server rebuilds the web with hot reload.
|
||||
* `manager.serve.on_shutdown` - Triggers when the server is shutdown. E.g., when the `dx serve` process is terminated.
|
||||
|
||||
To subscribe to an event, you simply need to assign it to a function:
|
||||
|
||||
```lua
|
||||
manager.build.on_start = function (info)
|
||||
log.info("[plugin] Build starting: " .. info.name)
|
||||
end
|
||||
```
|
||||
|
||||
### Plugin template
|
||||
|
||||
```lua
|
||||
package.path = library_dir .. "/?.lua"
|
||||
|
||||
local plugin = require("plugin")
|
||||
local manager = require("manager")
|
||||
|
||||
-- deconstruct api functions
|
||||
local log = plugin.log
|
||||
|
||||
-- plugin information
|
||||
manager.name = "Hello Dixous Plugin"
|
||||
manager.repository = "https://github.com/mrxiaozhuox/hello-dioxus-plugin"
|
||||
manager.author = "YuKun Liu <mrxzx.info@gmail.com>"
|
||||
manager.version = "0.0.1"
|
||||
|
||||
-- init manager info to plugin api
|
||||
plugin.init(manager)
|
||||
|
||||
manager.on_init = function ()
|
||||
-- when the first time plugin been load, this function will be execute.
|
||||
-- system will create a `dcp.json` file to verify init state.
|
||||
log.info("[plugin] Start to init plugin: " .. manager.name)
|
||||
end
|
||||
|
||||
---@param info BuildInfo
|
||||
manager.build.on_start = function (info)
|
||||
-- before the build work start, system will execute this function.
|
||||
log.info("[plugin] Build starting: " .. info.name)
|
||||
end
|
||||
|
||||
---@param info BuildInfo
|
||||
manager.build.on_finish = function (info)
|
||||
-- when the build work is done, system will execute this function.
|
||||
log.info("[plugin] Build finished: " .. info.name)
|
||||
end
|
||||
|
||||
---@param info ServeStartInfo
|
||||
manager.serve.on_start = function (info)
|
||||
-- this function will after clean & print to run, so you can print some thing.
|
||||
log.info("[plugin] Serve start: " .. info.name)
|
||||
end
|
||||
|
||||
---@param info ServeRebuildInfo
|
||||
manager.serve.on_rebuild = function (info)
|
||||
-- this function will after clean & print to run, so you can print some thing.
|
||||
local files = plugin.tool.dump(info.changed_files)
|
||||
log.info("[plugin] Serve rebuild: '" .. files .. "'")
|
||||
end
|
||||
|
||||
manager.serve.on_shutdown = function ()
|
||||
log.info("[plugin] Serve shutdown")
|
||||
end
|
||||
|
||||
manager.serve.interval = 1000
|
||||
|
||||
return manager
|
||||
```
|
||||
@@ -1,21 +0,0 @@
|
||||
# Command Functions
|
||||
|
||||
You can use command functions to execute code and scripts.
|
||||
|
||||
Type definition:
|
||||
```
|
||||
Stdio: "Inherit" | "Piped" | "Null"
|
||||
```
|
||||
|
||||
### `exec(commands: [string], stdout: Stdio, stderr: Stdio)`
|
||||
|
||||
You can use this function to run some commands on the current system.
|
||||
|
||||
```lua
|
||||
local cmd = plugin.command
|
||||
|
||||
manager.test = function ()
|
||||
cmd.exec({"git", "clone", "https://github.com/DioxusLabs/cli-plugin-library"})
|
||||
end
|
||||
```
|
||||
> Warning: This function doesn't catch exceptions.
|
||||
@@ -1,30 +0,0 @@
|
||||
# Dirs Functions
|
||||
|
||||
Dirs functions are for getting various directory paths. Not to be confused with `plugin.path`.
|
||||
|
||||
### `plugin_dir() -> string`
|
||||
|
||||
Get the plugin's root directory path.
|
||||
|
||||
```lua
|
||||
local path = plugin.dirs.plugin_dir()
|
||||
-- example: ~/Development/DioxusCli/plugin/test-plugin/
|
||||
```
|
||||
|
||||
### `bin_dir() -> string`
|
||||
|
||||
Get the plugin's binary directory path. Put binary files like `tailwind-cli` or `sass-cli` in this directory.
|
||||
|
||||
```lua
|
||||
local path = plugin.dirs.bin_dir()
|
||||
-- example: ~/Development/DioxusCli/plugin/test-plugin/bin/
|
||||
```
|
||||
|
||||
### `temp_dir() -> string`
|
||||
|
||||
Get the plugin's temporary directory path. Put any temporary files here.
|
||||
|
||||
```lua
|
||||
local path = plugin.dirs.bin_dir()
|
||||
-- example: ~/Development/DioxusCli/plugin/test-plugin/temp/
|
||||
```
|
||||
@@ -1,48 +0,0 @@
|
||||
# Log Functions
|
||||
|
||||
You can use log functions to print various logging information.
|
||||
|
||||
### `trace(info: string)`
|
||||
|
||||
Print trace log info.
|
||||
|
||||
```lua
|
||||
local log = plugin.log
|
||||
log.trace("trace information")
|
||||
```
|
||||
|
||||
### `debug(info: string)`
|
||||
|
||||
Print debug log info.
|
||||
|
||||
```lua
|
||||
local log = plugin.log
|
||||
log.debug("debug information")
|
||||
```
|
||||
|
||||
### `info(info: string)`
|
||||
|
||||
Print info log info.
|
||||
|
||||
```lua
|
||||
local log = plugin.log
|
||||
log.info("info information")
|
||||
```
|
||||
|
||||
### `warn(info: string)`
|
||||
|
||||
Print warning log info.
|
||||
|
||||
```lua
|
||||
local log = plugin.log
|
||||
log.warn("warn information")
|
||||
```
|
||||
|
||||
### `error(info: string)`
|
||||
|
||||
Print error log info.
|
||||
|
||||
```lua
|
||||
local log = plugin.log
|
||||
log.error("error information")
|
||||
```
|
||||
@@ -1,37 +0,0 @@
|
||||
# Network Functions
|
||||
|
||||
You can use Network functions to download & read some data from the internet.
|
||||
|
||||
### `download_file(url: string, path: string) -> boolean`
|
||||
|
||||
Downloads a file from the specified URL,
|
||||
and returns a `boolean` that represents the download status (true: success, false: failure).
|
||||
|
||||
You need to pass a target URL and a local path (where you want to save this file).
|
||||
|
||||
```lua
|
||||
-- this file will download to plugin temp directory
|
||||
local status = plugin.network.download_file(
|
||||
"http://xxx.com/xxx.zip",
|
||||
plugin.dirs.temp_dir()
|
||||
)
|
||||
if status != true then
|
||||
log.error("Download Failed")
|
||||
end
|
||||
```
|
||||
|
||||
### `clone_repo(url: string, path: string) -> boolean`
|
||||
|
||||
Clone a repository from the given URL into the given path.
|
||||
Returns a `boolean` that represents the clone status (true: success, false: failure).
|
||||
The system executing this function must have git installed.
|
||||
|
||||
```lua
|
||||
local status = plugin.network.clone_repo(
|
||||
"http://github.com/mrxiaozhuox/dioxus-starter",
|
||||
plugin.dirs.bin_dir()
|
||||
)
|
||||
if status != true then
|
||||
log.error("Clone Failed")
|
||||
end
|
||||
```
|
||||
@@ -1,11 +0,0 @@
|
||||
# OS Functions
|
||||
|
||||
OS functions are for getting system information.
|
||||
|
||||
### `current_platform() -> string ("windows" | "macos" | "linux")`
|
||||
|
||||
Get the current OS platform.
|
||||
|
||||
```lua
|
||||
local platform = plugin.os.current_platform()
|
||||
```
|
||||
@@ -1,38 +0,0 @@
|
||||
# Path Functions
|
||||
|
||||
You can use path functions to perform operations on valid path strings.
|
||||
|
||||
### `join(path: string, extra: string) -> string`
|
||||
|
||||
<!-- TODO: Add specifics.
|
||||
From the example given, it seems like it just creates a subdirectory path.
|
||||
What would it do when "extending" file paths? -->
|
||||
Extend a path; you can extend both directory and file paths.
|
||||
|
||||
```lua
|
||||
local current_path = "~/hello/dioxus"
|
||||
local new_path = plugin.path.join(current_path, "world")
|
||||
-- new_path = "~/hello/dioxus/world"
|
||||
```
|
||||
|
||||
### `parent(path: string) -> string`
|
||||
|
||||
Return the parent path of the specified path. The parent path is always a directory.
|
||||
|
||||
```lua
|
||||
local current_path = "~/hello/dioxus"
|
||||
local new_path = plugin.path.parent(current_path)
|
||||
-- new_path = "~/hello/"
|
||||
```
|
||||
|
||||
### `exists(path: string) -> boolean`
|
||||
|
||||
Check if the specified path exists, as either a file or a directory.
|
||||
|
||||
### `is_file(path: string) -> boolean`
|
||||
|
||||
Check if the specified path is a file.
|
||||
|
||||
### `is_dir(path: string) -> boolean`
|
||||
|
||||
Check if the specified path is a directory.
|
||||
Whitespace-only changes.
@@ -1,18 +0,0 @@
|
||||
local Api = require("./interface")
|
||||
local log = Api.log;
|
||||
|
||||
local manager = {
|
||||
name = "Dioxus-CLI Plugin Demo",
|
||||
repository = "http://github.com/DioxusLabs/cli",
|
||||
author = "YuKun Liu <mrxzx.info@gmail.com>",
|
||||
}
|
||||
|
||||
manager.onLoad = function ()
|
||||
log.info("plugin loaded.")
|
||||
end
|
||||
|
||||
manager.onStartBuild = function ()
|
||||
log.warn("system start to build")
|
||||
end
|
||||
|
||||
return manager
|
||||
@@ -1,25 +0,0 @@
|
||||
local interface = {}
|
||||
|
||||
if plugin_logger ~= nil then
|
||||
interface.log = plugin_logger
|
||||
else
|
||||
interface.log = {
|
||||
trace = function (info)
|
||||
print("trace: " .. info)
|
||||
end,
|
||||
debug = function (info)
|
||||
print("debug: " .. info)
|
||||
end,
|
||||
info = function (info)
|
||||
print("info: " .. info)
|
||||
end,
|
||||
warn = function (info)
|
||||
print("warn: " .. info)
|
||||
end,
|
||||
error = function (info)
|
||||
print("error: " .. info)
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
return interface
|
||||
@@ -23,7 +23,7 @@ title = "Dioxus | An elegant GUI library for Rust"
|
||||
|
||||
index_on_404 = true
|
||||
|
||||
watch_path = ["src"]
|
||||
watch_path = ["src", "examples"]
|
||||
|
||||
# include `assets` in web platform
|
||||
[web.resource]
|
||||
|
||||
@@ -254,6 +254,7 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResul
|
||||
let mut cmd = subprocess::Exec::cmd("cargo")
|
||||
.cwd(&config.crate_dir)
|
||||
.arg("build")
|
||||
.arg("--quiet")
|
||||
.arg("--message-format=json");
|
||||
|
||||
if config.release {
|
||||
@@ -312,7 +313,7 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResul
|
||||
if !config.out_dir.is_dir() {
|
||||
create_dir_all(&config.out_dir)?;
|
||||
}
|
||||
copy(res_path, &config.out_dir.join(target_file))?;
|
||||
copy(res_path, config.out_dir.join(target_file))?;
|
||||
|
||||
// this code will copy all public file to the output dir
|
||||
if config.asset_dir.is_dir() {
|
||||
@@ -436,14 +437,14 @@ pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
|
||||
String::from(include_str!("./assets/index.html"))
|
||||
};
|
||||
|
||||
let resouces = config.web.resource.clone();
|
||||
let resources = config.web.resource.clone();
|
||||
|
||||
let mut style_list = resouces.style.unwrap_or_default();
|
||||
let mut script_list = resouces.script.unwrap_or_default();
|
||||
let mut style_list = resources.style.unwrap_or_default();
|
||||
let mut script_list = resources.script.unwrap_or_default();
|
||||
|
||||
if serve {
|
||||
let mut dev_style = resouces.dev.style.clone();
|
||||
let mut dev_script = resouces.dev.script;
|
||||
let mut dev_script = resouces.dev.script.clone();
|
||||
style_list.append(&mut dev_style);
|
||||
script_list.append(&mut dev_script);
|
||||
}
|
||||
@@ -671,35 +672,3 @@ fn build_assets(config: &CrateConfig) -> Result<Vec<PathBuf>> {
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
// use binary_install::{Cache, Download};
|
||||
|
||||
// /// Attempts to find `wasm-opt` in `PATH` locally, or failing that downloads a
|
||||
// /// precompiled binary.
|
||||
// ///
|
||||
// /// Returns `Some` if a binary was found or it was successfully downloaded.
|
||||
// /// Returns `None` if a binary wasn't found in `PATH` and this platform doesn't
|
||||
// /// have precompiled binaries. Returns an error if we failed to download the
|
||||
// /// binary.
|
||||
// pub fn find_wasm_opt(
|
||||
// cache: &Cache,
|
||||
// install_permitted: bool,
|
||||
// ) -> Result<install::Status, failure::Error> {
|
||||
// // First attempt to look up in PATH. If found assume it works.
|
||||
// if let Ok(path) = which::which("wasm-opt") {
|
||||
// PBAR.info(&format!("found wasm-opt at {:?}", path));
|
||||
|
||||
// match path.as_path().parent() {
|
||||
// Some(path) => return Ok(install::Status::Found(Download::at(path))),
|
||||
// None => {}
|
||||
// }
|
||||
// }
|
||||
|
||||
// let version = "version_78";
|
||||
// Ok(install::download_prebuilt(
|
||||
// &install::Tool::WasmOpt,
|
||||
// cache,
|
||||
// version,
|
||||
// install_permitted,
|
||||
// )?)
|
||||
// }
|
||||
@@ -46,18 +46,28 @@ impl Autoformat {
|
||||
|
||||
// Format single file
|
||||
if let Some(file) = self.file {
|
||||
let file_content = fs::read_to_string(&file);
|
||||
let file_content = if file == "-" {
|
||||
let mut contents = String::new();
|
||||
std::io::stdin().read_to_string(&mut contents)?;
|
||||
Ok(contents)
|
||||
} else {
|
||||
fs::read_to_string(&file)
|
||||
};
|
||||
|
||||
match file_content {
|
||||
Ok(s) => {
|
||||
let edits = dioxus_autofmt::fmt_file(&s);
|
||||
let out = dioxus_autofmt::apply_formats(&s, edits);
|
||||
match fs::write(&file, out) {
|
||||
Ok(_) => {
|
||||
println!("formatted {}", file);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("failed to write formatted content to file: {}", e);
|
||||
if file == "-" {
|
||||
print!("{}", out);
|
||||
} else {
|
||||
match fs::write(&file, out) {
|
||||
Ok(_) => {
|
||||
println!("formatted {}", file);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("failed to write formatted content to file: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,10 +132,10 @@ impl Bundle {
|
||||
.project_out_directory(crate_config.out_dir)
|
||||
.package_settings(PackageSettings {
|
||||
product_name: crate_config.dioxus_config.application.name.clone(),
|
||||
version: package.version,
|
||||
description: package.description.unwrap_or_default(),
|
||||
homepage: package.homepage,
|
||||
authors: Some(package.authors),
|
||||
version: package.version().to_string(),
|
||||
description: package.description().unwrap_or_default().to_string(),
|
||||
homepage: Some(package.homepage().unwrap_or_default().to_string()),
|
||||
authors: Some(Vec::from(package.authors())),
|
||||
default_run: Some(crate_config.dioxus_config.application.name.clone()),
|
||||
})
|
||||
.binaries(binaries)
|
||||
|
||||
@@ -216,7 +216,7 @@ pub struct WebWatcherConfig {
|
||||
}
|
||||
|
||||
fn watch_path_default() -> Vec<PathBuf> {
|
||||
vec![PathBuf::from("src")]
|
||||
vec![PathBuf::from("src"), PathBuf::from("examples")]
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#![doc = include_str!("../README.md")]
|
||||
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
|
||||
#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
|
||||
|
||||
pub const DIOXUS_CLI_VERSION: &str = "0.4.1";
|
||||
|
||||
pub mod builder;
|
||||
|
||||
@@ -124,27 +124,34 @@ async fn start_desktop_hot_reload(hot_reload_state: HotReloadState) -> Result<()
|
||||
let _ = local_socket_stream.set_nonblocking(true);
|
||||
move || {
|
||||
loop {
|
||||
if let Ok(mut connection) = local_socket_stream.accept() {
|
||||
// send any templates than have changed before the socket connected
|
||||
let templates: Vec<_> = {
|
||||
file_map
|
||||
.lock()
|
||||
.unwrap()
|
||||
.map
|
||||
.values()
|
||||
.filter_map(|(_, template_slot)| *template_slot)
|
||||
.collect()
|
||||
};
|
||||
for template in templates {
|
||||
if !send_msg(
|
||||
HotReloadMsg::UpdateTemplate(template),
|
||||
&mut connection,
|
||||
) {
|
||||
continue;
|
||||
match local_socket_stream.accept() {
|
||||
Ok(mut connection) => {
|
||||
// send any templates than have changed before the socket connected
|
||||
let templates: Vec<_> = {
|
||||
file_map
|
||||
.lock()
|
||||
.unwrap()
|
||||
.map
|
||||
.values()
|
||||
.filter_map(|(_, template_slot)| *template_slot)
|
||||
.collect()
|
||||
};
|
||||
for template in templates {
|
||||
if !send_msg(
|
||||
HotReloadMsg::UpdateTemplate(template),
|
||||
&mut connection,
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
channels.lock().unwrap().push(connection);
|
||||
println!("Connected to hot reloading 🚀");
|
||||
}
|
||||
Err(err) => {
|
||||
if err.kind() != std::io::ErrorKind::WouldBlock {
|
||||
println!("Error connecting to hot reloading: {} (Hot reloading is a feature of the dioxus-cli. If you are not using the CLI, this error can be ignored)", err);
|
||||
}
|
||||
}
|
||||
channels.lock().unwrap().push(connection);
|
||||
println!("Connected to hot reloading 🚀");
|
||||
}
|
||||
if *aborted.lock().unwrap() {
|
||||
break;
|
||||
|
||||
@@ -112,12 +112,12 @@ async fn setup_file_watcher<F: Fn() -> Result<BuildResult> + Send + 'static>(
|
||||
.unwrap();
|
||||
|
||||
for sub_path in allow_watch_path {
|
||||
watcher
|
||||
.watch(
|
||||
&config.crate_dir.join(sub_path),
|
||||
notify::RecursiveMode::Recursive,
|
||||
)
|
||||
.unwrap();
|
||||
if let Err(err) = watcher.watch(
|
||||
&config.crate_dir.join(sub_path),
|
||||
notify::RecursiveMode::Recursive,
|
||||
) {
|
||||
log::error!("Failed to watch path: {}", err);
|
||||
}
|
||||
}
|
||||
Ok(watcher)
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ pub fn print_console_info(
|
||||
log::warn!(
|
||||
"{}",
|
||||
format!(
|
||||
"There were {} warning messages during the build.",
|
||||
"There were {} warning messages during the build. Run `cargo check` to see them.",
|
||||
options.warnings.len() - 1
|
||||
)
|
||||
.yellow()
|
||||
|
||||
Reference in new issue
Block a user