2021-06-18 10:35:35 -04:00
|
|
|
import { resolve } from 'path'
|
2021-06-22 08:47:47 -04:00
|
|
|
import { readFileSync } from 'fs'
|
2021-06-18 07:05:01 -04:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
import preact from '@preact/preset-vite'
|
2021-06-18 14:25:33 -04:00
|
|
|
import { VitePWA } from 'vite-plugin-pwa'
|
2021-06-22 08:47:47 -04:00
|
|
|
import replace from '@rollup/plugin-replace'
|
|
|
|
|
|
|
|
function getGitRevision() {
|
|
|
|
try {
|
|
|
|
const rev = readFileSync('.git/HEAD').toString().trim();
|
|
|
|
if (rev.indexOf(':') === -1) {
|
|
|
|
return rev;
|
|
|
|
} else {
|
|
|
|
return readFileSync('.git/' + rev.substring(5)).toString().trim();
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Failed to get Git revision.');
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
}
|
2021-06-18 07:05:01 -04:00
|
|
|
|
2021-06-22 14:45:44 -04:00
|
|
|
function getGitBranch() {
|
|
|
|
try {
|
|
|
|
const rev = readFileSync('.git/HEAD').toString().trim();
|
|
|
|
if (rev.indexOf(':') === -1) {
|
|
|
|
return 'DETACHED';
|
|
|
|
} else {
|
|
|
|
return rev.split('/').pop();
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Failed to get Git branch.');
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-22 14:34:52 -04:00
|
|
|
function getVersion() {
|
|
|
|
return readFileSync('VERSION').toString();
|
|
|
|
}
|
|
|
|
|
2021-06-22 14:59:02 -04:00
|
|
|
const branch = getGitBranch();
|
|
|
|
const isNightly = branch !== 'production';
|
|
|
|
const iconPrefix = isNightly ? 'nightly-' : '';
|
|
|
|
|
2021-06-18 07:05:01 -04:00
|
|
|
export default defineConfig({
|
2021-06-18 14:25:33 -04:00
|
|
|
plugins: [
|
|
|
|
preact(),
|
|
|
|
VitePWA({
|
2021-06-22 09:22:35 -04:00
|
|
|
srcDir: 'src',
|
|
|
|
filename: 'sw.ts',
|
|
|
|
strategies: 'injectManifest',
|
2021-06-18 14:25:33 -04:00
|
|
|
manifest: {
|
2021-06-22 14:59:02 -04:00
|
|
|
name: isNightly ? "REVOLT nightly" : "REVOLT",
|
2021-06-22 09:22:35 -04:00
|
|
|
short_name: "REVOLT",
|
2021-06-22 14:59:02 -04:00
|
|
|
description: isNightly ? "Early preview builds of REVOLT." : "User-first, privacy-focused chat platform.",
|
2021-06-18 14:25:33 -04:00
|
|
|
categories: ["messaging"],
|
|
|
|
start_url: "/",
|
|
|
|
display: "standalone",
|
|
|
|
orientation: "portrait",
|
|
|
|
background_color: "#101823",
|
|
|
|
icons: [
|
|
|
|
{
|
2021-06-22 14:59:02 -04:00
|
|
|
"src": `/assets/icons/${iconPrefix}android-chrome-192x192.png`,
|
2021-06-18 14:25:33 -04:00
|
|
|
"type": "image/png",
|
|
|
|
"sizes": "192x192"
|
|
|
|
},
|
|
|
|
{
|
2021-06-22 14:59:02 -04:00
|
|
|
"src": `/assets/icons/${iconPrefix}android-chrome-512x512.png`,
|
2021-06-18 14:25:33 -04:00
|
|
|
"type": "image/png",
|
|
|
|
"sizes": "512x512"
|
|
|
|
}
|
|
|
|
]
|
2021-06-22 09:22:35 -04:00
|
|
|
}
|
2021-06-22 08:47:47 -04:00
|
|
|
}),
|
|
|
|
replace({
|
|
|
|
__GIT_REVISION__: getGitRevision(),
|
2021-06-22 14:45:44 -04:00
|
|
|
__GIT_BRANCH__: getGitBranch(),
|
2021-06-22 14:34:52 -04:00
|
|
|
__APP_VERSION__: getVersion(),
|
2021-06-22 08:47:47 -04:00
|
|
|
preventAssignment: true
|
2021-06-18 14:25:33 -04:00
|
|
|
})
|
|
|
|
],
|
2021-06-18 10:35:35 -04:00
|
|
|
build: {
|
2021-06-19 07:34:53 -04:00
|
|
|
sourcemap: true,
|
2021-06-18 10:35:35 -04:00
|
|
|
rollupOptions: {
|
|
|
|
input: {
|
|
|
|
main: resolve(__dirname, 'index.html'),
|
|
|
|
ui: resolve(__dirname, 'ui/index.html')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-18 07:05:01 -04:00
|
|
|
})
|