@syncbridge/syncbuild
v0.6.4
Published
SyncBridge Extension Package Builder
Readme
@syncbridge/syncbuild
SyncBridge Extension Package Builder - A powerful tool for building and bundling SyncBridge extension packages.
Installation
npm install @syncbridge/syncbuildCLI Usage
The syncbuild CLI tool allows you to build and bundle your SyncBridge extension packages from the command line.
Basic Usage
syncbuild [options]CLI Options
| Option | Description | Default |
|----------------------------|-----------------------------------|-----------------|
| -p, --path <packagePath> | Directory of the package to build | - |
| -o, --out <fileName> | Output package file name | - |
| --tsconfig <fileName> | Path to tsconfig file | tsconfig.json |
| --no-color | Disables colors in log messages | - |
| -V, --version | Output the version number | - |
| -h, --help | Display help information | - |
CLI Examples
Build a package from a specific directory:
syncbuild --path ./my-extensionBuild with a custom tsconfig:
syncbuild --path ./my-extension --tsconfig tsconfig.build.jsonDisable colored output:
syncbuild --path ./my-extension --no-colorAPI Usage
You can also use syncbuild programmatically in your Node.js applications.
Basic API Usage
import { bundlePackage } from '@syncbridge/syncbuild';
await bundlePackage({
packageDir: './my-extension',
tsconfig: 'tsconfig.json'
});API Configuration
bundlePackage(config: PackageBuildConfig): Promise<void>
The main function for building and bundling packages.
PackageBuildConfig Interface
| Property | Type | Description | Default |
|---------------------|--------------------------|-------------------------------------------------|-----------------|
| packageDir | string | Directory of the package to be built (required) | - |
| outDir | string | Output directory for the build | - |
| tsconfig | string | Path to the tsconfig file | tsconfig.json |
| external | Record<string, string> | External dependencies to exclude from the build | - |
| minify | boolean | Minify the output bundle | true |
| minifyWhitespace | boolean | Minify whitespace in the output | true |
| minifyIdentifiers | boolean | Minify identifiers in the output | true |
| minifySyntax | boolean | Minify syntax in the output | true |
| banner | string | Custom banner to prepend to the output | - |
| keepNames | boolean | Keep names of variables and functions | false |
API Examples
Basic Build
import { bundlePackage } from '@syncbridge/syncbuild';
await bundlePackage({
packageDir: './my-extension'
});Advanced Build with Options
import { bundlePackage } from '@syncbridge/syncbuild';
await bundlePackage({
packageDir: './my-extension',
outDir: './dist',
tsconfig: 'tsconfig.build.json',
minify: true,
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true,
keepNames: false,
external: {
'external-module': '^1.0.0'
},
banner: '// Copyright 2024 My Company'
});With Error Handling
import { bundlePackage } from '@syncbridge/syncbuild';
import { SbError } from '@syncbridge/common';
try {
await bundlePackage({
packageDir: './my-extension',
tsconfig: 'tsconfig.json'
});
console.log('Build completed successfully!');
} catch (error) {
if (error instanceof SbError) {
console.error('Build failed:', error.message);
} else {
console.error('Unexpected error:', error);
}
}Build Process
The build process performs the following steps:
- Context Creation - Initializes build context with configuration
- TypeScript Configuration - Reads and validates tsconfig.json
- Source Building - Compiles TypeScript sources using esbuild
- Export Extraction - Extracts and processes package exports
- Package Generation - Creates package.json for output
- Zipping - Bundles the built package into a distributable format
Requirements
- Node.js >= 20.0
- TypeScript project with valid tsconfig.json
- Valid package.json in the package directory
License
Author
Panates Inc
