This repository was archived by the owner on Apr 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
Add build system from Meson to esbuild with efficient hot reload support for development #988
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f121d34
build: :zap: migrate from Meson to esbuild for faster, smaller and moβ¦
KernelDiego f11b58e
chore: :adhesive_bandage: change the name to a more reasonable command
KernelDiego 1c99999
chore: :memo: translate code comments for English
KernelDiego 5a26364
fix: :lock: add missing sudo for command requiring elevated permissions
KernelDiego dd891bf
build: :zap: conditionally minify code based on -dev flag for optimizβ¦
KernelDiego 4fcc581
chore: π§Ή clean up comments
KernelDiego b97a76a
chore: π§Ή remove sudo from package.json scripts
KernelDiego c336d6d
chore: π§Ή remove sudo from package.json scripts
KernelDiego e386c0d
build: change esbuild platform from 'node' to 'neutral'
KernelDiego File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,5 +3,7 @@ node_modules | |
| prepare | ||
|
|
||
| @girs | ||
| @types | ||
| dist | ||
|
|
||
| **/.claude/settings.local.json | ||
| **/.claude/settings.local.json | ||
This file contains hidden or 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,175 @@ | ||
| import esbuild from 'esbuild'; | ||
| import { promises as fs } from 'fs'; | ||
| import path from 'path'; | ||
|
|
||
| const isDevelopment = process.argv.includes('-dev') || process.argv.includes('--dev') || process.argv.includes('-d'); | ||
| const isWatch = process.argv.includes('-watch') || process.argv.includes('--watch') || process.argv.includes('-w'); | ||
| console.log(`π Building in ${isDevelopment ? 'development' : 'production'} mode`); | ||
|
|
||
| const outdir = isDevelopment ? './dist' : '/usr'; | ||
| const hyprpanelDir = path.join(outdir, 'share/hyprpanel'); | ||
|
|
||
| const entryPoints = ['app.ts']; | ||
| const staticDirs = ['scripts', 'themes', 'assets', 'src/style']; | ||
|
|
||
| const copyStaticFiles = { | ||
| name: 'copy-static', | ||
| setup(build) { | ||
| build.onEnd(async () => { | ||
| try { | ||
| console.log('π Copying static files...'); | ||
| // Create output directory if it doesn't exist | ||
| await fs.mkdir(outdir, { recursive: true }); | ||
| await copyDirs(staticDirs); | ||
| await copyLauncherScript(); | ||
| } catch (error) { | ||
| console.error('β Error copying static files:', error.message); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| const buildOptions = { | ||
| entryPoints, | ||
| entryNames: 'hyprpanel', | ||
| outdir: hyprpanelDir, | ||
| bundle: true, | ||
| format: 'esm', | ||
| platform: 'neutral', | ||
| external: [ | ||
| 'gi://*', | ||
| 'system', | ||
| ], | ||
| plugins: [copyStaticFiles], // Plugin to copy static files | ||
| tsconfig: './tsconfig.json', // Use tsconfig for type checking and other settings | ||
| keepNames: true, // Keep function names for better debugging | ||
| sourcemap: false, // Generate sourcemaps in development mode | ||
| minify: !isDevelopment, // Minify in production mode | ||
| treeShaking: true, | ||
| metafile: isDevelopment, // Generate metafile only in development mode | ||
| splitting: false, // Disable code splitting for simplicity | ||
| logLevel: 'info', | ||
| color: true, // Enable colored output | ||
| write: true, // Write output to disk | ||
| define: { | ||
| 'DATADIR': JSON.stringify(hyprpanelDir) | ||
| }, | ||
| resolveExtensions: ['.ts', '.tsx', '.js', '.jsx'], | ||
| loader: { | ||
| '.ts': 'ts', | ||
| '.tsx': 'tsx' | ||
| } | ||
| }; | ||
|
|
||
| async function copyLauncherScript() { | ||
| const sourceFile = 'scripts/hyprpanel_launcher.sh.in'; | ||
| const destDir = path.join(outdir, 'bin'); | ||
| const destFile = path.join(destDir, 'hyprpanel'); | ||
|
|
||
| try { | ||
| await fs.access(sourceFile); | ||
| const templateContent = await fs.readFile(sourceFile, 'utf8'); | ||
| const processedContent = templateContent.replace(/@DATADIR@/g, hyprpanelDir); | ||
| await fs.mkdir(destDir, { recursive: true }); | ||
| await fs.writeFile(destFile, processedContent, { mode: 0o755 }); // Make it executable | ||
| console.log(`β Launcher script copied to ${hyprpanelDir}`); | ||
| } catch (error) { | ||
| if (error.code === 'ENOENT') { | ||
| console.log('β οΈ Launcher script not found, skipping...'); | ||
| } else { | ||
| console.error('β Error copying launcher script:', error.message); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Plugin for copying static files | ||
| async function copyDirs(dirs) { | ||
| const copyPromises = dirs.map(async (dir) => { | ||
| try { | ||
| await fs.access(dir); | ||
| const destDir = path.join(outdir, '/share/hyprpanel', dir); | ||
|
|
||
| const needsCopy = await shouldCopyDirectory(dir, destDir); | ||
|
|
||
| if (needsCopy) { | ||
| await fs.mkdir(path.dirname(destDir), { recursive: true }); | ||
| await fs.cp(dir, destDir, { | ||
| recursive: true, | ||
| force: true, | ||
| preserveTimestamps: true // Preserve timestamps for future incremental builds | ||
| }); | ||
| console.log(`β ${dir} copied`); | ||
| } else { | ||
| console.log(`βοΈ ${dir} skipped (no changes)`); | ||
| } | ||
|
|
||
| return { dir, success: true, copied: needsCopy }; | ||
| } catch (err) { | ||
| console.log('β οΈ No scripts directory found'); | ||
| return { dir, success: false, error: err.message }; | ||
| } | ||
| }) | ||
| const results = await Promise.all(copyPromises); | ||
| return results; | ||
| }; | ||
|
|
||
| // Function to check if a directory needs to be copied | ||
| async function shouldCopyDirectory(sourceDir, destDir) { | ||
| try { | ||
| const [sourceStat, destStat] = await Promise.all([ | ||
| fs.stat(sourceDir), | ||
| fs.stat(destDir).catch(() => null) | ||
| ]); | ||
|
|
||
| if (!destStat) return true; | ||
|
|
||
| return sourceStat.mtime > destStat.mtime; | ||
| } catch { | ||
| return true; | ||
| } | ||
| }; | ||
|
|
||
| // Main build function | ||
| async function build() { | ||
| try { | ||
| await esbuild.build(buildOptions); | ||
| console.log(`β Build completed successfully!`); | ||
| console.log(`π¦ Output directory: ${outdir}`); | ||
| } catch (error) { | ||
| console.error('β Build failed:', error); | ||
| process.exit(1); | ||
| } | ||
| }; | ||
|
|
||
| // Function for watch mode | ||
| async function watch() { | ||
| try { | ||
| console.log('π Starting watch mode...'); | ||
| const ctx = await esbuild.context({ | ||
| ...buildOptions, | ||
| plugins: [ | ||
| copyStaticFiles, | ||
| ] | ||
| }); | ||
|
|
||
| await ctx.watch(); | ||
| console.log('π Watching for changes... (Press Ctrl+C to stop)'); | ||
|
|
||
| // Keeping the process alive | ||
| process.on('SIGINT', async () => { | ||
| console.log('\nπ Stopping watch mode...'); | ||
| await ctx.dispose(); | ||
| process.exit(0); | ||
| }); | ||
|
|
||
| } catch (error) { | ||
| console.error('β Watch mode failed:', error); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| if (isWatch) { | ||
| watch(); | ||
| } else { | ||
| build(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Development vs Prod makes no sense for hyprpanel