diff --git a/package.json b/package.json index 564cbba0..11a86c00 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,12 @@ "description": "vimmatic", "version": "0.6.0", "scripts": { - "start": "NODE_ENV=development nodemon --watch ./src --ext js,jsx,ts,tsx,css,html,json script/build", + "start": "NODE_ENV=development nodemon --watch ./src --ext js,jsx,ts,tsx,css,html,json script/build.mjs", "clean": "rm -rf ./dist", "prebuild": "pnpm clean", - "build": "script/build", + "build": "node script/build.mjs", "prepackage": "pnpm build", - "package": "pnpm build && script/package", + "package": "node script/package.mjs", "lint": "eslint --ext .ts,.tsx .", "lint:fix": "eslint --ext .ts,.tsx . --fix", "type-checks": "tsc --noEmit", diff --git a/script/build b/script/build.mjs old mode 100755 new mode 100644 similarity index 67% rename from script/build rename to script/build.mjs index 11e52454..ff09638f --- a/script/build +++ b/script/build.mjs @@ -1,8 +1,6 @@ -#!/usr/bin/env node +import fs from "node:fs/promises"; +import { build } from "esbuild"; -const fs = require("node:fs/promises"); -const version = require("../package.json").version; -const { build } = require("esbuild"); const targets = { firefox: "firefox91", chrome: "chrome100", @@ -11,8 +9,8 @@ const targets = { const buildScripts = async (browser) => { await build({ define: { - 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? ""), - 'process.env.BROWSER': JSON.stringify(browser), + "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV ?? ""), + "process.env.BROWSER": JSON.stringify(browser), }, entryPoints: { console: "src/console/index.tsx", @@ -33,15 +31,18 @@ const buildAssets = async (browser) => { await fs.cp("resources/", `dist/${browser}/resources/`, { recursive: true }); await fs.copyFile( `src/console/index.html`, - `dist/${browser}/lib/console.html` + `dist/${browser}/lib/console.html`, ); await fs.copyFile( `src/options/index.html`, - `dist/${browser}/lib/options.html` + `dist/${browser}/lib/options.html`, ); - const manifest = require(`../src/manifest.${browser}.json`); - manifest.version = version; + const manifest = JSON.parse( + await fs.readFile(`src/manifest.${browser}.json`, "utf-8"), + ); + const packageJson = JSON.parse(await fs.readFile(`package.json`, "utf-8")); + manifest.version = packageJson.version; fs.writeFile(`dist/${browser}/manifest.json`, JSON.stringify(manifest)); }; diff --git a/script/package b/script/package.mjs old mode 100755 new mode 100644 similarity index 80% rename from script/package rename to script/package.mjs index 32a68646..c84e3797 --- a/script/package +++ b/script/package.mjs @@ -1,9 +1,6 @@ -#!/usr/bin/env node - -const fs = require("node:fs"); -const path = require("node:path"); -const JSZip = require("jszip"); -const version = require("../package.json").version; +import fs from "node:fs"; +import path from "node:path"; +import JSZip from "jszip"; async function* tree(dir) { const dirents = await fs.promises.readdir(dir, { withFileTypes: true }); @@ -18,7 +15,11 @@ async function* tree(dir) { } const zipPackage = async (browser) => { - const root = path.join(__dirname, "..", "dist", browser); + const packageJson = JSON.parse( + await fs.promises.readFile("package.json", "utf8"), + ); + const version = packageJson.version; + const root = path.join("dist", browser); const output = path.join("dist", `vimmatic_v${version}_${browser}.zip`); const zip = new JSZip();