compile-upload

This commit is contained in:
Quaternions 2024-07-01 18:03:36 -07:00
parent 63d22846cd
commit 44ef08cc73

View File

@ -25,6 +25,7 @@ enum Commands{
Create(CreateSubcommand),
Upload(UploadSubcommand),
Compile(CompileSubcommand),
CompileUpload(CompileUploadSubcommand),
Decompile(DecompileSubcommand),
DecompileHistoryIntoGit(DecompileHistoryIntoGitSubcommand),
DownloadAndDecompileHistoryIntoGit(DownloadAndDecompileHistoryIntoGitSubcommand),
@ -113,6 +114,25 @@ struct CompileSubcommand{
template:Option<PathBuf>,
}
#[derive(Args)]
struct CompileUploadSubcommand{
#[arg(long)]
asset_id:AssetID,
#[arg(long)]
cookie_type:CookieType,
#[arg(long)]
cookie:String,
#[arg(long)]
input_file:PathBuf,
#[arg(long)]
group:Option<u64>,
#[arg(long)]
input_folder:Option<PathBuf>,
#[arg(long)]
style:Option<Style>,
#[arg(long)]
template:Option<PathBuf>,
}
#[derive(Args)]
struct DecompileSubcommand{
#[arg(long)]
input_file:PathBuf,
@ -241,6 +261,14 @@ async fn main()->AResult<()>{
template:subcommand.template,
style:subcommand.style,
}).await,
Commands::CompileUpload(subcommand)=>compile_upload(CompileUploadConfig{
input_folder:subcommand.input_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
template:subcommand.template,
style:subcommand.style,
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
group:subcommand.group,
asset_id:subcommand.asset_id,
}).await,
Commands::Decompile(subcommand)=>decompile(DecompileConfig{
style:subcommand.style,
input_file:subcommand.input_file,
@ -797,3 +825,40 @@ async fn compile(config:CompileConfig)->AResult<()>{
rbx_binary::to_writer(output,&dom,dom.root().children())?;
Ok(())
}
struct CompileUploadConfig{
input_folder:PathBuf,
template:Option<PathBuf>,
style:Option<Style>,
cookie:String,
group:Option<u64>,
asset_id:AssetID,
}
async fn compile_upload(config:CompileUploadConfig)->AResult<()>{
let mut dom=match config.template{
//mr dom doesn't like tokio files
Some(template_path)=>load_dom(std::io::BufReader::new(std::fs::File::open(template_path)?))?,
None=>rbx_dom_weak::WeakDom::new(rbx_dom_weak::InstanceBuilder::new("DataModel")),
};
rox_compiler::compile(rox_compiler::CompileConfig{
input_folder:config.input_folder,
style:config.style.map(|s|s.rox()),
},&mut dom).await?;
//make a binary file in a buffer in memory
let mut data=Vec::new();
rbx_binary::to_writer(std::io::Cursor::new(&mut data),&dom,dom.root().children())?;
//upload it
let context=RobloxContext::new(config.cookie);
context.upload(rbx_asset::context::UploadRequest{
assetid:config.asset_id,
name:None,
description:None,
ispublic:None,
allowComments:None,
groupId:config.group,
},data).await?;
Ok(())
}