2021-08-04 21:51:25 +02:00
|
|
|
import path from 'path'
|
|
|
|
import {writeFileSync} from 'fs'
|
2021-08-04 22:56:03 +02:00
|
|
|
import {keyBy} from 'lodash-es'
|
2021-08-04 21:51:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2021-08-04 22:56:03 +02:00
|
|
|
const packagesToBuild = [
|
|
|
|
'theatre',
|
|
|
|
'@theatre/dataverse',
|
|
|
|
'@theatre/dataverse-react',
|
|
|
|
'@theatre/plugin-r3f',
|
|
|
|
]
|
|
|
|
|
|
|
|
const packagesToPublish = [
|
|
|
|
'@theatre/core',
|
|
|
|
'@theatre/studio',
|
|
|
|
'@theatre/dataverse',
|
|
|
|
'@theatre/dataverse-react',
|
|
|
|
'@theatre/plugin-r3f',
|
|
|
|
]
|
|
|
|
|
2021-08-04 21:51:25 +02:00
|
|
|
;(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
|
|
|
|
|
2021-08-04 22:56:03 +02:00
|
|
|
$.verbose = false
|
|
|
|
const gitTags = (await $`git tag --list`).toString().split('\n')
|
2021-08-04 21:51:25 +02:00
|
|
|
|
2021-08-04 22:56:03 +02:00
|
|
|
const allPackages = keyBy(
|
|
|
|
(await $`yarn workspaces list --json`)
|
|
|
|
.toString()
|
|
|
|
.split('\n')
|
|
|
|
.filter((s) => s.trim().length > 0)
|
|
|
|
.map((s) => JSON.parse(s)),
|
|
|
|
'name',
|
|
|
|
)
|
|
|
|
|
|
|
|
if ((await $`git status -s`).toString().length > 0) {
|
|
|
|
console.error(`Git working directory contains uncommitted changes:`)
|
|
|
|
$.verbose = true
|
|
|
|
await $`git status -s`
|
|
|
|
console.log('Commit/stash them and try again.')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2021-08-04 21:51:25 +02:00
|
|
|
|
2021-08-04 22:56:03 +02:00
|
|
|
$.verbose = true
|
|
|
|
console.log('Running a typecheck and lint pass')
|
|
|
|
await Promise.all([
|
|
|
|
$`yarn run typecheck`,
|
|
|
|
$`yarn run lint:all --max-warnings 0`,
|
|
|
|
])
|
2021-08-04 21:51:25 +02:00
|
|
|
|
2021-08-04 22:56:03 +02:00
|
|
|
const [didOverwriteVersions, monorepoVersion] = syncVersionNumbers()
|
|
|
|
|
|
|
|
console.log('Building all packages')
|
2021-08-04 21:51:25 +02:00
|
|
|
await Promise.all(
|
2021-08-04 22:56:03 +02:00
|
|
|
packagesToBuild.map(
|
|
|
|
(workspace) => $`yarn workspace ${workspace} run build`,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
'Checking if the build produced artifacts that must first be comitted to git',
|
2021-08-04 21:51:25 +02:00
|
|
|
)
|
2021-08-04 22:56:03 +02:00
|
|
|
$.verbose = false
|
|
|
|
if ((await $`git status -s`).toString().length > 0) {
|
|
|
|
console.error(`Git directory contains uncommitted changes.`)
|
|
|
|
$.verbose = true
|
|
|
|
await $`git status -s`
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
$.verbose = true
|
2021-08-04 21:51:25 +02:00
|
|
|
|
2021-08-04 22:56:03 +02:00
|
|
|
if (!gitTags.some((tag) => tag === monorepoVersion)) {
|
|
|
|
console.log(
|
|
|
|
`No git tag found for version "${monorepoVersion}". Run \`$ git tag ${monorepoVersion}\` and try again.`,
|
|
|
|
)
|
|
|
|
process.exit()
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Publishing to npm')
|
2021-08-04 21:51:25 +02:00
|
|
|
await Promise.all(
|
2021-08-04 22:56:03 +02:00
|
|
|
packagesToPublish.map(
|
2021-08-04 21:51:25 +02:00
|
|
|
(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
|
|
|
|
|
2021-08-04 22:56:03 +02:00
|
|
|
console.log(`Syncing packages versions to ${monorepoVersion}`)
|
|
|
|
|
|
|
|
let didOverwrite = false
|
2021-08-04 21:51:25 +02:00
|
|
|
|
|
|
|
for (const packagePathRelativeFromRoot of workspaces) {
|
|
|
|
const pathToPackage = path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../',
|
|
|
|
packagePathRelativeFromRoot,
|
|
|
|
'./package.json',
|
|
|
|
)
|
|
|
|
|
|
|
|
const original = require(pathToPackage)
|
|
|
|
|
|
|
|
if (original.version !== monorepoVersion) {
|
2021-08-04 22:56:03 +02:00
|
|
|
didOverwrite = true
|
2021-08-04 21:51:25 +02:00
|
|
|
console.log(`Setting version of ${original.name} to ${monorepoVersion}`)
|
|
|
|
|
|
|
|
const newJson = {...original}
|
|
|
|
newJson.version = monorepoVersion
|
|
|
|
writeFileSync(
|
|
|
|
path.join(pathToPackage),
|
|
|
|
JSON.stringify(newJson, undefined, 2),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2021-08-04 22:56:03 +02:00
|
|
|
return [didOverwrite, monorepoVersion]
|
2021-08-04 21:51:25 +02:00
|
|
|
}
|