-
Notifications
You must be signed in to change notification settings - Fork 2
/
builder.js
70 lines (62 loc) · 2.21 KB
/
builder.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
66
67
68
69
70
'use strict';
/**
* This module is used to load the base KSS builder class needed by this builder
* and to define any custom CLI options or extend any base class methods.
*
* Note: since this builder wants to extend the KssBuilderBaseTwig class, it
* must export a KssBuilderBaseTwig sub-class as a module. Otherwise, kss-node
* will assume the builder wants to use the KssBuilderBaseHandlebars class.
*
* This file's name should follow standard node.js require() conventions. It
* should either be named index.js or have its name set in the "main" property
* of the builder's package.json. See
* http://nodejs.org/api/modules.html#modules_folders_as_modules
*
* @module kss/builder/twig
*/
const path = require('path');
// We want to extend kss-node's Twig builder so we can add options that
// are used in our templates.
let KssBuilderBaseTwig;
try {
// In order for a builder to be "kss clone"-able, it must use the
// require('kss/builder/path') syntax.
KssBuilderBaseTwig = require('kss/builder/base/twig');
} catch (e) {
// The above require() line will always work.
//
// Unless you are one of the developers of kss-node and are using a git clone
// of kss-node where this code will not be inside a "node_modules/kss" folder
// which would allow node.js to find it with require('kss/anything'), forcing
// you to write a long-winded comment and catch the error and try again using
// a relative path.
KssBuilderBaseTwig = require('../base/twig');
}
/**
* A kss-node builder that takes input files and builds a style guide using Twig
* templates.
*/
class KssBuilderTwig extends KssBuilderBaseTwig {
/**
* Create a builder object.
*/
constructor() {
// First call the constructor of KssBuilderBaseTwig.
super();
// Then tell kss which Yargs-like options this builder adds.
this.addOptionDefinitions({
title: {
group: 'Style guide:',
string: true,
multiple: false,
describe: 'Title of the style guide',
default: 'KSS Style Guide'
}
});
}
prepareExtend(templateEngine) {
this.options.extend.push(path.resolve(__dirname, 'extend'));
return super.prepareExtend(templateEngine);
}
}
module.exports = KssBuilderTwig;