This commit is contained in:
2026-02-21 23:57:03 +01:00
commit 2d9e3a6044
26 changed files with 6716 additions and 0 deletions

127
scripts/build-plugin.ts Normal file
View File

@@ -0,0 +1,127 @@
#!/usr/bin/env tsx
import { execSync } from 'child_process';
import { existsSync, mkdirSync, rmSync, cpSync, createWriteStream } from 'fs';
import { join } from 'path';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const archiver = require('archiver');
const version = process.argv[2];
if (!version) {
console.error('Version is required as first argument');
process.exit(1);
}
const rootDir = process.cwd();
const releaseDir = join(rootDir, 'release');
const zipName = `leetify-extension-v${version}.zip`;
console.log(`Building plugin version ${version}...`);
async function buildPlugin() {
try {
// Clean up any existing release directory
if (existsSync(releaseDir)) {
rmSync(releaseDir, { recursive: true, force: true });
}
// Create release directory
mkdirSync(releaseDir, { recursive: true });
// Copy necessary files and directories
const filesToCopy = [
{ src: '.millennium', dest: '.millennium' },
{ src: 'backend', dest: 'backend' },
{ src: 'plugin.json', dest: 'plugin.json' },
{ src: 'requirements.txt', dest: 'requirements.txt' },
{ src: 'README.md', dest: 'README.md' },
];
// Check if LICENSE file exists and add it if it does
if (existsSync(join(rootDir, 'LICENSE'))) {
filesToCopy.push({ src: 'LICENSE', dest: 'LICENSE' });
}
// Copy styles if they exist
if (existsSync(join(rootDir, 'styles'))) {
mkdirSync(join(releaseDir, 'static'), { recursive: true });
cpSync(join(rootDir, 'styles'), join(releaseDir, 'static'), { recursive: true });
}
// Copy all files
for (const { src, dest } of filesToCopy) {
const srcPath = join(rootDir, src);
const destPath = join(releaseDir, dest);
if (existsSync(srcPath)) {
cpSync(srcPath, destPath, { recursive: true });
console.log(`Copied ${src} to release directory`);
} else {
console.warn(`Warning: ${src} does not exist, skipping...`);
}
}
// Generate Git metadata
console.log('Generating Git metadata...');
try {
const commitId = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
const pluginId = execSync('git rev-list --max-parents=0 HEAD', { encoding: 'utf8' }).trim();
const metadata = {
id: pluginId,
commitId: commitId,
};
const metadataPath = join(releaseDir, 'metadata.json');
// Write metadata.json to release directory
require('fs').writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
console.log('Generated metadata.json with Git information');
} catch (error) {
console.warn('Warning: Could not generate Git metadata:', error);
}
// Create zip file using archiver for cross-platform compatibility
console.log('Creating zip file...');
const zipPath = join(rootDir, zipName);
const output = createWriteStream(zipPath);
const archive = archiver('zip', { zlib: { level: 9 } });
// Listen for archive events
archive.on('error', (err: any) => {
throw err;
});
output.on('close', () => {
console.log(`✅ Successfully created ${zipName}`);
// Clean up release directory
rmSync(releaseDir, { recursive: true, force: true });
});
// Pipe archive data to the file
archive.pipe(output);
// Add all files from release directory to archive
archive.directory(releaseDir, false);
// Finalize the archive
await archive.finalize();
} catch (error) {
console.error('❌ Build failed:', error);
// Clean up on error
if (existsSync(releaseDir)) {
rmSync(releaseDir, { recursive: true, force: true });
}
process.exit(1);
}
}
// Run the build
buildPlugin().catch((error) => {
console.error('❌ Build failed:', error);
process.exit(1);
});

56
scripts/sync-version.ts Normal file
View File

@@ -0,0 +1,56 @@
#!/usr/bin/env node
/// <reference types="node" />
import { readFileSync, writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const rootDir = join(__dirname, '..');
interface PackageJson {
version: string;
[key: string]: any;
}
interface PluginJson {
version: string;
[key: string]: any;
}
function syncVersion(newVersion: string = '1.0.0'): void {
if (!newVersion) {
console.error('Error: Version argument is required');
process.exit(1);
}
try {
// Update package.json
const packagePath: string = join(rootDir, 'package.json');
const packageJson: PackageJson = JSON.parse(readFileSync(packagePath, 'utf8'));
packageJson.version = newVersion;
writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + '\n');
console.log(`✓ Updated package.json to version ${newVersion}`);
// Update plugin.json
const pluginPath: string = join(rootDir, 'plugin.json');
const pluginJson: PluginJson = JSON.parse(readFileSync(pluginPath, 'utf8'));
pluginJson.version = newVersion;
writeFileSync(pluginPath, JSON.stringify(pluginJson, null, '\t') + '\n');
console.log(`✓ Updated plugin.json to version ${newVersion}`);
console.log(`✅ Version synchronization complete: ${newVersion}`);
} catch (error: any) {
console.error('Error syncing version:', error.message);
process.exit(1);
}
}
// Run if called directly
if (import.meta.url.startsWith('file:') && process.argv[1] === fileURLToPath(import.meta.url)) {
// Get version from command line argument
const newVersion: string = process.argv[2];
syncVersion(newVersion);
}

17
scripts/tsconfig.json Normal file
View File

@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"strict": true,
"noImplicitReturns": false,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"types": ["node"]
},
"include": ["*.ts"],
"exclude": ["node_modules", "build"]
}