Skip to content

Commit bc64f6a

Browse files
committed
first commit
0 parents  commit bc64f6a

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

Cargo.lock

+87
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "pn"
3+
version = "0.0.0"
4+
authors = ["Zoltan Kochan <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
serde_json="1.0"
9+
serde = { version = "1.0", features = ["derive"] }
10+

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# pn

src/main.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::{path::{Path}};
2+
use std::fs::File;
3+
use std::process::Command;
4+
5+
fn main() -> Result<(), std::io::Error> {
6+
let manifest = read_manifest(Path::new("package.json"))?;
7+
let script_name: Vec<String> = std::env::args().collect();
8+
let script = manifest["scripts"][&script_name[2]].as_str().unwrap();
9+
println!("> {:?}", script);
10+
let mut path_env: String = "node_modules/.bin".to_owned();
11+
path_env.push_str(":");
12+
path_env.push_str(env!("PATH"));
13+
let mut child = Command::new("sh")
14+
.env("PATH", path_env)
15+
.arg("-c")
16+
.arg(script)
17+
.stdout(std::process::Stdio::inherit())
18+
.spawn()?;
19+
child.wait()?;
20+
Ok(())
21+
}
22+
23+
fn read_manifest<P: AsRef<Path>>(path: P) -> Result<serde_json::Value, std::io::Error> {
24+
let file = File::open(path)?;
25+
let manifest: serde_json::Value = serde_json::de::from_reader(file)?;
26+
Ok(manifest)
27+
}

0 commit comments

Comments
 (0)