diff --git a/.gitignore b/.gitignore index 9927dcf26..cba07382e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ zig-cache/ zig-out/ # Build Artifacts +.out/ out/ dist/ target/ diff --git a/.moon/toolchain.yml b/.moon/toolchain.yml index d93129e3c..eae0a9a7b 100644 --- a/.moon/toolchain.yml +++ b/.moon/toolchain.yml @@ -6,4 +6,7 @@ bun: node: packageManager: bun -rust: {} \ No newline at end of file +rust: + bins: + - 'cargo-make@0.37.12' + - 'cargo-nextest' \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index eeefbee57..d01e122ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -964,6 +964,7 @@ version = "0.1.0" dependencies = [ "boa_engine", "deno_core", + "tokio", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b91eda452..3caa7f0ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,3 +21,5 @@ serde = "1.0.203" serde_json = "1.0.117" serde_v8 = "0.192.0" tokio = "1.10.0" + + diff --git a/apps/cli/Cargo.toml b/apps/cli/Cargo.toml new file mode 100644 index 000000000..8abf1e126 --- /dev/null +++ b/apps/cli/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "morphir" +version.workspace = true +description = "Morphir CLI" +homepage.workspace = true +keywords = ["morphir", "finos"] +authors.workspace = true +license.workspace = true +edition.workspace = true + +[badges] +maintnance = { status = "actively-developer" } + +[[bin]] +name = "morphir" +path = "src/main.rs" + +[lib] +name = "morphir" +path = "src/lib.rs" + +[features] + +[dependencies] +#boa_engine.workspace = true +tokio.workspace = true + +[build-dependencies] +#git-download = "0.1.1" +download_git = "0.0.2" diff --git a/apps/cli/build.rs b/apps/cli/build.rs new file mode 100644 index 000000000..e1790c979 --- /dev/null +++ b/apps/cli/build.rs @@ -0,0 +1,23 @@ +use download_git; + +fn main() -> Result<(), Box> { + // download_git::download( + // "https://github.com/twbs/bootstrap.git:main", + // download_git::DownloadOptions { + // target_files: Some(vec!["dist".to_string(), "README.md".to_string()]), + // dest_path: String::from(TEST_FOLDER), + // }, + // )?; + // git_download::repo("https://github.com/akiradeveloper/lol") + // // Tag name can be used. + // .branch_name("v0.9.1") + // // Can be saved in a different name. + // .add_file("lol-core/proto/lol-core.proto", "proto/lol.proto") + // .exec()?; + + // tonic_build::configure() + // .build_server(false) + // .compile(&["lol.proto"], &["proto"])?; + + Ok(()) +} diff --git a/apps/cli/src/lib.rs b/apps/cli/src/lib.rs new file mode 100644 index 000000000..e69de29bb diff --git a/apps/cli/src/main.rs b/apps/cli/src/main.rs new file mode 100644 index 000000000..9091e7725 --- /dev/null +++ b/apps/cli/src/main.rs @@ -0,0 +1,4 @@ +#[tokio::main] +async fn main() -> MainResult { + Ok(()) +} diff --git a/crates/morphir-runtime/Cargo.toml b/crates/morphir-runtime/Cargo.toml index 5cece9cbd..e4b2db91f 100644 --- a/crates/morphir-runtime/Cargo.toml +++ b/crates/morphir-runtime/Cargo.toml @@ -23,6 +23,7 @@ path = "src/lib.rs" [dependencies] boa_engine.workspace = true +tokio.workspace = true [build-dependencies] -deno_core.workspace = true \ No newline at end of file +deno_core.workspace = true diff --git a/crates/morphir-runtime/src/main.rs b/crates/morphir-runtime/src/main.rs index d00493e01..e7a11a969 100644 --- a/crates/morphir-runtime/src/main.rs +++ b/crates/morphir-runtime/src/main.rs @@ -1,151 +1,3 @@ -use std::env; -use deno_ast::MediaType; -use deno_ast::ParseParams; -use deno_ast::SourceTextInfo; -use deno_core::error::AnyError; -use deno_core::futures::FutureExt; -use deno_core::op2; -use deno_core::Extension; -use deno_core::Snapshot; -use std::rc::Rc; - -#[op2(async)] -#[string] -async fn op_read_file(#[string] path: String) -> Result { - let contents = tokio::fs::read_to_string(path).await?; - Ok(contents) -} - -#[op2(async)] -#[string] -async fn op_write_file(#[string] path: String, #[string] contents: String) -> Result<(), AnyError> { - tokio::fs::write(path, contents).await?; - Ok(()) -} - -#[op2(async)] -#[string] -async fn op_fetch(#[string] url: String) -> Result { - let body = reqwest::get(url).await?.text().await?; - Ok(body) -} - -#[op2(async)] -async fn op_set_timeout(delay: f64) -> Result<(), AnyError> { - tokio::time::sleep(std::time::Duration::from_millis(delay as u64)).await; - Ok(()) -} - -#[op2(fast)] -fn op_remove_file(#[string] path: String) -> Result<(), AnyError> { - std::fs::remove_file(path)?; - Ok(()) -} - -struct TsModuleLoader; - -impl deno_core::ModuleLoader for TsModuleLoader { - fn resolve( - &self, - specifier: &str, - referrer: &str, - _kind: deno_core::ResolutionKind, - ) -> Result { - deno_core::resolve_import(specifier, referrer).map_err(|e| e.into()) - } - - fn load( - &self, - module_specifier: &deno_core::ModuleSpecifier, - _maybe_referrer: Option<&reqwest::Url>, - _is_dyn_import: bool, - ) -> std::pin::Pin> { - let module_specifier = module_specifier.clone(); - async move { - let path = module_specifier.to_file_path().unwrap(); - - let media_type = MediaType::from_path(&path); - let (module_type, should_transpile) = match MediaType::from_path(&path) { - MediaType::JavaScript | MediaType::Mjs | MediaType::Cjs => { - (deno_core::ModuleType::JavaScript, false) - } - MediaType::Jsx => (deno_core::ModuleType::JavaScript, true), - MediaType::TypeScript - | MediaType::Mts - | MediaType::Cts - | MediaType::Dts - | MediaType::Dmts - | MediaType::Dcts - | MediaType::Tsx => (deno_core::ModuleType::JavaScript, true), - MediaType::Json => (deno_core::ModuleType::Json, false), - _ => panic!("Unknown extension {:?}", path.extension()), - }; - - let code = std::fs::read_to_string(&path)?; - let code = if should_transpile { - let parsed = deno_ast::parse_module(ParseParams { - specifier: module_specifier.to_string(), - text_info: SourceTextInfo::from_string(code), - media_type, - capture_tokens: false, - scope_analysis: false, - maybe_syntax: None, - })?; - parsed.transpile(&Default::default())?.text - } else { - code - }; - let module = deno_core::ModuleSource::new( - module_type, - deno_core::ModuleCode::from(code), - &module_specifier - ); - Ok(module) - } - .boxed_local() - } -} - -static RUNTIME_SNAPSHOT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/MORPHIRJS_SNAPSHOT.bin")); - -async fn run_js(file_path: &str) -> Result<(), AnyError> { - let main_module = deno_core::resolve_path(file_path, env::current_dir()?.as_path())?; - let runjs_extension = Extension::builder("morphir") - .ops(vec![ - op_read_file::decl(), - op_write_file::decl(), - op_remove_file::decl(), - op_fetch::decl(), - op_set_timeout::decl(), - ]) - .build(); - let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions { - module_loader: Some(Rc::new(TsModuleLoader)), - startup_snapshot: Some(Snapshot::Static(RUNTIME_SNAPSHOT)), - extensions: vec![runjs_extension], - ..Default::default() - }); - - let mod_id = js_runtime.load_main_module(&main_module, None).await?; - let result = js_runtime.mod_evaluate(mod_id); - js_runtime.run_event_loop(false).await?; - result.await? -} - fn main() { - let args = &env::args().collect::>()[1..]; - - if args.is_empty() { - eprintln!("Usage: morphirx "); - std::process::exit(1); - } - let file_path = &args[0]; - - let runtime = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap(); - if let Err(error) = runtime.block_on(run_js(file_path)) { - eprintln!("error: {error}"); - } -} \ No newline at end of file + println!("Hello, world!"); +} diff --git a/moon.yml b/moon.yml index 456acc24a..6660ff2ec 100644 --- a/moon.yml +++ b/moon.yml @@ -1 +1,84 @@ -language: elm \ No newline at end of file +language: 'rust' +type: 'application' +tags: + - 'elm' + +env: + CARGO_TERM_COLOR: 'always' + +fileGroups: + elm-sources: + - 'src/**/*.elm' + sources: + - 'apps/cli/src/**/*' + - 'crates/*/src/**/*' + - 'crates/*/Cargo.toml' + - 'Cargo.toml' + tests: + - 'crates/*/benches/**/*' + - 'crates/*/tests/**/*' + +tasks: + build: + command: 'cargo build' + inputs: + - '@globs(sources)' + check: + command: 'cargo check --workspace' + inputs: + - '@globs(sources)' + format: + command: 'cargo fmt --all --check' + inputs: + - '@globs(sources)' + - '@globs(tests)' + lint: + command: 'cargo clippy --workspace' + inputs: + - '@globs(sources)' + - '@globs(tests)' + test: + command: 'cargo test --workspace' + inputs: + - '@globs(sources)' + - '@globs(tests)' + ensure-elm-docs-dir: + command: 'mkdir -p @out(0)' + outputs: + - '.out/elm-out/finos/morphir' + check-elm-docs: + command: 'elm make --docs=./.out/elm-out/finos/morphir/docs.json' + inputs: + - '@globs(elm-sources)' + outputs: + - '.out/elm-out/finos/morphir/docs.json' + deps: + - target: "~:ensure-elm-docs-dir" + cargo-clean: + inputs: [] + command: 'cargo clean' + elm-clean-outputs: + inputs: + - '.out/elm-out' + command: 'rm -rf @in(0)' + clean: + inputs: [] + deps: + - "~:cargo-clean" + - "~:elm-clean-outputs" + purge: + inputs: [] + deps: + - "~:clean" + - "~:purge-targets" + - "~:purge-elm-dependencies" + - "~:purge-node-dependencies" + purge-targets: + inputs: [] + command: 'rm -rf target' + purge-elm-dependencies: + inputs: [] + command: 'rm -rf elm-stuff' + purge-node-dependencies: + inputs: [] + command: 'rm -rf node_modules' diff --git a/package.json b/package.json index 5571531d2..d5f84d863 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,10 @@ ], "scripts": { "build": "moon run :build", + "clean": "moon run clean", + "pruge": "moon run pruge", "build:verify-elm-package": "zig build verify-elm-package --summary all", - "build:check-elm-docs": "zig build check-elm-docs --summary all", + "check-elm-docs": "moon run check-elm-docs", "postinstall": "elm-tooling install", "list-projects": "moon project-graph --json | bunx --bun node-jq '.projects| keys[]'" },