-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
180 lines (152 loc) · 6.85 KB
/
index.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* @fileoverview Exports module:GsDhtml.
* @copyright Robert Gaines 2020
* @license Apache-2.0
* @author Robert Gaines <rob@communitywebservice.com>
*/
"use strict";
/**
* Gulp Swallower plugin providing utility tasks for plugins that build DHTML based websites.
* DHTML = HTML + CSS + JavaScript
* Use gs-www as a generic output wrapper for this plugin.
* Lints (ESLint), bundles (Webpack), minifies (Uglify), maps, and documents JS.
* Can be extended with Mustache, SASS, SCSS, PHP and other Swallower plugins.
* @module {Function} GsDhtml
* @requires module:GulpSwallower
* @implements {module:GulpSwallower.SwallowerPlugin}
* @param {GulpSwallower} gulpSwallower Gulp Swallower.
* @param {object} [templateOptions] Default Swallower task template options.
* @future More fully integrate Webpack
* @future Beautify all modules
* @future Rethink how dest directories are handled.
* @future Rethink how lib is handled, since it is being processed twice in some cases.
* @future Automatically test output against browserlist.
* @future Consider stylelint
* @future Consider tinyify
* @future Consider eslint-plugin-compat
* @future Consider postcss-import
* @future Consider postcss-preset-env
* @future Consider cssnano
* @future Consider gulp-clean-css
* @future Consider postcss-sass
* @future Consider gulp-concat-css
* @future Consider input/output formats (index|main|bundle) -> (index|main|bundle)
* @future implement since, version, and require jsDoc tags.
* @future Document private methods and properties.
* @future Lint and add jsDoc to child modules.
* @future Consistent variable and file names. i.e. globSet instead of globs.
* @future .gitignore is not always working.
* @future dotFolders excluded by .gitignore are being copied.
* @future Consider stream-combiner;
* @future Consider gulp-wrap
* @future Consider gulp-declare
* @future Consider gulp-filter
* @future Consider gulp-autoprefixer
* @future Change var names to the following pattern: fileType + "Files" | Directories + Src | Dest
* @future Consider splitting gitignore, linting, jsDoc, and Source Map functionality into core modules.
* @future Convert ES5 classes to ES6 classes.
*/
module.exports = function GsDhtml(gulpSwallower, templateOptions) {
var _this = {}; // Private scope.
_this.gulpSwallower = gulpSwallower;
_this.templateOptions = typeof templateOptions !== "undefined" ? templateOptions : {};
_this.namedGlobs = [];
/**
* Run the plugin. Usually called internally by Gulp Swallower.
* @method run
*/
this.run = function run() {
_this.loadSettings();
_this.loadGlobSets();
_this.addBeeperToGulp();
_this.addGitignoreToGulp();
_this.addJsDocToGulp();
_this.addLintJsToGulp();
_this.addGenericFileCleanersToGulp();
_this.addGenericFileCopiersToGulp();
_this.addBundleToGulp();
_this.addBuildToGulp();
_this.addDefaultToGulp();
};
/**
* Get plugin ID.
* @method getId
* @returns {string} plugin ID.
*/
this.getId = function () {
return "gs-dhtml";
};
/**
* Get plugin requirements.
* @method getRequirements
* @returns {string} plugin ID.
*/
this.getRequirements = function () {
return [];
};
_this.loadSettings = function loadSettings() {
var defaultTemplateOptions = require("./defaultSettings.js");
_this.templateOptions = Object.assign(defaultTemplateOptions, templateOptions);
_this.templateOptions.defaultGlobOptions.base = _this.templateOptions.wwwBase;
}.bind(this);
_this.loadGlobSets = function loadGlobSets() {
_this.namedGlobs = require("./namedGlobs.js");
_this.gulpSwallower.registerNamedGlobSets(_this.namedGlobs);
}.bind(this);
// @future Reduce boilerplate, but consider the dangers of loading files from arbitrary strings.
_this.addBeeperToGulp = function addBeeperToGulp() {
var taskTemplate = require("./taskTemplates/beep.js");
var taskDefinitions = require("./taskDefinitions/beep.js");
var taskDefinitionOptions = _this.templateOptions;
_this.gulpSwallower.defineTasks(taskTemplate, taskDefinitions, taskDefinitionOptions);
}.bind(this);
_this.addGitignoreToGulp = function addGitignoreToGulp() {
var taskTemplate = require("./taskTemplates/gitignore.js");
var taskDefinitions = require("./taskDefinitions/gitignore.js");
var taskDefinitionOptions = _this.templateOptions;
_this.gulpSwallower.defineTasks(taskTemplate, taskDefinitions, taskDefinitionOptions);
}.bind(this);
_this.addJsDocToGulp = function addJsDocToGulp() {
var taskTemplate = require("./taskTemplates/jsDoc.js");
var taskDefinitions = require("./taskDefinitions/jsDoc.js");
var taskDefinitionOptions = _this.templateOptions;
_this.gulpSwallower.defineTasks(taskTemplate, taskDefinitions, taskDefinitionOptions);
}.bind(this);
_this.addLintJsToGulp = function addLintJsToGulp() {
var taskTemplate = require("./taskTemplates/lintJs.js");
var taskDefinitions = require("./taskDefinitions/lintJs.js");
var taskDefinitionOptions = _this.templateOptions;
_this.gulpSwallower.defineTasks(taskTemplate, taskDefinitions, taskDefinitionOptions);
}.bind(this);
_this.addGenericFileCleanersToGulp = function addGenericFileCleanersToGulp() {
var taskTemplate = require("./taskTemplates/genericFileCleaner.js");
var taskDefinitions = require("./taskDefinitions/genericFileCleaner.js");
var taskDefinitionOptions = _this.templateOptions;
_this.gulpSwallower.defineTasks(taskTemplate, taskDefinitions, taskDefinitionOptions);
}.bind(this);
_this.addGenericFileCopiersToGulp = function addGenericFileCopiersToGulp() {
var taskTemplate = require("./taskTemplates/genericFileCopier.js");
var taskDefinitions = require("./taskDefinitions/genericFileCopier.js");
var taskDefinitionOptions = _this.templateOptions;
_this.gulpSwallower.defineTasks(taskTemplate, taskDefinitions, taskDefinitionOptions);
}.bind(this);
_this.addBundleToGulp = function addBundleToGulp() {
var taskTemplate = require("./taskTemplates/bundleJs.js");
var taskDefinitions = require("./taskDefinitions/bundleJs.js");
var taskDefinitionOptions = _this.templateOptions;
_this.gulpSwallower.defineTasks(taskTemplate, taskDefinitions, taskDefinitionOptions);
}.bind(this);
_this.addBuildToGulp = function addBuildToGulp() {
_this.gulpSwallower.extendTaskSet("buildParallel", "parallel", "lintJs");
_this.gulpSwallower.extendTaskSet("buildParallel", "parallel", "bundleJs");
_this.gulpSwallower.extendTaskSet("buildParallel", "parallel", "jsDoc");
_this.gulpSwallower.extendTaskSet("build", "series", "clean");
_this.gulpSwallower.extendTaskSet("build", "series", "gitignore");
_this.gulpSwallower.extendTaskSet("build", "series", "copyStaticAssets");
_this.gulpSwallower.extendTaskSet("build", "series", "buildParallel");
_this.gulpSwallower.extendTaskSet("build", "series", "beep");
}.bind(this);
_this.addDefaultToGulp = function addDefaultToGulp() {
_this.gulpSwallower.extendTaskSet("default", "series", "build");
}.bind(this);
};