Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundle-dts #82

Merged
merged 1 commit into from
Dec 17, 2023
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
50 changes: 23 additions & 27 deletions scripts/build.js → build.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import fs from "node:fs";
import path from "node:path";
import { execSync } from "node:child_process";

import * as esbuild from "esbuild";
import { rimraf } from "rimraf";
import { bundle } from "dts-bundle";

/** @type {(str: string) => string} */
const blue = str => `\x1b[34m${str}\x1b[0m`;

/** @type {(str: string) => string} */
const green = str => `\x1b[32m${str}\x1b[0m`;

/** @type {(dir: string) => void} */
const finishedBuild = dir => console.log(`${green("✔︎")} build: ${blue(dir)}`);
const blue = (str: string) => `\x1b[34m${str}\x1b[0m`;
const green = (str: string) => `\x1b[32m${str}\x1b[0m`;
const finishedBuild = (dir: string) => console.log(`${green("✔︎")} build: ${blue(dir)}`);

const CLI_OUT_DIR = `packages/tools/bin`;

/**
* @type {() => PromiseLike<void>}
*/
export const buildCli = async () => {
/**
* @type {import('esbuild').BuildOptions}
*/
await esbuild.build({
entryPoints: [path.resolve("packages/tools/src/bin")],
bundle: true,
Expand All @@ -44,48 +36,52 @@ export const buildCli = async () => {
finishedBuild(`${CLI_OUT_DIR}/jTegaki.zip)`);
};

/**
* @type {() => void}
*/
export const clearCliSync = () => {
rimraf.sync(CLI_OUT_DIR);
};

const PACKAGES = ["tecack", "frontend", "backend", "dataset", "shared"];

/**
* @type {() => PromiseLike<import('esbuild').BuildResult<{ entryPoints: string, outdir: string }>>[]}
*/
export const buildTecack = () =>
PACKAGES.map(pkg => {
/**
* @type {import('esbuild').BuildOptions}
*/
const res = esbuild.build({
entryPoints: [path.resolve(`packages/${pkg}/src/index`)],
bundle: true,
minify: true,
target: "es2018",
outdir: `packages/${pkg}/dist`,
format: "esm",
plugins: [
{
name: "TypeScriptDeclarationsPlugin",
setup(build) {
build.onEnd(() => {
bundle({
name: pkg,
main: `temp/packages/${pkg}/src/index.d.ts`,
out: path.resolve(`packages/${pkg}/dist/index.d.ts`),
});
});
},
},
],
});
res.then(() => finishedBuild(`packages/${pkg}/dist`));
return res;
});

/**
* @type {function(): void}
*/
export const clearTecackSync = () => {
PACKAGES.map(pkg => `packages/${pkg}/dist`).forEach(dir => rimraf.sync(dir));
};

(async function main() {
await (async function main() {
console.log("clear dist...");
await Promise.allSettled([clearCliSync(), clearTecackSync()]);
console.log(`${green("✔︎")} finished clearing dist`);
console.log("building tecack...");
execSync("tsc -p tsconfig.build.json");
const buildingTecack = buildTecack();
const buildingCli = buildCli();
await Promise.all([...buildingTecack, buildingCli]);
execSync("rm -rf temp");
})();
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"scripts": {
"prepare": "husky install",
"deploy": "nr build && sh scripts/deploy.sh",
"build": "pnpm run bundle && pnpm run build:dts",
"bundle": "node scripts/build.js",
"build:dts": "rm -rf temp && tsc -p tsconfig.build.json && node scripts/dts.js && rm -rf temp",
"build": "tsx build",
"fmt": "prettier",
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint",
"spell-check": "cspell lint \"**\" --no-progress --show-suggestions --show-context --cache",
Expand All @@ -45,13 +43,15 @@
},
"devDependencies": {
"cspell": "^7.3.8",
"dts-bundle": "^0.7.3",
"esbuild": "^0.19.4",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"husky": "^8.0.3",
"lint-staged": "^15.0.1",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"tsx": "^3.12.2",
"typescript": "^5.2.2",
"vitepress": "1.0.0-rc.22"
}
Expand Down
95 changes: 91 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 0 additions & 51 deletions scripts/dts.js

This file was deleted.

Loading