This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
gulpfile.js
185 lines (168 loc) · 5.43 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
var gulp = require('gulp');
var ts = require('gulp-typescript');
var tslint = require('gulp-tslint');
var del = require('del');
var server = require('gulp-develop-server');
var mocha = require('gulp-spawn-mocha');
var sourcemaps = require('gulp-sourcemaps');
var zip = require('gulp-zip');
var rename = require('gulp-rename');
var jsonTransform = require('gulp-json-transform');
var path = require('path');
var minimist = require('minimist');
var fs = require('fs');
var _ = require('lodash');
var knownOptions = {
string: 'packageName',
string: 'packagePath',
default: {packageName: 'Package.zip', packagePath: path.join(__dirname, '_package')}
};
var options = minimist(process.argv.slice(2), knownOptions);
var tsProject = ts.createProject('./tsconfig.json', {
// Point to the specific typescript package we pull in, not a machine-installed one
typescript: require('typescript'),
});
var filesToWatch = ['**/*.ts', '!node_modules/**'];
var filesToLint = ['**/*.ts', '!src/typings/**', '!node_modules/**', '!src_old/typings/**'];
var staticFiles = ['src/**/*.json', 'src/**/*.hbs'];
/**
* Clean build output.
*/
gulp.task('clean', function () {
return del([
'build/**/*',
// Azure doesn't like it when we delete build/src
'!build/src'
]);
});
/**
* Generate constants from string tables.
*/
gulp.task('locale:generate', function() {
return gulp.src('./src/locale/en/index.json')
.pipe(jsonTransform(function(data, file) {
let result =
'/* ------------------------------------------------------------------- */\n' +
'/* DO NOT MODIFY, THIS FILE IS GENERATED from src\\locale\\en\\index.json.*/\n' +
'/* in gulpfile.js under task \'locale:generate\' */\n' +
'/* ------------------------------------------------------------------- */\n' +
'\n' +
'// tslint:disable-next-line:variable-name\n' +
'export const Strings = {\n';
for (var p in data) {
if( data.hasOwnProperty(p) ) {
result += ' ' + p + ': "'+ p + '",\n';
}
}
result += '};\n';
return result;
}))
.pipe(rename('locale.ts'))
.pipe(gulp.dest('./src/locale'));
});
/**
* Lint all TypeScript files.
*/
gulp.task('ts:lint', ['locale:generate'], function () {
if (!process.env.GLITCH_NO_LINT) {
return gulp
.src(filesToLint)
.pipe(tslint({
formatter: 'verbose'
}))
.pipe(tslint.report({
summarizeFailureOutput: true
}));
}
});
/**
* Compile TypeScript and include references to library.
*/
gulp.task('ts', ['clean', 'locale:generate'], function() {
return tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.once('error', function () {
this.once('finish', () => process.exit(1));
})
.pipe(sourcemaps.write('.', { sourceRoot: function(file) { return file.cwd + '/build'; }}))
.pipe(gulp.dest('build'));
});
/**
* Copy statics to build directory.
*/
gulp.task('statics:copy', ['clean'], function () {
return gulp.src(staticFiles, { base: '.' })
.pipe(gulp.dest('./build'));
});
/**
* Copy .ts dialog files to build directory as .txt files for browser viewing
*/
gulp.task('exampleDialogs:copy', ['clean'], function() {
return gulp.src(['./src/dialogs/examples/auth/*.ts',
'./src/dialogs/examples/basic/*.ts',
'./src/dialogs/examples/moderate/*.ts',
'./src/dialogs/examples/teams/*.ts'])
.pipe(rename(function (path) {
path.extname = ".txt";
}))
.pipe(gulp.dest("./build/src/public/exampleDialogs"));
});
/**
* Build application.
*/
gulp.task('build', ['clean', 'ts:lint', 'ts', 'statics:copy', 'exampleDialogs:copy']);
/**
* Run tests.
*/
gulp.task('test', ['ts', 'statics:copy'], function() {
return gulp
.src('build/test/*.js', {read: false})
.pipe(mocha({cwd: 'build/src'}))
.once('error', function () {
process.exit(1);
})
.once('end', function () {
process.exit();
});
});
/**
* Package up app into a ZIP file for Azure deployment.
*/
gulp.task('package', ['build'], function () {
var packagePaths = [
'build/**/*',
'public/**/*',
'web.config',
'package.json',
'**/node_modules',
'!build/src/**/*.js.map',
'!build/test/**/*',
'!build/test',
'!build/src/typings/**/*'];
//add exclusion patterns for all dev dependencies
var packageJSON = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
var devDeps = packageJSON.devDependencies;
for (var propName in devDeps)
{
var excludePattern1 = '!**/node_modules/' + propName + '/**';
var excludePattern2 = '!**/node_modules/' + propName;
packagePaths.push(excludePattern1);
packagePaths.push(excludePattern2);
}
return gulp.src(packagePaths, { base: '.' })
.pipe(zip(options.packageName))
.pipe(gulp.dest(options.packagePath));
});
gulp.task('server:start', ['build'], function() {
server.listen({path: 'build/src/app.js'}, function(error) {
console.log(error);
});
});
gulp.task('server:restart', ['build'], function() {
server.restart();
});
gulp.task('default', ['server:start'], function() {
gulp.watch(filesToWatch, ['server:restart']);
});