From 8314faf868b2d20ed338d80f2007cd5ef0b9ffbc Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 21 Feb 2024 13:15:56 +0800 Subject: [PATCH] Update build script (#229) --- package.json | 5 +++-- scripts/generate-types.mjs | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 5f69d1c..31adcee 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "node": ">=18" }, "scripts": { - "test": "xo && ava && tsd", + "test": "npm run build && xo && ava && tsd", "prepare": "npm run build", "update": "node scripts/update.mjs", "update:browser": "node scripts/update.mjs --environment=browser", @@ -23,9 +23,10 @@ "update:nodeBuiltin": "node scripts/update.mjs --environment=nodeBuiltin", "update:worker": "node scripts/update.mjs --environment=worker", "update:shelljs": "node scripts/update.mjs --environment=shelljs", + "build": "run-s build:data build:types", "build": "run-p \"build:*\"", "build:data": "node scripts/generate-data.mjs", - "build:types": "node scripts/generate-types.mjs > index.d.ts" + "build:types": "node scripts/generate-types.mjs" }, "files": [ "index.js", diff --git a/scripts/generate-types.mjs b/scripts/generate-types.mjs index b849ec3..4be6d80 100644 --- a/scripts/generate-types.mjs +++ b/scripts/generate-types.mjs @@ -1,8 +1,5 @@ -import fs from 'node:fs/promises'; - -const DATA_FILE = new URL('../globals.json', import.meta.url); - -const globals = JSON.parse(await fs.readFile(DATA_FILE)); +import fs from 'node:fs'; +import globals from '../index.js'; const getGroupTypeName = group => `Globals${group[0].toUpperCase() + group.slice(1).replaceAll('-', '')}`; @@ -33,4 +30,7 @@ for (const [group, groupType] of Object.entries(groups)) { output.push('}\n', 'declare const globals: Globals;\n', 'export = globals;'); -console.log(output.join('\n')); +fs.writeFileSync( + new URL('../index.d.ts', import.meta.url), + output.join('\n'), +);