diff --git a/libraries/nip66/adapters/cache/NostrSqliteAdapter/build.js b/libraries/nip66/adapters/cache/NostrSqliteAdapter/build.js new file mode 100644 index 00000000..4f629300 --- /dev/null +++ b/libraries/nip66/adapters/cache/NostrSqliteAdapter/build.js @@ -0,0 +1,65 @@ +import esbuild from 'esbuild'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { clean } from 'esbuild-plugin-clean'; +import alias from 'esbuild-plugin-alias'; +import esbuildPluginTsc from 'esbuild-plugin-tsc'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const production = process.env.NODE_ENV === 'production'; + +const watchMode = process.argv.includes('--watch'); + +const commonPlugins = [ + clean({ patterns: ['./dist'] }), + alias({ + entries: [ + { find: 'node:module', replacement: path.resolve(__dirname, 'src/shims/node-module-shim.js') }, + ], + }), + esbuildPluginTsc({ force: true }), +]; + +const browserBuildOptions = { + entryPoints: ['src/index.ts', 'src/workers/nostrsqlite.worker.ts'], + outdir: 'dist/browser', + bundle: true, + platform: 'browser', + target: 'esnext', + format: 'esm', + sourcemap: !production, + minify: production, + plugins: commonPlugins, + external: ['@nostrwatch/worker-relay'], + loader: { + '.ts': 'ts', + '.js': 'js', + '.wasm': 'file', + }, + resolveExtensions: ['.ts', '.js'], +}; + +async function build() { + try { + if (watchMode) { + const context = await esbuild.context(browserBuildOptions); + await context.watch(); + console.log('Watching for changes...'); + } else { + await esbuild.build(browserBuildOptions); + console.log('Build completed successfully.'); + } + } catch (error) { + console.error('Build failed:', error); + process.exit(1); + } +} + +process.on('SIGINT', () => { + console.log('Terminating process...'); + process.exit(0); +}); + +build(); diff --git a/libraries/nip66/build.js b/libraries/nip66/build.js new file mode 100644 index 00000000..28da72bd --- /dev/null +++ b/libraries/nip66/build.js @@ -0,0 +1,72 @@ +import esbuild from 'esbuild'; +import alias from 'esbuild-plugin-alias'; +import clean from 'esbuild-plugin-clean'; + +// Common plugins +const plugins = [ + clean({ patterns: ['./dist'] }), + alias({ + '@adapters': './adapters', + '@core': './src/core', + '@base': './src', + '@models': './src/models', + '@interfaces': './src/interfaces', + '@services': './src/services', + '@workers': './src/workers', + }), +]; + +// Build configurations +const buildConfigs = [ + // Browser build + { + entryPoints: ['src/index.ts'], + bundle: true, + platform: 'browser', + format: 'esm', + outdir: 'dist/browser', + sourcemap: true, + define: { + 'process.env.NODE_ENV': JSON.stringify('production'), + }, + external: ['@nostrwatch/nip66', '@nostrwatch/utils'], + plugins, + loader: { + '.ts': 'ts', + '.tsx': 'tsx', + }, + minify: true, + }, + // Server build + { + entryPoints: ['src/index.ts'], + bundle: true, + platform: 'node', + format: 'cjs', + outdir: 'dist/server', + sourcemap: true, + define: { + 'process.env.NODE_ENV': JSON.stringify('production'), + }, + external: ['@nostrwatch/nip66', '@nostrwatch/utils'], + plugins, + loader: { + '.ts': 'ts', + '.tsx': 'tsx', + }, + minify: true, + }, +]; + +// Build process +(async () => { + try { + await Promise.all( + buildConfigs.map((config) => esbuild.build(config)) + ); + console.log('Build completed successfully!'); + } catch (err) { + console.error('Build failed:', err); + process.exit(1); + } +})();