diff --git a/.prettierignore b/.prettierignore index 65e93aabfd2..cfc7104a84c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,6 +10,7 @@ !/packages/compute-baseline/** !/packages/web-features/** +!/scripts/build.ts !/scripts/dist.ts !/scripts/feature-init.ts !/scripts/find-troublesome-ancestors.ts diff --git a/package.json b/package.json index 67daac3532b..26caf5ff579 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "node": ">=18.19.0" }, "scripts": { - "build": "tsx scripts/build.ts", + "build": "tsx scripts/build.ts package", "dist": "tsx scripts/dist.ts", "schema-defs": "ts-json-schema-generator --tsconfig ./tsconfig.json --type FeatureData --path ./types.ts --id defs", "schema-defs:write": "npm run schema-defs -- --out ./schemas/defs.schema.json", diff --git a/scripts/build.ts b/scripts/build.ts index e0c84a7f57d..70994b3d56a 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -1,25 +1,37 @@ -import fs from 'fs'; +import { execSync } from "child_process"; +import stringify from "fast-json-stable-stringify"; +import fs from "fs"; +import yargs from "yargs"; +import features from "../index.js"; -import stringify from 'fast-json-stable-stringify'; +const rootDir = new URL("..", import.meta.url); -import features from '../index.js'; -import { execSync } from 'child_process'; +yargs(process.argv.slice(2)) + .scriptName("build") + .command({ + command: "package", + describe: "Generate the web-features npm package", + handler: buildPackage, + }) + .parseSync(); -const rootDir = new URL('..', import.meta.url); -const packageDir = new URL('./packages/web-features/', rootDir); +function buildPackage() { + const packageDir = new URL("./packages/web-features/", rootDir); + const filesToCopy = ["LICENSE.txt", "types.ts"]; -const filesToCopy = ["LICENSE.txt", "types.ts"]; - -function build() { - const json = stringify(features); - // TODO: Validate the resulting JSON against a schema. - const path = new URL('index.json', packageDir); - fs.writeFileSync(path, json); - for (const file of filesToCopy) { - fs.copyFileSync(new URL(file, rootDir), new URL(file, packageDir)); - } - execSync("npm install", { cwd: "./packages/web-features", encoding: "utf-8"}); - execSync("npm run prepare", { cwd: "./packages/web-features", encoding: "utf-8"}); + const json = stringify(features); + // TODO: Validate the resulting JSON against a schema. + const path = new URL("index.json", packageDir); + fs.writeFileSync(path, json); + for (const file of filesToCopy) { + fs.copyFileSync(new URL(file, rootDir), new URL(file, packageDir)); + } + execSync("npm install", { + cwd: "./packages/web-features", + encoding: "utf-8", + }); + execSync("npm run prepare", { + cwd: "./packages/web-features", + encoding: "utf-8", + }); } - -build();