Skip to content
Snippets Groups Projects
Verified Commit 7043da52 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Add config, readFiles, and print jobs

Config - returns configuration
ReadFiles - reads files from config.articlesLocation
Print - prints everything it gets
parent 80e1a6eb
Branches
No related tags found
No related merge requests found
#!/usr/bin/env node
require('./sitegin/sitegin')({
watch: false
}, function onLoad(jobs) {
watch: true
})
.then(function onLoad(jobs) {
var sass = require('node-sass');
var fs = require('fs');
function run() {
jobs.runSequence('config','readFiles','print')
.catch(e => console.log(e.stack));
}
console.log('Sitegin successfully loaded');
jobs.onReload(function() {
console.log("Sitegin reloaded");
run();
})
/*
var builddir = "build";
if(process.argv[2] !== "compileonly") builddir = "build-debug";
var oldEmit = sequencer.emit;
sequencer.emit = function() {
console.log("Event:",arguments[0]);
oldEmit.apply(sequencer, arguments);
}
sequencer.on("", function(ev) {
console.log("Event:",ev);
})
var tasks = [];
var onDone = function(what) {
console.log(what, 'done');
var removed = false;
for(var i = 0; i < tasks.length; i++) {
if(tasks[i] == what) {
removed = true;
tasks.splice(i,1);
break;
}
}
if(!removed && process.argv[2] == "compileonly") throw new Error("Task "+what+" ended but was never registered");
if(tasks.length == 0 && process.argv[2] == "compileonly") {
console.log("exitting");
process.exit();
}
}
// PIPELINE
sequencer
.load(input)
.registerNext(transformerGit)
.registerNext(transformerOther)
.registerNext(transformerImages)
.registerNext(transformerMD)
.registerNext(transformerUrlizeTags)
.registerNext(transformerTags)
.registerNext(transformerNunjucks)
.registerNext(output)
.finish(function(list) {
onDone("sequencer");
})
tasks.push('sequencer');
try {fs.mkdirSync(builddir);}catch(e){}
try {fs.mkdirSync(builddir+"/theme");}catch(e){}
// SASS
var rendersass = function() {
sass.render ({file: "theme/sass/style.scss"},function(err, result) {
if(err == null) {
console.log("compiled sass");
fs.writeFile(builddir+"/theme/style.css",result.css);
} else console.log("error ", err);
onDone("sass");
});
};
tasks.push('sass');
rendersass();
// STATIC FILES
var fsextra = require('node-fs-extra');
tasks.push('copy static');
fsextra.copy(
'static',
builddir,
function(file){ return !(file.match(".git") || file.match("static/articles")); },
function(){onDone("copy static");}
);
tasks.push('copy static/articles');
fsextra.copy(
'static/articles',
builddir+"/clanek",
function(){onDone("copy static/articles");}
);
tasks.push('copy theme static');
fsextra.copy(
'theme/static',
builddir,
function(file){ return !file.match("\\.git") },
function(){onDone("copy theme static");}
);
// DEVEL INCOMING
if(process.argv[2] !== "compileonly") {
var sync = require('browser-sync').create();
sync.init({
server: {
baseDir: builddir
},
ui: {
port: 1338
},
port: 1337
});
// CHANGE WATCHER
var chokidar = require('chokidar');
chokidar.watch('theme/static', {ignoreInitial: true, usePolling: false})
.on('all', (event, path) => {
console.log(path);
console.log("theme static copy watcher");
fsextra.copy(
'theme/static',
builddir,
function(file){ return !file.match(".git"); },
function(){}
);
sync.reload(path);
});
chokidar.watch('static/', {ignoreInitial: true, usePolling: false})
.on('all', (event, path) => {
if(path.match(/^static\/articles\/.*$/)) return;
console.log("static copy watcher");
fsextra.copy(
'static',
builddir,
function(file){ return !(file.match(".git") || file.match("static/articles")); },
function(){}
);
sync.reload(path);
})
.unwatch('static/articles');
chokidar.watch('static/articles', {ignoreInitial: true, usePolling: false})
.on('all', (event, path) => {
console.log("static articles copy watcher");
fsextra.copy('static/articles',builddir+"/clanek",function(){});
sync.reload(path);
})
.unwatch('static/articles');
chokidar.watch(['theme/','content/'], {ignoreInitial: true, usePolling: false})
.on('all', (event, path) => {
if(path.match(/^theme\/static\/.*$/)) return;
if(path.match(/^theme\/sass\/.*$/)) return;
console.log("rebuild watcher",path);
sequencer.load(input);
})
.unwatch("theme/static")
.unwatch("theme/sass");
sequencer.finish(function() {
sync.reload("*.html");
});
chokidar.watch('theme/sass', {ignoreInitial: true, usePolling: false})
.on('all', function(event, path) {
console.log("sass: file change detected - rerendering "+event+" "+path);
rendersass();
sync.reload(path);
});
}
*/
run();
})
.catch(function(e) {
console.log(e.stack);
process.exit();
});
......@@ -23,7 +23,8 @@
"nunjucks-date-filter": "^0.1.1",
"syntax-error": "^1.1.5",
"toml": "~2.3.0",
"toml-js": "0.0.8"
"toml-js": "0.0.8",
"walk": "^2.3.9"
},
"devDependencies": {
"istanbul": "^0.4.2",
......
/*
* This file specifies whole configuration of sitegin.
* In future it might actually read configuration files but for now - if you
* want to configure sitegin you have to modify this file.
* (or write config reader which would replace this file - I'd appreciate
* merge request for this feature ;) )
*/
module.exports = function() {
var builddir = "build";
if(process.argv[2] !== "compileonly") builddir = "build-debug";
var watch = true;
if(process.argv[2] == "compileonly") watch = false;
return Promise.resolve({
config: {
builddir: builddir,
watch: watch,
articlesLocation: 'content/articles'
}
})
}
module.exports = function(a) {
var pages = a.pages
a.pages = ['...']
console.log(a)
a.pages = pages
return Promise.resolve(a)
}
/*
* This job reads files from config.articlesLocation and loads this list to `pages`
*/
var walk = require('walk');
var fs = require('fs');
var path = require('path');
module.exports = function(obj) {
return new Promise(function(resolve, reject) {
var pages = [];
walk.walk(obj.config.articlesLocation)
.on('file',function(root, fileStats, next) {
var file = path.join(root,fileStats.name);
fs.readFile(file, 'utf8', function(err,data) {
if(err) {
console.log('Error reading file '+file)
console.log(err);
} else {
pages.push({
filename: file,
content: data
})
}
next()
})
})
.on('errors',function(root, nodeStatsArray, next) {
console.log('Walker error', root, nodeStatsArray);
next();
})
.on('end', function() {
obj.pages = pages;
resolve(obj);
})
})
}
var jobs = require('./jobs');
module.exports = function(config, onDone) {
jobs.registerMultiple(
module.exports = function(config) {
return jobs.registerMultiple(
config,
/*['input-hugo', './input-hugo'],
['config', './config'],
['readFiles', './read-files'],
['parseHugo', './input-hugo'],
['print', './print'],
['transformer-git', './transformer-git'],
['output-console', './output-console'],
['output-filesystem', './output-filesystem'],
['transformer-basichtml', './transformer-basichtml'],
['transformer-git', './transformer-git'],
['transformer-markdown', './transformer-markdown'],
['transformer-nunjucks', './transformer-nunjucks'],
['transformer-tags', './transformer-tags'],
['transformer-urlizetags', './transformer-urlizetags'],*/
['transformer-other', './transformer-other']
//['transformer-images', './transformer-images']
['transformer-urlizetags', './transformer-urlizetags'],
['transformer-other', './transformer-other'],
['transformer-images', './transformer-images']
)
.then(function() {
if(onDone) onDone(jobs);
return jobs;
})
.catch(function(e) {
console.log(e.stack)
jobs.close();
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment