#!/usr/bin/env node csv_parse = require("csv-parse/sync"); fs = require("fs") var csv_parse, dictionary_cedict_to_json, read_csv_file, read_text_file, replace_placeholders, update_hover_dictionary; read_text_file = function(a) { return fs.readFileSync(a, "utf8"); }; read_csv_file = function(path, delimiter) { return csv_parse.parse(read_text_file(path), { delimiter: delimiter || " ", relax_column_count: true }); }; replace_placeholders = function(text, mapping) { return text.replace(/__(.*?)__/g, function(_, k) { return mapping[k] || ""; }); }; dictionary_cedict_to_json = function(data) { return JSON.stringify(data.map(function(a) { a[2] = a[2].split("/"); a.push(a[1].replace(/[0-4]/g, "")); return a; })); }; update_hover_dictionary = function() { var script, word_data; word_data = read_csv_file("../../data/cedict.csv"); word_data = dictionary_cedict_to_json(word_data); script = read_text_file("js/content-template.js"); script = replace_placeholders(script, { word_data }); return fs.writeFileSync("compiled/content.js", script); }; update_hover_dictionary()