-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
239 lines (191 loc) · 7.78 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
226
227
228
229
230
231
232
233
234
235
236
237
/// <binding AfterBuild='copy-all' Clean='clean' />
/// <vs SolutionOpened='sync, copy-folders' />
/*
npm install --save-dev gulp gulp-chmod
npm install --save-dev gulp gulp-changed
npm install --save-dev gulp del
npm install --save-dev gulp gulp-sourcemaps
npm install --save-dev gulp gulp-concat
npm install --save-dev gulp gulp-uglify
npm install --save-dev gulp gulp-order
npm install --save-dev gulp-inject
npm install --save-dev gulp-zip
*/
var gulp = require("gulp");
//chmod changes the file permisions so we can overwrite without errors from gulp
var chmod = require('gulp-chmod');
var changed = require('gulp-changed');
var del = require('del');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var order = require('gulp-order');
var inject = require('gulp-inject');
var zip = require('gulp-zip');
//var browserSync = require('browser-sync').create();
var clientPath = "../../../../../../[branch]/imis.net/Packages/Platform/Asi.WebAppRoot[subfolder]";
//var clientPath = "../../../../../../../SpecialBranches/ScrumV3/[branch]/imis.net/Packages/Platform/Asi.WebAppRoot[subfolder]";
var sources = ["app/**/*.*", "Content/**/*.*", "views/**/*.*", "Examples/**/*.*"];
var app = "app",
content = "Content",
scripts = "Scripts",
views = "views";
//Watch for changed files and folders and make sure they are copied to our destination
//at the moment we just copy everything, even files that have not changed
gulp.task("sync", function () {
gulp.watch(sources, ["copy-all"])
.on("error", swallowError)
.on("change", function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
})
.on("delete", function (event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});
//Copy all files/folders on startup
gulp.task("copy-all", ["copy-sources", "copy-samples"], function () {
});
gulp.task("copy-bundles", ["bundle-angular-asiCore", "copy-bundles"], function () {
});
gulp.task("copy-sources", function () {
var clientPath100 = buildClientPath("Main100", "/Areas/ng/");
var clientPath10 = buildClientPath("Main10", "/Areas/ng/");
copyFiles(sources, clientPath100, ".");
copyFiles(sources, clientPath10, ".");
});
//copy the samples, but do not keep the example folder in the destination
gulp.task("copy-samples", function () {
var clientPath100 = buildClientPath("Main100", "/Areas");
var clientPath10 = buildClientPath("Main10", "/Areas");
copyFiles("examples/**/*.*", clientPath100, "examples");
copyFiles("examples/**/*.*", clientPath10, "examples");
});
//copy the bundles
gulp.task("copy-bundles", function () {
var clientPath100 = buildClientPath("Main100","/AsiCommon/Scripts/AngularBundles");
var clientPath10 = buildClientPath("Main10", "/AsiCommon/Scripts/AngularBundles");
copyFiles("Scripts/bundle/*.*", clientPath100, "Scripts/bundle");
copyFiles("Scripts/bundle/*.*", clientPath10, "Scripts/bundle");
});
function copyFiles(sourcesFiles, destination, basePath) {
return gulp.src(sourcesFiles, { base: basePath })
.pipe(changed(destination))
.pipe(chmod(755))
.pipe(gulp.dest(destination));
}
//Build our destination path, injecting the right branch and subfolder
function buildClientPath(branch, subfolder) {
return clientPath.replace("[branch]", branch).replace("[subfolder]", subfolder);
}
//Clean out destination folders
gulp.task("clean", function () {
var clientPath100 = buildClientPath("Main100", "/ng/");
var clientPath10 = buildClientPath("Main10", "/ng/");
del(clientPath100, { force: true });
del(clientPath10, { force: true });
});
//Clean out folders and copy
gulp.task("clean-copy", ["clean","copy-all"], function () {
});
function swallowError(error) {
console.log(error);
}
var angularFiles = ["Scripts/angular.js", "Scripts/angular-sanitize.js", "Scripts/angular-ui-router.js", "Scripts/angular-ui/ui-bootstrap-tpls.min.js"];
var angularSpinFiles =["Scripts/spin/spin.min.js", "Scripts/spin/angular-spinner.min.js", "Scripts/spin/angular-loading-spinner.js"];
gulp.task("bundle-angular", function() {
return gulp.src(angularFiles, { base: "." })
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(concat('angular-bundle.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('maps'))
.pipe(chmod(755))
.pipe(gulp.dest("Scripts/bundle"));
});
gulp.task("bundle-angular-spin", function() {
return gulp.src(angularSpinFiles, { base: "./Scripts/spin" })
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(concat('angular-spin-bundle.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('maps'))
.pipe(chmod(755))
.pipe(gulp.dest("Scripts/bundle"))
.on("error", swallowError);
});
//bundles our 3rd party stuff
gulp.task("bundle", ["bundle-angular", "bundle-angular-spin", "bundle-angular-asiCore"], function () {
});
//Build our client side API and spit it out to the right folders.
//We build it slightly differently for our release machines
/*
/*Angular Core API bundling TODO - make this generic so it will work with all our folders/modules and with either branch
* At the moment we do not have gulp in our CI build so i'm going to checkin the output into TFS in v10 and v100
*/
var coreFiles = ["app/core/*.js", "!app/core/*spec.js"];
gulp.task("bundle-angular-asiCore", function () {
return gulp.src(coreFiles, { base: "." })
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(order([
"**/*angularGlobals.js",
"**/app.module.js",
"**/*module.js",
"**/*controller.js",
"**/*.js"
]))
.pipe(concat('angular-asi-core-bundle.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('maps'))
.pipe(chmod(755))
.pipe(gulp.dest("Scripts/bundle"));
});
/*
Inject the source files into each index.html file, in the correct order
At the moment this only works for one iPArt at a time, we need to change the paths for each iPart
*/
gulp.task('inject', function () {
//var iPartPath = "./app/fundraising/donationentry/";
var iPartPath = "./examples/innov/helloworld/"; //INNOVATIONS
//var iPartPath = "./examples/innov/GetAndSave/"; //INNOVATIONS
//var iPartPath = "./examples/innov/Party/AddressEdit/"; //INNOVATIONS
var prefix = "~/Areas";
//var prefix = "http://[yourDevMachineName]/innov";
var codePaths =
[
iPartPath + "/**/*.js",
"!./**/*.spec.js"
];
var target = gulp.src(iPartPath + 'index.html');
// It's not necessary to read the files (will speed up things), we're only after their paths:
var sources = gulp.src(codePaths, { read: false }).pipe(
order([
"**/*angularGlobals.js",
"**/app.module.js",
"**/*module.js",
"**/*.service.js",
"!**/*ontroller.js",
"**/*ontroller.js"
]));
return target.pipe(inject(sources, {
//Options:
addPrefix: prefix,
addRootSlash: false,
transform: transformHtmlJs
}))
.pipe(gulp.dest(iPartPath));
});
function transformHtmlJs(filepath) {
filepath = filepath.replace("examples/", "");
return '<script src="' + filepath + '" defer></script>';
};
/*
Create our iPart zip file ready for upload
*/
gulp.task('zip', function () {
var zipPath = "./examples/innov";
var company = "innov";
return gulp.src([zipPath + "/**", "!./**/*.zip"])
.pipe(zip(company + ".zip"))
.pipe(gulp.dest(zipPath));
});
/*
TODO create a task that will Bundle all our iPart code, putting our files in the correct order and including maps and create us a zip file
*/