Skip to content

Commit fb2adc7

Browse files
authored
Merge pull request #10 from olback/0.1.2
0.1.2
2 parents a52a554 + 4f00fd4 commit fb2adc7

File tree

20 files changed

+249
-121
lines changed

20 files changed

+249
-121
lines changed

.circleci/deploy/deploy.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,20 @@ let currentVersion = cargoToml.filter(l => l.includes('version = '))[0].split('
4444

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

47+
const clogStr = fs.readFileSync('CHANGELOG.md', 'utf8').toString();
48+
const clogLines = clogStr.split('\n#')[0].split('\n');
49+
clogLines.shift();
50+
const changelog = clogLines.join('\n');
51+
4752
let newReleaseRes = await (await fetch(`${gh.url}repos/${gh.user}/${gh.repo}/releases`, {
4853
headers: gh.headers,
4954
method: 'POST',
5055
body: JSON.stringify({
5156
tag_name: currentVersion,
5257
target_commitish: gh.branch,
5358
name: `Release v${currentVersion}`,
54-
body: '',
59+
// body: 'Please see the [changelog](CHANGELOG.md) for details!',
60+
body: changelog,
5561
draft: false,
5662
prerelease: false
5763
})

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 0.1.2
2+
* Automatic update checks
3+
* No longer creates a folder for downloaded library unless the format specifies it
4+
* No longer overwrites output files
5+
* Code refactoring

Cargo.lock

Lines changed: 19 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[package]
22
name = "library-loader"
3-
version = "0.1.1"
4-
authors = ["Edwin Svensson <git@olback.net>"]
3+
version = "0.1.2"
4+
authors = ["Edwin Svensson <libloader@olback.net>"]
55
edition = "2018"
66

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

99
[dependencies]
1010
reqwest = "0.9.22"
11-
base64 = "0.10.1"
11+
base64 = "0.11.0"
1212
clap = { version = "2.33.0", features = ["yaml"] }
13-
serde = "1.0.101"
13+
serde = "1.0.102"
1414
dirs = "2.0.2"
15-
toml = "0.5.3"
15+
toml = "0.5.4"
1616
rpassword = "4.0.1"
1717
zip = "0.5.3"
1818
crossbeam-channel = "0.3.9"

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* [x] [Feature] Auto unzip folder and copy lib to libs folder
1010
* [x] [Code] New struct for CLI-only options
1111
* [x] [Feature] When using `-g`, treat input as output path
12-
* [ ] [Code] Split extractor from format
12+
* [x] [Code] Split extractor from format
1313
* [ ] [Docs] Proper documentation
1414
* [ ] [Code] Document the code...
1515
* [ ] [Feature] Show Desktop Notification?

src/check_updates.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use reqwest;
2+
use toml;
3+
use serde::Deserialize;
4+
use super::error::LLResult;
5+
use super::consts::REMOTE_CARGO_TOML;
6+
7+
pub struct UpdateInfo {
8+
pub local: String,
9+
pub remote: String
10+
}
11+
12+
#[derive(Deserialize)]
13+
struct CargoToml {
14+
package: Package
15+
}
16+
17+
#[derive(Deserialize)]
18+
struct Package {
19+
version: String
20+
}
21+
22+
pub fn check() -> LLResult<Option<UpdateInfo>> {
23+
24+
let remote_toml_str = reqwest::get(REMOTE_CARGO_TOML)?.text()?;
25+
let local_toml_str = std::include_str!("../Cargo.toml");
26+
27+
28+
let remote_toml: CargoToml = toml::from_str(remote_toml_str.as_str())?;
29+
let local_toml: CargoToml = toml::from_str(local_toml_str)?;
30+
31+
if remote_toml.package.version != local_toml.package.version {
32+
33+
Ok(Some(UpdateInfo {
34+
local: local_toml.package.version,
35+
remote: remote_toml.package.version
36+
}))
37+
38+
} else {
39+
40+
Ok(None)
41+
42+
}
43+
44+
}

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl Default for Config {
241241
settings: Settings {
242242
output_path: String::from("download"),
243243
watch_path: None,
244-
format: Format::ZIP
244+
format: Format::from("zip")
245245
},
246246
profile: profile,
247247
cli: Cli {

src/consts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ pub const COMPONENT_SEARCH_ENGINE_URL: &str = "http://componentsearchengine.com/
33

44
// Main config file to look for in working dir
55
pub const LL_CONFIG: &str = "LibraryLoader.toml";
6+
7+
// Github urls
8+
pub const DOWNLOAD_URL: &str = "https://github.com/olback/library-loader/releases/latest";
9+
pub const REMOTE_CARGO_TOML: &str = "https://raw.githubusercontent.com/olback/library-loader/master/Cargo.toml";

src/cse.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::config::Config;
2-
use super::format::{self, Extractor, Format, Files};
2+
use super::format::{Files, ECAD};
33
use super::epw::Epw;
44
use super::error::{LLResult, LLError};
55
use super::cse_result::CSEResult;
@@ -79,7 +79,7 @@ impl CSE {
7979
println!("-- End debug info from {file}#{line} --", file = std::file!(), line = std::line!());
8080
}
8181

82-
if &self.config.settings.format == &Format::ZIP {
82+
if &self.config.settings.format.ecad == &ECAD::ZIP {
8383

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

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

124118
}
125119

126-
let path = PathBuf::from(&self.config.settings.output_path).join(lib_name);
120+
let path = match &self.config.settings.format.create_folder {
121+
true => PathBuf::from(&self.config.settings.output_path).join(lib_name),
122+
false => PathBuf::from(&self.config.settings.output_path)
123+
};
127124

128125
Ok(CSEResult {
129126
output_path: path.to_string_lossy().to_string(),

src/cse_result.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ impl CSEResult {
4646

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

49+
let p = path.to_str().unwrap().to_string();
50+
51+
if path.exists() {
52+
return Err(LLError::new(format!("{}#{}: {} already exists!", std::file!(), std::line!(), p)));
53+
}
54+
4955
match fs::write(&path, &data) {
50-
Ok(_) => Ok(path.to_str().unwrap().to_string()),
56+
Ok(_) => Ok(p),
5157
Err(e) => Err(LLError::new(format!("{}#{}: {}", std::file!(), std::line!(), e)))
5258
}
5359

0 commit comments

Comments
 (0)