Skip to content

Commit

Permalink
Merge branch 'master' into docs-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Jan 9, 2025
2 parents b19073f + 4711759 commit c0d8491
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 68 deletions.
43 changes: 36 additions & 7 deletions bin/build-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

'use strict';

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 exec = require('child-process-promise').exec;
var mkdirp = require('mkdirp');
var cssmin = require('cssmin');
const terser = require('terser');

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 @@ -20,8 +25,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 @@ -39,15 +44,35 @@ function buildJekyll(path) {
return highlightEs6();
}).then(function () {
console.log('=> Highlighted ES6');

const srcPath = resolvePath('docs/src/code.js');
const targetPath = resolvePath('docs/_site/static/js/code.min.js');
const src = fs.readFileSync(srcPath, { encoding:'utf8' });
const mangle = { toplevel: true };
const output = { ascii_only: true };
const { code, error } = terser.minify(src, { mangle, output });
if (error) {
if (process.env.BUILD) {
throw error;
} else {
console.log(
`Javascript minification failed on line ${error.line} col ${error.col}:`,
error.message,
);
}
} else {
fs.writeFileSync(targetPath, code);
console.log('Minified javascript.');
}
});
}

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
// in this blog post.
// in blog posts & documentation.
replace({
regex: '<span class="nx">(await|async|of)</span>',
replacement: '<span class="kd">$1</span>',
Expand All @@ -69,6 +94,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
2 changes: 2 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ github:
collections:
guides:
output: true
exclude:
- src
File renamed without changes.
1 change: 0 additions & 1 deletion docs/static/js/code.min.js

This file was deleted.

59 changes: 0 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"chai": "3.5.0",
"chai-as-promised": "5.3.0",
"change-case": "4.0.1",
"child-process-promise": "2.2.1",
"cssmin": "0.4.3",
"denodeify": "1.2.1",
"derequire": "2.1.1",
Expand Down

0 comments on commit c0d8491

Please sign in to comment.