Skip to content

Commit

Permalink
Update build.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlol committed Nov 2, 2023
1 parent 6f4f821 commit abb412e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions scripts/tasks/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "node:fs";
import { rm, writeFile } from "node:fs/promises";
import { copyFile, rm, writeFile } from "node:fs/promises";
import path from "node:path";

import git from "isomorphic-git";
Expand All @@ -13,7 +13,9 @@ import prettierOptions from "../../.config/prettier/.prettierrc.json";
import pkg from "../../eslint-flat-config-gitignore/package.json";
import { license } from "../../package.json";

const clean = () => rm(path.resolve(projectRoot, pkg.name, "dist"), { recursive: true, force: true });
const dist = path.resolve(projectRoot, pkg.name, "dist");

const clean = () => rm(dist, { recursive: true, force: true });

const compile = () => $$`tsc --project ${path.resolve(projectRoot, pkg.name, "tsconfig.json")}`;

Expand All @@ -22,20 +24,27 @@ const writePackageJson = async () => {
const url = (await git.listRemotes({ fs, dir: projectRoot })).at(0)?.url;
const pkgJson: PackageJson = Object.assign({}, pkg as PackageJson, {
version: semverRsort(tags)[0],
repository: url ?? { type: "git", url },
repository: url && { type: "git", url },
license,
exports: {
types: "./index.d.ts",
import: "./index.js",
},
});
const filepath = path.resolve(projectRoot, pkg.name, "dist/package.json");
const filepath = path.resolve(dist, "package.json");
const packageJson = await prettier.format(JSON.stringify(pkgJson), { ...prettierOptions, filepath });
await writeFile(filepath, packageJson);
};

const copyFiles = async (...files: string[]) => {
for (const file of files) {
await copyFile(path.resolve(projectRoot, file), path.resolve(dist, file));
}
};

export const build = async () => {
await clean();
await compile();
await writePackageJson();
await copyFiles("ReadMe.md", "LICENSE");
};

0 comments on commit abb412e

Please sign in to comment.