eslint (mostly use double quotes)

This commit is contained in:
Ashley Engelund (weedySeaDragon @ github) 2022-09-05 18:27:58 -07:00
parent 7e68e06a3a
commit 0c85e8ee53
1 changed files with 24 additions and 24 deletions

View File

@ -1,26 +1,26 @@
import { remark } from 'remark';
import type { Code, Root } from 'mdast';
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'fs';
import { remark } from "remark";
import type { Code, Root } from "mdast";
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
// @ts-ignore
import flatmap from 'unist-util-flatmap';
import { globby } from 'globby';
import { join, dirname } from 'path';
import { exec } from 'child_process';
import prettier from 'prettier';
import flatmap from "unist-util-flatmap";
import { globby } from "globby";
import { join, dirname } from "path";
import { exec } from "child_process";
import prettier from "prettier";
const verify = process.argv.includes('--verify');
const git = process.argv.includes('--git');
const verify = process.argv.includes("--verify");
const git = process.argv.includes("--git");
let fileChanged = false;
// Possible Improvement: combine with lint-staged to only copy files that have changed
const prepareOutFile = (file: string): string => {
const outFile = join('docs', file.replace('src/docs/', ''));
const outFile = join("docs", file.replace("src/docs/", ""));
mkdirSync(dirname(outFile), { recursive: true });
return outFile;
};
const verifyAndCopy = (file: string, content?: string) => {
const outFile = prepareOutFile(file);
const existingBuffer = existsSync(outFile) ? readFileSync(outFile) : Buffer.from('#NEW FILE#');
const existingBuffer = existsSync(outFile) ? readFileSync(outFile) : Buffer.from("#NEW FILE#");
const newBuffer = content ? Buffer.from(content) : readFileSync(file);
if (existingBuffer.equals(newBuffer)) {
// Files are same, skip.
@ -34,16 +34,16 @@ const verifyAndCopy = (file: string, content?: string) => {
};
const transform = (file: string) => {
const doc = readFileSync(file, 'utf8');
const doc = readFileSync(file, "utf8");
const ast: Root = remark.parse(doc);
const out = flatmap(ast, (c: Code) => {
if (c.type !== 'code' || !c.lang?.startsWith('mermaid')) {
if (c.type !== "code" || !c.lang?.startsWith("mermaid")) {
return [c];
}
if (c.lang === 'mermaid' || c.lang === 'mmd') {
c.lang = 'mermaid-example';
if (c.lang === "mermaid" || c.lang === "mmd") {
c.lang = "mermaid-example";
}
return [c, Object.assign({}, c, { lang: 'mermaid' })];
return [c, Object.assign({}, c, { lang: "mermaid" })];
});
const transformed = `# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.\n${remark.stringify(
@ -52,20 +52,20 @@ const transform = (file: string) => {
verifyAndCopy(
file,
prettier.format(transformed, {
parser: 'markdown',
parser: "markdown",
useTabs: false,
tabWidth: 2,
endOfLine: 'auto',
endOfLine: "auto",
printWidth: 100,
singleQuote: true,
singleQuote: true
})
);
};
(async () => {
const mdFiles = await globby(['./src/docs/**/*.md'], { dot: true });
const mdFiles = await globby(["./src/docs/**/*.md"], { dot: true });
mdFiles.forEach(transform);
const nonMDFiles = await globby(['src/docs/**', '!**/*.md'], { dot: true });
const nonMDFiles = await globby(["src/docs/**", "!**/*.md"], { dot: true });
nonMDFiles.forEach((file) => {
verifyAndCopy(file);
});
@ -77,8 +77,8 @@ const transform = (file: string) => {
process.exit(1);
}
if (git) {
console.log('Adding changes in docs folder to git');
exec('git add docs');
console.log("Adding changes in docs folder to git");
exec("git add docs");
}
}
})();