forked from jarrodek/ChromeRestClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
225 lines (202 loc) · 6.02 KB
/
gulpfile.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
'use strict';
var gulp = require('gulp');
var minimist = require('minimist');
var conventionalChangelog = require('gulp-conventional-changelog');
var fs = require('fs');
require('./tasks/dev-server.js');
var Cli = {
getParams: (defaults) => {
return minimist(process.argv.slice(2), defaults);
},
get buildOptions() {
return {
string: 'target',
default: {
target: process.env.NODE_ENV
}
};
},
get publishTarget() {
return {
string: 'target',
default: {
target: process.env.NODE_ENV
}
};
},
get publishAudience() {
return {
string: 'audience',
default: {
target: process.env.NODE_ENV
}
};
}
};
// Lint JavaScript files
gulp.task('lint', function() {
var lint = require('./tasks/lint.js');
return lint();
});
// tasks to be prformed when bower is updated.
gulp.task('bower-update', (done) => {
var bu = require('./tasks/bower-update.js');
bu.postInstall()
.then(() => {
console.log('Project builded after bower update.');
done();
})
.catch((e) => {
console.log('unable to build project after bower update.');
done(e);
});
});
// Load tasks for web-component-tester
// Adds tasks for `gulp test`
require('web-component-tester').gulp.init(gulp);
// Load custom tasks from the `tasks` directory
try {
require('require-dir')('tasks');
} catch (err) {}
var buildHelpMessage = `Usage:
gulp build --target <TARGET> [--hotfix] [--build-only] [--publish]
Targets:
canary Build a canary (daily) release
dev Build a dev (feature) release
beta Build a beta (RC) release
stable Build a stable release
Options:
--hotfix Treat the release as a hotfix release. It matters only for versioning
system (during version bump) See tasks/bump-version.js for more info.
Bu default it's full release.
--build-only Don't push changes to git and don't publish the app in the store. It
overrides --publish and prevent script from publishing the app.
--publish If set the script will publish the app. You'll be asked to log in to your
Google account during the process. By detault the app is not published.
Note that the app will be uploaded to the store but not published even if
--publish is not set.
Description:
Build the app, update git repository and publish the app in the store.
Examples:
gulp build --target canary --publish
This will build canary release, push changes to the git repository and publish the app.
gulp build --target beta --hotfix --build-only
This will only build beta release as a hotfix (only minor number will increase).
`;
var build = (done) => {
var params = Cli.getParams(Cli.buildOptions);
if (params.help) {
console.log(buildHelpMessage);
done();
return;
}
var Builder = require('./tasks/builder.js');
var options = {
isHotfix: params.hotfix || false,
buildOnly: params['build-only'] || false,
publish: params.publish || false
};
if (options.buildOnly && options.publish) {
options.publish = false;
}
switch (params.target) {
case 'canary':
Builder.buildCanary(options, done);
break;
case 'dev':
Builder.buildDev(options, done);
break;
case 'beta':
if (!options.isHotfix) {
let confirm = require('confirm-simple');
confirm('Upgrade the version major version?', ['ok', 'cancel'] , (ok) => {
if (!ok) {
done();
} else {
Builder.buildBeta(options, done);
}
});
} else {
Builder.buildBeta(options, done);
}
break;
case 'stable':
Builder.buildStable(options, done);
break;
default:
let msg = `Unknown target ${params.target}.
${buildHelpMessage}
`;
console.log(msg);
done();
}
};
var publish = (done) => {
var params = Cli.getParams(Cli.publishTarget);
switch (params.target) {
case 'canary':
case 'dev':
case 'beta':
case 'stable':
let Publisher = require('./tasks/cws-uploader.js');
Publisher.publishTarget(params.target, params.audience)
.then(() => {
console.log('The item has been published.');
done();
})
.catch((err) => {
done(err);
});
break;
default:
let msg = `Unknown target ${params.target}.
Usage:
gulp publish --target <TARGET> [--audience <AUDIENCE>]
Targets:
canary Publish a canary channel app in the store.
dev Publish a dev channel app in the store.
beta Publish a beta channel app in the store.
stable Publish the app in the store.
Audience:
all The app will be publicly available
testers The app will be published for testers.
Description:
The command will publish the app for given channel. If --audience parameter is not present
the one from cws-config.json file will be used.
The app must have testers group assigned in order to publish to testers.
`;
console.log(msg);
done();
}
};
gulp.task('build', build);
gulp.task('publish', publish);
var testServer = () => {
let srv = require('./tasks/ssl.js');
srv.create();
};
gulp.task('test-server', testServer);
gulp.task('srv', testServer);
gulp.task('test', function(done) {
var analyzer = require('./tasks/tree-analyzer.js');
analyzer.analyseDependencies().then(() => done()).catch((e) => {
console.error('An error occured', Object.getOwnPropertyNames(e));
console.error(e.message);
console.error(e.stack);
done();
});
});
gulp.task('changelog', function() {
return gulp.src('CHANGELOG.md', {
buffer: false
})
.pipe(conventionalChangelog({
preset: 'eslint',
releaseCount: 0
}))
.pipe(gulp.dest('./'));
// return conventionalChangelog({
// preset: 'eslint',
// releaseCount: 0
// }).pipe(fs.createWriteStream('CHANGELOG.md'));
});