86 lines
2.6 KiB
JavaScript
86 lines
2.6 KiB
JavaScript
/**
|
|
* Simple bundler for NOSTR_LOGIN_LITE
|
|
* Combines all files into a single distributable script
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
async function bundleLite() {
|
|
const mainFile = path.join(__dirname, 'nostr-login-lite.js');
|
|
const nip46File = path.join(__dirname, 'core/nip46-client.js');
|
|
const modalFile = path.join(__dirname, 'ui/modal.js');
|
|
|
|
let bundle = `/**
|
|
* NOSTR_LOGIN_LITE
|
|
* Single-file Nostr authentication library
|
|
* Generated on: ${new Date().toISOString()}
|
|
*/
|
|
|
|
// ======================================
|
|
// Core Classes and Components
|
|
// ======================================
|
|
`;
|
|
|
|
// Read and combine files
|
|
const files = [modalFile, nip46File, mainFile];
|
|
|
|
for (const file of files) {
|
|
if (fs.existsSync(file)) {
|
|
let content = fs.readFileSync(file, 'utf8');
|
|
|
|
// Skip the initial comment and license if present
|
|
let lines = content.split('\n');
|
|
|
|
// Find and skip complete JSDoc blocks at the beginning
|
|
let skipUntil = 0;
|
|
let inJSDocBlock = false;
|
|
for (let i = 0; i < lines.length; i++) {
|
|
const line = lines[i].trim();
|
|
|
|
if (line.startsWith('/**')) {
|
|
inJSDocBlock = true;
|
|
skipUntil = i;
|
|
} else if (inJSDocBlock && line.startsWith('*/')) {
|
|
skipUntil = i;
|
|
break;
|
|
} else if (i < 10 && (line.startsWith('const') || line.startsWith('class') || line.startsWith('function'))) {
|
|
// Hit actual code before finding end of JSDoc block
|
|
inJSDocBlock = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (inJSDocBlock) {
|
|
lines = lines.slice(skipUntil + 1); // Skip the entire JSDoc block
|
|
} else {
|
|
// Fallback to old filtering (skip comment-like lines in first 10)
|
|
lines = lines.filter((line, index) => {
|
|
return index >= 10 || !line.trim().startsWith('*') && !line.trim().startsWith('//');
|
|
});
|
|
}
|
|
|
|
bundle += '\n// ======================================\n';
|
|
bundle += `// ${path.basename(file)}\n`;
|
|
bundle += '// ======================================\n\n';
|
|
bundle += lines.join('\n');
|
|
bundle += '\n\n';
|
|
}
|
|
}
|
|
|
|
// Write the bundled file
|
|
const outputPath = path.join(__dirname, 'nostr-login-lite.bundle.js');
|
|
fs.writeFileSync(outputPath, bundle);
|
|
|
|
console.log('Bundle created:', outputPath);
|
|
console.log('Bundle size:', (bundle.length / 1024).toFixed(2), 'KB');
|
|
}
|
|
|
|
if (typeof module !== 'undefined' && module.exports) {
|
|
module.exports = { bundleLite };
|
|
}
|
|
|
|
// Run if called directly
|
|
if (typeof require !== 'undefined' && require.main === module) {
|
|
bundleLite().catch(console.error);
|
|
} |