-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathgeneratorTasks.js
190 lines (144 loc) · 5.85 KB
/
generatorTasks.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
181
182
183
184
185
186
187
188
189
190
var curVersion = 'v55';
var request = require('request');
module.exports = function(grunt) {
var firebaseUrl = 'webhook';
var firebaseUri = null;
if(firebaseUrl) {
firebaseUri = 'https://' + firebaseUrl + '.firebaseio.com/generator_version.json';
}
var checkVersion = function(callback) {
if(firebaseUri === null) {
callback();
} else {
request({ url: firebaseUri, json: true }, function(e, r, body) {
if(body) {
if(body !== curVersion) {
console.log('========================================================'.red);
console.log('# This site is using old Webhook code. #'.red);
console.log('========================================================'.red);
console.log('#'.red + ' To update, run "wh update" in this folder.')
console.log('# ---------------------------------------------------- #'.red)
}
callback();
} else {
callback();
}
});
}
};
var npmBin = grunt.option('npmbin');
var nodeBin = grunt.option('nodebin');
var gruntBin = grunt.option('gruntbin');
var token = grunt.option('token');
var email = grunt.option('email');
var npmCache = grunt.option('npmcache');
var generator = require('../libs/generator').generator(grunt.config, { npm: npmBin, node: nodeBin, grunt: gruntBin, token: token, email: email, npmCache: npmCache }, grunt.log, grunt.file, root);
grunt.registerTask('buildTemplates', 'Generate static files from templates directory', function() {
var done = this.async();
var production = grunt.option('production');
if(production === true) {
generator.enableProduction();
}
generator.renderTemplates(done, generator.reloadFiles);
});
grunt.registerTask('buildPages', 'Generate static files from pages directory', function() {
var done = this.async();
var production = grunt.option('production');
if(production === true) {
generator.enableProduction();
}
generator.renderPages(done, generator.reloadFiles);
});
grunt.registerTask('scaffolding', 'Generate scaffolding for a new object', function(name) {
var done = this.async();
var force = grunt.option('force');
var result = generator.makeScaffolding(name, done, force);
});
grunt.registerTask('watch', 'Watch for changes in templates and regenerate site', function() {
generator.startLiveReload();
grunt.task.run('simple-watch');
});
grunt.registerTask('webListener', 'Listens for commands from CMS through websocket', function() {
var done = this.async();
generator.webListener(done);
});
grunt.registerTask('webListener-open', 'Listens for commands from CMS through websocket', function() {
var done = this.async();
generator.webListener(done);
grunt.util.spawn({
grunt: true,
args: ['open:wh-open'].concat(grunt.option.flags()),
opts: { stdio: 'inherit' }
}, function (err, result, code) {
if (err || code > 0) {
grunt.log.warn('A problem occured while trying to open a browser window to connect to the site.')
grunt.log.warn(result.stderr || result.stdout);
grunt.log.warn('In order to access the site, please navigate to \'localhost:2002\' in your web browser.')
}
grunt.log.writeln('\n' + result.stdout);
});
});
grunt.registerTask('clean', 'Clean build files', function() {
var done = this.async();
generator.cleanFiles(done);
});
grunt.registerTask('build-static', 'Just builds the static files, meant to be used with watch tasks.', function() {
var done = this.async();
var strict = grunt.option('strict');
if(strict === true) {
generator.enableStrictMode();
}
var production = grunt.option('production');
if(production === true) {
generator.enableProduction();
}
checkVersion(function() {
generator.buildStatic(done);
})
});
// Build Task.
grunt.registerTask('build', 'Clean files and then generate static site into build', function() {
var done = this.async();
var strict = grunt.option('strict');
if(strict === true) {
generator.enableStrictMode();
}
var production = grunt.option('production');
if(production === true) {
generator.enableProduction();
}
checkVersion(function() {
generator.buildBoth(done);
})
});
// Change this to optionally prompt instead of requiring a sitename
grunt.registerTask('assets', 'Initialize the firebase configuration file (installer should do this as well)', function() {
var done = this.async();
generator.assets(grunt, done);
});
grunt.registerTask('assetsMiddle', 'Initialize the firebase configuration file (installer should do this as well)', function() {
generator.assetsMiddle(grunt);
});
grunt.registerTask('assetsAfter', 'Initialize the firebase configuration file (installer should do this as well)', function() {
var done = this.async();
generator.assetsAfter(grunt, done);
});
// Change this to optionally prompt instead of requiring a sitename
grunt.registerTask('init', 'Initialize the firebase configuration file (installer should do this as well)', function() {
var done = this.async();
var sitename = grunt.option('sitename');
var secretkey = grunt.option('secretkey');
var server = grunt.option('server');
var copyCms = grunt.option('copycms');
var firebase = grunt.option('firebase');
generator.init(sitename, secretkey, copyCms, firebase, server, done);
});
// Check if initialized properly before running all these tasks
grunt.registerTask('default', 'Clean, Build, Start Local Server, and Watch', function() {
grunt.task.run('configureProxies:wh-server')
grunt.task.run('connect:wh-server');
grunt.task.run('build');
grunt.task.run('concurrent:wh-concurrent');
});
};
module.exports.version = curVersion;