Skip to content

Commit

Permalink
Merge pull request #186 from Ubugeeei/workspace
Browse files Browse the repository at this point in the history
refactor: 🛠️ migrate to workspace
  • Loading branch information
ubugeeei committed Dec 29, 2023
2 parents e7bd1ab + 6f5bc82 commit 1d60c16
Show file tree
Hide file tree
Showing 166 changed files with 2,054 additions and 1,624 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
node_modules
dist
example/playground
example/vue
examples/playground
examples/vue
.env
tools/translator/ja2en/input.md
tools/translator/ja2en/output.md
book/online-book/.vitepress/cache
book/online-book/.vitepress/cache
book/online-book/.vitepress/dist
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cSpell.words": [
"antfu",
"augmentor",
"chainsi",
"chibi",
"chibivue",
"citty",
Expand All @@ -13,6 +14,7 @@
"hyperscript",
"jiti",
"klass",
"lightningcss",
"nocheck",
"paren",
"RAWTEXT",
Expand Down
115 changes: 115 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import path from "node:path";
import { execSync } from "node:child_process";

import { build } from "esbuild";
import { rimraf } from "rimraf";
import { bundle } from "dts-bundle";
import { t } from "chainsi";

const finishedBuild = (dir: string) =>
console.log(`${t("✔︎").green._} build: ${t(dir).blue._}`);

const NODE_EXTERNALS = [
"assert",
"buffer",
"child_process",
"cluster",
"console",
"constants",
"crypto",
"dgram",
"dns",
"domain",
"events",
"fs",
"http",
"http2",
"https",
"module",
"net",
"os",
"path",
"perf_hooks",
"process",
"punycode",
"querystring",
"readline",
"repl",
"stream",
"string_decoder",
"sys",
"timers",
"tls",
"tty",
"url",
"util",
"v8",
"vm",
"wasi",
"worker_threads",
"zlib",
].flatMap((name) => [name, `node:${name}`]);

const PACKAGES: Record<string, { external?: string[] }> = {
chibivue: {},
"compiler-core": {},
"compiler-dom": {},
"compiler-sfc": {},
"runtime-core": {},
"runtime-dom": {},
"runtime-vapor": {},
reactivity: {},
shared: {},
"@extensions/chibivue-router": {},
"@extensions/chibivue-store": {},
"@extensions/vite-plugin-chibivue": {
external: ["vite"],
},
};

export const buildMain = () => {
execSync("tsc -p tsconfig.build.json");

const promises = Object.entries(PACKAGES).map(async ([pkg, { external }]) => {
const res = await build({
entryPoints: [path.resolve(`packages/${pkg}/src/index`)],
target: "esnext",
bundle: true,
outdir: `packages/${pkg}/dist`,
external: [...NODE_EXTERNALS, ...(external ?? [])],
format: "esm",
plugins: [
{
name: "TypeScriptDeclarationsPlugin",
setup(build: any) {
build.onEnd(() => {
bundle({
name: pkg,
main: `temp/${pkg}/src/index.d.ts`,
out: path.resolve(`packages/${pkg}/dist/index.d.ts`),
});
});
},
},
],
});
finishedBuild(`packages/${pkg}/dist`);
return res;
});
return promises;
};

export const clearMain = () =>
Object.entries(PACKAGES)
.map(([pkg]) => `packages/${pkg}/dist`)
.map((dir) => rimraf(dir));

(async function main() {
console.log("clear dist...");
await Promise.allSettled([...clearMain()]);
console.log(`${t("✔︎").green._} finished clearing dist`);
console.log("building...");
const buildingMain = buildMain();
await Promise.all([...buildingMain]);
execSync("rm -rf temp");
})();
Loading

0 comments on commit 1d60c16

Please sign in to comment.