From 79a833133c82c556e7abe0d4fdfa2d1881e68b04 Mon Sep 17 00:00:00 2001 From: ewin Date: Wed, 20 Aug 2025 00:02:08 -0600 Subject: [PATCH] Add .env support to make life easier --- .env.example | 3 +++ .gitignore | 1 + README.md | 8 +++++++- bin/add-edb-ids | 2 +- bin/add-gt-ids | 2 +- bin/one-time/7-3-stellar-mission-renames | 2 +- bin/one-time/hrothgar-viera-headwear | 4 ++-- 7 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..90876d7 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +MW_SCRIPTPATH="https://ffxiv.consolegameswiki.com/mediawiki" +MW_USERNAME="Wind-up Umbreon" +MW_PASSWORD="..." diff --git a/.gitignore b/.gitignore index 3c3629e..37d7e73 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +.env diff --git a/README.md b/README.md index e08e402..3c2a242 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,10 @@ Scripts for other one-time maintenance tasks (e.g. bulk renames) can be found fo ## Usage -You'll need a recent version of Node.js (22+). Install dependencies via `npm ci`, set the `MW_USERNAME` and `MW_PASSWORD` environment variables to your account username and [bot password](https://www.mediawiki.org/wiki/Manual:Bot_passwords) respectively, then run the scripts in the `bin` folder. +You'll need a recent version of Node.js (22+). Install dependencies: `npm ci`, rename `.env.example` to `.env` and set `MW_USERNAME` and `MW_PASSWORD` to your account username and [bot password](https://www.mediawiki.org/wiki/Manual:Bot_passwords) respectively, then run the scripts in the `bin` folder. + +### Environment variables + +- `MW_SCRIPTPATH`: The base URL for API requests for your wiki. For the XIV wiki it's `https://ffxiv.consolegameswiki.com/mediawiki`; other wikis may use paths other than `/mediawiki`, which can be identified in Special:Version as "Script path". +- `MW_USERNAME` and `MW_PASSWORD`: Account username and [bot password](https://www.mediawiki.org/wiki/Manual:Bot_passwords), respectively +- `MW_KILLPAGE`: The name of a page that will be checked when running unattended scripts. If this page contains content, the bot will be killed. This allows other editors to kill the bot if it starts misbehaving and you're not watching it. diff --git a/bin/add-edb-ids b/bin/add-edb-ids index f48a2ff..c388da3 100755 --- a/bin/add-edb-ids +++ b/bin/add-edb-ids @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --env-file-if-exists=.env import {findEDBEntryID} from '../lib/api/lodestone.js'; import {getMediawikiClient} from '../lib/config.js'; diff --git a/bin/add-gt-ids b/bin/add-gt-ids index 0df8cf1..49b47f7 100755 --- a/bin/add-gt-ids +++ b/bin/add-gt-ids @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --env-file-if-exists=.env import {findItemGTID} from '../lib/api/xivapi.js'; import {getMediawikiClient} from '../lib/config.js'; diff --git a/bin/one-time/7-3-stellar-mission-renames b/bin/one-time/7-3-stellar-mission-renames index bf30036..369e96a 100755 --- a/bin/one-time/7-3-stellar-mission-renames +++ b/bin/one-time/7-3-stellar-mission-renames @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --env-file-if-exists=.env // Renames A-class Stellar Missions to replace A-1, A-2, A-3 difficulty // indicators with the new empty/EX/EX+ naming used in patch 7.3. // https://na.finalfantasyxiv.com/lodestone/topics/detail/907c6d2aa020c0e4458ed1477668521fb4a117ec#:~:text=The%20notation,adjusted%2E diff --git a/bin/one-time/hrothgar-viera-headwear b/bin/one-time/hrothgar-viera-headwear index 25aa6bb..4d9da58 100755 --- a/bin/one-time/hrothgar-viera-headwear +++ b/bin/one-time/hrothgar-viera-headwear @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --env-file-if-exists=.env // Adds infobox parameters for Viera and Hrothgar hat compatibility based on // data compiled by Crye. Expects there to be a `hats.csv` file in the repo root // which is an export of the "HEAD" sheet of this Google Sheets document: @@ -14,7 +14,7 @@ import {addParameterAtBottom, setExistingParameter} from '../../lib/util/templat const mw = await getMediawikiClient(); // parse CSV, naively assume there are no quotes or backslashes (because i checked) -const data = readFileSync(join(import.meta.dirname, '../../hats.csv'), 'utf-8').split(/\r?\n/g).map(line => line && line.split(',')); +const data = readFileSync(join(import.meta.dirname, '../../hats.csv'), 'utf-8').split(/\r?\n/g).filter(l => l).map(line => line && line.split(',')); const headers = data.splice(0, 1)[0]; const COL_ITEM = headers.findIndex(field => field.toLowerCase() === 'item'); const COL_VIERA = headers.findIndex(field => field.toLowerCase().includes('viera'));