1pub mod logger;
4pub mod utils;
5
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8use std::{
9 fs::File,
10 io::{Read, Seek, SeekFrom},
11};
12
13#[macro_export]
14macro_rules! rew_error {
15 ($msg:expr) => {
16 deno_core::error::CoreErrorKind::Io(::std::io::Error::new(
17 std::io::ErrorKind::InvalidData,
18 $msg,
19 ))
20 .into()
21 };
22
23 ($msg:expr, $kind:expr) => {
24 deno_core::error::CoreErrorKind::Io(::std::io::Error::new($kind, $msg)).into()
25 };
26}
27
28#[derive(Debug, Clone, Default)]
30pub struct BuildOptions {
31 pub bundle_all: bool,
32 pub entry_file: Option<PathBuf>,
33}
34
35#[derive(Debug, Deserialize, Serialize, Clone)]
37pub struct AppManifest {
38 pub package: Option<String>,
39 pub version: Option<String>,
40 pub description: Option<String>,
41 pub entries: Option<String>,
42}
43
44#[derive(Debug, Deserialize, Serialize, Clone)]
45pub struct AppConfig {
46 pub manifest: Option<AppManifest>,
47 pub entries: Option<std::collections::HashMap<String, String>>,
48}
49
50#[derive(Debug, Clone)]
51pub struct AppInfo {
52 pub path: PathBuf,
53 pub config: AppConfig,
54}
55
56#[derive(Default)]
57pub struct RuntimeState {
58 pub current_dir: PathBuf,
59 pub args: Vec<String>,
60}
61
62pub fn load_embedded_script() -> Option<String> {
63 let exe = std::env::current_exe().ok()?;
64 let mut f = File::open(&exe).ok()?;
65
66 f.seek(SeekFrom::End(-12)).ok()?;
68 let mut footer = [0u8; 12];
69 f.read_exact(&mut footer).ok()?;
70
71 if &footer[8..12] != b"REW!" {
72 return None; }
74 let len = u64::from_le_bytes(footer[0..8].try_into().unwrap());
75
76 f.seek(SeekFrom::End(-(12 + len as i64))).ok()?;
78 let mut data = vec![0u8; len as usize];
79 f.read_exact(&mut data).ok()?;
80
81 String::from_utf8(data).ok()
82}