mirror of
https://github.com/hanzoai/extension.git
synced 2026-10-31 21:57:06 +00:00
`pnpm build` failed in clio, epic, notion, office, outlook and sketch with
esbuild's "Transforming destructuring to the configured target
environment ("safari14") is not supported yet". esbuild 0.28, the
catalog's version, does not count Safari 14.0 as supporting
destructuring (14.1 passes), and cannot lower it, so a plain
`const { a } = b` stopped the build, in these packages' own code and in
@hanzo/ai and @hanzo/iam.
The other fourteen packages that name a Safari target, the browser
extension among them, already name Safari 15. These six now do too.
Co-authored-by: Hanzo Dev <[email protected]>
111 lines
3.8 KiB
JavaScript
111 lines
3.8 KiB
JavaScript
// Assemble the .sketchplugin bundle into dist/. A Sketch plugin is a macOS
|
|
// bundle laid out as:
|
|
//
|
|
// Hanzo AI.sketchplugin/
|
|
// Contents/
|
|
// Sketch/
|
|
// manifest.json β commands + menu
|
|
// command.js β plugin entry (CommonJS, CocoaScript runtime)
|
|
// Resources/
|
|
// webview.html β the assistant panel
|
|
// app.js β the WebView bundle (browser, @hanzo/ai)
|
|
// icon.png
|
|
//
|
|
// node build.js β production build
|
|
// node build.js --watch β rebuild on change
|
|
//
|
|
// Two esbuild passes because the two runtimes differ: command.js runs on
|
|
// Sketch's JavaScriptCore/CocoaScript (CommonJS, `require('sketch/*')` external),
|
|
// and the WebView bundle runs in a real WebView (browser, `fetch` available, so
|
|
// @hanzo/ai is bundled in).
|
|
|
|
import esbuild from 'esbuild';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const watch = process.argv.includes('--watch');
|
|
const root = path.dirname(fileURLToPath(import.meta.url));
|
|
const src = path.join(root, 'src');
|
|
const dist = path.join(root, 'dist');
|
|
const bundle = path.join(dist, 'Hanzo AI.sketchplugin');
|
|
const sketchDir = path.join(bundle, 'Contents', 'Sketch');
|
|
const resDir = path.join(bundle, 'Contents', 'Resources');
|
|
|
|
// The `sketch` runtime modules are provided by the Sketch app β never bundled.
|
|
const SKETCH_EXTERNALS = [
|
|
'sketch',
|
|
'sketch/dom',
|
|
'sketch/ui',
|
|
'sketch/settings',
|
|
'sketch-module-web-view',
|
|
];
|
|
|
|
async function build() {
|
|
fs.rmSync(dist, { recursive: true, force: true });
|
|
fs.mkdirSync(sketchDir, { recursive: true });
|
|
fs.mkdirSync(resDir, { recursive: true });
|
|
|
|
// 1) The plugin entry β CommonJS for CocoaScript. sketch-bridge + design-core
|
|
// (its pure exports) are bundled in; the sketch/* runtime stays external.
|
|
// design-core imports @hanzo/ai, but command.js never calls runAction (the
|
|
// model call is in the WebView), so tree-shaking drops @hanzo/ai here.
|
|
const commandCtx = await esbuild.context({
|
|
entryPoints: [path.join(src, 'command.cjs')],
|
|
outfile: path.join(sketchDir, 'command.js'),
|
|
bundle: true,
|
|
format: 'cjs',
|
|
platform: 'node',
|
|
target: ['es2017'],
|
|
external: SKETCH_EXTERNALS,
|
|
sourcemap: false,
|
|
minify: !watch,
|
|
logLevel: 'info',
|
|
});
|
|
await commandCtx.rebuild();
|
|
|
|
// 2) The WebView bundle β browser IIFE, @hanzo/ai bundled in (it needs fetch,
|
|
// which the WebView has). design-core rides along.
|
|
const webCtx = await esbuild.context({
|
|
entryPoints: [path.join(src, 'webview', 'app.ts')],
|
|
outfile: path.join(resDir, 'app.js'),
|
|
bundle: true,
|
|
format: 'iife',
|
|
platform: 'browser',
|
|
target: ['safari15'],
|
|
sourcemap: false,
|
|
minify: !watch,
|
|
logLevel: 'info',
|
|
});
|
|
await webCtx.rebuild();
|
|
|
|
// 3) Static: manifest β Sketch/, webview HTML + icon β Resources/.
|
|
fs.copyFileSync(path.join(src, 'manifest.json'), path.join(sketchDir, 'manifest.json'));
|
|
fs.copyFileSync(path.join(src, 'webview', 'index.html'), path.join(resDir, 'webview.html'));
|
|
|
|
const icon = path.join(root, 'assets', 'icon.png');
|
|
if (fs.existsSync(icon)) {
|
|
fs.copyFileSync(icon, path.join(resDir, 'icon.png'));
|
|
} else {
|
|
console.log(' β assets/icon.png missing β bundle builds, but add an icon before publishing.');
|
|
}
|
|
|
|
console.log(`β
Built ${path.relative(root, bundle)}`);
|
|
console.log(' Install: double-click the .sketchplugin, or copy it into');
|
|
console.log(' ~/Library/Application Support/com.bohemiancoding.sketch3/Plugins/');
|
|
|
|
if (watch) {
|
|
await commandCtx.watch();
|
|
await webCtx.watch();
|
|
console.log('π watchingβ¦');
|
|
} else {
|
|
await commandCtx.dispose();
|
|
await webCtx.dispose();
|
|
}
|
|
}
|
|
|
|
build().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|