Switch to a .env file instead of config.json.
This commit is contained in:
parent
54a99c618c
commit
cd755fcd1c
6 changed files with 60 additions and 27 deletions
18
.env.example
Normal file
18
.env.example
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Values contained below are also the defaults.
|
||||||
|
|
||||||
|
# Enable debug mode
|
||||||
|
# Primarily turns off minification of output styles, might also display more info in the console
|
||||||
|
#MAMI_DEBUG=1
|
||||||
|
|
||||||
|
# Application title
|
||||||
|
# Sets the title of the application, might be overridden for the window title by the common settings below once they're loaded
|
||||||
|
#MAMI_TITLE="Flashii Chat"
|
||||||
|
|
||||||
|
# Common configuration location
|
||||||
|
# Contains further information shared by the other chat client
|
||||||
|
#FUTAMI_URL="//futami.flashii.net/common.json"
|
||||||
|
|
||||||
|
# Compatibility client location
|
||||||
|
# Alternative chat client for older browser, redirected to when checks in init.js fail
|
||||||
|
# Also has a handy little button in the settings.
|
||||||
|
#AMI_URL="//sockchat.flashii.net"
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@
|
||||||
/public/assets
|
/public/assets
|
||||||
/public/index.html
|
/public/index.html
|
||||||
/public/mami.webmanifest
|
/public/mami.webmanifest
|
||||||
|
/.env
|
||||||
|
|
11
Makefile
11
Makefile
|
@ -2,6 +2,7 @@ NODE_EXE := $(shell which node)
|
||||||
NPM_EXE := $(shell which npm)
|
NPM_EXE := $(shell which npm)
|
||||||
|
|
||||||
BUILD_EXE := build.js
|
BUILD_EXE := build.js
|
||||||
|
ENV_FILE := .env
|
||||||
|
|
||||||
all: install build
|
all: install build
|
||||||
|
|
||||||
|
@ -12,18 +13,18 @@ update:
|
||||||
${NPM_EXE} update --save
|
${NPM_EXE} update --save
|
||||||
|
|
||||||
build:
|
build:
|
||||||
${NODE_EXE} ${BUILD_EXE}
|
${NODE_EXE} --env-file-if-exists ${ENV_FILE} ${BUILD_EXE}
|
||||||
|
|
||||||
rebuild-css:
|
rebuild-css:
|
||||||
${NODE_EXE} ${BUILD_EXE} css
|
${NODE_EXE} --env-file-if-exists ${ENV_FILE} ${BUILD_EXE} css
|
||||||
|
|
||||||
rebuild-html:
|
rebuild-html:
|
||||||
${NODE_EXE} ${BUILD_EXE} html
|
${NODE_EXE} --env-file-if-exists ${ENV_FILE} ${BUILD_EXE} html
|
||||||
|
|
||||||
rebuild-js:
|
rebuild-js:
|
||||||
${NODE_EXE} ${BUILD_EXE} js
|
${NODE_EXE} --env-file-if-exists ${ENV_FILE} ${BUILD_EXE} js
|
||||||
|
|
||||||
rebuild-webmanifest:
|
rebuild-webmanifest:
|
||||||
${NODE_EXE} ${BUILD_EXE} webmanifest
|
${NODE_EXE} --env-file-if-exists ${ENV_FILE} ${BUILD_EXE} webmanifest
|
||||||
|
|
||||||
.PHONY: all install update build rebuild-css rebuild-html rebuild-js rebuild-webmanifest
|
.PHONY: all install update build rebuild-css rebuild-html rebuild-js rebuild-webmanifest
|
||||||
|
|
26
README.md
26
README.md
|
@ -4,17 +4,29 @@ The Flashii Chat client.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Configuration consists of a `config.json` file that contains the various URLs and a default chat title (the unified one is taken from whatever the remote `common.json` supplies).
|
Configuration consists of a `.env` file that contains the various URLs and a default chat title (the unified one is taken from whatever the remote `common.json` supplies).
|
||||||
Make sure you create the file before building. An example is also supplied.
|
The defaults supplied by `build.js` are what are used for the production instance. Make sure you modify them as needed!
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
Mami uses a build script written in Node.js; make sure you have NPM available and then run the following commands.
|
Mami uses a build script written in Node.js and a Makefile to make life easier.
|
||||||
|
I recommend using something like `nvm` with a Node version of at least `v22.14.0 (LTS)`.
|
||||||
|
|
||||||
|
The following make recipes are available:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Installs packages without updating package.json or package-lock.json
|
# Runs the package install and build recipes
|
||||||
npm ci
|
make [all]
|
||||||
|
|
||||||
# Runs the build process, make sure to run this after updates or changes as well
|
# Installs package versions expected by package-lock.json
|
||||||
node build.js
|
make install
|
||||||
|
|
||||||
|
# Runs the build process
|
||||||
|
make build
|
||||||
|
|
||||||
|
# Updates latest versions of packages expected by package.json
|
||||||
|
make update
|
||||||
|
|
||||||
|
# Rebuild a specific type of asset for speedier development
|
||||||
|
make rebuild-css / rebuild-html / rebuild-js / rebuild-webmanifest
|
||||||
```
|
```
|
||||||
|
|
25
build.js
25
build.js
|
@ -4,8 +4,8 @@ const fs = require('fs');
|
||||||
const exec = require('util').promisify(require('child_process').exec);
|
const exec = require('util').promisify(require('child_process').exec);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const config = JSON.parse(fs.readFileSync(pathJoin(__dirname, 'config/config.json')));
|
const title = process.env.MAMI_TITLE ?? 'Flashii Chat';
|
||||||
const isDebug = fs.existsSync(pathJoin(__dirname, '.debug'));
|
const isDebug = !!process.env.MAMI_DEBUG;
|
||||||
|
|
||||||
const env = {
|
const env = {
|
||||||
root: __dirname,
|
root: __dirname,
|
||||||
|
@ -15,14 +15,11 @@ const exec = require('util').promisify(require('child_process').exec);
|
||||||
swc: { es: 'es2021' },
|
swc: { es: 'es2021' },
|
||||||
housekeep: [ pathJoin(__dirname, 'public', 'assets') ],
|
housekeep: [ pathJoin(__dirname, 'public', 'assets') ],
|
||||||
vars: {
|
vars: {
|
||||||
html: {
|
html: { title },
|
||||||
title: config.title,
|
|
||||||
},
|
|
||||||
build: {
|
build: {
|
||||||
FUTAMI_DEBUG: isDebug,
|
FUTAMI_DEBUG: isDebug,
|
||||||
FUTAMI_URL: config.common_url,
|
FUTAMI_URL: process.env.FUTAMI_URL ?? '//futami.flashii.net/common.json',
|
||||||
MAMI_URL: config.modern_url,
|
AMI_URL: process.env.AMI_URL ?? '//sockchat.flashii.net',
|
||||||
AMI_URL: config.compat_url,
|
|
||||||
GIT_HASH: (await exec('git log --pretty="%H" -n1 HEAD')).stdout,
|
GIT_HASH: (await exec('git log --pretty="%H" -n1 HEAD')).stdout,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -37,7 +34,17 @@ const exec = require('util').promisify(require('child_process').exec);
|
||||||
{ source: 'mami.css', target: '/assets', name: 'mami.{hash}.css', vars: { html: ':source' } },
|
{ source: 'mami.css', target: '/assets', name: 'mami.{hash}.css', vars: { html: ':source' } },
|
||||||
],
|
],
|
||||||
webmanifest: [
|
webmanifest: [
|
||||||
{ source: 'mami.webmanifest', target: '/', name: 'mami.webmanifest', icons: '/icons', vars: { html: ':source' }, body: { name: config.title, short_name: config.title } }
|
{
|
||||||
|
source: 'mami.webmanifest',
|
||||||
|
target: '/',
|
||||||
|
name: 'mami.webmanifest',
|
||||||
|
icons: '/icons',
|
||||||
|
vars: { html: ':source' },
|
||||||
|
body: {
|
||||||
|
name: title,
|
||||||
|
short_name: title,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
html: [
|
html: [
|
||||||
{ source: 'mami.html', target: '/', name: 'index.html', template: 'html' },
|
{ source: 'mami.html', target: '/', name: 'index.html', template: 'html' },
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"title": "Flashii Chat",
|
|
||||||
"common_url": "//futami.flashii.net/common.json",
|
|
||||||
"modern_url": "//chat.flashii.net",
|
|
||||||
"compat_url": "//sockchat.flashii.net"
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue