Skip to content

Commit

Permalink
Fix cli build
Browse files Browse the repository at this point in the history
  • Loading branch information
AriaMinaei committed Jan 1, 2024
1 parent ef9b4c0 commit 24f9abf
Show file tree
Hide file tree
Showing 66 changed files with 1,004 additions and 597 deletions.
63 changes: 14 additions & 49 deletions devEnv/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,31 @@ $.quote = function quote(arg) {
)
}

const packagesToBuild = [
'@theatre/saaz',
'@theatre/core',
'@theatre/studio',
'@theatre/dataverse',
'@theatre/react',
'@theatre/browser-bundles',
'@theatre/r3f',
'theatric',
]

prog
.command(
'build clean',
'Cleans the build artifacts and output directories of all the main packages',
)
.action(async () => {
const packages = [
'@theatre/saaz',
'theatre',
'@theatre/dataverse',
'@theatre/react',
'@theatre/browser-bundles',
'@theatre/r3f',
'theatric',
]
const packages = [...packagesToBuild]

await Promise.all([
...packages.map((workspace) => $`yarn workspace ${workspace} run clean`),
])
})

prog.command('build', 'Builds all the main packages').action(async () => {
const packagesToBuild = [
'@theatre/saaz',
'theatre',
'@theatre/dataverse',
'@theatre/react',
'@theatre/browser-bundles',
'@theatre/r3f',
'theatric',
]
async function build() {
await Promise.all([
$`yarn run build:ts`,
Expand All @@ -80,42 +74,13 @@ prog
*
* It assigns the same version number to all packages (like lerna's fixed mode).
**/
const packagesToBuild = [
'@theatre/saaz',
'theatre',
'@theatre/dataverse',
'@theatre/react',
'@theatre/browser-bundles',
'@theatre/r3f',
'theatric',
]

const packagesToPublish = [
'@theatre/core',
'@theatre/studio',
'@theatre/dataverse',
'@theatre/saaz',
'@theatre/react',
'@theatre/browser-bundles',
'@theatre/r3f',
'theatric',
]
const packagesToPublish = [...packagesToBuild]

/**
* All these packages will have the same version from monorepo/package.json
*/
const packagesWhoseVersionsShouldBump = [
'.',
'theatre',
'theatre/core',
'theatre/studio',
'packages/dataverse',
'packages/react',
'packages/saaz',
'packages/browser-bundles',
'packages/r3f',
'packages/theatric',
]
const packagesWhoseVersionsShouldBump = ['.', ...packagesToPublish]

// 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 release`
Expand Down
5 changes: 1 addition & 4 deletions devEnv/ensurePublishing.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
if (
process.env.THEATRE_IS_PUBLISHING !== 'true' &&
process.env.USING_YALC !== 'true'
) {
if (process.env.THEATRE_IS_PUBLISHING !== 'true') {
throw Error(
`This script may run only when the "release" command in monorepo's root is running.`,
)
Expand Down
53 changes: 20 additions & 33 deletions packages/browser-bundles/devEnv/build.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import * as path from 'path'
import {build} from 'esbuild'
import type {Plugin} from 'esbuild'
import * as esbuild from 'esbuild'
import {definedGlobals} from '../../core/devEnv/definedGlobals'

const definedGlobals = {
global: 'window',
'process.env.THEATRE_VERSION': JSON.stringify(
require('../package.json').version,
),
}

function createBundles(watch: boolean) {
function createBundles() {
const pathToPackage = path.join(__dirname, '../')
const esbuildConfig: Parameters<typeof build>[0] = {
const esbuildConfig: Parameters<typeof esbuild.context>[0] = {
bundle: true,
sourcemap: true,
define: definedGlobals,
watch,
define: {
...definedGlobals,
__IS_VISUAL_REGRESSION_TESTING: 'false',
'process.env.NODE_ENV': '"production"',
},
platform: 'browser',
supported: {
// 'unicode-escapes': false,
'template-literal': false,
},
loader: {
'.png': 'dataurl',
'.glb': 'dataurl',
Expand All @@ -28,37 +28,24 @@ function createBundles(watch: boolean) {
conditions: ['browser', 'node'],
}

// build({
// ...esbuildConfig,
// entryPoints: [path.join(pathToPackage, 'src/core-only.ts')],
// outfile: path.join(pathToPackage, 'dist/core-only.js'),
// format: 'iife',
// })

void build({
void esbuild.build({
...esbuildConfig,
entryPoints: [path.join(pathToPackage, 'src/core-and-studio.ts')],
outfile: path.join(pathToPackage, 'dist/core-and-studio.js'),
format: 'iife',
minifyIdentifiers: false,
minifySyntax: true,
minifyWhitespace: false,
treeShaking: true,
})

void build({
void esbuild.build({
...esbuildConfig,
entryPoints: [path.join(pathToPackage, 'src/core-only.ts')],
outfile: path.join(pathToPackage, 'dist/core-only.min.js'),
minify: true,
format: 'iife',
define: {
...definedGlobals,
'process.env.NODE_ENV': JSON.stringify('production'),
},
})

// build({
// ...esbuildConfig,
// outfile: path.join(pathToPackage, 'dist/index.mjs'),
// format: 'esm',
// })
}

createBundles(false)
createBundles()
10 changes: 4 additions & 6 deletions packages/browser-bundles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
"clean": "rm -rf ./dist && rm -f tsconfig.tsbuildinfo"
},
"devDependencies": {
"esbuild": "^0.12.15",
"esbuild-register": "^2.5.0",
"@theatre/core": "*",
"@theatre/studio": "*",
"esbuild": "^0.19.11",
"esbuild-register": "^3.5.0",
"npm-run-all": "^4.1.5",
"typescript": "5.1.6"
},
"peerDependencies": {
"@theatre/core": "*",
"@theatre/studio": "*"
}
}
6 changes: 2 additions & 4 deletions packages/browser-bundles/src/core-and-studio.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as core from '@theatre/core'
import '@theatre/studio'

// @ts-ignore
window.Theatre = {
core,
studio,
}
window.Theatre = core
10 changes: 1 addition & 9 deletions packages/browser-bundles/src/core-only.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import * as core from '@theatre/core'

// @ts-ignore
window.Theatre = {
core,
get studio() {
alert(
"Theatre.studio is only available in the core-and-studio.js bundle. You're using the core-only.min.js bundle.",
)
return undefined
},
}
window.Theatre = core
8 changes: 1 addition & 7 deletions packages/browser-bundles/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"lib": ["ESNext", "DOM"],
Expand All @@ -9,10 +8,5 @@
"target": "es6",
"composite": true
},
"include": ["./src/**/*"],
"references": [
{"path": "../dataverse"},
{"path": "../core"},
{"path": "../studio"}
]
"include": ["./src/**/*"]
}
3 changes: 0 additions & 3 deletions packages/core/devEnv/bundle.ts

This file was deleted.

72 changes: 72 additions & 0 deletions packages/core/devEnv/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import sade from 'sade'
import {path, $} from '@cspotcode/zx'
import * as esbuild from 'esbuild'
import {definedGlobals} from './definedGlobals'
const packageRoot = path.join(__dirname, '..')

const prog = sade('cli')

prog
.command('build js', 'Generate the .js bundle')
.option('--watch', 'Watch')
.action(async (opts) => {
await bundle(opts.watch)
})

prog.command('build ts', 'Generate the .d.ts bundle').action(async () => {
await bundleTypes()
})

prog.command('build', 'Generate the .js and .d.ts bundles').action(async () => {
await Promise.all([bundle(false), bundleTypes()])
})

prog.parse(process.argv)

async function bundleTypes() {
await $`tsc --build`
await $`rollup -c devEnv/declarations-bundler/rollup.config.js --bundleConfigAsCjs`
}

async function bundle(watch: boolean) {
console.log('bu')
const esbuildConfig: Parameters<typeof esbuild.context>[0] = {
entryPoints: [path.join(packageRoot, 'src/index.ts')],
target: ['es6'],
// loader: {'.png': 'file', '.svg': 'dataurl'},
bundle: true,
sourcemap: true,
supported: {
// 'unicode-escapes': false,
'template-literal': false,
},
define: {
...definedGlobals,
__IS_VISUAL_REGRESSION_TESTING: 'false',
'process.env.NODE_ENV': '"production"',
},
external: ['@theatre/dataverse'],
minifyIdentifiers: false,
minifySyntax: true,
minifyWhitespace: false,
treeShaking: true,
}

esbuildConfig.platform = 'neutral'
esbuildConfig.mainFields = ['browser', 'module', 'main']
esbuildConfig.target = ['firefox57', 'chrome58']
esbuildConfig.conditions = ['browser', 'node']

const ctx = await esbuild.context({
...esbuildConfig,
outfile: path.join(packageRoot, 'dist/index.js'),
format: 'cjs',
})

if (watch) {
await ctx.watch()
} else {
await ctx.rebuild()
await ctx.dispose()
}
}
Loading

0 comments on commit 24f9abf

Please sign in to comment.