Files
twenty/packages/twenty-sdk/scripts/front-component-stories/build-source-examples.ts
T
Charles Bochet f17cc4d190 Improve building of twenty-sdk (#17913)
## Split twenty-sdk build into separate Node and browser targets

The SDK was bundling Node.js code (CLI, SDK API) and browser code (UI
components, front-component renderer) through a single Vite config. This
caused incorrect externalization — Node builtins leaked into browser
bundles and browser-specific chunking logic applied to CLI output.

This PR splits the build into `vite.config.node.ts` and
`vite.config.browser.ts` so each target gets the right externals and
output format.

Also includes a few housekeeping renames:
- `front-component` export path → `front-component-renderer` (matches
what it actually is)
- `front-component-common` merged into `front-component-api` (was a
needless extra module)
2026-02-13 15:58:19 +01:00

54 lines
1.8 KiB
TypeScript

import * as esbuild from 'esbuild';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import { createFrontComponentBuildOptions } from './utils/create-front-component-build-options';
const dirname = path.dirname(fileURLToPath(import.meta.url));
const exampleSourcesDir = path.resolve(dirname, '../../src/front-component-renderer/__stories__/example-sources');
const exampleSourcesBuiltDir = path.resolve(dirname, '../../src/front-component-renderer/__stories__/example-sources-built');
const sdkRoot = path.resolve(dirname, '../../../..');
const STORY_COMPONENTS = [
'static.front-component',
'interactive.front-component',
'lifecycle.front-component',
'chakra-example.front-component',
'tailwind-example.front-component',
];
export const buildSourceExamples = async (): Promise<void> => {
fs.mkdirSync(exampleSourcesBuiltDir, { recursive: true });
const entryPoints: Record<string, string> = {};
for (const name of STORY_COMPONENTS) {
const filePath = path.join(exampleSourcesDir, `${name}.tsx`);
if (!fs.existsSync(filePath)) {
throw new Error(
`Story component source file not found: ${filePath}\n` +
`Ensure the file exists in ${exampleSourcesDir} and the name in STORY_COMPONENTS is correct.`,
);
}
entryPoints[name] = filePath;
}
const buildOptions = createFrontComponentBuildOptions({
entryPoints,
outdir: exampleSourcesBuiltDir,
tsconfigPath: path.join(dirname, '../../tsconfig.json'),
});
await esbuild.build(buildOptions);
console.log(
`Built ${STORY_COMPONENTS.length} story components to ${exampleSourcesBuiltDir}`,
);
};
buildSourceExamples().catch((error) => {
console.error('Failed to build mock components:', error);
process.exit(1);
});