|
| 1 | +// eslint-disable-next-line n/no-unsupported-features/node-builtins |
| 2 | +import { cp, mkdir, rm, writeFile } from "node:fs/promises"; |
| 3 | +import path from "node:path"; |
| 4 | + |
| 5 | +import { $ } from "execa"; |
| 6 | + |
| 7 | +import pkg from "@/create-devcontainer/package.json"; |
| 8 | +import { projectRoot } from "@/scripts/project.js"; |
| 9 | +import { build } from "@/scripts/tasks/build.js"; |
| 10 | + |
| 11 | +const XDG_DATA_HOME = process.env.XDG_DATA_HOME; |
| 12 | +if (!XDG_DATA_HOME) { |
| 13 | + throw new Error("XDG_DATA_HOME is not set"); |
| 14 | +} |
| 15 | + |
| 16 | +await build(); |
| 17 | + |
| 18 | +// Copy the dist folder to a temporary location |
| 19 | +const tempPath = `/tmp/${pkg.name}`; |
| 20 | +await rm(tempPath, { recursive: true, force: true }); |
| 21 | +await mkdir(tempPath, { recursive: true }); |
| 22 | +await cp(path.resolve(projectRoot, pkg.name, "dist"), tempPath, { recursive: true }); |
| 23 | +await writeFile(path.resolve(tempPath, "pnpm-workspace.yaml"), ""); |
| 24 | + |
| 25 | +// Install the package globally after pnpm deploy. |
| 26 | +process.env.NODE_ENV = "production"; |
| 27 | +const installPath = path.resolve(XDG_DATA_HOME, pkg.name); |
| 28 | +await rm(installPath, { recursive: true, force: true }); |
| 29 | +const $$ = $({ stdio: "inherit", verbose: "full", cwd: tempPath }); |
| 30 | +await $$`pnpm deploy --filter=${pkg.name} --prod ${installPath}`; |
| 31 | +await $$`npm uninstall --global ${pkg.name}`; |
| 32 | +await $$`npm install --global ${installPath}`; |
| 33 | +await $$`rm --recursive ${tempPath}`; |
0 commit comments