Skip to content

Commit

Permalink
feat(bindings): remove dsl types file
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime authored and amaanq committed Mar 10, 2024
1 parent 072865e commit b60b248
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 36 deletions.
33 changes: 0 additions & 33 deletions cli/src/generate/grammar_files.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use super::write_file;
use anyhow::{anyhow, Context, Result};
use filetime::FileTime;
use heck::{ToKebabCase, ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase};
use serde::Deserialize;
use serde_json::{json, Map, Value};
use std::fs::File;
use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::time::{Duration, SystemTime};
use std::{fs, str};

const BUILD_TIME: &str = env!("BUILD_TIME");

const CLI_VERSION: &str = env!("CARGO_PKG_VERSION");
const CLI_VERSION_PLACEHOLDER: &str = "CLI_VERSION";

Expand All @@ -20,7 +16,6 @@ const CAMEL_PARSER_NAME_PLACEHOLDER: &str = "CAMEL_PARSER_NAME";
const UPPER_PARSER_NAME_PLACEHOLDER: &str = "UPPER_PARSER_NAME";
const LOWER_PARSER_NAME_PLACEHOLDER: &str = "LOWER_PARSER_NAME";

const DSL_D_TS_FILE: &str = include_str!("../../npm/dsl.d.ts");
const GRAMMAR_JS_TEMPLATE: &str = include_str!("./templates/grammar.js");
const PACKAGE_JSON_TEMPLATE: &str = include_str!("./templates/package.json");
const GITIGNORE_TEMPLATE: &str = include_str!("./templates/gitignore");
Expand Down Expand Up @@ -209,7 +204,6 @@ pub fn generate_grammar_files(
json!([
"grammar.js",
"binding.gyp",
"types/dsl.d.ts",
"prebuilds/**",
"bindings/node/*",
"queries/*",
Expand Down Expand Up @@ -244,33 +238,6 @@ pub fn generate_grammar_files(
return Ok(());
}

// Rewrite dsl.d.ts only if its mtime differs from what was set on its creation
missing_path(repo_path.join("types"), create_dir)?.apply(|path| {
missing_path(path.join("dsl.d.ts"), |path| {
write_file(path, DSL_D_TS_FILE)
})?
.apply_state(|state| {
let build_time =
SystemTime::UNIX_EPOCH + Duration::from_secs_f64(BUILD_TIME.parse::<f64>()?);

match state {
PathState::Exists(path) => {
let mtime = fs::metadata(path)?.modified()?;
if mtime != build_time {
write_file(path, DSL_D_TS_FILE)?;
filetime::set_file_mtime(path, FileTime::from_system_time(build_time))?;
}
}
PathState::Missing(path) => {
filetime::set_file_mtime(path, FileTime::from_system_time(build_time))?;
}
}

Ok(())
})?;
Ok(())
})?;

// Write .gitignore file
missing_path(repo_path.join(".gitignore"), |path| {
generate_file(path, GITIGNORE_TEMPLATE, language_name)
Expand Down
1 change: 0 additions & 1 deletion cli/src/generate/templates/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ dist/
/examples/*/

# Grammar volatiles
dsl.d.ts
*.wasm
*.obj
*.o
2 changes: 1 addition & 1 deletion cli/src/generate/templates/grammar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="./types/dsl" />
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check

module.exports = grammar({
Expand Down
1 change: 0 additions & 1 deletion cli/src/generate/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"files": [
"grammar.js",
"binding.gyp",
"types/dsl.d.ts",
"prebuilds/**",
"bindings/node/*",
"queries/*",
Expand Down

0 comments on commit b60b248

Please sign in to comment.