This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xtask to download and parse js libs (#1816)
* download and parse js libs
- Loading branch information
Showing
6 changed files
with
177 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ pub mod compare; | |
pub mod coverage; | ||
pub mod docgen; | ||
pub mod glue; | ||
pub mod libs; | ||
|
||
use std::{ | ||
env, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js | ||
https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.global.prod.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::{path::PathBuf, str::FromStr}; | ||
|
||
fn err_to_string<E: std::fmt::Debug>(e: E) -> String { | ||
format!("{:?}", e) | ||
} | ||
|
||
pub fn get_code(lib: &str) -> Result<String, String> { | ||
let url = url::Url::from_str(lib).map_err(err_to_string)?; | ||
let segments = url | ||
.path_segments() | ||
.ok_or_else(|| "lib url has no segments".to_string())?; | ||
let filename = segments | ||
.last() | ||
.ok_or_else(|| "lib url has no segments".to_string())?; | ||
|
||
let mut file = PathBuf::from_str("target").map_err(err_to_string)?; | ||
file.push(filename); | ||
|
||
match std::fs::read_to_string(&file) { | ||
Ok(code) => { | ||
println!("[{}] - using [{}]", filename, file.display()); | ||
Ok(code) | ||
} | ||
Err(_) => { | ||
println!( | ||
"[{}] - Downloading [{}] to [{}]", | ||
filename, | ||
lib, | ||
file.display() | ||
); | ||
match ureq::get(lib).call() { | ||
Ok(response) => { | ||
let mut reader = response.into_reader(); | ||
|
||
let _ = std::fs::remove_file(&file); | ||
let mut writer = std::fs::File::create(&file).map_err(err_to_string)?; | ||
let _ = std::io::copy(&mut reader, &mut writer); | ||
|
||
std::fs::read_to_string(&file).map_err(err_to_string) | ||
} | ||
Err(e) => Err(format!("{:?}", e)), | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn run() { | ||
let libs = include_str!("libs.txt").lines(); | ||
for lib in libs { | ||
let code = get_code(lib); | ||
match code { | ||
Ok(code) => { | ||
let _ = std::panic::catch_unwind(|| rslint_parser::parse_module(code.as_str(), 0)); | ||
} | ||
Err(e) => println!("{:?}", e), | ||
} | ||
} | ||
|
||
println!("end"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters