Skip to content

Commit

Permalink
Make build script reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel K committed Nov 5, 2020
1 parent 44b6413 commit a06d6cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/mobx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"scripts": {
"test": "jest",
"lint": "eslint src/**/*",
"build": "node scripts/build.js",
"build": "node ../../scripts/build.js mobx",
"perf": "scripts/perf.sh",
"test:performance": "yarn perf proxy && yarn perf legacy",
"test:mixed-versions": "yarn test --testRegex mixed-versions",
Expand Down
29 changes: 13 additions & 16 deletions packages/mobx/scripts/build.js → scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const path = require("path")
const execa = require("execa")

const stdio = ["ignore", "inherit", "ignore"]
const cwd = path.resolve("../")
const opts = { stdio }

const packageName = process.argv[2]

// build to publish needs to do more things so it's slower
// for the CI run and local testing this is not necessary
const isPublish = process.argv[2] === "publish"
const isPublish = process.argv[3] === "publish"

const tempMove = name => fs.move(`dist/${name}`, `temp/${name}`)
const moveTemp = name => fs.move(`temp/${name}`, `dist/${name}`)
Expand All @@ -19,27 +20,23 @@ const run = async () => {
// and these builds cannot be run in parallel because tsdx doesn't allow to change target dir
await execa("tsdx", ["build", "--format", "esm", "--env", "development"], opts)
// tsdx will purge dist folder, so it's necessary to move these
await tempMove("mobx.esm.development.js")
await tempMove("mobx.esm.development.js.map")
await tempMove(`${packageName}.esm.development.js`)
await tempMove(`${packageName}.esm.development.js.map`)

await execa("tsdx", ["build", "--format", "esm", "--env", "production"], opts)
await tempMove("mobx.esm.production.min.js")
await tempMove("mobx.esm.production.min.js.map")
await tempMove(`${packageName}.esm.production.min.js`)
await tempMove(`${packageName}.esm.production.min.js.map`)
}

await execa("tsdx", ["build", "--name", "mobx", "--format", "esm,cjs,umd"], opts)
await execa("tsdx", ["build", "--name", packageName, "--format", "esm,cjs,umd"], opts)

if (isPublish) {
await moveTemp("mobx.esm.development.js")
await moveTemp("mobx.esm.development.js.map")
await moveTemp("mobx.esm.production.min.js")
await moveTemp("mobx.esm.production.min.js.map")

// move ESM bundles back to dist folder and remove temp
await moveTemp(`${packageName}.esm.development.js`)
await moveTemp(`${packageName}.esm.development.js.map`)
await moveTemp(`${packageName}.esm.production.min.js`)
await moveTemp(`${packageName}.esm.production.min.js.map`)
await fs.remove("temp")

await fs.copy("flow-typed/mobx.js", "dist/index.js.flow")
await fs.copy("../../README.md", "./README.md")
await fs.copy("../../LICENSE", "./LICENSE")
}
}

Expand Down

0 comments on commit a06d6cb

Please sign in to comment.