From 17a3b3b70bd3b17510b7f04c1594b9101b768872 Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:04:20 +0300 Subject: [PATCH] refactor(build-site): standardise path resolution (#9050) --- bin/build-site.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/build-site.js b/bin/build-site.js index c2ac0bf2cc..94f2f0a08e 100755 --- a/bin/build-site.js +++ b/bin/build-site.js @@ -6,12 +6,14 @@ const { promisify } = require('node:util'); const exec = promisify(require('node:child_process').exec); var fs = require('fs'); +const Path = require('node:path'); + var replace = require('replace'); var mkdirp = require('mkdirp'); var cssmin = require('cssmin'); -var POUCHDB_CSS = __dirname + '/../docs/static/css/pouchdb.css'; -var POUCHDB_LESS = __dirname + '/../docs/static/less/pouchdb/pouchdb.less'; +const POUCHDB_CSS = resolvePath('docs/static/css/pouchdb.css'); +const POUCHDB_LESS = resolvePath('docs/static/less/pouchdb/pouchdb.less'); process.chdir('docs'); @@ -22,8 +24,8 @@ function checkJekyll() { } function buildCSS() { - mkdirp.sync(__dirname + '/../docs/static/css'); - var cmd = __dirname + '/../node_modules/less/bin/lessc ' + POUCHDB_LESS; + mkdirp.sync(resolvePath('docs/static/css')); + const cmd = [ resolvePath('node_modules/less/bin/lessc'), POUCHDB_LESS ].join(' '); return exec(cmd).then(function (child) { var minifiedCss = cssmin(child.stdout); fs.writeFileSync(POUCHDB_CSS, minifiedCss); @@ -45,7 +47,7 @@ function buildJekyll(path) { } function highlightEs6() { - var path = require('path').resolve(__dirname, '../docs/_site'); + const path = resolvePath('docs/_site'); // TODO: this is a fragile and hacky way to get // 'async' and 'await' to highlight correctly @@ -71,6 +73,10 @@ function buildEverything() { .catch(onError); } +function resolvePath(projectLocalPath) { + return Path.resolve(__dirname, '..', projectLocalPath); +} + if (!process.env.BUILD) { const http_server = require('http-server'); const watchGlob = require('glob-watcher');