Simplified the deployment script

* Implemented yarn run deploy, which deploys all packages to npm, with the same version assigned to all of them.
This commit is contained in:
Aria Minaei 2021-08-04 21:51:25 +02:00
parent 4395c62b17
commit c2b5dca63b
11 changed files with 152 additions and 24 deletions

84
devEnv/deploy.mjs Normal file
View file

@ -0,0 +1,84 @@
import path from 'path'
import {writeFileSync} from 'fs'
/**
* This script publishes all packages to npm.
*
* It assigns the same version number to all packages (like lerna's fixed mode).
**/
// It's written in .mjs because I kept running into issues with zx+typescript
;(async function () {
// our packages will check for this env variable to make sure their
// prepublish script is only called from the `$ cd /path/to/monorepo; yarn run deploy`
process.env.THEATRE_IS_PUBLISHING = true
await $`yarn run typecheck`
syncVersionNumbers()
return
await Promise.all(
[
'theatre',
'@theatre/dataverse',
'@theatre/dataverse-react',
'@theatre/plugin-r3f',
].map((workspace) => $`yarn workspace ${workspace} run build`),
)
await Promise.all(
[
'@theatre/core',
'@theatre/studio',
'@theatre/dataverse',
'@theatre/dataverse-react',
'@theatre/plugin-r3f',
].map(
(workspace) => $`yarn workspace ${workspace} npm publish --access public`,
),
)
})()
function syncVersionNumbers() {
/**
* All these packages will have the same version from monorepo/package.json
*/
const workspaces = [
'theatre',
'theatre/core',
'theatre/studio',
'packages/dataverse',
'packages/dataverse-react',
'packages/plugin-r3f',
]
const monorepoVersion = require('../package.json').version
console.log(
`sync-versions: Setting versions of all packages to ${monorepoVersion}`,
)
for (const packagePathRelativeFromRoot of workspaces) {
const pathToPackage = path.resolve(
__dirname,
'../',
packagePathRelativeFromRoot,
'./package.json',
)
const original = require(pathToPackage)
if (original.version !== monorepoVersion) {
console.log(`Setting version of ${original.name} to ${monorepoVersion}`)
const newJson = {...original}
newJson.version = monorepoVersion
writeFileSync(
path.join(pathToPackage),
JSON.stringify(newJson, undefined, 2),
)
}
}
console.log('sync-versions: Done.')
}

View file

@ -0,0 +1,5 @@
if (process.env.THEATRE_IS_PUBLISHING !== 'true') {
throw Error(
`This script may run only when the "deploy" command in monorepo's root is running.`,
)
}

View file

@ -1,6 +1,7 @@
{ {
"name": "theatre-monorepo", "name": "theatre-monorepo",
"license": "Apache-2.0", "license": "Apache-2.0",
"version": "0.4.0-dev.4",
"workspaces": [ "workspaces": [
"packages/*", "packages/*",
"theatre" "theatre"
@ -9,6 +10,7 @@
"typecheck": "tsc --build ./devEnv/typecheck-all-projects/tsconfig.all.json", "typecheck": "tsc --build ./devEnv/typecheck-all-projects/tsconfig.all.json",
"test": "jest", "test": "jest",
"postinstall": "husky install", "postinstall": "husky install",
"deploy": "zx devEnv/deploy.mjs",
"lint:all": "eslint . --ext ts,tsx --ignore-path=.gitignore --rulesdir ./devEnv/eslint/rules" "lint:all": "eslint . --ext ts,tsx --ignore-path=.gitignore --rulesdir ./devEnv/eslint/rules"
}, },
"lint-staged": { "lint-staged": {
@ -38,7 +40,8 @@
"lerna": "^4.0.0", "lerna": "^4.0.0",
"lint-staged": "^11.0.0", "lint-staged": "^11.0.0",
"prettier": "^2.3.1", "prettier": "^2.3.1",
"typescript": "^4.3.2" "typescript": "^4.3.2",
"zx": "^2.0.0"
}, },
"dependencies": { "dependencies": {
"node-gyp": "^8.1.0" "node-gyp": "^8.1.0"

View file

@ -1,6 +1,6 @@
{ {
"name": "@theatre/dataverse-react", "name": "@theatre/dataverse-react",
"version": "1.0.0-dev.2", "version": "0.4.0-dev.4",
"license": "Apache-2.0", "license": "Apache-2.0",
"author": { "author": {
"name": "Aria Minaei", "name": "Aria Minaei",
@ -31,7 +31,8 @@
"typecheck": "yarn run build", "typecheck": "yarn run build",
"build": "run-s build:ts build:js", "build": "run-s build:ts build:js",
"build:ts": "tsc --build ./tsconfig.json", "build:ts": "tsc --build ./tsconfig.json",
"build:js": "node -r esbuild-register ./devEnv/build.ts" "build:js": "node -r esbuild-register ./devEnv/build.ts",
"prepublish": "node ../../devEnv/ensurePublishing.js"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/jest": "^26.0.23",

View file

@ -1,6 +1,6 @@
{ {
"name": "@theatre/dataverse", "name": "@theatre/dataverse",
"version": "1.0.0-dev.2", "version": "0.4.0-dev.4",
"license": "Apache-2.0", "license": "Apache-2.0",
"author": { "author": {
"name": "Aria Minaei", "name": "Aria Minaei",
@ -31,7 +31,8 @@
"typecheck": "yarn run build", "typecheck": "yarn run build",
"build": "run-s build:ts build:js", "build": "run-s build:ts build:js",
"build:ts": "tsc --build ./tsconfig.json", "build:ts": "tsc --build ./tsconfig.json",
"build:js": "node -r esbuild-register ./devEnv/build.ts" "build:js": "node -r esbuild-register ./devEnv/build.ts",
"prepublish": "node ../../devEnv/ensurePublishing.js"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/jest": "^26.0.23",

View file

@ -1,6 +1,6 @@
{ {
"name": "@theatre/plugin-r3f", "name": "@theatre/plugin-r3f",
"version": "1.0.0-dev.1", "version": "0.4.0-dev.4",
"license": "Apache-2.0", "license": "Apache-2.0",
"authors": [ "authors": [
{ {
@ -27,7 +27,8 @@
"scripts": { "scripts": {
"prepack": "yarn run build", "prepack": "yarn run build",
"typecheck": "yarn run build", "typecheck": "yarn run build",
"build": "tsc --build ./tsconfig.json" "build": "tsc --build ./tsconfig.json",
"prepublish": "node ../../devEnv/ensurePublishing.js"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/jest": "^26.0.23",

View file

@ -1,6 +1,6 @@
{ {
"name": "@theatre/core", "name": "@theatre/core",
"version": "0.4.0-dev.3", "version": "0.4.0-dev.4",
"license": "Apache-2.0", "license": "Apache-2.0",
"description": "Motion design editor for the web", "description": "Motion design editor for the web",
"repository": { "repository": {
@ -36,7 +36,7 @@
"dist/index.d.ts" "dist/index.d.ts"
], ],
"scripts": { "scripts": {
"prepublish": "cd .. && yarn run ensure-publishing" "prepublish": "node ../../devEnv/ensurePublishing.js"
}, },
"sideEffects": true, "sideEffects": true,
"dependencies": { "dependencies": {

View file

@ -1,5 +0,0 @@
if (process.env.THEATRE_IS_PUBLISHING !== 'true') {
throw Error(
`This script may run only when the "deploy" command in root/theatre is running.`,
)
}

View file

@ -1,7 +1,7 @@
{ {
"name": "theatre", "name": "theatre",
"private": true, "private": true,
"version": "0.4.0-dev.3", "version": "0.4.0-dev.4",
"workspaces": [ "workspaces": [
"./shared", "./shared",
"./core", "./core",
@ -13,13 +13,7 @@
"build:js:watch": "node -r esbuild-register devEnv/watch.ts", "build:js:watch": "node -r esbuild-register devEnv/watch.ts",
"build:dts": "run-s typecheck build:dts:bundle", "build:dts": "run-s typecheck build:dts:bundle",
"build:dts:bundle": "rollup -c devEnv/declarations-bundler/rollup.config.js", "build:dts:bundle": "rollup -c devEnv/declarations-bundler/rollup.config.js",
"build": "run-p build:dts build:js", "build": "run-p build:dts build:js"
"deploy": "cross-env-shell THEATRE_IS_PUBLISHING=true \"yarn run _deploy:steps\"",
"_deploy:steps": "run-s ensure-publishing update-versions build _deploy:core _deploy:studio",
"_deploy:core": "yarn workspace @theatre/core npm publish --access public",
"_deploy:studio": "yarn workspace @theatre/studio npm publish --access public",
"ensure-publishing": "node ./devEnv/ensurePublishing.js",
"update-versions": "node -r esbuild-register devEnv/updateVersions.ts"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.14.3", "@babel/cli": "^7.14.3",

View file

@ -1,6 +1,6 @@
{ {
"name": "@theatre/studio", "name": "@theatre/studio",
"version": "0.4.0-dev.3", "version": "0.4.0-dev.4",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"description": "Motion design editor for the web", "description": "Motion design editor for the web",
"repository": { "repository": {
@ -36,7 +36,7 @@
"dist/index.d.ts" "dist/index.d.ts"
], ],
"scripts": { "scripts": {
"prepublish": "cd .. && yarn run ensure-publishing" "prepublish": "node ../../devEnv/ensurePublishing.js"
}, },
"sideEffects": true, "sideEffects": true,
"peerDependencies": { "peerDependencies": {

View file

@ -3957,6 +3957,23 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@types/minimist@npm:^1.2.1":
version: 1.2.2
resolution: "@types/minimist@npm:1.2.2"
checksum: 8dd59cefa7be641b961ccfe65f6ff16aaa6735412f47d5c993543d4e92590465a0d728abc0dad36e4957d105a44357379adadbca4baaa2926427d4eb66d74d0d
languageName: node
linkType: hard
"@types/node-fetch@npm:^2.5.10":
version: 2.5.12
resolution: "@types/node-fetch@npm:2.5.12"
dependencies:
"@types/node": "*"
form-data: ^3.0.0
checksum: f648728116a24b9b5abc117e08788ed859283548ed65d374dba333d4604a7e8d22934cb4dbe7d64498c5c7f04885d84a2dc11c9a4115d426c242e74fb2f2a6a6
languageName: node
linkType: hard
"@types/node@npm:*": "@types/node@npm:*":
version: 14.14.37 version: 14.14.37
resolution: "@types/node@npm:14.14.37" resolution: "@types/node@npm:14.14.37"
@ -3978,6 +3995,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@types/node@npm:^16.0":
version: 16.4.12
resolution: "@types/node@npm:16.4.12"
checksum: 4bac961fa0bfe72c4303ca7574c8a824d159f0e01c19671be649d97e54f26959f7545ed9693a18a5d19839c8c3b85019e41c6614ee11a1e59d7265ffa26050fc
languageName: node
linkType: hard
"@types/normalize-package-data@npm:^2.4.0": "@types/normalize-package-data@npm:^2.4.0":
version: 2.4.0 version: 2.4.0
resolution: "@types/normalize-package-data@npm:2.4.0" resolution: "@types/normalize-package-data@npm:2.4.0"
@ -16377,6 +16401,7 @@ fsevents@^1.2.7:
node-gyp: ^8.1.0 node-gyp: ^8.1.0
prettier: ^2.3.1 prettier: ^2.3.1
typescript: ^4.3.2 typescript: ^4.3.2
zx: ^2.0.0
languageName: unknown languageName: unknown
linkType: soft linkType: soft
@ -17776,3 +17801,22 @@ fsevents@^1.2.7:
checksum: fdd1e6caaecbb0c3b7e869064752ace7113a16eabca56ab2f8cae6b1a0588ead08662289b7b7dde6a550d9ddf30881af370292406ca0b37d6d5d78a93e7db2b2 checksum: fdd1e6caaecbb0c3b7e869064752ace7113a16eabca56ab2f8cae6b1a0588ead08662289b7b7dde6a550d9ddf30881af370292406ca0b37d6d5d78a93e7db2b2
languageName: node languageName: node
linkType: hard linkType: hard
"zx@npm:^2.0.0":
version: 2.0.0
resolution: "zx@npm:2.0.0"
dependencies:
"@types/fs-extra": ^9.0.11
"@types/minimist": ^1.2.1
"@types/node": ^16.0
"@types/node-fetch": ^2.5.10
chalk: ^4.1.1
fs-extra: ^10.0.0
minimist: ^1.2.5
node-fetch: ^2.6.1
which: ^2.0.2
bin:
zx: zx.mjs
checksum: 5859c0c4326350f52fbb750fdd35264ed4983158fa06e6628103314ec6424d8536f9ec9fbf2fda981bb7187781af7c068998e9daf7cd5fa1440a1fe56a568c1a
languageName: node
linkType: hard