Add cargo index build task to Makafile

This commit is contained in:
Folyd 2020-04-23 14:36:33 +08:00
parent 254fb91dc3
commit 26d41bb7fd
3 changed files with 27 additions and 5 deletions

View file

@ -2,3 +2,15 @@
manifest:
@jsonnet $@.jsonnet --ext-str browser=$(browser) -o extension/$@.json
books-index:
RUST_BACKTRACE=full cargo run --bin books-index --features books-index --manifest-path=rust/Cargo.toml extension/index/books.js
crates-index:
RUST_BACKTRACE=full cargo run --bin crates-index --features crates-index --manifest-path=rust/Cargo.toml /tmp/db-dump.tar.gz extension/index/crates.js
lints-index:
RUST_BACKTRACE=full cargo run --bin lints-index --features books-index --manifest-path=rust/Cargo.toml extension/index/lints.js
labels-index:
RUST_BACKTRACE=full cargo run --bin labels-index --features labels-index --manifest-path=rust/Cargo.toml extension/index/labels.js

View file

@ -1,7 +1,7 @@
#![cfg(feature = "books-index")]
use std::fs;
use std::path::Path;
use std::{env, fs};
use futures::future::try_join_all;
use reqwest;
@ -98,6 +98,11 @@ async fn fetch_book(mut book: Book) -> Result<Book, Box<dyn std::error::Error>>
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().collect();
let path_name = match args.get(1) {
Some(path_name) => path_name,
None => BOOKS_INDEX_PATH,
};
let futures: Vec<_> = serde_json::from_str::<Vec<Book>>(include_str!("books.json"))?
.into_iter()
.map(fetch_book)
@ -109,8 +114,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
"var N=null;var booksIndex={};",
serde_json::to_string(&books)?
);
let path = Path::new(BOOKS_INDEX_PATH);
fs::write(path, &Minifier::minify_js(contents))?;
let path = Path::new(path_name);
fs::write(path, &Minifier::minify_js(contents)).unwrap();
}
Err(error) => {
println!("{:?}", error);

View file

@ -1,7 +1,7 @@
use std::clone::Clone;
use std::collections::HashMap;
use std::fs;
use std::path::Path;
use std::{env, fs};
use reqwest;
use serde_derive::Deserialize;
@ -53,6 +53,11 @@ async fn fetch_clippy_lints() -> Result<Vec<Lint>> {
#[tokio::main]
async fn main() -> Result<()> {
let args: Vec<String> = env::args().collect();
let path_name = match args.get(1) {
Some(path_name) => path_name,
None => LINTS_INDEX_PATH,
};
let lints: HashMap<String, [String; 2]> = fetch_clippy_lints()
.await?
.iter()
@ -65,7 +70,7 @@ async fn main() -> Result<()> {
.collect();
let contents = format!("var lintsIndex={};", serde_json::to_string(&lints)?);
let path = Path::new(LINTS_INDEX_PATH);
let path = Path::new(path_name);
fs::write(path, &Minifier::minify_js(contents))?;
println!("\nGenerate javascript lints index successful!");
Ok(())