diff --git a/index.js b/index.js index 3231a53a4809a32a92c7f9ced7f5654ed9d55cae..dbc6dd87c2aba7ca6e58ed096bd70a0c82d9315c 100755 --- a/index.js +++ b/index.js @@ -51,19 +51,19 @@ var sitegin = function(config) { .catch(function(e) { isRunning = false; console.log('Generator crashed in',moment().diff(startTime,'seconds'),'seconds') - if(config.options.noserver) process.exit(13); if(runAgain) run(); if(e.stack) console.log(e.stack) else console.log(e) + if(config.options.noserver) process.exit(13); }); } console.log('Sitegin successfully loaded'); run(); - copyStaticFiles(config.builddir, config.staticDir); - rendersass(config.builddir); + copyStaticFiles(config.builddir, config.staticDir, config.themeDir); + rendersass(config.builddir, config.themeDir); if(!options.noserver) { var sync = require('browser-sync').create(); @@ -82,7 +82,7 @@ var sitegin = function(config) { var chokidar = require('chokidar'); // article or theme reload - chokidar.watch([config.sourceDir,'theme/'], {ignoreInitial: true}) + chokidar.watch([config.sourceDir,config.themeDir], {ignoreInitial: true}) .on('all', function(event, path) { console.log('Content or theme changed. Rebuilding...'); run(); @@ -101,7 +101,7 @@ var sitegin = function(config) { }); } -var copyStaticFiles = function(builddir, staticdir) { +var copyStaticFiles = function(builddir, staticdir,themedir) { // STATIC FILES var fsextra = require('node-fs-extra'); fsextra.copy( @@ -116,19 +116,19 @@ var copyStaticFiles = function(builddir, staticdir) { function(){console.log('copy static/articles done');} ); fsextra.copy( - 'theme/static', + themedir+'/static', builddir, function(file){ return !file.match('\\.git') }, - function(){console.log('copy theme/static done');} + function(){console.log('copy '+themedir+'/static done');} ); } -var rendersass = function(builddir) { +var rendersass = function(builddir, themedir) { // SASS var sass = require('node-sass'); var fs = require('fs'); - sass.render ({file: 'theme/sass/style.scss'},function(err, result) { + sass.render ({file: themedir+'/sass/style.scss'},function(err, result) { if(err === null) { console.log('compiled sass'); fs.writeFile(builddir+'/theme/style.css',result.css); diff --git a/sitegin/config.js b/sitegin/config.js index 23ddaa8e723891d3c47d7d6f575b7316d37a9734..e43f4ec148f02c457458ee228e45edbd5d868290 100644 --- a/sitegin/config.js +++ b/sitegin/config.js @@ -13,15 +13,18 @@ var options = cli.parse({ uiport: [null, 'BrowserSync UI port', 'number', 'port+1'], httpsonly: [null, 'Converts all http://ok1kvk.cz links to https'], httponly: [null, 'Converts all https://ok1kvk.cz links to http'], - contentdir: [null, 'Allows to specify arbitrary content directory. '+ - 'Can also be http(s) url to zip file.', 'string', 'content'], - staticdir: [null, 'Allows to specify arbitrary directory for static files. '+ - 'Can also be http(s) url to zip file.', 'string', 'static'] + contentdir: [null, 'Allows to specify arbitrary content directory.', 'string', 'static'], + themedir: [null, 'Allows to specify arbitrary content directory.', 'string', 'theme'], + builddir: [null, 'Allows to specify arbitrary content directory.', 'string', null], + staticdir: [null, 'Allows to specify arbitrary directory for static files.', 'string', 'static'] }); module.exports = function() { + console.log('Build step: Config'); var builddir = 'build'; - if(!options.noserver) builddir = 'build-debug'; + if(options.builddir) + builddir = options.builddir; + else if(!options.noserver) builddir = 'build-debug'; if(options.uiport == 'port+1') { options.uiport = options.port+1; @@ -34,6 +37,7 @@ module.exports = function() { builddir: builddir, sourceDir: options.contentdir, staticDir: options.staticdir, + themeDir: options.themedir, articlesLocation: 'articles', linksPerPage: 6 }}); @@ -42,3 +46,4 @@ module.exports = function() { }) } module.exports.watch = !options.noserver; +module.exports.themeDir = options.themedir; diff --git a/sitegin/gitInfo.js b/sitegin/gitInfo.js index 867cac524feb47fb36e0faa2ea3973213ed03bce..e27c47216bed0fc4fe1405880b761975bb860599 100644 --- a/sitegin/gitInfo.js +++ b/sitegin/gitInfo.js @@ -7,7 +7,7 @@ var nodegit = require('nodegit'); var path = require('path'); var moment = require('moment'); -var pathToRepo = path.resolve('content'); +var pathToRepo; // Returns promise for patch of single commit var gitShow = function(repo, commitData) { @@ -116,6 +116,8 @@ var getFilesHistory = function() { } module.exports = function(obj) { + console.log('Build step: GitInfo'); + pathToRepo = path.resolve(obj.config.sourceDir); return getFilesHistory() .then((filesHistory) => { obj.pages.forEach(function(article) { diff --git a/sitegin/markdown.js b/sitegin/markdown.js index 99daeef2e737d4556ec92e51ceb0a113c71de72d..df8dd7188b8cb6df82d11f5041a43becc3f09197 100644 --- a/sitegin/markdown.js +++ b/sitegin/markdown.js @@ -113,6 +113,7 @@ marked.setOptions({ }); module.exports = function(obj) { + console.log('Build step: Markdown'); var options = obj.config.options; renderer.link = function(href, title, text) { if(options.httponly) { diff --git a/sitegin/nunjucks.js b/sitegin/nunjucks.js index 0a364b95460e6b232fa80c0729e7e38e7fdc8bb0..32fc645c7c90baaeef4e7a0cd64ecc714fcd46c7 100644 --- a/sitegin/nunjucks.js +++ b/sitegin/nunjucks.js @@ -8,10 +8,10 @@ var fs = require('fs'); var dateFilter = require('nunjucks-date-filter'); var util = require('util'); -var watch = require('./config').watch; -console.log('watch: '+watch); +var config = require('./config'); +console.log('watch: '+config.watch); var env = new nunjucks.Environment( - new nunjucks.FileSystemLoader('theme/templates',{watch: watch}) + new nunjucks.FileSystemLoader(config.themeDir+'/templates',{watch: config.watch}) ); env.addFilter('date', dateFilter); @@ -56,8 +56,11 @@ module.exports = function(data, type) { return new Promise(function(resolve, reject) { if(formats[type]) resolve(formats[type]); else { - fs.readdir('theme/templates',function(err, files) { - if(err) return reject(new Error('Error listing files in theme/templates')); + fs.readdir(config.themeDir+'/templates',function(err, files) { + if(err) { + console.log(config); + return reject(new Error('Error listing files in '+config.themeDir+'/templates')); + } files = files.filter(function(file) { return file.match(type+'\..*\.nunj'); @@ -66,8 +69,8 @@ module.exports = function(data, type) { var filteredFiles = []; var todo = 0; files.forEach(function(file) { - fs.stat('theme/templates/'+file,function(err, stat) { - if(err) reject(new Error('Error stating theme/templates/'+file)); + fs.stat(config.themeDir+'/templates/'+file,function(err, stat) { + if(err) reject(new Error('Error stating '+config.themeDir+'/templates'+file)); if(stat.isFile()) filteredFiles.push(file); todo--; diff --git a/sitegin/parseHugo.js b/sitegin/parseHugo.js index c76b35372c57cdfe87b3233f7841c4e71936382d..e685065f8bafe636f2576b957b6ff0440bfacd50 100644 --- a/sitegin/parseHugo.js +++ b/sitegin/parseHugo.js @@ -27,6 +27,7 @@ var readPageWorker = function(content, obj) { } module.exports = function(obj) { + console.log('Build step: ParseHugo'); return new Promise(function(resolve, reject) { var pages = []; obj.pages.forEach(function(page) { diff --git a/sitegin/readFiles.js b/sitegin/readFiles.js index 83fa9a5ae560c0e317ecd9ba1a637825cc0af354..e467e78254bc35f67ea8815e82192365af0c4406 100644 --- a/sitegin/readFiles.js +++ b/sitegin/readFiles.js @@ -6,6 +6,7 @@ var fs = require('fs'); var path = require('path'); module.exports = function(obj) { + console.log('Build step: ReadFiles'); return new Promise(function(resolve, reject) { var pages = []; walk.walk(path.join(obj.config.sourceDir,obj.config.articlesLocation)) diff --git a/sitegin/sitemap.js b/sitegin/sitemap.js index af09456d22257f95b250a3266c5f831b5e1e5870..73b0129fa99f13c9e5e2ff5de8c98e56cc001b7f 100644 --- a/sitegin/sitemap.js +++ b/sitegin/sitemap.js @@ -1,5 +1,6 @@ var fs = require('fs'); module.exports = function(obj) { + console.log('Build step: Sitemap'); return new Promise(function(resolve, reject) { var file = '<?xml version="1.0" encoding="UTF-8"?>\n'+ '<urlset\n'+ diff --git a/sitegin/tags.js b/sitegin/tags.js index 42b14afb35453d709ea99303b89fe7a7dd0f801e..be2386ed1b137fe98daded528fd9d7af8cb780cd 100644 --- a/sitegin/tags.js +++ b/sitegin/tags.js @@ -8,6 +8,7 @@ var toURL = function(url) { } module.exports = function(obj) { + console.log('Build step: Tags'); return new Promise(function(resolve, reject) { var tags = []; var tagPages = {}; diff --git a/sitegin/theme.js b/sitegin/theme.js index bb743ea7393260311b8763455c7beed1c2ac0903..dde9b8a7bde123885dda55798fca1406692dcc40 100644 --- a/sitegin/theme.js +++ b/sitegin/theme.js @@ -1,6 +1,7 @@ var jobs = require('./jobs'); module.exports = function(obj) { + console.log('Build step: Theme'); return new Promise(function(resolve,reject){ var todo = 0; var done = function(){ diff --git a/sitegin/urls.js b/sitegin/urls.js index 11693250eded17a113efbd10eb2be356fa135f42..e4263f0815c701abe5980ea0e46dc22a9fb28716 100644 --- a/sitegin/urls.js +++ b/sitegin/urls.js @@ -3,6 +3,7 @@ */ module.exports = function(obj) { + console.log('Build step: URLs'); return new Promise(function(resolve, reject) { obj.pages.forEach(function(page) { var file = page.file; diff --git a/sitegin/writeFiles.js b/sitegin/writeFiles.js index 7fbfa8b3fe72dd7a36cc1a793cbfe1ce622229eb..afc4ff2a0df6c328b567f55ecbc08b965233b91e 100644 --- a/sitegin/writeFiles.js +++ b/sitegin/writeFiles.js @@ -4,6 +4,7 @@ var path = require('path'); var mkdirp = require('mkdirp'); module.exports = function(obj) { + console.log('Build step: WriteFiles'); return new Promise(function(resolve,reject) { var builddir = obj.config.builddir; var todo = 0;