Skip to content

Commit

Permalink
feat(bindings): update npm scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Mar 25, 2024
1 parent b7fcf98 commit 3434d07
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
36 changes: 17 additions & 19 deletions cli/src/generate/grammar_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn generate_grammar_files(
.unwrap();
if dependencies.remove("nan").is_some() {
eprintln!("Replacing nan dependency with node-addon-api in package.json");
dependencies.insert("node-addon-api".to_string(), "^7.1.0".into());
dependencies.insert("node-addon-api".to_string(), "^8.0.0".into());
updated = true;
}
if !dependencies.contains_key("node-gyp-build") {
Expand All @@ -145,24 +145,22 @@ pub fn generate_grammar_files(
.or_insert_with(|| Value::Object(Map::new()))
.as_object_mut()
.unwrap();
match scripts.get("install") {
None => {
eprintln!("Adding an install script to package.json");
scripts.insert("install".to_string(), "node-gyp-build".into());
updated = true;
}
Some(Value::String(v)) if v != "node-gyp-build" => {
eprintln!("Updating the install script in package.json");
scripts.insert("install".to_string(), "node-gyp-build".into());
updated = true;
}
Some(_) => {}
}
if !scripts.contains_key("prebuildify") {
eprintln!("Adding a prebuildify script to package.json");
scripts.insert(
"prebuildify".to_string(),
"prebuildify --napi --strip".into(),
if !scripts.contains_key("prestart") {
eprintln!("Updating package.json scripts");
scripts.clear();
let prestart =
format!("tree-sitter build --wasm -o tree-sitter-{language_name}.wasm");
scripts.append(
json!({
"build": "prebuildify --napi --strip",
"install": "node-gyp-build",
"prestart": prestart,
"start": "tree-sitter playground",
"test": "node --test",
"version": "make update",
})
.as_object_mut()
.unwrap(),
);
updated = true;
}
Expand Down
9 changes: 8 additions & 1 deletion cli/src/generate/templates/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,11 @@ clean:
test:
$(TS) test

.PHONY: all install uninstall clean test
update: VERSION := $(shell awk -F '"' '/^ "version"/{print $$4}' package.json)
update:
sed -i Makefile -e 's/^VERSION := .*/VERSION := $(VERSION)/'
sed -i Cargo.toml -e 's/^version = .*/version = "$(VERSION)"/'
sed -i pyproject.toml -e 's/^version = .*/version = "$(VERSION)"/'
git add package.json package-lock.json Cargo.toml pyproject.toml Makefile

.PHONY: all install uninstall clean test update
12 changes: 6 additions & 6 deletions cli/src/generate/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"src/**"
],
"dependencies": {
"node-addon-api": "^7.1.0",
"node-addon-api": "^8.0.0",
"node-gyp-build": "^4.8.0"
},
"devDependencies": {
Expand All @@ -37,12 +37,12 @@
}
},
"scripts": {
"build": "prebuildify --napi --strip",
"install": "node-gyp-build",
"prebuildify": "prebuildify --napi --strip",
"build": "tree-sitter generate --no-bindings",
"build-wasm": "tree-sitter build --wasm",
"test": "tree-sitter test",
"parse": "tree-sitter parse"
"prestart": "tree-sitter build --wasm -o tree-sitter-PARSER_NAME.wasm",
"start": "tree-sitter playground",
"test": "node --test",
"version": "make update"
},
"tree-sitter": [
{
Expand Down

0 comments on commit 3434d07

Please sign in to comment.