refactor: consolidate all Node.js development into lib package

- Move scripts/ to lib/scripts/ and convert to ESM modules
- Consolidate dependencies: add live-server to lib/package.json
- Remove root package.json and node_modules split
- Preserve CLI integration via existing rebuild-library.sh
- Add development quickstart guide for new unified workflow
- Clean up outdated file references and duplicate assets
This commit is contained in:
2025-09-04 21:40:45 +02:00
parent 6fef293df3
commit c777fc92dd
18 changed files with 2539 additions and 2769 deletions

2375
lib/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -12,7 +12,12 @@
"scripts": {
"build": "rollup -c",
"watch": "rollup -c -w",
"dev": "rollup -c -w"
"dev": "rollup -c -w",
"serve": "node scripts/dev.js serve",
"serve:about": "live-server ../demo-site --port=3000 --open=/about.html",
"check": "node scripts/dev.js check",
"demo": "node scripts/dev.js demo",
"build:all": "node scripts/build.js"
},
"keywords": [
"cms",
@@ -25,6 +30,7 @@
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-terser": "^0.4.0",
"rollup": "^3.0.0"
"rollup": "^3.0.0",
"live-server": "^1.2.2"
}
}

58
lib/scripts/build.js Executable file
View File

@@ -0,0 +1,58 @@
#!/usr/bin/env node
/**
* Build script for Insertr library and CLI integration
* This ensures the CLI always has the latest library version embedded
*/
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
console.log('🔨 Building Insertr library and CLI...\n');
// 1. Build the library
console.log('📦 Building JavaScript library...');
try {
execSync('npm run build', { stdio: 'inherit' });
console.log('✅ Library built successfully\n');
} catch (error) {
console.error('❌ Library build failed:', error.message);
process.exit(1);
}
// 2. Copy built library to CLI assets
console.log('📁 Copying library to CLI assets...');
const srcDir = './dist';
const destDir = '../insertr-cli/pkg/content/assets';
// Ensure destination directory exists
fs.mkdirSync(destDir, { recursive: true });
// Copy files
const files = fs.readdirSync(srcDir);
files.forEach(file => {
const src = path.join(srcDir, file);
const dest = path.join(destDir, file);
fs.copyFileSync(src, dest);
console.log(` ✅ Copied ${file}`);
});
console.log('📁 Assets copied successfully\n');
// 3. Build the CLI
console.log('🔧 Building Go CLI...');
try {
execSync('go build -o insertr', { cwd: '../insertr-cli', stdio: 'inherit' });
console.log('✅ CLI built successfully\n');
} catch (error) {
console.error('❌ CLI build failed:', error.message);
process.exit(1);
}
console.log('🎉 Build complete!\n');
console.log('📋 What was built:');
console.log(' • JavaScript library (lib/dist/)');
console.log(' • Go CLI with embedded library (insertr-cli/insertr)');
console.log('\n🚀 Ready to use:');
console.log(' cd ../insertr-cli && ./insertr --help');

115
lib/scripts/dev.js Executable file
View File

@@ -0,0 +1,115 @@
#!/usr/bin/env node
/**
* Development helper script for Insertr
* Provides common development tasks and utilities
*/
import { execSync, spawn } from 'child_process';
import fs from 'fs';
import path from 'path';
const commands = {
serve: {
description: 'Start development server with live reload',
action: () => {
console.log('🚀 Starting Insertr development server...');
console.log('📂 Serving demo-site/ at http://localhost:3000');
console.log('🔄 Live reload enabled');
console.log('\n💡 Test the three user types:');
console.log(' 👥 Customer: Visit the site normally');
console.log(' ✏️ Client: Click "Login as Client" → "Edit Mode: On"');
console.log(' 🔧 Developer: View source to see integration\n');
spawn('npx', ['live-server', '../demo-site', '--port=3000', '--open=/index.html'], {
stdio: 'inherit'
});
}
},
check: {
description: 'Check project status and validate setup',
action: () => {
console.log('🔍 Checking Insertr project status...\n');
// Check files exist
const requiredFiles = [
'../demo-site/index.html',
'../demo-site/about.html',
'dist/insertr.js',
'dist/insertr.min.js',
'package.json'
];
let allGood = true;
requiredFiles.forEach(file => {
if (fs.existsSync(file)) {
console.log('✅', file);
} else {
console.log('❌', file, '(missing)');
allGood = false;
}
});
if (allGood) {
console.log('\n🎉 All core files present!');
console.log('\n📊 Project stats:');
// Count editable elements
const indexContent = fs.readFileSync('../demo-site/index.html', 'utf8');
const aboutContent = fs.readFileSync('../demo-site/about.html', 'utf8');
const insertrMatches = (indexContent + aboutContent).match(/class="insertr"/g) || [];
console.log(` 📝 Editable elements: ${insertrMatches.length}`);
// Check library size
const libSize = fs.statSync('dist/insertr.js').size;
console.log(` 📦 Library size: ${(libSize / 1024).toFixed(1)}KB`);
console.log('\n🚀 Ready to develop! Run: npm run serve');
} else {
console.log('\n❌ Some files are missing. Please check your setup.');
process.exit(1);
}
}
},
demo: {
description: 'Show demo instructions',
action: () => {
console.log('🎬 Insertr Demo Instructions\n');
console.log('1. 🌐 Start server: npm run serve');
console.log('2. 👀 Customer view: Browse the site normally');
console.log('3. 🔑 Client login: Click "Login as Client"');
console.log('4. ✏️ Edit mode: Click "Edit Mode: Off" to enable editing');
console.log('5. 📝 Edit content: Click any ✏️ button to edit');
console.log('6. 🔄 Try different content types (simple text vs rich markdown)');
console.log('7. 📄 Multi-page: Navigate to About page to see persistence\n');
console.log('🎯 Key features to test:');
console.log(' • Inline text editing');
console.log(' • Markdown editing for rich content');
console.log(' • Auto-save with visual feedback');
console.log(' • Content persistence across pages');
console.log(' • Responsive design on mobile\n');
}
}
};
// Parse command line arguments
const command = process.argv[2] || 'help';
if (commands[command]) {
commands[command].action();
} else if (command === 'help' || command === '--help' || command === '-h') {
console.log('🛠️ Insertr Development Helper\n');
console.log('Available commands:\n');
Object.entries(commands).forEach(([name, cmd]) => {
console.log(` ${name.padEnd(12)} ${cmd.description}`);
});
console.log('\nUsage: node scripts/dev.js <command>');
console.log(' or: npm run check\n');
} else {
console.log(`❌ Unknown command: ${command}`);
console.log('Run: node scripts/dev.js help');
process.exit(1);
}

View File

@@ -509,16 +509,16 @@ export class InsertrAuth {
}
/* Hide editing interface when not in edit mode */
body:not(.insertr-edit-mode) [data-insertr-enhanced]:hover::after {
body:not(.insertr-edit-mode) .insertr:hover::after {
display: none !important;
}
/* Only show editing features when in edit mode */
.insertr-authenticated.insertr-edit-mode [data-insertr-enhanced] {
.insertr-authenticated.insertr-edit-mode .insertr {
cursor: pointer;
}
.insertr-authenticated.insertr-edit-mode [data-insertr-enhanced]:hover {
.insertr-authenticated.insertr-edit-mode .insertr:hover {
outline: 2px dashed #007cba !important;
outline-offset: 2px !important;
background-color: rgba(0, 124, 186, 0.05) !important;

View File

@@ -130,7 +130,7 @@ export class InsertrEditor {
background-color: rgba(0, 124, 186, 0.05) !important;
}
[data-insertr-enhanced="true"]:hover::after {
.insertr:hover::after {
content: "✏️ " attr(data-content-type);
position: absolute;
top: -25px;

View File

@@ -12,7 +12,7 @@ export class InsertrCore {
// Find all enhanced elements on the page
findEnhancedElements() {
return document.querySelectorAll('[data-insertr-enhanced="true"]');
return document.querySelectorAll('.insertr');
}
// Get element metadata

View File

@@ -14,25 +14,25 @@ window.Insertr = {
core: null,
editor: null,
auth: null,
// Initialize the library
init(options = {}) {
console.log('🔧 Insertr v1.0.0 initializing... (Hot Reload Ready)');
this.core = new InsertrCore(options);
this.auth = new InsertrAuth(options);
this.editor = new InsertrEditor(this.core, this.auth, options);
// Auto-initialize if DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => this.start());
} else {
this.start();
}
return this;
},
// Start the system - only creates the minimal trigger
start() {
if (this.auth) {
@@ -47,37 +47,36 @@ window.Insertr = {
this.editor.start();
}
},
// Public API methods
login() {
return this.auth ? this.auth.toggleAuthentication() : null;
},
logout() {
if (this.auth && this.auth.isAuthenticated()) {
this.auth.toggleAuthentication();
}
},
toggleEditMode() {
return this.auth ? this.auth.toggleEditMode() : null;
},
isAuthenticated() {
return this.auth ? this.auth.isAuthenticated() : false;
},
isEditMode() {
return this.auth ? this.auth.isEditMode() : false;
},
// Version info
version: '1.0.0'
// TODO: Version info based on package.json?
};
// Auto-initialize in development mode with proper DOM ready handling
function autoInitialize() {
if (document.querySelector('[data-insertr-enhanced="true"]')) {
if (document.querySelector('.insertr')) {
window.Insertr.init();
}
}
@@ -90,4 +89,4 @@ if (document.readyState === 'loading') {
autoInitialize();
}
export default window.Insertr;
export default window.Insertr;