@@ -17,53 +17,49 @@ const POUCHDB_LESS = resolvePath('docs/src/less/pouchdb/pouchdb.less');
1717
1818process . chdir ( 'docs' ) ;
1919
20- function checkJekyll ( ) {
21- return exec ( 'bundle check' ) . catch ( function ( ) {
20+ async function checkJekyll ( ) {
21+ try {
22+ await exec ( 'bundle check' ) ;
23+ } catch ( err ) {
2224 throw new Error ( 'Jekyll is not installed. You need to do: npm run install-jekyll' ) ;
23- } ) ;
25+ }
2426}
2527
26- function buildCSS ( ) {
28+ async function buildCSS ( ) {
2729 fs . mkdirSync ( __dirname + '/../docs/static/css' , { recursive :true } ) ;
2830 const cmd = [ resolvePath ( 'node_modules/less/bin/lessc' ) , POUCHDB_LESS ] . join ( ' ' ) ;
29- return exec ( cmd ) . then ( function ( child ) {
30- var minifiedCss = cssmin ( child . stdout ) ;
31- fs . writeFileSync ( POUCHDB_CSS , minifiedCss ) ;
32- console . log ( 'Updated: ' , POUCHDB_CSS ) ;
33- } ) ;
31+ const { stdout } = await exec ( cmd ) ;
32+ const minifiedCss = cssmin ( stdout ) ;
33+ fs . writeFileSync ( POUCHDB_CSS , minifiedCss ) ;
34+ console . log ( 'Updated:' , POUCHDB_CSS ) ;
3435}
3536
36- function buildJekyll ( path ) {
37- // Don't rebuild on website artifacts being written
38- if ( path && / ^ _ s i t e / . test ( path . relative ) ) {
39- return ;
40- }
41- return exec ( 'bundle exec jekyll build' ) . then ( function ( ) {
42- console . log ( '=> Rebuilt jekyll' ) ;
43- return highlightEs6 ( ) ;
44- } ) . then ( function ( ) {
45- console . log ( '=> Highlighted ES6' ) ;
46-
47- const srcPath = resolvePath ( 'docs/src/code.js' ) ;
48- const targetPath = resolvePath ( 'docs/_site/static/js/code.min.js' ) ;
49- const src = fs . readFileSync ( srcPath , { encoding :'utf8' } ) ;
50- const mangle = { toplevel : true } ;
51- const output = { ascii_only : true } ;
52- const { code, error } = terser . minify ( src , { mangle, output } ) ;
53- if ( error ) {
54- if ( process . env . BUILD ) {
55- throw error ;
56- } else {
57- console . log (
58- `Javascript minification failed on line ${ error . line } col ${ error . col } :` ,
59- error . message ,
60- ) ;
61- }
37+ async function buildJekyll ( ) {
38+ await exec ( 'bundle exec jekyll build' ) ;
39+ console . log ( '=> Rebuilt jekyll' ) ;
40+
41+ highlightEs6 ( ) ;
42+ console . log ( '=> Highlighted ES6' ) ;
43+
44+ const srcPath = resolvePath ( 'docs/src/code.js' ) ;
45+ const targetPath = resolvePath ( 'docs/_site/static/js/code.min.js' ) ;
46+ const src = fs . readFileSync ( srcPath , { encoding :'utf8' } ) ;
47+ const mangle = { toplevel : true } ;
48+ const output = { ascii_only : true } ;
49+ const { code, error } = terser . minify ( src , { mangle, output } ) ;
50+ if ( error ) {
51+ if ( process . env . BUILD ) {
52+ throw error ;
6253 } else {
63- fs . writeFileSync ( targetPath , code ) ;
64- console . log ( 'Minified javascript.' ) ;
54+ console . log (
55+ `Javascript minification failed on line ${ error . line } col ${ error . col } :` ,
56+ error . message ,
57+ ) ;
6558 }
66- } ) ;
59+ } else {
60+ fs . writeFileSync ( targetPath , code ) ;
61+ console . log ( 'Minified javascript.' ) ;
62+ }
6763}
6864
6965function highlightEs6 ( ) {
@@ -101,8 +97,23 @@ if (!process.env.BUILD) {
10197 const http_server = require ( 'http-server' ) ;
10298 const watchGlob = require ( 'glob-watcher' ) ;
10399
104- watchGlob ( '**' , buildJekyll ) ;
100+ // Simpler ways of blacklisting certain paths here would be very welcome.
101+ fs . readdirSync ( '.' )
102+ . forEach ( path => {
103+ if ( path === '_site' || path . startsWith ( 'Gemfile' ) ) {
104+ return ;
105+ }
106+
107+ if ( fs . statSync ( path ) . isDirectory ( ) ) {
108+ watchGlob ( `${ path } /**` , buildJekyll ) ;
109+ } else {
110+ watchGlob ( path , buildJekyll ) ;
111+ }
112+ } ) ;
113+
114+
105115 watchGlob ( 'static/src/*/*.less' , buildCSS ) ;
116+
106117 http_server . createServer ( { root : '_site' , cache : '-1' } ) . listen ( 4000 ) ;
107118 console . log ( 'Server address: http://localhost:4000' ) ;
108119}
0 commit comments