Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Add Plugin Support #57

Merged
merged 54 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c7d962f
fix: ignore `.DS_Store`
mrxiaozhuox Jul 24, 2022
09311ff
feat: add `plugin` mod
mrxiaozhuox Jul 24, 2022
ca8855b
feat: move `hot_reload` code
mrxiaozhuox Jul 24, 2022
bd2853a
feat: commit lua code
mrxiaozhuox Jul 25, 2022
d5afbef
feat: commit code
mrxiaozhuox Jul 25, 2022
ded8f86
feat: commit code
mrxiaozhuox Jul 26, 2022
a214330
fix: update wasm-bindgen version
mrxiaozhuox Jul 26, 2022
da53c67
feat: commit plugin interface
mrxiaozhuox Jul 27, 2022
99b300d
feat: commit code
mrxiaozhuox Jul 27, 2022
2065193
feat: commit code
mrxiaozhuox Jul 27, 2022
59acefa
feat: commit code
mrxiaozhuox Jul 28, 2022
3630224
feat: commit codee
mrxiaozhuox Jul 28, 2022
54dc593
feat: commit dirs library
mrxiaozhuox Jul 30, 2022
d13955e
feat: commit code
mrxiaozhuox Jul 31, 2022
2ad5c7e
feat: commit file download
mrxiaozhuox Aug 1, 2022
7609406
feat: commit version info
mrxiaozhuox Aug 1, 2022
f915a38
feat: commit plugin init
mrxiaozhuox Aug 2, 2022
d850630
feat: commit generate info
mrxiaozhuox Aug 2, 2022
b28043a
feat: commit `unzip_file` function
mrxiaozhuox Aug 13, 2022
6f4028f
feat: make new plugin api
mrxiaozhuox Aug 15, 2022
d9891d9
feat: commit `build` field
mrxiaozhuox Aug 18, 2022
0e8414b
Merge branch 'master' into master
mrxiaozhuox Aug 18, 2022
6c1374e
feat: commit code
mrxiaozhuox Aug 22, 2022
062d0ea
feat: commit `serve` info
mrxiaozhuox Aug 23, 2022
6cce4b9
feat: commit code
mrxiaozhuox Aug 26, 2022
603aaa1
feat: plugin `serve` support
mrxiaozhuox Aug 27, 2022
1aaedab
Merge branch 'master' of https://github.com/mrxiaozhuox/dioxus-cli
mrxiaozhuox Aug 27, 2022
9f20337
feat: `rebuild` supported
mrxiaozhuox Aug 28, 2022
59b8a84
feat: commit code
mrxiaozhuox Aug 31, 2022
37ef7c3
feat: support some event
mrxiaozhuox Sep 21, 2022
f47d2d3
feat: empty manager check
mrxiaozhuox Sep 22, 2022
20c29ed
feat: add `serve-shutdown` support
mrxiaozhuox Sep 22, 2022
f099042
docs: commit new document
mrxiaozhuox Sep 22, 2022
d473195
docs: commit new document
mrxiaozhuox Sep 22, 2022
1c59c90
docs: commit docs
mrxiaozhuox Sep 22, 2022
b59e41e
fix: move `is_dir` & `is_file` to path
mrxiaozhuox Sep 23, 2022
e2852a6
feat: commit code
mrxiaozhuox Sep 23, 2022
9ee572a
docs: add path docs
mrxiaozhuox Sep 23, 2022
6004cfd
feat: add some command
mrxiaozhuox Sep 23, 2022
6ad1333
feat: commit code
mrxiaozhuox Sep 25, 2022
52e8d9f
Merge branch 'master' into master
mrxiaozhuox Sep 25, 2022
7620930
feat: commit code
mrxiaozhuox Sep 28, 2022
77393b2
feat: commit plugin error handle
mrxiaozhuox Oct 1, 2022
b3dcebc
feat: commit code
mrxiaozhuox Oct 3, 2022
5104f76
Merge branch 'master' of https://github.com/DioxusLabs/cli
mrxiaozhuox Oct 3, 2022
f238e43
feat: commit code
mrxiaozhuox Oct 7, 2022
cf9a951
feat: commit code
mrxiaozhuox Oct 9, 2022
e1497ac
feat: types
mrxiaozhuox Oct 11, 2022
96ebe74
feat: custom plugin config support
mrxiaozhuox Oct 11, 2022
0fe8e4b
fix: plugin init problem
mrxiaozhuox Oct 12, 2022
39e3891
feat: add api function
mrxiaozhuox Oct 12, 2022
ad1ed6c
Merge branch 'master' into master
mrxiaozhuox Nov 3, 2022
bbc9e1b
feat: default plugin info
mrxiaozhuox Nov 3, 2022
24249a7
feet: merged
mrxiaozhuox Nov 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .fleet/settings.json
Empty file.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
.idea/
.idea/

.DS_Store
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{}
{
"Lua.diagnostics.globals": [
"plugin_logger",
"PLUGIN_DOWNLOADER"
]
}
114 changes: 113 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ walkdir = "2"

# tools download
dirs = "4.0.0"
reqwest = { version = "0.11", features = ["rustls-tls", "stream", "trust-dns"] }
reqwest = { version = "0.11", features = ["rustls-tls", "stream", "trust-dns", "blocking"] }
flate2 = "1.0.22"
tar = "0.4.38"
zip = "0.6.2"
Expand All @@ -58,7 +58,11 @@ dioxus-core = { git = "https://github.com/dioxuslabs/dioxus/", features = ["hot-
dioxus-rsx = { git = "https://github.com/dioxuslabs/dioxus/", features = ["hot-reload"] }

proc-macro2 = { version = "1.0", features = ["span-locations"] }
lazy_static = "1.4.0"

# plugin packages
mlua = { version = "0.8.1", features = ["lua54", "vendored", "async", "send", "macros"] }
ctrlc = "3.2.3"

[[bin]]
path = "src/main.rs"
Expand Down
9 changes: 8 additions & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@
- [Build](./cmd/build.md)
- [Serve](./cmd/serve.md)
- [Clean](./cmd/clean.md)
- [Translate](./cmd/translate.md)
- [Translate](./cmd/translate.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)
79 changes: 79 additions & 0 deletions docs/src/plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# CLI Plugin Development

> For Cli 0.2.0 we will add `plugin-develop` support.

Before the 0.2.0 we use `dioxus tool` to use & install some plugin, but we think that is not good for extend cli program, some people want tailwind support, some people want sass support, we can't add all this thing in to the cli source code and we don't have time to maintain a lot of tools that user request, so maybe user make plugin by themself is a good choice.

### Why Lua ?

We choose `Lua: 5.4` to be the plugin develop language, because cli plugin is not complex, just like a workflow, and user & developer can write some easy code for their plugin. We have **vendored** lua in cli program, and user don't need install lua runtime in their computer, and the lua parser & runtime doesn't take up much disk memory.

### Event Management

The plugin library have pre-define some important event you can control:

- `build.on_start`
- `build.on_finished`
- `serve.on_start`
- `serve.on_rebuild`
- `serve.on_shutdown`

### 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
```
21 changes: 21 additions & 0 deletions docs/src/plugin/interface/command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Command Functions

> you can use command functions to execute some code & script

Type Define:
```
Stdio: "Inhert" | "Piped" | "Null"
```

### `exec(commands: [string], stdout: Stdio, stderr: Stdio)`

you can use this function to run some command 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 don't have exception catch.
35 changes: 35 additions & 0 deletions docs/src/plugin/interface/dirs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Dirs Functions

> you can use Dirs functions to get some directory path


### plugin_dir() -> string

You can get current plugin **root** directory path

```lua
local path = plugin.dirs.plugin_dir()
-- example: ~/Development/DioxusCli/plugin/test-plugin/
```

### bin_dir() -> string

You can get plugin **bin** direcotry path

Sometime you need install some binary file like `tailwind-cli` & `sass-cli` to help your plugin work, then you should put binary file in this directory.

```lua
local path = plugin.dirs.bin_dir()
-- example: ~/Development/DioxusCli/plugin/test-plugin/bin/
```

### temp_dir() -> string

You can get plugin **temp** direcotry path

Just put some temporary file in this directory.

```lua
local path = plugin.dirs.bin_dir()
-- example: ~/Development/DioxusCli/plugin/test-plugin/temp/
```
Loading