2022-09-05 11:37:32 +08:00
|
|
|
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);
|
2022-10-11 13:49:33 +08:00
|
|
|
if (yamlState.mtimeMs > jsonState.mtimeMs) {
|
2022-09-05 11:37:32 +08:00
|
|
|
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');
|
|
|
|
}
|
2022-09-06 10:08:52 +08:00
|
|
|
|
|
|
|
if (isGrammarOutdate('cmdsignature.tmLanguage.json')) {
|
|
|
|
execSync('npm run grammar-cmdsignature');
|
|
|
|
}
|
2022-09-05 11:37:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
yamlToJson();
|