Releases were built and signed in CI, which meant AMO credentials had to live on the runner. Move the whole flow local: builds and Firefox signing happen on the maintainer's machine and only the finished artifacts are published. Add `ext:pack:firefox` and `ext:pack:chrome` (production builds; the Firefox one is signed via `web-ext sign` unlisted with credentials read from the GNOME Keyring through `secret-tool`, the Chrome one is zipped) and wire them to the `version` lifecycle: - `preversion` runs lint and tests. - `version` builds and signs into `web-ext-artifacts/`. - `postversion` pushes the bump commit and tag, then uploads both artifacts to the Gitea release and publishes it if still a draft. Switch the plain `ext:build:*` scripts to production and add `ext:build:dev:*` for development builds; `ext:dev` is unchanged. The build manifest now takes its version from package.json and drops the "(dev)" name suffix when `DASHTAB_RELEASE=1`. Because packaging needs a production build, relax the AGENTS.md production-build restriction to allow it for packaging and releasing.
110 lines
3.5 KiB
JavaScript
110 lines
3.5 KiB
JavaScript
import { defineConfig } from 'vite';
|
|
import { extensions, classicEmberSupport, ember } from '@embroider/vite';
|
|
import { babel } from '@rollup/plugin-babel';
|
|
import tailwindcss from '@tailwindcss/vite';
|
|
import corsAnywhere from 'cors-anywhere';
|
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
const CORS_PROXY_HOST = '127.0.0.1';
|
|
const CORS_PROXY_PORT = Number(process.env.DASHTAB_CORS_PROXY_PORT || 8081);
|
|
const CORS_PROXY_ORIGINS = ['http://localhost:4200', 'http://127.0.0.1:4200'];
|
|
|
|
// Local, dev-only CORS proxy so Discourse (and other cross-origin) requests
|
|
// work when opening http://localhost:4200 directly. Bound to loopback and
|
|
// restricted to the app origin plus a required header, so other pages cannot
|
|
// use it as an open/SSRF proxy.
|
|
function corsProxyPlugin() {
|
|
return {
|
|
name: 'dashtab-cors-proxy',
|
|
apply: 'serve',
|
|
configureServer(server) {
|
|
const proxy = corsAnywhere.createServer({
|
|
originWhitelist: CORS_PROXY_ORIGINS,
|
|
requireHeader: ['x-dashtab-proxy'],
|
|
removeHeaders: ['x-dashtab-proxy', 'cookie', 'cookie2'],
|
|
corsMaxAge: 600,
|
|
});
|
|
|
|
proxy.listen(CORS_PROXY_PORT, CORS_PROXY_HOST, () => {
|
|
server.config.logger.info(
|
|
` ➜ CORS proxy: http://${CORS_PROXY_HOST}:${CORS_PROXY_PORT}/`,
|
|
);
|
|
});
|
|
|
|
server.httpServer?.once('close', () => proxy.close());
|
|
},
|
|
};
|
|
}
|
|
|
|
// Emits the target browser's manifest into the extension build output so the
|
|
// packaged app can be loaded as an unpacked extension or linted with web-ext.
|
|
// The manifest is written into Vite's resolved output directory, its version is
|
|
// kept in sync with package.json (the single source of truth), and release
|
|
// builds (DASHTAB_RELEASE=1) drop the "(dev)" name suffix.
|
|
function extensionManifestPlugin(target) {
|
|
let outDir;
|
|
return {
|
|
name: 'dashtab-extension-manifest',
|
|
apply: 'build',
|
|
configResolved(config) {
|
|
outDir = config.build.outDir;
|
|
},
|
|
closeBundle() {
|
|
const pkg = JSON.parse(
|
|
readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
|
|
);
|
|
const manifest = JSON.parse(
|
|
readFileSync(
|
|
new URL(`./extension/manifest.${target}.json`, import.meta.url),
|
|
'utf8',
|
|
),
|
|
);
|
|
|
|
manifest.version = pkg.version;
|
|
|
|
if (process.env.DASHTAB_RELEASE) {
|
|
manifest.name = 'Dashtab';
|
|
}
|
|
|
|
mkdirSync(outDir, { recursive: true });
|
|
writeFileSync(
|
|
join(outDir, 'manifest.json'),
|
|
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
);
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig(() => {
|
|
const isExtension = Boolean(process.env.DASHTAB_EXT);
|
|
const target = process.env.DASHTAB_EXT_TARGET ?? 'firefox';
|
|
|
|
return {
|
|
// Extension pages load from the extension root, so assets must resolve
|
|
// relative to index.html rather than the site root.
|
|
base: isExtension ? './' : '/',
|
|
build: isExtension
|
|
? {
|
|
outDir: `extension/build/${target}`,
|
|
emptyOutDir: true,
|
|
target: 'es2022',
|
|
// MV3 forbids inline scripts; opting out of the polyfill keeps the
|
|
// generated index.html free of them.
|
|
modulePreload: { polyfill: false },
|
|
}
|
|
: {},
|
|
plugins: [
|
|
classicEmberSupport(),
|
|
ember(),
|
|
tailwindcss(),
|
|
corsProxyPlugin(),
|
|
isExtension && extensionManifestPlugin(target),
|
|
babel({
|
|
babelHelpers: 'runtime',
|
|
extensions,
|
|
}),
|
|
].filter(Boolean),
|
|
};
|
|
});
|