Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored and astrobot-houston committed Mar 22, 2024
1 parent 3e93693 commit b4ab19c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/vscode/scripts/build-grammar.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
// @ts-check
import fs from "node:fs";
import { fileURLToPath } from "node:url";
import yaml from "js-yaml";
import { dim, green } from "kleur/colors";
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import yaml from 'js-yaml';
import { dim, green } from 'kleur/colors';

const dt = new Intl.DateTimeFormat('en-us', {
hour: '2-digit',
minute: '2-digit',
});

// Rebuild grammar when any yaml in the syntaxes directory changes
const syntaxesDir = new URL("../syntaxes/", import.meta.url);
const isWatch = process.argv.includes("--watch");
const syntaxesDir = new URL('../syntaxes/', import.meta.url);
const isWatch = process.argv.includes('--watch');

if (isWatch) {
console.log("Watching for changes in the syntaxes directory...");
console.log('Watching for changes in the syntaxes directory...');
}

// Absolute paths to the grammars
const grammarFiles = fs.readdirSync(syntaxesDir).filter((file) => file.endsWith(".src.yaml")).map((path) => new URL(path, syntaxesDir));
const grammarFiles = fs
.readdirSync(syntaxesDir)
.filter((file) => file.endsWith('.src.yaml'))
.map((path) => new URL(path, syntaxesDir));
for (const grammarFile of grammarFiles) {
if (isWatch) {
fs.watch(grammarFile, () => {
Expand All @@ -33,8 +36,8 @@ for (const grammarFile of grammarFiles) {
* @param {URL} grammarFile
*/
function buildGrammar(grammarFile) {
const grammar = yaml.load(fs.readFileSync(grammarFile, "utf8"));
const finalPath = fileURLToPath(grammarFile).replace(".src.yaml", ".json")
const grammar = yaml.load(fs.readFileSync(grammarFile, 'utf8'));
const finalPath = fileURLToPath(grammarFile).replace('.src.yaml', '.json');
fs.writeFileSync(finalPath, JSON.stringify(grammar, null, 2));

const date = dt.format(new Date());
Expand Down

0 comments on commit b4ab19c

Please sign in to comment.