This repository has been archived by the owner on Oct 17, 2020. It is now read-only.
forked from uscensusbureau/citysdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
183 lines (159 loc) · 6.36 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
var del = require('del');
var gulp = require('gulp');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var rollup = require('rollup');
var replace = require('gulp-replace');
var rollupJson = require('rollup-plugin-json');
var rollupBabel = require('rollup-plugin-babel');
/************************************************************************
* Common tasks *
/************************************************************************/
// ----------------------------------------------------------------------
// Task: Clean: All
//
// Fresh start, delete dist folder.
// ----------------------------------------------------------------------
gulp.task('clean', function() {
del.sync(['dist']);
});
// ----------------------------------------------------------------------
// Task: Copy: Resources
//
// Copy all static json files to their corresponding directories inside
// dist directory.
// ----------------------------------------------------------------------
gulp.task('copy:resources', function() {
return gulp.src('src/resources/*.json')
.pipe(gulp.dest('dist/resources'));
});
gulp.task('copy:citysdk', ['build:sdk'], function() {
return gulp.src('dist/sdk/core/citysdk.js')
.pipe(gulp.dest('.'));
});
// ----------------------------------------------------------------------
// Task: Watch
//
// Watches the typescript and json files in src/api and excutes the build
// task if a change is detected.
// ----------------------------------------------------------------------
gulp.task('watch', ['build:services', 'build:sdk'], function() {
gulp.watch('./src/sdk/core/*.js', ['compile:core']);
gulp.watch('./src/resources/*.json', ['copy:resources']);
});
// ----------------------------------------------------------------------
// Task: Default
//
// Cleans the dist directory and builds both the Node API and JS SDK
// ----------------------------------------------------------------------
gulp.task('default', ['clean', 'build:sdk', 'build:services', 'copy:citysdk']);
/***********************************************************************
* Node API tasks *
/***********************************************************************/
// ----------------------------------------------------------------------
// Task: Build: Services
//
// Cleans the dist directory and builds both the Node API and JS SDK
// ----------------------------------------------------------------------
gulp.task('build:services', function() {
return gulp.src('src/api/services/*.js')
.pipe(babel({presets: ['es2015']}))
.pipe(gulp.dest('dist/api/services'));
});
/***********************************************************************
* JS SDK tasks *
/***********************************************************************/
var corePath = 'src/sdk/core/';
var distCorePath = 'dist/sdk/core/';
var rollupOpts = {
plugins: [
rollupJson(),
rollupBabel({exclude: 'node_modules/**'})
]
};
var rollupWriteOpts = {
format: 'umd',
globals: {
'jquery': '$',
'promise': 'Promise',
'terraformer': 'Terraformer',
'terraformer-arcgis-parser': 'Terraformer.ArcGIS'
},
sourceMap: true
};
var rollItUp = function(filename, moduleName) {
rollupOpts.entry = corePath + filename;
return rollup.rollup(rollupOpts).then(function(bundle) {
rollupWriteOpts.moduleName = moduleName;
rollupWriteOpts.dest = distCorePath + filename;
bundle.write(rollupWriteOpts);
});
};
// ----------------------------------------------------------------------
// Task: Compile: CitySdk
//
// Uses the rollup to compile the ES6 census module into browser
// compatible javascript
// ----------------------------------------------------------------------
gulp.task('compile:CitySdk', function() {
return rollItUp('citysdk.js', 'CitySdk');
});
// ----------------------------------------------------------------------
// Task: Compile: CensusGeoRequest
//
// Uses the rollup to compile the ES6 census module into browser
// compatible javascript
// ----------------------------------------------------------------------
gulp.task('compile:CitySdkGeoRequest', function() {
return rollItUp('citysdk-geo-request.js', 'CitySdkGeoRequest');
});
// ----------------------------------------------------------------------
// Task: Compile: CensusTigerwebRequest
//
// Uses the rollup to compile the ES6 census module into browser
// compatible javascript
// ----------------------------------------------------------------------
gulp.task('compile:CitySdkTigerwebRequest', function() {
return rollItUp('citysdk-tigerweb-request.js', 'CitySdkTigerwebRequest');
});
// ----------------------------------------------------------------------
// Task: Compile: CensusRequestValidator
//
// Uses the rollup to compile the ES6 census module into browser
// compatible javascript
// ----------------------------------------------------------------------
gulp.task('compile:CitySdkRequestValidator', function() {
return rollItUp('citysdk-request-validator.js', 'CitySdkRequestValidator');
});
// ----------------------------------------------------------------------
// Task: Compile: CensusRequestUtils
//
// Uses the rollup to compile the ES6 census module into browser
// compatible javascript
// ----------------------------------------------------------------------
gulp.task('compile:CitySdkRequestUtils', function() {
return rollItUp('citysdk-request-utils.js', 'CitySdkRequestUtils');
});
// ----------------------------------------------------------------------
// Task: Compile: CensusSummaryRequest
//
// Uses the rollup to compile the ES6 census module into browser
// compatible javascript
// ----------------------------------------------------------------------
gulp.task('compile:CitySdkSummaryRequest', function() {
return rollItUp('citysdk-summary-request.js', 'CitySdkSummaryRequest');
});
// ----------------------------------------------------------------------
// Task: Build: SDK
//
// Compiles all core modules using rollup.
// ----------------------------------------------------------------------
gulp.task('build:sdk', [
'compile:CitySdk',
'compile:CitySdkGeoRequest',
'compile:CitySdkTigerwebRequest',
'compile:CitySdkRequestValidator',
'compile:CitySdkRequestUtils',
'compile:CitySdkSummaryRequest',
'copy:resources'
]);