Skip to content

Commit

Permalink
refactor(build-site): standardise path resolution (pouchdb#9050)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn authored Jan 9, 2025
1 parent 9121f6e commit 17a3b3b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions bin/build-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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');
Expand Down

0 comments on commit 17a3b3b

Please sign in to comment.