This repository has been archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jekyll.js
65 lines (53 loc) · 1.5 KB
/
jekyll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import BaseRecipe from './baseRecipe'
import tmp from 'tmp'
import fs from 'fs-extra'
import Ruby from './ruby/ruby'
const Default = {
watch: false,
presetType: 'macro',
task: {
name: 'jekyll',
description: 'Builds a jekyll site'
},
options: {
baseCommand: 'bundle exec',
config: '_config.yml',
incremental: false,
raw: undefined // 'baseurl: "/bootstrap-material-design"'
}
}
const Jekyll = class extends BaseRecipe {
/**
*
* @param gulp - gulp instance
* @param config - customized overrides
*/
constructor(gulp, preset, ...configs) {
super(gulp, preset, Default, ...configs)
}
run(done) {
let config = `--config ${this.config.options.config}`
let rawConfigFile = this.rawConfig()
// If raw is specified, add the temporary config file to the list of configs passed into the jekyll command
if (rawConfigFile) {
config += `,${rawConfigFile}`
}
this.exec(`${Ruby.localPath(('rubyRunner.sh'))} ${this.config.options.baseCommand} jekyll build ${config}`)
this.donezo(done)
}
// Create temporary config file if needed
rawConfig() {
if (this.config.options.raw) {
// Tmp file is only available within the context of this function
let tmpFile = tmp.fileSync({prefix: '_config.', postfix: '.yml'})
// Write raw to file
fs.writeFileSync(tmpFile.name, this.config.options.raw)
// return the file path
return tmpFile.name
}
else {
return null
}
}
}
export default Jekyll