Convert yml to json only if yml is changed
This commit is contained in:
parent
8005b3dce5
commit
e6559bdc7c
|
@ -0,0 +1,33 @@
|
|||
import { execSync } from 'child_process';
|
||||
import { existsSync, statSync } from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
|
||||
function isGrammarOutdate(fileName) {
|
||||
const thisFile = fileURLToPath(import.meta.url);
|
||||
const json = path.join(path.dirname(thisFile), '..', 'syntaxes', fileName);
|
||||
if (!existsSync(json)) {
|
||||
return true;
|
||||
}
|
||||
const yaml = json.replace('.json', '.yml');
|
||||
const jsonState = statSync(json);
|
||||
const yamlState = statSync(yaml);
|
||||
if (yamlState.mtime.toString() > jsonState.mtime.toString()) {
|
||||
console.log(`${yaml} changed, Grammar is outdate, re-generate it.`);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function yamlToJson() {
|
||||
if (isGrammarOutdate('cmake.tmLanguage.json')) {
|
||||
execSync('npm run grammar-cmake');
|
||||
}
|
||||
|
||||
if (isGrammarOutdate('cmakecache.tmLanguage.json')) {
|
||||
execSync('npm run grammar-cmakecache');
|
||||
}
|
||||
}
|
||||
|
||||
yamlToJson();
|
|
@ -97,7 +97,7 @@
|
|||
"vscode:prepublish": "npm run compile",
|
||||
"grammar-cmake": "npx js-yaml ./syntaxes/cmake.tmLanguage.yml > ./syntaxes/cmake.tmLanguage.json",
|
||||
"grammar-cmakecache": "npx js-yaml ./syntaxes/cmakecache.tmLanguage.yml > ./syntaxes/cmakecache.tmLanguage.json",
|
||||
"grammar": "npm run grammar-cmake && npm run grammar-cmakecache",
|
||||
"grammar": "node ./build/yaml-to-json.mjs",
|
||||
"compile": "npm run grammar && tsc -p ./",
|
||||
"watch": "npm run grammar && tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
|
|
Loading…
Reference in New Issue