-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
libraries/nip66/adapters/cache/NostrSqliteAdapter/build.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
})(); |