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
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Tests

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Run tests
run: cargo test
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ edition = "2021"
authors = ["OpacityLabs"]
description = "A CLI tool for bundling and analyzing Luau files"

[lib]
name = "opacity_cli"
path = "src/lib.rs"

Comment on lines +8 to +11
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we can actually include modules from our "lib" in the tests

[dependencies]
anyhow = "1.0.95"
clap = { version = "4.5.1", features = ["derive", "cargo"] }
serde = { version = "1.0", features = ["derive"] }
toml = "0.8.20"
which = "7.0.2"
darklua = "0.16.0"
darklua = "0.17.1"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.17 has additions that we use, can't remember which ones exactly, doe

serde_derive = "1.0.217"
clap_complete = "4.5.46"
axum = "0.8.3"
Expand All @@ -25,3 +29,4 @@ chrono = "0.4.40"
tracing-subscriber = "0.3.19"
notify = "6.1.1"
sha2 = "0.10.9"
toml_edit = "0.23.4"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom serialization (kinda). Otherwise the output looks terrible

70 changes: 70 additions & 0 deletions src/commands/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use std::path::PathBuf;
use std::time::Instant;
use tracing::info;

pub mod param_extractor;

fn get_global_inject_rules(platform: &Platform, flow: &Flow) -> Vec<Box<dyn Rule>> {
let mut rules: Vec<Box<dyn Rule>> = vec![
Box::new(InjectGlobalValue::string("FLOW_NAME", flow.name.clone())),
Expand Down Expand Up @@ -72,10 +74,43 @@ fn compute_hashes(file_paths: &mut Vec<PathBuf>) -> Result<Vec<(String, String)>
Ok(hashes)
}

fn serialize_flows_with_param_variants_to_toml(
flows_with_params: &Vec<(String, Vec<param_extractor::ParamVariant>)>,
) -> String {
use toml_edit::*;
let mut doc = DocumentMut::new();

let flows_with_params = flows_with_params
.iter()
.map(|(alias, param_variants)| {
let mut table = Table::new();
table.insert("alias", alias.clone().into());

let params = param_variants
.iter()
.map(|param_variant| {
param_variant
.iter()
.map(|param| param.to_toml_table().into_inline_table())
.collect::<Array>()
})
.collect::<Array>();

table.insert("params", params.into());
table
})
.collect::<ArrayOfTables>();

doc.insert("flows_with_params", flows_with_params.into());
doc.to_string()
}

pub fn bundle(config_path: &str, is_rebundle: bool) -> Result<()> {
let config = config::Config::from_file(config_path)?;
let resources = Resources::from_file_system();

let mut flows_with_params: Vec<(String, Vec<param_extractor::ParamVariant>)> = Vec::new();

std::fs::create_dir_all(&config.settings.output_directory)?;

let mut file_paths: Vec<PathBuf> = Vec::new();
Expand Down Expand Up @@ -110,6 +145,25 @@ pub fn bundle(config_path: &str, is_rebundle: bool) -> Result<()> {
.with_configuration(config);

process_bundle(&resources, options)?;

let parent_path_as_cwd = std::fs::canonicalize(config_path)
.ok()
.and_then(|abs_path| {
abs_path
.parent()
.map(|p| p.to_str().map(|s| s.to_owned()))
.flatten()
})
.map(|s| s.to_string());

flows_with_params.push((
flow.alias.clone(),
param_extractor::extract_params(
&std::fs::read_to_string(&flow.path)?,
&flow.path,
parent_path_as_cwd,
)?,
));
}
}

Expand All @@ -126,6 +180,22 @@ pub fn bundle(config_path: &str, is_rebundle: bool) -> Result<()> {
.join("\n"),
)?;

std::fs::write(
config_path_dir_buf.join("flows_with_params.toml"),
serialize_flows_with_param_variants_to_toml(
&flows_with_params
.iter()
.filter_map(|(alias, param_variants)| {
if param_variants.is_empty() {
None
} else {
Some((alias.clone(), param_variants.clone()))
}
})
.collect::<Vec<(String, Vec<param_extractor::ParamVariant>)>>(),
),
)?;

if is_rebundle {
info!("Rebundled all flows successfully");
} else {
Expand Down
Loading