This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_generator.js
More file actions
98 lines (78 loc) · 3.07 KB
/
_generator.js
File metadata and controls
98 lines (78 loc) · 3.07 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var vendorScriptMap = {
bootstrap: 'bootstrap-3.3.7.min.js',
html5shiv: 'html5shiv-3.7.3.min.js',
respond: 'respond-1.4.2.min.js',
jquery: 'jquery-3.3.1.min.js',
modernizr: 'modernizr-3.6.0.min.js'
};
generator.applyToOutputNode = function(outputFolderNode, inputFolderNode) {
// Read config and set default values
var config = generator.config || {};
config.base = config.base || 'none';
config.polyfill = config.polyfill || 'modernizr';
config.serverExtras = !!config.serverExtras;
config.ieTags = (config.ieTags === undefined) ? true : !!config.ieTags;
config.ga = !!config.ga;
config.ga_siteId = config.ga ? config.ga_siteId || '' : undefined;
// Add common files from H5BP
var boilerplateInputNode = inputFolderNode.folderForPath('html5-boilerplate_v6.1.0');
var boilerplateOutputNode = outputFolderNode.addFolderAtPath(boilerplateInputNode, './', OverwriteOnConflict);
var excludePaths = ['css/', 'doc/', 'js/vendor/', 'index.html' ];
if (!config.serverExtras) {
excludePaths = excludePaths.concat(['.htaccess', '404.html', 'humans.txt', 'robots.txt']);
}
excludePaths.forEach(function(excludePath) {
var currentNode = null;
if (excludePath.slice(-1) === '/') {
currentNode = boilerplateInputNode.folderForPath(excludePath);
}
else {
currentNode = boilerplateInputNode.fileForPath(excludePath);
}
boilerplateOutputNode.excludeNode(currentNode);
});
// Add vendor script libraries
function addVendorScript(vendorFileName) {
if (vendorFileName) {
var vendorInputFile = inputFolderNode.fileForPath('vendor-scripts/' + vendorFileName);
outputFolderNode.addFileAtPath(vendorInputFile, 'js/vendor/' + vendorFileName, OverwriteOnConflict);
}
};
addVendorScript(vendorScriptMap.jquery);
addVendorScript(vendorScriptMap[config.polyfill]);
if (config.base === 'responsive' || config.base === 'bootstrap') {
addVendorScript(vendorScriptMap.respond);
}
if (config.base === 'bootstrap') {
addVendorScript(vendorScriptMap.bootstrap);
}
// Add template styles
var styleInputFolderNode = inputFolderNode.folderForPath('templates/' + config.base);
if (styleInputFolderNode !== null) {
for (var i = 0, styleChildNodes = styleInputFolderNode.childNodes; i < styleChildNodes.length; i++) {
var childNode = styleChildNodes[i];
var childNodePath = childNode.path.split('/').slice(2).join('/');
if (childNode.type === FolderNode) {
outputFolderNode.addFolderAtPath(childNode, childNodePath);
}
else {
outputFolderNode.addFileAtPath(childNode, childNodePath);
}
}
}
// Translate our configuration to the index page
var boilerplateIndexNode = outputFolderNode.fileForPath('index.html');
if (boilerplateIndexNode !== null) {
boilerplateIndexNode.assignVariable(config.polyfill, 'true');
if (config.ieTags) {
boilerplateIndexNode.assignVariable('ieTags', true);
}
if (config.ga) {
boilerplateIndexNode.assignVariable('googleAnalytics', true);
}
if (config.ga_siteId) {
boilerplateIndexNode.assignVariable('googleAnalyticsSiteID', config.ga_siteId);
}
}
return true;
};