b7d9c8684c
This PR moves code between our packages so that: - @tldraw/editor is a “core” library with the engine and canvas but no shapes, tools, or other things - @tldraw/tldraw contains everything particular to the experience we’ve built for tldraw At first look, this might seem like a step away from customization and configuration, however I believe it greatly increases the configuration potential of the @tldraw/editor while also providing a more accurate reflection of what configuration options actually exist for @tldraw/tldraw. ## Library changes @tldraw/editor re-exports its dependencies and @tldraw/tldraw re-exports @tldraw/editor. - users of @tldraw/editor WITHOUT @tldraw/tldraw should almost always only import things from @tldraw/editor. - users of @tldraw/tldraw should almost always only import things from @tldraw/tldraw. - @tldraw/polyfills is merged into @tldraw/editor - @tldraw/indices is merged into @tldraw/editor - @tldraw/primitives is merged mostly into @tldraw/editor, partially into @tldraw/tldraw - @tldraw/file-format is merged into @tldraw/tldraw - @tldraw/ui is merged into @tldraw/tldraw Many (many) utils and other code is moved from the editor to tldraw. For example, embeds now are entirely an feature of @tldraw/tldraw. The only big chunk of code left in core is related to arrow handling. ## API Changes The editor can now be used without tldraw's assets. We load them in @tldraw/tldraw instead, so feel free to use whatever fonts or images or whatever that you like with the editor. All tools and shapes (except for the `Group` shape) are moved to @tldraw/tldraw. This includes the `select` tool. You should use the editor with at least one tool, however, so you now also need to send in an `initialState` prop to the Editor / <TldrawEditor> component indicating which state the editor should begin in. The `components` prop now also accepts `SelectionForeground`. The complex selection component that we use for tldraw is moved to @tldraw/tldraw. The default component is quite basic but can easily be replaced via the `components` prop. We pass down our tldraw-flavored SelectionFg via `components`. Likewise with the `Scribble` component: the `DefaultScribble` no longer uses our freehand tech and is a simple path instead. We pass down the tldraw-flavored scribble via `components`. The `ExternalContentManager` (`Editor.externalContentManager`) is removed and replaced with a mapping of types to handlers. - Register new content handlers with `Editor.registerExternalContentHandler`. - Register new asset creation handlers (for files and URLs) with `Editor.registerExternalAssetHandler` ### Change Type - [x] `major` — Breaking change ### Test Plan - [x] Unit Tests - [x] End to end tests ### Release Notes - [@tldraw/editor] lots, wip - [@tldraw/ui] gone, merged to tldraw/tldraw - [@tldraw/polyfills] gone, merged to tldraw/editor - [@tldraw/primitives] gone, merged to tldraw/editor / tldraw/tldraw - [@tldraw/indices] gone, merged to tldraw/editor - [@tldraw/file-format] gone, merged to tldraw/tldraw --------- Co-authored-by: alex <alex@dytry.ch>
134 lines
3.5 KiB
TypeScript
134 lines
3.5 KiB
TypeScript
import kleur from 'kleur'
|
|
import path from 'path'
|
|
import { REPO_ROOT, writeJsonFile } from './lib/file'
|
|
import { nicelog } from './lib/nicelog'
|
|
import { getAllWorkspacePackages } from './lib/workspace'
|
|
|
|
function scriptPath(packageDir: string, scriptName: string) {
|
|
return path.relative(packageDir, path.join(__dirname, scriptName))
|
|
}
|
|
|
|
function tsScript(scriptName: string) {
|
|
return (packageDir: string) => `yarn run -T tsx ${scriptPath(packageDir, scriptName)}`
|
|
}
|
|
|
|
// all packages should have these scripts
|
|
const expectedScripts = {
|
|
lint: tsScript('lint.ts'),
|
|
}
|
|
|
|
// packages (in packages/) should have these scripts
|
|
const expectedPackageScripts = {
|
|
...expectedScripts,
|
|
test: () => 'lazy inherit',
|
|
}
|
|
|
|
// published packages should have these scripts
|
|
const expectedPublishedPackageScripts = {
|
|
...expectedPackageScripts,
|
|
build: tsScript('build-package.ts'),
|
|
'build-api': tsScript('build-api.ts'),
|
|
prepack: tsScript('prepack.ts'),
|
|
postpack: (packageDir: string) => scriptPath(packageDir, 'postpack.sh'),
|
|
'pack-tarball': () => 'yarn pack',
|
|
}
|
|
|
|
// individual packages can have different scripts than the above if needed
|
|
const perPackageExceptions: Record<string, Record<string, () => string | undefined>> = {
|
|
config: {
|
|
lint: () => undefined,
|
|
},
|
|
tsconfig: {
|
|
lint: () => undefined,
|
|
},
|
|
'@tldraw/monorepo': {
|
|
lint: () => 'lazy lint',
|
|
},
|
|
'@tldraw/assets': {
|
|
test: () => undefined,
|
|
build: () => undefined,
|
|
'build-api': () => undefined,
|
|
prepack: () => undefined,
|
|
postpack: () => undefined,
|
|
},
|
|
}
|
|
|
|
async function main({ fix }: { fix?: boolean }) {
|
|
const packages = await getAllWorkspacePackages()
|
|
const needsFix = new Set()
|
|
|
|
let errorCount = 0
|
|
for (const { path: packageDir, relativePath, packageJson, name } of packages) {
|
|
if (!packageJson.scripts) {
|
|
packageJson.scripts = {}
|
|
}
|
|
const packageScripts = packageJson.scripts
|
|
|
|
let expected =
|
|
name.startsWith('@tldraw/') &&
|
|
(relativePath.startsWith('bublic/packages/') || relativePath.startsWith('packages/'))
|
|
? packageJson.private
|
|
? expectedPackageScripts
|
|
: expectedPublishedPackageScripts
|
|
: expectedScripts
|
|
|
|
if (perPackageExceptions[name]) {
|
|
expected = {
|
|
...expected,
|
|
...perPackageExceptions[name],
|
|
}
|
|
}
|
|
|
|
for (const [scriptName, getExpectedScript] of Object.entries(expected)) {
|
|
const actualScript = packageScripts[scriptName]
|
|
const expectedScript = getExpectedScript(packageDir)
|
|
if (actualScript !== expectedScript) {
|
|
nicelog(
|
|
[
|
|
'❌ ',
|
|
kleur.red(`${name}: `),
|
|
kleur.blue(`$ yarn ${scriptName}`),
|
|
kleur.grey(' -> '),
|
|
kleur.red(actualScript ?? '<missing>'),
|
|
kleur.gray(' (expected: '),
|
|
kleur.green(expectedScript),
|
|
kleur.gray(')'),
|
|
].join('')
|
|
)
|
|
packageScripts[scriptName] = expectedScript
|
|
needsFix.add(name)
|
|
errorCount++
|
|
} else {
|
|
nicelog(
|
|
[
|
|
'✅ ',
|
|
kleur.green(`${name}: `),
|
|
kleur.blue(`$ yarn ${scriptName}`),
|
|
kleur.grey(' -> '),
|
|
kleur.green(actualScript ?? '<missing>'),
|
|
].join('')
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (errorCount) {
|
|
if (fix) {
|
|
for (const { packageJson, name, relativePath } of packages) {
|
|
if (needsFix.has(name)) {
|
|
nicelog(kleur.yellow(`Fixing ${name}...`))
|
|
await writeJsonFile(path.join(REPO_ROOT, relativePath, 'package.json'), packageJson)
|
|
}
|
|
}
|
|
nicelog(kleur.yellow(`Fixed ${errorCount} errors`))
|
|
process.exit(0)
|
|
} else {
|
|
nicelog(kleur.red(`Found ${errorCount} errors`))
|
|
process.exit(1)
|
|
}
|
|
}
|
|
}
|
|
|
|
main({
|
|
fix: process.argv.includes('--fix'),
|
|
})
|