Skip to content

Commit

Permalink
chore: migrate scripts to mjs (#314)
Browse files Browse the repository at this point in the history
Migrate build scripts to esm scripts.
  • Loading branch information
ueokande authored Jan 13, 2024
1 parent fcf757e commit dbcfde9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 11 additions & 10 deletions script/build → script/build.mjs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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));
};

Expand Down
15 changes: 8 additions & 7 deletions script/package → script/package.mjs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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 });
Expand All @@ -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();
Expand Down

0 comments on commit dbcfde9

Please sign in to comment.