PMS Basic Update
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Andrey Tkachenko 2022-03-28 17:19:23 +04:00
parent 0325be4ddc
commit 47f8b48407
12 changed files with 446 additions and 1 deletions

13
.drone.yml Normal file
View File

@ -0,0 +1,13 @@
kind: pipeline
name: default
steps:
- name: build
image: hub.aidev.ru/rust
commands:
- cargo build --verbose --all
- name: fmt-check
image: hub.aidev.ru/rust
commands:
- cargo fmt --all -- --check

View File

@ -10,3 +10,9 @@ name = "wplug"
path = "./bin/wplug.rs" path = "./bin/wplug.rs"
[dependencies] [dependencies]
clap = {version = "3.1.6", features = ["derive"]}
serde = "1.0.136"
serde_derive = "1.0.136"
slab = "0.4.5"
thiserror = "1.0.30"
toml = "0.5.8"

View File

@ -6,3 +6,5 @@ Create and manage `wplug` packages:
- create packages - create packages
- verify - verify
- upload to registry - upload to registry

View File

@ -1,6 +1,25 @@
use clap::{Parser, Subcommand};
#[derive(Debug, Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(propagate_version = true)]
pub struct Args {
#[clap(subcommand)]
cmd: ArgsCoommans,
}
#[derive(Debug, Subcommand)]
pub enum ArgsCoommans {
Info,
List,
Search { query: String },
Publish,
Login,
Add { name: String },
Remove { name: String },
Update,
}
pub fn main() { pub fn main() {
println!("{:?}", Args::parse());
} }

35
src/catalog.rs Normal file
View File

@ -0,0 +1,35 @@
use serde_derive::{Deserialize, Serialize};
use crate::{metadata::PluginMetadata, Error, PluginId, PluginLink};
#[derive(Debug, Clone, Deserialize)]
pub struct PluginSearchResult {
items: Vec<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct PluginSearchQuery {
pub title: String,
pub keywords: String,
pub categories: Vec<String>,
}
pub struct PluginCatalog {}
impl PluginCatalog {
pub fn new() -> Self {
Self {}
}
pub async fn search_plugin(
&self,
query: PluginSearchQuery,
) -> Result<PluginSearchResult, Error> {
unimplemented!()
}
pub async fn plugin_metadata(&self, plugin_id: PluginId) -> Result<PluginMetadata, Error> {
unimplemented!()
}
pub async fn plugin_link(&self) -> Result<PluginLink, Error> {
unimplemented!()
}
}

7
src/error.rs Normal file
View File

@ -0,0 +1,7 @@
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("test")]
Variant1,
}

View File

@ -1,4 +1,83 @@
mod catalog;
mod error;
mod metadata;
mod plugin;
use std::{collections::HashMap, sync::Arc};
pub use catalog::{PluginCatalog, PluginSearchQuery};
pub use error::Error;
use metadata::PluginMetadata;
pub use plugin::Plugin;
use serde_derive::Deserialize;
use slab::Slab;
use toml::Value;
pub type PluginId = u64;
#[derive(Debug, Clone, Deserialize)]
pub enum PluginState {
Running,
Failed,
Unloaded,
Updating,
Disabled,
}
#[derive(Debug, Clone, Deserialize)]
pub enum PluginLink {
GitRepo(String),
Url(String),
}
#[derive(Debug, Clone, Deserialize)]
pub struct PluginDescription {
metadata: PluginMetadata,
state: PluginState,
}
pub struct PluginManager {
options: HashMap<(PluginId, String), Value>,
plugins: Slab<Plugin>,
}
impl PluginManager {
pub fn new() -> Self {
Self {
options: Default::default(),
plugins: Default::default(),
}
}
pub async fn start() {}
pub fn plugin_list(&self) -> Vec<Arc<PluginDescription>> {
vec![]
}
pub async fn update_plugin_option() {}
pub async fn send_message() {}
pub async fn request() {}
// Plugin Management
pub async fn install_plugin() {}
pub async fn uninstall_plugin() {}
pub async fn download_plugin(&self, link: PluginLink) -> Result<(), Error> {
Ok(())
}
pub async fn disable_plugin() {}
// Plugin Runtime
pub async fn reset_plugin() {}
pub async fn load_plugin() {}
pub async fn unload_plugin() {}
}

221
src/metadata.rs Normal file
View File

@ -0,0 +1,221 @@
use std::collections::HashMap;
use serde_derive::Deserialize;
use toml::Value;
///
///
///
#[derive(Debug, Clone, Deserialize)]
pub struct PluginMetadataHook {
entry: String,
}
///
///
///
#[derive(Debug, Clone, Deserialize)]
pub struct PluginMetadataExportArgument {
name: String,
#[serde(rename = "type")]
ty: String,
default: Option<Value>,
required: bool,
}
///
/// Plugin Export Definition
///
#[derive(Debug, Clone, Deserialize)]
pub struct PluginMetadataExport {
name: String,
args: Vec<PluginMetadataExportArgument>,
entry: String,
}
///
/// Plugin Export Key Mapping
///
#[derive(Debug, Clone, Deserialize)]
pub struct PluginMetadataExportKeyMapping {
entry: String,
args: Vec<PluginMetadataExportArgument>,
mapping: String,
}
///
/// Plugin Metadata Dependency
///
#[derive(Debug, Clone, Deserialize)]
pub struct PluginMetadataDependency {
///
/// Dependecy name
name: String,
///
/// Version match pattern
version: Option<String>,
///
/// Git repository url
git: Option<String>,
///
/// Branch name in case of git repository url set
branch: Option<String>,
///
/// Revision number in case of git repository url set
rev: Option<String>,
///
/// Path in case package is in file system
path: Option<String>,
}
///
/// Plugin Metadata Configuration Option
///
///
#[derive(Debug, Clone, Deserialize)]
pub struct PluginMetadataOption {
///
/// Option name
///
name: String,
///
/// Value Type
///
#[serde(rename = "type")]
ty: String,
///
/// Description
///
description: Option<String>,
///
/// Option default value
///
default: Option<Value>,
///
/// Option required flag
required: bool,
}
///
/// Plugin Metadata
///
#[derive(Debug, Clone, Deserialize)]
pub struct PluginMetadata {
///
/// Plugin name
///
name: String,
///
/// Plugin version signature
///
version: String,
///
/// Licence
///
licence: String,
///
/// Title
///
title: String,
///
/// Description
///
description: String,
///
/// List of plugin's authors
///
authors: Vec<String>,
///
/// Plugin documentation URL
///
documentation: String,
///
/// Plugin homepage URL
///
homepage: String,
///
/// Plugin repository URL
///
repository: String,
///
/// Plugin keywords for search optiomization
///
keywords: Vec<String>,
///
/// API set pluging is using
/// - if plugin uses only editor api (i.e. cursor or buffer content) it should be installed
/// locally
/// - if plugin needs to run commands or acces to fs - so it should be installed remotly
///
api_version: String,
///
/// List of categories the plugin is related to
///
categories: String,
///
/// Resources to include to publishing package
///
include: Vec<String>,
///
/// Files or folders to exclude from publishing the plugin
///
exclude: Vec<String>,
///
/// Plugin dependencies
///
dependencies: Vec<PluginMetadataDependency>,
///
/// Configuration options for the plugin
///
options: Vec<PluginMetadataOption>,
///
/// Plugin event hooks
///
hooks: HashMap<String, PluginMetadataHook>,
///
/// Plugin Exports
///
exports: Vec<PluginMetadataExport>,
///
/// Key Mapping Exports
///
export_key_mappings: Vec<PluginMetadataExportKeyMapping>,
///
/// Assets
/// - binary: Wasm Binary
/// - tree-sitter: tree-sitter plugin
/// - theme: App theme styles
/// - icons: icon pack
/// - syntax: Syntax theme colors
/// - readme: Readme file
///
assets: HashMap<String, String>,
}

43
src/plugin.rs Normal file
View File

@ -0,0 +1,43 @@
use std::{collections::HashMap, sync::Arc};
use toml::Value;
use crate::{metadata::PluginMetadata, Error};
pub struct PluginApiInfo {}
pub struct PluginInfo {
pub api: PluginApiInfo,
pub options: HashMap<String, Value>,
}
pub struct Plugin {
metadata: Arc<PluginMetadata>,
}
impl Plugin {
pub fn metadata(&self) -> Result<PluginMetadata, Error> {
unimplemented!()
}
pub fn enumerate_callables(&self) -> impl Iterator<Item = ()> {
vec![].into_iter()
}
// Plugin API
pub async fn initialize(&mut self) -> Result<(), Error> {
unimplemented!()
}
pub async fn destroy(&mut self) {}
pub async fn handle(&self, cmd_id: String, args: Vec<Value>) -> Result<Value, Error> {
unimplemented!()
}
}
pub struct PluginCall {
name: String,
args: Vec<Value>,
}

8
wplug_lib/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "wplug_lib"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

12
wplug_lib/src/core.rs Normal file
View File

@ -0,0 +1,12 @@
pub async fn api_call_async() {
}
pub fn api_call() {
}
pub fn host_info() {
}

0
wplug_lib/src/lib.rs Normal file
View File