compile-upload
This commit is contained in:
parent
6720f6213f
commit
c08ff63033
65
src/main.rs
65
src/main.rs
@ -25,6 +25,7 @@ enum Commands{
|
|||||||
Create(CreateSubcommand),
|
Create(CreateSubcommand),
|
||||||
Upload(UploadSubcommand),
|
Upload(UploadSubcommand),
|
||||||
Compile(CompileSubcommand),
|
Compile(CompileSubcommand),
|
||||||
|
CompileUpload(CompileUploadSubcommand),
|
||||||
Decompile(DecompileSubcommand),
|
Decompile(DecompileSubcommand),
|
||||||
DecompileHistoryIntoGit(DecompileHistoryIntoGitSubcommand),
|
DecompileHistoryIntoGit(DecompileHistoryIntoGitSubcommand),
|
||||||
DownloadAndDecompileHistoryIntoGit(DownloadAndDecompileHistoryIntoGitSubcommand),
|
DownloadAndDecompileHistoryIntoGit(DownloadAndDecompileHistoryIntoGitSubcommand),
|
||||||
@ -113,6 +114,25 @@ struct CompileSubcommand{
|
|||||||
template:Option<PathBuf>,
|
template:Option<PathBuf>,
|
||||||
}
|
}
|
||||||
#[derive(Args)]
|
#[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{
|
struct DecompileSubcommand{
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
input_file:PathBuf,
|
input_file:PathBuf,
|
||||||
@ -241,6 +261,14 @@ async fn main()->AResult<()>{
|
|||||||
template:subcommand.template,
|
template:subcommand.template,
|
||||||
style:subcommand.style,
|
style:subcommand.style,
|
||||||
}).await,
|
}).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{
|
Commands::Decompile(subcommand)=>decompile(DecompileConfig{
|
||||||
style:subcommand.style,
|
style:subcommand.style,
|
||||||
input_file:subcommand.input_file,
|
input_file:subcommand.input_file,
|
||||||
@ -797,3 +825,40 @@ async fn compile(config:CompileConfig)->AResult<()>{
|
|||||||
rbx_binary::to_writer(output,&dom,dom.root().children())?;
|
rbx_binary::to_writer(output,&dom,dom.root().children())?;
|
||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user