Browse Source

Added normalize tool

master
Michaël Lemaire 1 year ago
commit
e7c9eecb22
  1. 9
      .editorconfig
  2. 3
      .vscode/settings.json
  3. 3211
      deno.d.ts
  4. 93
      normalize.ts
  5. 10
      tsconfig.json

9
.editorconfig

@ -0,0 +1,9 @@
root = true
[*.ts]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

3
.vscode/settings.json

@ -0,0 +1,3 @@
{
"deno.enabled": true
}

3211
deno.d.ts

File diff suppressed because it is too large

93
normalize.ts

@ -0,0 +1,93 @@
#!/usr/bin/env -S deno run --allow-run --allow-read --allow-write
// Normalize deno projects
/// <reference path="./deno.d.ts" />
async function isDirectory(path: string): Promise<boolean> {
try {
return (await Deno.stat(path)).isDirectory;
} catch {
return false;
}
}
async function readContent(path: string): Promise<string> {
try {
return await Deno.readTextFile(path);
} catch {
return "";
}
}
async function ensureDirectory(path: string) {
if (!await isDirectory(path)) {
await Deno.mkdir(path, { recursive: true });
}
}
async function updateDenoDefs() {
const process = await Deno.run({
cmd: ["deno", "types"],
stdout: "piped",
});
const defs = new TextDecoder("utf-8").decode(await process.output());
await Deno.writeTextFile("deno.d.ts", defs);
}
async function updateEditorConfig() {
await Deno.writeTextFile(
".editorconfig",
`root = true
[*.ts]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
`,
);
}
async function updateTsConfig() {
await Deno.writeTextFile(
"tsconfig.json",
`{
"compilerOptions": {
"module": "esnext",
"target": "ESNext",
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"preserveConstEnums": true
}
}
`,
);
}
async function updateVscodeConf() {
await ensureDirectory(".vscode");
const path = ".vscode/settings.json";
const json_config = await readContent(path);
const config = JSON.parse(json_config || "{}");
if (!config["deno.enabled"]) {
config["deno.enabled"] = true;
await Deno.writeTextFile(path, JSON.stringify(config));
}
}
export async function normalize() {
if (!await isDirectory(".git")) {
throw new Error("Not in a git repository");
}
await updateDenoDefs();
await updateVscodeConf();
await updateTsConfig();
await updateEditorConfig();
}
if (import.meta.main) {
await normalize();
}

10
tsconfig.json

@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "esnext",
"target": "ESNext",
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"preserveConstEnums": true
}
}
Loading…
Cancel
Save