chore: esm compatible scripts

This commit is contained in:
Dan Ribbens
2024-03-06 12:11:12 -05:00
parent a7dcdc8df2
commit 19d2a4d1cd
3 changed files with 40 additions and 18 deletions

View File

@@ -1,5 +1,9 @@
import fse from 'fs-extra'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const packagesDir = path.resolve(__dirname, '../../packages')

View File

@@ -1,7 +1,7 @@
import type { ExecSyncOptions } from 'child_process'
import { execSync } from 'child_process'
import chalk from 'chalk'
import { execSync } from 'child_process'
import execa from 'execa'
import fse from 'fs-extra'
import minimist from 'minimist'
@@ -12,6 +12,7 @@ import simpleGit from 'simple-git'
import { getPackageDetails } from './lib/getPackageDetails'
import { updateChangelog } from './utils/updateChangelog'
import { fileURLToPath } from 'url'
// Update this list with any packages to publish
const packageWhitelist = [
@@ -20,14 +21,20 @@ const packageWhitelist = [
'ui',
'next',
'graphql',
'db-mongodb',
'db-postgres',
'richtext-slate',
'richtext-lexical',
'plugin-cloud',
'plugin-cloud-storage',
'plugin-seo',
]
const rootPath = path.resolve(__dirname, '..')
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const cwd = path.resolve(__dirname, '..')
const git = simpleGit(rootPath)
const git = simpleGit(cwd)
const execOpts: ExecSyncOptions = { stdio: 'inherit' }
const args = minimist(process.argv.slice(2))
@@ -120,16 +127,12 @@ async function main() {
// Prebuild all packages
header(`\n🔨 Prebuilding all packages...`)
await execa('pnpm', ['install'], {
cwd: rootPath,
stdio: 'inherit',
})
const buildResult = await execa('pnpm', ['build:core', '--output-logs=errors-only'], {
cwd: rootPath,
// stdio: ['ignore', 'ignore', 'pipe'],
stdio: 'inherit',
})
const execaOpts: execa.Options = { ...execOpts, stdio: 'inherit' }
await execa('pnpm', ['install'], execaOpts)
const buildResult = await execa('pnpm', ['build:core', '--output-logs=errors-only'], execaOpts)
// const buildResult = execSync('pnpm build:all', execOpts)
if (buildResult.exitCode !== 0) {
console.error(chalk.bold.red('Build failed'))
@@ -137,10 +140,22 @@ async function main() {
abort('Build failed')
}
const buildPluginsResult = await execa(
'pnpm',
['build:plugins', '--output-logs=errors-only'],
execaOpts,
)
if (buildPluginsResult.exitCode !== 0) {
console.error(chalk.bold.red('Build failed'))
console.log(buildPluginsResult.stderr)
abort('Build failed')
}
// Update changelog
if (changelog) {
header(`${logPrefix}📝 Updating changelog...`)
await updateChangelog({ newVersion: nextReleaseVersion, dryRun })
await updateChangelog({ dryRun, newVersion: nextReleaseVersion })
} else {
console.log(chalk.bold.yellow('📝 Skipping changelog update'))
}
@@ -191,7 +206,7 @@ async function main() {
cmdArgs.push('--otp', otp)
}
const { exitCode } = await execa('pnpm', cmdArgs, {
cwd: rootPath,
cwd,
stdio: ['ignore', 'ignore', 'pipe'],
// stdio: 'inherit',
})

View File

@@ -9,11 +9,13 @@ import addStream from 'add-stream'
import conventionalChangelog from 'conventional-changelog'
import { default as getConventionalPreset } from 'conventional-changelog-conventionalcommits'
import { once } from 'events'
import fse, { createReadStream, createWriteStream } from 'fs-extra'
import fse from 'fs-extra'
import minimist from 'minimist'
import simpleGit from 'simple-git'
import tempfile from 'tempfile'
const { createReadStream, createWriteStream } = fse
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN })
const git = simpleGit()
@@ -105,8 +107,9 @@ export const updateChangelog = async ({ newVersion, dryRun }: Args) => {
await once(emitter, 'finish')
}
// If file is executed directly, run the function
if (require.main === module) {
// module import workaround for ejs
if (import.meta.url === `file://${process.argv[1]}`) {
// This module is being run directly
const { newVersion } = minimist(process.argv.slice(2))
updateChangelog({ dryRun: true, newVersion })
.then(() => {