forked from Sitecore/Habitat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
209 lines (193 loc) · 6.58 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
var gulp = require("gulp");
var msbuild = require("gulp-msbuild");
var debug = require("gulp-debug");
var foreach = require("gulp-foreach");
var rename = require("gulp-rename");
var watch = require("gulp-watch");
var newer = require("gulp-newer");
var runSequence = require("run-sequence");
var path = require("path");
var config = require("./gulp-config.js")();
module.exports.config = config;
/*****************************
Initial setup
*****************************/
gulp.task("01-Copy-Sitecore-Lib", function () {
console.log("Copying Sitecore Libraries");
var files = config.sitecoreLibraries + "/**/*";
gulp.src(files)
.pipe(gulp.dest("./lib/Sitecore"));
});
gulp.task("02-Publish-All-Projects", function (callback) {
runSequence(
"Publish-Foundation-Projects",
"Publish-Feature-Projects",
"Publish-Project-Projects", callback);
});
gulp.task("03-Apply-Xml-Transform", function () {
return gulp.src("./src/Project/**/code/*.csproj")
.pipe(foreach(function (stream, file) {
return stream
.pipe(debug({ title: "Applying transform project:" }))
.pipe(msbuild({
targets: ["ApplyTransform"],
configuration: config.buildConfiguration,
logCommand: false,
verbosity: "normal",
maxcpucount: 0,
toolsVersion: 14.0,
properties: {
WebConfigToTransform: config.websiteRoot + "\\web.config"
}
}));
}));
});
gulp.task("04-Optional-Copy-Local-Assemblies", function () {
console.log("Copying site assemblies to all local projects");
var files = config.sitecoreLibraries + "/**/*";
var root = "./src";
var projects = root + "/**/code/bin";
gulp.src(projects, { base: root })
.pipe(foreach(function (stream, file) {
console.log("copying to " + file.path);
gulp.src(files)
.pipe(gulp.dest(file.path));
return stream;
}));
});
/*****************************
Publish
*****************************/
var publishProjects = function (location, dest) {
dest = dest || config.websiteRoot;
console.log("publish to " + dest + " folder");
return gulp.src([location + "/**/code/*.csproj"])
.pipe(foreach(function (stream, file) {
return stream
.pipe(debug({ title: "Building project:" }))
.pipe(msbuild({
targets: ["Build"],
configuration: config.buildConfiguration,
logCommand: false,
verbosity: "minimal",
maxcpucount: 0,
toolsVersion: 14.0,
properties: {
DeployOnBuild: "true",
DeployDefaultTarget: "WebPublish",
WebPublishMethod: "FileSystem",
DeleteExistingFiles: "false",
publishUrl: dest,
_FindDependencies: "false"
}
}));
}));
};
gulp.task("Publish-Foundation-Projects", function () {
return publishProjects("./src/Foundation");
});
gulp.task("Publish-Feature-Projects", function () {
return publishProjects("./src/Feature");
});
gulp.task("Publish-Project-Projects", function () {
return publishProjects("./src/Project");
});
gulp.task("Publish-Assemblies", function () {
var root = "./src";
var binFiles = root + "/**/code/**/bin/Sitecore.{Feature,Foundation,Habitat}.*.{dll,pdb}";
var destination = config.websiteRoot + "/bin/";
return gulp.src(binFiles, { base: root })
.pipe(rename({ dirname: "" }))
.pipe(newer(destination))
.pipe(debug({ title: "Copying " }))
.pipe(gulp.dest(destination));
});
gulp.task("Publish-All-Views", function () {
var root = "./src";
var roots = [root + "/**/Views", "!" + root + "/**/obj/**/Views"];
var files = "/**/*.cshtml";
var destination = config.websiteRoot + "\\Views";
return gulp.src(roots, { base: root }).pipe(
foreach(function (stream, file) {
console.log("Publishing from " + file.path);
gulp.src(file.path + files, { base: file.path })
.pipe(newer(destination))
.pipe(debug({ title: "Copying " }))
.pipe(gulp.dest(destination));
return stream;
})
);
});
gulp.task("Publish-All-Configs", function () {
var root = "./src";
var roots = [root + "/**/App_Config", "!" + root + "/**/obj/**/App_Config"];
var files = "/**/*.config";
var destination = config.websiteRoot + "\\App_Config";
return gulp.src(roots, { base: root }).pipe(
foreach(function (stream, file) {
console.log("Publishing from " + file.path);
gulp.src(file.path + files, { base: file.path })
.pipe(newer(destination))
.pipe(debug({ title: "Copying " }))
.pipe(gulp.dest(destination));
return stream;
})
);
});
/*****************************
Watchers
*****************************/
gulp.task("Auto-Publish-Css", function () {
var root = "./src";
var roots = [root + "/**/stylesheets", "!" + root + "/**/obj/**/stylesheets"];
var files = "/**/*.css";
var destination = config.websiteRoot + "\\stylesheets";
gulp.src(roots, { base: root }).pipe(
foreach(function (stream, rootFolder) {
gulp.watch(rootFolder.path + files, function (event) {
if (event.type === "changed") {
console.log("publish this file " + event.path);
gulp.src(event.path, { base: rootFolder.path }).pipe(gulp.dest(destination));
}
console.log("published " + event.path);
});
return stream;
})
);
});
gulp.task("Auto-Publish-Views", function () {
var root = "./src";
var roots = [root + "/**/Views", "!" + root + "/**/obj/**/Views"];
var files = "/**/*.cshtml";
var destination = config.websiteRoot + "\\Views";
gulp.src(roots, { base: root }).pipe(
foreach(function (stream, rootFolder) {
gulp.watch(rootFolder.path + files, function (event) {
if (event.type === "changed") {
console.log("publish this file " + event.path);
gulp.src(event.path, { base: rootFolder.path }).pipe(gulp.dest(destination));
}
console.log("published " + event.path);
});
return stream;
})
);
});
gulp.task("Auto-Publish-Assemblies", function () {
var root = "./src";
var roots = [root + "/**/code/**/bin"];
var files = "/**/Sitecore.{Feature,Foundation,Habitat}.*.{dll,pdb}";;
var destination = config.websiteRoot + "/bin/";
gulp.src(roots, { base: root }).pipe(
foreach(function (stream, rootFolder) {
gulp.watch(rootFolder.path + files, function (event) {
if (event.type === "changed") {
console.log("publish this file " + event.path);
gulp.src(event.path, { base: rootFolder.path }).pipe(gulp.dest(destination));
}
console.log("published " + event.path);
});
return stream;
})
);
});