Skip to content

Instantly share code, notes, and snippets.

@cwparsons
Last active February 16, 2016 22:37
Show Gist options
  • Select an option

  • Save cwparsons/17407bdd06cb32b40d11 to your computer and use it in GitHub Desktop.

Select an option

Save cwparsons/17407bdd06cb32b40d11 to your computer and use it in GitHub Desktop.
A simple gulpfile for legacy SharePoint projects that use MSBuild targets.
/*!
* Front end build and development scripts for Client.Internet.WebSite
*/
// Dependencies
var exec = require('gulp-exec'),
gulp = require('gulp'),
gutil = require('gulp-util'),
livereload = require('gulp-livereload'),
watch = require('gulp-watch');
// Default configuration
var config = {
package: 'pkg/Debug/',
project: 'Client.Internet.WebSite/',
repository: '../',
deployment: 'C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/15/TEMPLATE/LAYOUTS/',
target: '/t:CompileCSS'
};
var files = {
csproj: '*.csproj',
css: '**/*.css',
less: '**/*.less',
lessImports: '**/_*.less',
msbuild: 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe'
};
//
// `package-styles` copiies our LESS styles into the pkg/Debug folder. This is much faster
// than running the MSBulid target `Package`.
//
gulp.task('package-styles', function () {
return gulp.src([
config.repository + config.project + 'Layouts/' + files.less
])
.pipe(gulp.dest(config.repository + config.package + config.project + '/Layouts'));
});
//
// `build-styles` runs the MSBuild target `CompileCSS`. This is necessary so we can continue to
// use the same dotless version that is across the multiple projects and sites.
//
gulp.task('build-styles', ['package-styles'], function () {
return gulp.src([config.repository + config.project + files.csproj])
.pipe(exec(files.msbuild + ' "<%= file.path %>" ' + config.target).on('error', gutil.log))
.pipe(exec.reporter());
});
//
// `copy-styles` copies the compiled CSS to the SharePoint deployment folder.
//
gulp.task('copy-styles', ['build-styles'], function () {
return gulp.src([config.repository + config.package + config.project + 'Layouts/' + files.css])
.pipe(gulp.dest(config.deployment))
.pipe(livereload());
});
//
// `watch` looks at all LESS files across each project.
//
gulp.task('watch', function () {
livereload.listen({
port: 35729
});
gulp.watch([
config.repository + config.project + files.less,
'!**/node_modules/' + files.less,
'!**/pkg/' + files.less
], ['copy-styles']);
});
//
// Set the default task to watch
//
gulp.task('default', ['copy-styles', 'watch']);
{
"name": "Client.Internet.Website.DevelopmentTools",
"version": "1.0.0",
"description": "Front end build and development scripts for Client.Internet.WebSite",
"scripts": {
"copy": "gulp copy-styles",
"watch": "gulp watch"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^3.9.1",
"gulp-util": "^3.0.7",
"gulp-livereload": "^3.8.1",
"gulp-watch": "^4.3.5",
"gulp-shell": "^0.5.2",
"gulp-exec": "^2.1.2",
"habanero-code-style": "^0.4.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment