gulpfile.js (184 lines of code) (raw):

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; }) ); });