Skip to content
Merged
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
8 changes: 7 additions & 1 deletion .circleci/deploy/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@ let currentVersion = cargoToml.filter(l => l.includes('version = '))[0].split('

console.log('Creating new release!');

const clogStr = fs.readFileSync('CHANGELOG.md', 'utf8').toString();
const clogLines = clogStr.split('\n#')[0].split('\n');
clogLines.shift();
const changelog = clogLines.join('\n');

let newReleaseRes = await (await fetch(`${gh.url}repos/${gh.user}/${gh.repo}/releases`, {
headers: gh.headers,
method: 'POST',
body: JSON.stringify({
tag_name: currentVersion,
target_commitish: gh.branch,
name: `Release v${currentVersion}`,
body: '',
// body: 'Please see the [changelog](CHANGELOG.md) for details!',
body: changelog,
draft: false,
prerelease: false
})
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 0.1.2
* Automatic update checks
* No longer creates a folder for downloaded library unless the format specifies it
* No longer overwrites output files
* Code refactoring
32 changes: 19 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[package]
name = "library-loader"
version = "0.1.1"
authors = ["Edwin Svensson <git@olback.net>"]
version = "0.1.2"
authors = ["Edwin Svensson <libloader@olback.net>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = "0.9.22"
base64 = "0.10.1"
base64 = "0.11.0"
clap = { version = "2.33.0", features = ["yaml"] }
serde = "1.0.101"
serde = "1.0.102"
dirs = "2.0.2"
toml = "0.5.3"
toml = "0.5.4"
rpassword = "4.0.1"
zip = "0.5.3"
crossbeam-channel = "0.3.9"
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* [x] [Feature] Auto unzip folder and copy lib to libs folder
* [x] [Code] New struct for CLI-only options
* [x] [Feature] When using `-g`, treat input as output path
* [ ] [Code] Split extractor from format
* [x] [Code] Split extractor from format
* [ ] [Docs] Proper documentation
* [ ] [Code] Document the code...
* [ ] [Feature] Show Desktop Notification?
Expand Down
44 changes: 44 additions & 0 deletions src/check_updates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use reqwest;
use toml;
use serde::Deserialize;
use super::error::LLResult;
use super::consts::REMOTE_CARGO_TOML;

pub struct UpdateInfo {
pub local: String,
pub remote: String
}

#[derive(Deserialize)]
struct CargoToml {
package: Package
}

#[derive(Deserialize)]
struct Package {
version: String
}

pub fn check() -> LLResult<Option<UpdateInfo>> {

let remote_toml_str = reqwest::get(REMOTE_CARGO_TOML)?.text()?;
let local_toml_str = std::include_str!("../Cargo.toml");


let remote_toml: CargoToml = toml::from_str(remote_toml_str.as_str())?;
let local_toml: CargoToml = toml::from_str(local_toml_str)?;

if remote_toml.package.version != local_toml.package.version {

Ok(Some(UpdateInfo {
local: local_toml.package.version,
remote: remote_toml.package.version
}))

} else {

Ok(None)

}

}
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl Default for Config {
settings: Settings {
output_path: String::from("download"),
watch_path: None,
format: Format::ZIP
format: Format::from("zip")
},
profile: profile,
cli: Cli {
Expand Down
4 changes: 4 additions & 0 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ pub const COMPONENT_SEARCH_ENGINE_URL: &str = "http://componentsearchengine.com/

// Main config file to look for in working dir
pub const LL_CONFIG: &str = "LibraryLoader.toml";

// Github urls
pub const DOWNLOAD_URL: &str = "https://github.com/olback/library-loader/releases/latest";
pub const REMOTE_CARGO_TOML: &str = "https://raw.githubusercontent.com/olback/library-loader/master/Cargo.toml";
17 changes: 7 additions & 10 deletions src/cse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::config::Config;
use super::format::{self, Extractor, Format, Files};
use super::format::{Files, ECAD};
use super::epw::Epw;
use super::error::{LLResult, LLError};
use super::cse_result::CSEResult;
Expand Down Expand Up @@ -79,7 +79,7 @@ impl CSE {
println!("-- End debug info from {file}#{line} --", file = std::file!(), line = std::line!());
}

if &self.config.settings.format == &Format::ZIP {
if &self.config.settings.format.ecad == &ECAD::ZIP {

let mut files: Files = HashMap::new();
files.insert(filename, body);
Expand Down Expand Up @@ -113,17 +113,14 @@ impl CSE {
let mut item = archive.by_index(i)?;
let filename = String::from(item.name());

match &self.config.settings.format {
Format::EAGLE => format::eagle::Extractor::extract(&mut files, filename, &mut item)?,
Format::EASYEDA => format::easyeda::Extractor::extract(&mut files, filename, &mut item)?,
Format::KICAD => format::kicad::Extractor::extract(&mut files, filename, &mut item)?,
Format::ZIP => return Err(LLError::new("This should be unreachable!"))
// ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
};
&self.config.settings.format.extract(&mut files, filename, &mut item)?;

}

let path = PathBuf::from(&self.config.settings.output_path).join(lib_name);
let path = match &self.config.settings.format.create_folder {
true => PathBuf::from(&self.config.settings.output_path).join(lib_name),
false => PathBuf::from(&self.config.settings.output_path)
};

Ok(CSEResult {
output_path: path.to_string_lossy().to_string(),
Expand Down
8 changes: 7 additions & 1 deletion src/cse_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ impl CSEResult {

fn write(path: PathBuf, data: Vec<u8>) -> LLResult<String> {

let p = path.to_str().unwrap().to_string();

if path.exists() {
return Err(LLError::new(format!("{}#{}: {} already exists!", std::file!(), std::line!(), p)));
}

match fs::write(&path, &data) {
Ok(_) => Ok(path.to_str().unwrap().to_string()),
Ok(_) => Ok(p),
Err(e) => Err(LLError::new(format!("{}#{}: {}", std::file!(), std::line!(), e)))
}

Expand Down
14 changes: 0 additions & 14 deletions src/format/eagle.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/format/easyeda.rs

This file was deleted.

27 changes: 0 additions & 27 deletions src/format/extractor_prelude.rs

This file was deleted.

9 changes: 9 additions & 0 deletions src/format/extractors/eagle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use super::*;

pub fn extract(format: &Format, files: &mut Files, file_path: String, item: &mut ZipFile) -> LLResult<()> {


generic_extractor(format, files, file_path, item)

}

7 changes: 7 additions & 0 deletions src/format/extractors/easyeda.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use super::*;

pub fn extract(format: &Format, files: &mut Files, file_path: String, item: &mut ZipFile) -> LLResult<()> {

generic_extractor(format, files, file_path, item)

}
7 changes: 7 additions & 0 deletions src/format/extractors/kicad.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use super::*;

pub fn extract(format: &Format, files: &mut Files, file_path: String, item: &mut ZipFile) -> LLResult<()> {

generic_extractor(format, files, file_path, item)

}
Loading