Skip to content
Snippets Groups Projects
Unverified Commit 47bdda02 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Run eslint fix

parent 8664d3ae
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env node #!/usr/bin/env node
var moment = require('moment'); const moment = require('moment')
var cli = require('cli'); const cli = require('cli')
var config = require('./sitegin/config'); const path = require('path')
var path = require('path'); const config = require('./sitegin/config')
cli.main(function(args, options) { cli.main(function(args, options) {
console.log(options); console.log(options)
config() config()
.then(function(obj) { .then(function(obj) {
sitegin(obj.config); sitegin(obj.config)
}) })
.catch(function(e) { .catch(function(e) {
console.log(e.stack); console.log(e.stack)
process.exit(); process.exit()
}); })
}); })
var sitegin = function(config) { var sitegin = function(config) {
var options = config.options; const options = config.options
require('./sitegin/sitegin')({ require('./sitegin/sitegin')({
watch: !options.noserver && !options.nowatch watch: !options.noserver && !options.nowatch,
}) })
.then(function onLoad(jobs) { .then(function onLoad(jobs) {
var sass = require('node-sass'); const sass = require('node-sass')
var fs = require('fs'); const fs = require('fs')
// Main builder function // Main builder function
// If builder is not running - run it // If builder is not running - run it
// If it is running - schedule rerun after it finishes // If it is running - schedule rerun after it finishes
var isRunning = false; let isRunning = false
var runAgain = false; let runAgain = false
var first = false; let first = false
var doSync = function(){} let doSync = function() {}
function run() { function run() {
var startTime = moment(); const startTime = moment()
runAgain = false; runAgain = false
if(isRunning) { if (isRunning) {
console.log('Generator is still running. Queing another run after it finishes.') console.log(
runAgain = true; 'Generator is still running. Queing another run after it finishes.',
return; )
} runAgain = true
console.log('================================================================================') return
console.log('Running generator')
isRunning = true;
jobs.run('pipeline',jobs)
.then(function() {
isRunning = false;
console.log('Generator finished in',moment().diff(startTime,'seconds'),'seconds')
doSync();
if(!first) {
first = true;
copyStaticFiles(config.builddir, config.staticDir, config.themeDir);
} }
if(runAgain) run(); console.log(
}) '================================================================================',
.catch(function(e) { )
isRunning = false; console.log('Running generator')
console.log('Generator crashed in',moment().diff(startTime,'seconds'),'seconds') isRunning = true
if(runAgain) run(); jobs
if(e.stack) .run('pipeline', jobs)
console.log(e.stack) .then(function() {
else isRunning = false
console.log(e) console.log(
if(config.options.noserver) process.exit(13); 'Generator finished in',
}); moment().diff(startTime, 'seconds'),
} 'seconds',
)
doSync()
if (!first) {
first = true
copyStaticFiles(
config.builddir,
config.staticDir,
config.themeDir,
)
}
if (runAgain) run()
})
.catch(function(e) {
isRunning = false
console.log(
'Generator crashed in',
moment().diff(startTime, 'seconds'),
'seconds',
)
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'); console.log('Sitegin successfully loaded')
run(); run()
rendersass(config.builddir, config.themeDir);
if(!options.noserver) { rendersass(config.builddir, config.themeDir)
var sync = require('browser-sync').create();
doSync = function() {
sync.reload('*')
}
sync.init({
server: {
baseDir: config.builddir
},
ui: {
port: options.port+1
},
port: options.port
});
var chokidar = require('chokidar'); if (!options.noserver) {
// article or theme reload const sync = require('browser-sync').create()
if(!options.nowatch) { doSync = function() {
var watches = [path.join(config.sourceDir,'articles'),config.themeDir]; sync.reload('*')
console.log('Watching',watches,'for changes'); }
chokidar.watch(watches, {ignoreInitial: true}) sync.init({
.on('all', function(event, path) { server: {
console.log('Content or theme changed. Rebuilding...'); baseDir: config.builddir,
console.log('Change event:',event,'on path:',path); },
run(); ui: {
port: options.port + 1,
},
port: options.port,
}) })
}
// sitegin reload const chokidar = require('chokidar')
jobs.onReload(function() { // article or theme reload
console.log('Sitegin reloaded'); if (!options.nowatch) {
run(); const watches = [
}) path.join(config.sourceDir, 'articles'),
} config.themeDir,
}) ]
.catch(function(e) { console.log('Watching', watches, 'for changes')
console.log(e.stack); chokidar
process.exit(); .watch(watches, { ignoreInitial: true })
}); .on('all', function(event, path) {
console.log('Content or theme changed. Rebuilding...')
console.log('Change event:', event, 'on path:', path)
run()
})
}
// sitegin reload
jobs.onReload(function() {
console.log('Sitegin reloaded')
run()
})
}
})
.catch(function(e) {
console.log(e.stack)
process.exit()
})
} }
var copyStaticFiles = function(builddir, staticdir,themedir) { var copyStaticFiles = function(builddir, staticdir, themedir) {
// STATIC FILES // STATIC FILES
var fsextra = require('node-fs-extra'); const fsextra = require('node-fs-extra')
fsextra.copy(
staticdir,
builddir,
function(file){ return !(file.match('\\.git') || file.match('static/articles')); },
function(){console.log('copy static done');}
);
fsextra.copy( fsextra.copy(
staticdir+'/articles', staticdir,
builddir+'/clanek', builddir,
function(){console.log('copy static/articles done');} function(file) {
); return !(file.match('\\.git') || file.match('static/articles'))
},
function() {
console.log('copy static done')
},
)
fsextra.copy(`${staticdir}/articles`, `${builddir}/clanek`, function() {
console.log('copy static/articles done')
})
fsextra.copy( fsextra.copy(
themedir+'/static', `${themedir}/static`,
builddir, builddir,
function(file){ return !file.match('\\.git') }, function(file) {
function(){console.log('copy '+themedir+'/static done');} return !file.match('\\.git')
); },
function() {
console.log(`copy ${themedir}/static done`)
},
)
} }
var rendersass = function(builddir, themedir) { var rendersass = function(builddir, themedir) {
// SASS // SASS
var sass = require('node-sass'); const sass = require('node-sass')
var fs = require('filendir'); const fs = require('filendir')
sass.render ({file: themedir+'/sass/style.scss'},function(err, result) { sass.render({ file: `${themedir}/sass/style.scss` }, function(err, result) {
if(err === null) { if (err === null) {
console.log('compiled sass'); console.log('compiled sass')
fs.writeFile(builddir+'/theme/style.css',result.css); fs.writeFile(`${builddir}/theme/style.css`, result.css)
} else console.log('error ', err); } else console.log('error ', err)
}); })
}; }
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- sitegin/tests/ --recursive -R spec -u exports -t 60000" "test": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- sitegin/tests/ --recursive -R spec -u exports -t 60000",
"lint": "eslint sitegin index.js"
}, },
"author": "", "author": "",
"license": "UNSPECIFIED", "license": "UNSPECIFIED",
......
const youtube = require('./utils/youtube.js')
const path = require('path') const path = require('path')
const url = require('url') const url = require('url')
const youtube = require('./utils/youtube.js')
const jobs = require('./jobs') const jobs = require('./jobs')
const { rewriteURL } = require('./urls') const { rewriteURL } = require('./urls')
...@@ -101,7 +101,8 @@ module.exports = (href_, title, text, curFile_, cfg) => { ...@@ -101,7 +101,8 @@ module.exports = (href_, title, text, curFile_, cfg) => {
if (parsedHref.host) { if (parsedHref.host) {
return genHTML(href, true) return genHTML(href, true)
} else if (path.isAbsolute(href)) { }
if (path.isAbsolute(href)) {
return genHTML(href) return genHTML(href)
} }
curFile = curFile.replace(/\.md$/, '') curFile = curFile.replace(/\.md$/, '')
......
...@@ -48,12 +48,12 @@ module.exports = function imageResizer(file, targetDir, _width, _height) { ...@@ -48,12 +48,12 @@ module.exports = function imageResizer(file, targetDir, _width, _height) {
doResize() doResize()
} else if (height) { } else if (height) {
if (h > height) { if (h > height) {
width = Math.round(height * w / h) width = Math.round((height * w) / h)
doResize() doResize()
} }
} else if (width) { } else if (width) {
if (w > width) { if (w > width) {
height = Math.round(width * h / w) height = Math.round((width * h) / w)
doResize() doResize()
} }
} else { } else {
......
...@@ -111,11 +111,13 @@ module.exports = (data, type_) => ...@@ -111,11 +111,13 @@ module.exports = (data, type_) =>
tmpls.forEach(o => { tmpls.forEach(o => {
promises.push( promises.push(
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const param = Object.assign({}, data, { const param = {
config: Object.assign({}, data.config, { ...data,
config: {
...data.config,
baseurl: config ? config.options.baseurl : '', baseurl: config ? config.options.baseurl : '',
}), },
}) }
o.tmpl.render(param, (err, val) => { o.tmpl.render(param, (err, val) => {
if (err) { if (err) {
// reject(new Error('Error rendering template '+o.file)); // reject(new Error('Error rendering template '+o.file));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment