Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 32 additions & 20 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -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();