From 7abdb6b15a2683a97f6fbc25149ea2ea4c8846f7 Mon Sep 17 00:00:00 2001 From: Hysterelius Date: Mon, 22 Jul 2024 01:03:44 +1000 Subject: Bump replace-in-file (#182) * Update replace-in-file * Fix npm bugs * Fix npm bugs v2--- static/js/searchChange.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'static/js') diff --git a/static/js/searchChange.js b/static/js/searchChange.js index afe3214..8f776ae 100644 --- a/static/js/searchChange.js +++ b/static/js/searchChange.js @@ -1,11 +1,10 @@ const fs = require('fs'); const path = require("path"); -const replace = require('replace-in-file'); - // Path for config.toml const configTomlPath = path.join(__dirname, "../../config.toml"); async function main() { + const { replaceInFileSync } = await import('replace-in-file'); // Process arguments to determine the search mode const args = process.argv.slice(2); // Remove the first two default arguments @@ -14,11 +13,11 @@ async function main() { switch (args[0]) { case '--pagefind': console.log('Pagefind search mode activated.'); - await swapToPagefind(); + await swapToPagefind(replaceInFileSync); break; case '--elasticlunr': console.log('Elasticlunr search mode activated.'); - await swapToElasticlunr(); + await swapToElasticlunr(replaceInFileSync); break; default: console.log('Unknown search mode. Please use --pagefind or --elasticlunr.'); @@ -30,38 +29,38 @@ async function main() { main(); -async function swapToPagefind() { +async function swapToPagefind(replaceInFileSync) { // Edit the config.toml file - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /search_library = ['|"]\w+['|"]/g, to: 'search_library = "pagefind"', }); - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /online_indexformat = ['|"]\w+['|"]/g, to: 'online_indexformat = "fuse_json"', }); - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /index_format = ['|"]\w+['|"]/g, to: 'index_format = "fuse_json"', }); } -async function swapToElasticlunr() { +async function swapToElasticlunr(replaceInFileSync) { // Edit the config.toml file - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /search_library = ['|"]\w+['|"]/g, to: 'search_library = "elasticlunr"', }); - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /online_indexformat = ['|"]\w+['|"]/g, to: 'online_indexformat = "elasticlunr_json"', }); - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /index_format = ['|"]\w+['|"]/g, to: 'index_format = "elasticlunr_json"', -- cgit v1.3.1