Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
58 changes: 54 additions & 4 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ chrono = "^0"
anyhow = "1.0.57"
r2d2 = "0.8.9"
either = "1.6.1"
v8 = "0.44.2"
tokio = { version = "1.20.1", features = ["full"] }

4 changes: 2 additions & 2 deletions src/dev_server/dev_runner_api.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::dev_server::server::RunnerContext;
use crate::runner::script_exec_model::{save_script_entry, Pool};
use crate::runner::{pkg_json_utils, scripts_exec_utils, Configuration, Script, Scripts};
use actix_web::{get, post, web, Either, Error, HttpResponse};
use either::Left;
use serde::{Deserialize, Serialize};
use std::sync::RwLock;
use either::Left;
use crate::dev_server::server::RunnerContext;

// POST: url: /set-runnable-project, payload: { path: string }
// DELETE: url: /remove-runnable-project, payload: { path: string }
Expand Down
2 changes: 1 addition & 1 deletion src/dev_server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub(crate) mod server;
pub mod dev_runner_api;
pub(crate) mod server;
6 changes: 3 additions & 3 deletions src/dev_server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub async fn start() -> std::io::Result<()> {
.wrap(cors())
.wrap(Logger::default())
})
.bind(format!("{}:{}", host, port))?
.run()
.await
.bind(format!("{}:{}", host, port))?
.run()
.await
}
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#[macro_use]
extern crate diesel;

use crate::v8::js_run;

mod cli;
mod dev_server;
mod runner;
mod schema;
mod dev_server;
mod v8;

#[actix_web::main]
async fn main() -> std::io::Result<()> {
// js_run("/Users/lironh_1/dev-liron/dev-runner/dev-runner/src/v8/foo.js".to_string()).await;
// Ok(())
dev_server::server::start().await
}

2 changes: 1 addition & 1 deletion src/runner/pkg_json_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ pub fn extract_scripts(projects: Vec<String>) -> Vec<String> {
fn test_is_valid_path() {
let is_valid = is_valid_path("foo/bar");
assert_eq!(is_valid, false);
}
}
8 changes: 5 additions & 3 deletions src/runner/script_exec_model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use actix_web::web;
use crate::schema::scripts_exec_log;
use actix_web::web;
use chrono::Utc;
use diesel::prelude::*;
use diesel::{r2d2::ConnectionManager, PgConnection};
Expand All @@ -21,7 +21,10 @@ pub struct Script<'a> {
pub run_start: &'a chrono::NaiveDateTime,
}

pub fn save_script_entry(name: &str, either_conn: Either<web::Data<Pool>, PgConnection>) -> QueryResult<usize> {
pub fn save_script_entry(
name: &str,
either_conn: Either<web::Data<Pool>, PgConnection>,
) -> QueryResult<usize> {
println!("Creating script entry: {:?}", name);

let new_script = NewScript {
Expand All @@ -40,5 +43,4 @@ pub fn save_script_entry(name: &str, either_conn: Either<web::Data<Pool>, PgConn
.values(&new_script)
.execute(right)
}

}
2 changes: 1 addition & 1 deletion src/runner/scripts_exec_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn kill_by_id(id: &str) -> Child {
}

pub fn exec_scripts(command: &str, projects: Vec<String>) -> Option<HashMap<String, String>> {
//todo replace some with result to handle the projects count limitation error
//todo replace some with result to handle the projects count limitation error
if projects.len() > 4 || cfg!(target_os = "windows") {
return None;
};
Expand Down
1 change: 1 addition & 0 deletions src/v8/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1+2;
26 changes: 26 additions & 0 deletions src/v8/js_run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

async fn read_file(path: String) -> Result<String, anyhow::Error> {
Ok(tokio::fs::read_to_string(path).await?)
}

pub async fn js_run(path: String) {
let script = read_file(path).await.unwrap();
let platform = v8::new_default_platform(0, false).make_shared();
v8::V8::initialize_platform(platform);
v8::V8::initialize();

let isolate = &mut v8::Isolate::new(Default::default());

let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);

let code = v8::String::new(scope, script.as_str()).unwrap();
println!("javascript code: {}", code.to_rust_string_lossy(scope));

let script = v8::Script::compile(scope, code, None).unwrap();
let result = script.run(scope).unwrap();
let result = result.to_string(scope).unwrap();
println!("result: {}", result.to_rust_string_lossy(scope));
}

2 changes: 2 additions & 0 deletions src/v8/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) mod js_run;
pub use js_run::*;
3 changes: 3 additions & 0 deletions src/v8/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Experimental!!!

A try to run scripts on v8 isolate
Binary file added webapp/bun.lockb
Binary file not shown.