Skip to content

Commit

Permalink
build: save cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
cschroeter committed Sep 19, 2022
1 parent 814b1a8 commit 42b3dd2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
42 changes: 42 additions & 0 deletions scripts/clean-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import findPackages from "find-packages"
import { promises as fs } from "fs"

async function main() {
const pkgs = await findPackages("packages")
await Promise.all(
pkgs.map(async (pkg) => {
// check if src contains tsx files
let data = {
...pkg.manifest,
scripts: {
...pkg.manifest.scripts,
prepack: "clean-package",
postpack: "clean-package restore",
},
}

const config = {
replace: {
main: "dist/index.cjs.js",
module: "dist/index.esm.js",
types: "dist/index.d.ts",
exports: {
".": {
import: "./dist/index.esm.js",
require: "./dist/index.cjs.js",
},
"./package.json": "./package.json",
},
},
}

fs.writeFile(
`${pkg.dir}/clean-package.config.json`,
JSON.stringify(config, null, 2),
)
fs.writeFile(`${pkg.dir}/package.json`, JSON.stringify(data, null, 2))
}),
)
}

main()
10 changes: 7 additions & 3 deletions scripts/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ async function main() {
const pkgs = await findPackages("packages")
await Promise.all(
pkgs.map(async (pkg) => {
// check if src contains tsx files
const files = await fs.readdir(`${pkg.dir}/src`)
const tsx = files.some((f) => f.endsWith(".tsx"))

let data = {
...pkg.manifest,
main: "dist/index.cjs.js",
module: "dist/index.esm.js",
scripts: {
...pkg.manifest.scripts,
prepack: "clean-package",
postpack: "clean-package restore",
build: !tsx
? "tsup src/index.ts --dts"
: "JSX=1 tsup src/index.ts --dts",
"build:fast": !tsx ? "tsup src/index.ts" : "JSX=1 tsup src/index.ts",
dev: "pnpm build -- --watch",
},
}

Expand Down

0 comments on commit 42b3dd2

Please sign in to comment.