-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
398 additions
and
178 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ crossbeam = "*" | |
termion = "1.5" | ||
git2 = "*" | ||
run_script = "0.10" | ||
tempfile = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
target TypeScript | ||
|
||
main reactor { | ||
reaction(startup) {= console.log("Hello World"); =} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use crate::util::errors::LingoError; | ||
use crate::util::execute_command_to_build_result; | ||
use std::error::Error; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
use std::process::Command; | ||
|
||
pub struct Npm; | ||
|
||
pub struct TypeScriptToolCommands { | ||
pub binary_name: &'static str, | ||
pub install_command: &'static str, | ||
pub release_build_argument: &'static str, | ||
} | ||
|
||
use crate::backends::{ | ||
BatchBackend, BatchBuildResults, BuildCommandOptions, BuildProfile, CommandSpec, | ||
}; | ||
|
||
pub fn do_typescript_build( | ||
results: &mut BatchBuildResults, | ||
options: &BuildCommandOptions, | ||
commands: TypeScriptToolCommands, | ||
) { | ||
super::lfc::LFC::do_parallel_lfc_codegen(options, results, false); | ||
if !options.compile_target_code { | ||
return; | ||
} | ||
|
||
let extract_name = |path: &PathBuf| -> Result<String, Box<dyn Error + Send + Sync>> { | ||
match Path::new(&path).file_stem() { | ||
Some(value) => value | ||
.to_str() | ||
.map(String::from) | ||
.ok_or(Box::new(LingoError::InvalidMainReactor)), | ||
None => Err(Box::new(LingoError::InvalidMainReactor)), | ||
} | ||
}; | ||
|
||
results | ||
.map(|app| { | ||
let file_name = extract_name(&app.main_reactor)?; | ||
let path = app.output_root.join("src-gen").join(file_name); | ||
|
||
let mut npm_install = Command::new(commands.binary_name); | ||
npm_install.current_dir(path); | ||
npm_install.arg(commands.install_command); | ||
if options.profile == BuildProfile::Release { | ||
npm_install.arg(commands.release_build_argument); | ||
} | ||
execute_command_to_build_result(npm_install)?; | ||
Ok(()) | ||
}) | ||
.map(|app| { | ||
let file_name = extract_name(&app.main_reactor)?; | ||
let path = app.output_root.join("src-gen").join(file_name); | ||
|
||
let mut npm_build = Command::new(commands.binary_name); | ||
npm_build.current_dir(path); | ||
npm_build.arg("run"); | ||
npm_build.arg("build"); | ||
|
||
if options.profile == BuildProfile::Release { | ||
npm_build.arg(commands.release_build_argument); | ||
} | ||
execute_command_to_build_result(npm_build)?; | ||
|
||
Ok(()) | ||
}) | ||
.map(|app| { | ||
fs::create_dir_all(app.output_root.join("bin"))?; | ||
|
||
let file_name = extract_name(&app.main_reactor)?; | ||
let path = app | ||
.output_root | ||
.join("src-gen") | ||
.join(&file_name) | ||
.join("dist") | ||
.join(file_name + ".js"); | ||
|
||
// cleanup: rename executable to match the app name | ||
fs::rename(path, app.executable_path())?; | ||
Ok(()) | ||
}); | ||
} | ||
|
||
impl BatchBackend for Npm { | ||
fn execute_command(&mut self, command: &CommandSpec, results: &mut BatchBuildResults) { | ||
match command { | ||
CommandSpec::Build(options) => do_typescript_build( | ||
results, | ||
options, | ||
TypeScriptToolCommands { | ||
binary_name: "npm", | ||
install_command: "install", | ||
release_build_argument: "--production", | ||
}, | ||
), | ||
CommandSpec::Clean => { | ||
results.par_map(|app| { | ||
crate::util::default_build_clean(&app.output_root)?; | ||
crate::util::delete_subdirs(&app.output_root, &["node_modules", "dist"])?; | ||
Ok(()) | ||
}); | ||
} | ||
_ => todo!(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::backends::npm::{do_typescript_build, TypeScriptToolCommands}; | ||
|
||
pub struct Pnpm; | ||
|
||
use crate::backends::{BatchBackend, BatchBuildResults, CommandSpec}; | ||
|
||
impl BatchBackend for Pnpm { | ||
fn execute_command(&mut self, command: &CommandSpec, results: &mut BatchBuildResults) { | ||
match command { | ||
CommandSpec::Build(options) => do_typescript_build( | ||
results, | ||
options, | ||
TypeScriptToolCommands { | ||
binary_name: "pnpm", | ||
install_command: "install", | ||
release_build_argument: "--prod", | ||
}, | ||
), | ||
CommandSpec::Clean => { | ||
results.par_map(|app| { | ||
crate::util::default_build_clean(&app.output_root)?; | ||
crate::util::delete_subdirs(&app.output_root, &["node_modules", "dist"])?; | ||
Ok(()) | ||
}); | ||
} | ||
_ => todo!(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.