From b6428177e0c10a12194c69d560960652dac4eb50 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Mon, 2 Dec 2024 23:34:55 +0530 Subject: [PATCH] chore: clean up scripts --- deno.json | 1 + deno.lock | 11 ++++++++++- scripts/build.ts | 10 ++-------- scripts/patch.ts | 9 ++------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/deno.json b/deno.json index 1d2978d..db2a56b 100644 --- a/deno.json +++ b/deno.json @@ -32,6 +32,7 @@ "@ast-grep/napi": "npm:@ast-grep/napi@^0.31.0", "@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.11.0", "@std/assert": "jsr:@std/assert@^1.0.8", + "@std/fs": "jsr:@std/fs@^1.0.6", "esbuild": "npm:esbuild@^0.24.0", "prettier": "npm:prettier@^3.4.1", "typescript": "npm:typescript@^5.7.2", diff --git a/deno.lock b/deno.lock index e9db411..c4cb9c6 100644 --- a/deno.lock +++ b/deno.lock @@ -5,8 +5,10 @@ "jsr:@std/assert@^1.0.8": "1.0.8", "jsr:@std/bytes@^1.0.2": "1.0.4", "jsr:@std/encoding@^1.0.5": "1.0.5", + "jsr:@std/fs@^1.0.6": "1.0.6", "jsr:@std/internal@^1.0.5": "1.0.5", "jsr:@std/path@^1.0.6": "1.0.8", + "jsr:@std/path@^1.0.8": "1.0.8", "npm:@ast-grep/napi@0.31": "0.31.0", "npm:@types/unist@2": "2.0.11", "npm:esbuild@0.24": "0.24.0", @@ -20,7 +22,7 @@ "dependencies": [ "jsr:@std/bytes", "jsr:@std/encoding", - "jsr:@std/path" + "jsr:@std/path@^1.0.6" ] }, "@std/assert@1.0.8": { @@ -35,6 +37,12 @@ "@std/encoding@1.0.5": { "integrity": "ecf363d4fc25bd85bd915ff6733a7e79b67e0e7806334af15f4645c569fefc04" }, + "@std/fs@1.0.6": { + "integrity": "42b56e1e41b75583a21d5a37f6a6a27de9f510bcd36c0c85791d685ca0b85fa2", + "dependencies": [ + "jsr:@std/path@^1.0.8" + ] + }, "@std/internal@1.0.5": { "integrity": "54a546004f769c1ac9e025abd15a76b6671ddc9687e2313b67376125650dc7ba" }, @@ -298,6 +306,7 @@ "dependencies": [ "jsr:@luca/esbuild-deno-loader@0.11", "jsr:@std/assert@^1.0.8", + "jsr:@std/fs@^1.0.6", "npm:@ast-grep/napi@0.31", "npm:esbuild@0.24", "npm:prettier@^3.4.1", diff --git a/scripts/build.ts b/scripts/build.ts index bc218c6..bfc06b6 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -1,16 +1,10 @@ import { denoPlugins } from '@luca/esbuild-deno-loader' +import { emptyDir } from '@std/fs' import * as esbuild from 'esbuild' import tsid from 'unplugin-isolated-decl/esbuild' import denoJson from '../deno.json' with { type: 'json' } -try { - await Deno.remove('dist', { recursive: true }) - await Deno.mkdir('dist') -} catch (err) { - if (!(err instanceof Deno.errors.NotFound)) { - throw err - } -} +await emptyDir('dist') await esbuild.build({ plugins: [ diff --git a/scripts/patch.ts b/scripts/patch.ts index 55f6e1a..19d8601 100644 --- a/scripts/patch.ts +++ b/scripts/patch.ts @@ -1,4 +1,5 @@ import { Lang, parse } from '@ast-grep/napi' +import { ensureDir } from '@std/fs' import denoJson from '../deno.json' with { type: 'json' } const version = denoJson.imports.prettier.split('@')[1] @@ -18,13 +19,7 @@ const n2$D = node2.getMatch('D')!.text() const edit1 = node2.replace(`${n2$A}.use(${n2$D}).use`) const transformed = root.commitEdits([edit1]).toString() -try { - await Deno.mkdir('./vendor', { recursive: true }) -} catch (err) { - if (!(err instanceof Deno.errors.AlreadyExists)) { - throw err - } -} +await ensureDir('vendor') await Deno.writeTextFile('./vendor/prettier-plugin-markdown.js', transformed) await Deno.writeTextFile(