Skip to content

Commit

Permalink
filename consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Nov 25, 2024
1 parent 9a4abf0 commit ba9a612
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
65 changes: 65 additions & 0 deletions libraries/nip66/adapters/cache/NostrSqliteAdapter/build.js
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();
72 changes: 72 additions & 0 deletions libraries/nip66/build.js
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);
}
})();

0 comments on commit ba9a612

Please sign in to comment.