# Build System

> Gulp tasks for JS/CSS bundling, translations and versioning

---

Bundling, translation compilation and versioning are driven by [**Gulp**](https://gulpjs.com/) tasks in <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/gulpfile.mjs" target="_blank" rel="noopener"><code>gulpfile.mjs</code></a>
, invoked with `npx gulp <task>`. The `npm run *` scripts cover testing only — see the [Testing](./testing) page.

## Tasks

| Task | Command | What it does |
| --- | --- | --- |
| `build` | `npx gulp build` | `clean` → JS ([Rollup](https://rollupjs.org/)) + CSS ([PostCSS](https://postcss.org/)) |
| `devbuild` | `npx gulp devbuild` | like `build`, but Dev-Mode (no minify, source maps) |
| `updatepo` | `npx gulp updatepo` | runs <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/util/update-po-files.sh" target="_blank" rel="noopener"><code>update-po-files.sh</code></a>
 → `xgettext` over `src/` → <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/resources/lang/messages.pot" target="_blank" rel="noopener"><code>messages.pot</code></a>
 |
| `po2php` | `npx gulp po2php` | compiles `resources/lang/*.po` → `resources/lang/*.php` |
| `syncversion` | `npx gulp syncversion` | keeps <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/latest-version.txt" target="_blank" rel="noopener"><code>latest-version.txt</code></a>
 ↔ <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/src/LinkEnhancerModule.php" target="_blank" rel="noopener"><code>LinkEnhancerModule.php</code></a>
 in sync |
| `bumpversion` | `npx gulp bumpversion` | requires a clean git tree → version bump → `syncversion` |
| `archive` | `npx gulp archive` | `build` + `po2php` + <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/util/create-archive.sh" target="_blank" rel="noopener"><code>create-archive.sh</code></a>
 (release ZIP) |
| `forgejo:issue-refs` | `npx gulp forgejo:issue-refs[:dry]` | adds issue refs to commit messages (needs `FORGEJO_TOKEN` in `.env`) - was used only once to migrate the repo from GitHub to Codeberg |

## JS / CSS bundling

`build` = `clean` → (in parallel) JS + CSS.

- **clean** deletes `resources/js/bundle*` and `resources/css/bundle*` first.
- **JS** (Rollup): two entry bundles — `jsIndex` (the main <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/resources/js/index-le.js" target="_blank" rel="noopener"><code>index-le.js</code></a>
) and `jsExtractLeConfig` (<a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/resources/js/src/le-config.js" target="_blank" rel="noopener"><code>le-config.js</code></a>
). Output to `resources/js/bundle*`.
- **CSS** (PostCSS): per-file subtasks from `getCssSubTasks()`, with autoprefixer + cssnano. Output to `resources/css/bundle*`.

**Dev-Mode** (`devbuild`) toggles a flag via `toggleDevMode(true)` — it disables minification and emits source maps.

## Build & archive pipeline




<pre class="mermaid">flowchart LR
    subgraph B[&#34;🔧 npx gulp build&#34;]
        C[&#34;🧹 clean&lt;br/&gt;(bundle*)&#34;]
        J[&#34;`📜 Rollup&lt;br/&gt;**index-le.js** · le-config.js`&#34;]
        P[&#34;🎨 PostCSS&lt;br/&gt;autoprefixer · cssnano&#34;]
        C --&gt; J
        C --&gt; P
    end
    subgraph A[&#34;📦 npx gulp archive&#34;]
        A1[&#34;build&#34;]
        A2[&#34;po2php&#34;]
        A3[&#34;`create-archive.sh&lt;br/&gt;**dist/linkenhancer_v&lt;ver&gt;.zip**`&#34;]
        A1 --&gt; A2 --&gt; A3
    end

    classDef bStyle fill:#e3f2fd,stroke:#1565C0,stroke-width:2px
    classDef aStyle fill:#e8f5e9,stroke:#2E7D32,stroke-width:2px

    class C,J,P bStyle
    class A1,A2,A3 aStyle
</pre>

## Translation files

- `updatepo` only regenerates the **template** (`messages.pot`). The `.po` files themselves are updated via **Weblate**, not locally, to avoid conflicts — see the [Translation Pipeline](./translation-pipeline) page.
- `po2php` converts the committed `.po` files into the PHP arrays webtrees loads at runtime.
