hotfix(publish): Move install module and asset_map to main zellij package. publish should hopefully work now.

This commit is contained in:
Kunal Mohan 2021-05-27 15:30:14 +05:30
parent 1e5c688ed9
commit cb3072066d
7 changed files with 53 additions and 51 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

42
src/install.rs Normal file
View file

@ -0,0 +1,42 @@
use std::fs;
use std::path::Path;
use zellij_utils::{consts::VERSION, shared::set_permissions};
macro_rules! asset_map {
($($src:literal => $dst:literal),+ $(,)?) => {
{
let mut assets = std::collections::HashMap::new();
$(
assets.insert($dst, include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $src)).to_vec());
)+
assets
}
}
}
pub(crate) fn populate_data_dir(data_dir: &Path) {
// First run installation of default plugins & layouts
let mut assets = asset_map! {
"assets/layouts/default.yaml" => "layouts/default.yaml",
"assets/layouts/strider.yaml" => "layouts/strider.yaml",
};
assets.extend(asset_map! {
"assets/plugins/status-bar.wasm" => "plugins/status-bar.wasm",
"assets/plugins/tab-bar.wasm" => "plugins/tab-bar.wasm",
"assets/plugins/strider.wasm" => "plugins/strider.wasm",
});
assets.insert("VERSION", VERSION.as_bytes().to_vec());
let last_version = fs::read_to_string(data_dir.join("VERSION")).unwrap_or_default();
let out_of_date = VERSION != last_version;
for (path, bytes) in assets {
let path = data_dir.join(path);
let parent_path = path.parent().unwrap();
fs::create_dir_all(parent_path).unwrap();
set_permissions(parent_path).unwrap();
if out_of_date || !path.exists() {
fs::write(path, bytes).expect("Failed to install default assets!");
}
}
}

View file

@ -1,7 +1,9 @@
mod install;
mod sessions; mod sessions;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use crate::install::populate_data_dir;
use sessions::{assert_session, assert_session_ne, list_sessions}; use sessions::{assert_session, assert_session_ne, list_sessions};
use std::convert::TryFrom; use std::convert::TryFrom;
use std::process; use std::process;
@ -12,7 +14,7 @@ use zellij_utils::{
consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
input::config::Config, input::config::Config,
logging::*, logging::*,
setup::Setup, setup::{get_default_data_dir, Setup},
structopt::StructOpt, structopt::StructOpt,
}; };
@ -69,6 +71,12 @@ pub fn main() {
.clone() .clone()
.unwrap_or_else(|| names::Generator::default().next().unwrap()); .unwrap_or_else(|| names::Generator::default().next().unwrap());
assert_session_ne(&session_name); assert_session_ne(&session_name);
// Determine and initialize the data directory
let data_dir = opts.data_dir.clone().unwrap_or_else(get_default_data_dir);
#[cfg(not(disable_automatic_asset_installation))]
populate_data_dir(&data_dir);
start_client( start_client(
Box::new(os_input), Box::new(os_input),
opts, opts,

View file

@ -32,7 +32,7 @@ use zellij_utils::{
errors::{ContextType, ErrorInstruction, ServerContext}, errors::{ContextType, ErrorInstruction, ServerContext},
input::{get_mode_info, options::Options}, input::{get_mode_info, options::Options},
ipc::{ClientAttributes, ClientToServerMsg, ExitReason, ServerToClientMsg}, ipc::{ClientAttributes, ClientToServerMsg, ExitReason, ServerToClientMsg},
setup::{get_default_data_dir, install::populate_data_dir}, setup::get_default_data_dir,
}; };
/// Instructions related to server-side application /// Instructions related to server-side application
@ -312,9 +312,6 @@ fn init_session(
// Determine and initialize the data directory // Determine and initialize the data directory
let data_dir = opts.data_dir.unwrap_or_else(get_default_data_dir); let data_dir = opts.data_dir.unwrap_or_else(get_default_data_dir);
#[cfg(not(disable_automatic_asset_installation))]
populate_data_dir(&data_dir);
let capabilities = PluginCapabilities { let capabilities = PluginCapabilities {
arrow_fonts: config_options.simplified_ui, arrow_fonts: config_options.simplified_ui,
}; };

View file

@ -2,61 +2,16 @@ use crate::cli::CliArgs;
use crate::consts::{ use crate::consts::{
FEATURES, SYSTEM_DEFAULT_CONFIG_DIR, SYSTEM_DEFAULT_DATA_DIR_PREFIX, VERSION, ZELLIJ_PROJ_DIR, FEATURES, SYSTEM_DEFAULT_CONFIG_DIR, SYSTEM_DEFAULT_DATA_DIR_PREFIX, VERSION, ZELLIJ_PROJ_DIR,
}; };
use crate::shared::set_permissions;
use directories_next::BaseDirs; use directories_next::BaseDirs;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::io::Write; use std::io::Write;
use std::{fs, path::Path, path::PathBuf}; use std::{path::Path, path::PathBuf};
use structopt::StructOpt; use structopt::StructOpt;
const CONFIG_LOCATION: &str = ".config/zellij"; const CONFIG_LOCATION: &str = ".config/zellij";
const CONFIG_NAME: &str = "config.yaml"; const CONFIG_NAME: &str = "config.yaml";
static ARROW_SEPARATOR: &str = ""; static ARROW_SEPARATOR: &str = "";
#[macro_export]
macro_rules! asset_map {
($($src:literal => $dst:literal),+ $(,)?) => {
{
let mut assets = std::collections::HashMap::new();
$(
assets.insert($dst, include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $src)).to_vec());
)+
assets
}
}
}
pub mod install {
use super::*;
pub fn populate_data_dir(data_dir: &Path) {
// First run installation of default plugins & layouts
let mut assets = asset_map! {
"../assets/layouts/default.yaml" => "layouts/default.yaml",
"../assets/layouts/strider.yaml" => "layouts/strider.yaml",
};
assets.extend(asset_map! {
"../assets/plugins/status-bar.wasm" => "plugins/status-bar.wasm",
"../assets/plugins/tab-bar.wasm" => "plugins/tab-bar.wasm",
"../assets/plugins/strider.wasm" => "plugins/strider.wasm",
});
assets.insert("VERSION", VERSION.as_bytes().to_vec());
let last_version = fs::read_to_string(data_dir.join("VERSION")).unwrap_or_default();
let out_of_date = VERSION != last_version;
for (path, bytes) in assets {
let path = data_dir.join(path);
let parent_path = path.parent().unwrap();
fs::create_dir_all(parent_path).unwrap();
set_permissions(parent_path).unwrap();
if out_of_date || !path.exists() {
fs::write(path, bytes).expect("Failed to install default assets!");
}
}
}
}
#[cfg(not(any(feature = "test", test)))] #[cfg(not(any(feature = "test", test)))]
/// Goes through a predefined list and checks for an already /// Goes through a predefined list and checks for an already
/// existing config directory, returns the first match /// existing config directory, returns the first match