Created
October 7, 2015 18:10
-
-
Save dimkk/d8d7ba2ef91a39b5cf25 to your computer and use it in GitHub Desktop.
sample gulpfile for 1st article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { //Изолируем | |
if (!_spBodyOnLoadCalled) { //Используем вместо $(document).ready() | |
_spBodyOnLoadFunctions.push(pageLoad); | |
} else { | |
pageLoad(); | |
} | |
function pageLoad() { | |
var html = '<input type="text" id="message_notify" placeholder="Введите заголовок"></input>'+ | |
'<br/><br/>'+ | |
'<input placeholder="Введите текст" type="text" id="data_notify"></input>'+ | |
'<br/><br/>'+ | |
'<select id="type_notify">'+ | |
'<option>info</option><option>error</option><option>warning</option><option>success</option>'+ | |
'</select>'+ | |
'<br/><br/>'+ | |
'<button id="show_notify" type="button">Оповестить</button>'; | |
document.getElementById('app').innerHTML = html; //Вставляем нужную разметку | |
document.getElementById('show_notify').onclick = function(){ //Вешаем обработчик | |
var message = document.getElementById('message_notify').value;//Собираем данные | |
var data = document.getElementById('data_notify').value; | |
var e = document.getElementById("type_notify"); | |
var notType = e.options[e.selectedIndex].text; | |
writeLog(message, data, true, notType); //Выводим оповещение | |
}; | |
function writeLog(message, data, showNotification, notificationType) { | |
var title; | |
if (!message) message = 'Sample title'; | |
if (!data) data = 'Sample data'; | |
showNotification = showNotification || true; | |
if (showNotification) { | |
if (notificationType === 'info') | |
{ | |
title = 'ИНФО: ' + message; | |
} | |
else if (notificationType === 'error') | |
{ | |
title = 'ОШИБКА: ' + message; | |
} | |
else if (notificationType === 'warning') | |
{ | |
title = 'ПРЕДУПРЕЖДЕНИЕ: ' + message; | |
} | |
else if (notificationType === 'success') | |
{ | |
title = 'ОК: ' + message; | |
} | |
} | |
var notificationData = new SPStatusNotificationData( "", STSHtmlEncode(data), "", null); | |
var notification = new SPNotification( SPNotifications.ContainerID.Status, STSHtmlEncode(title), false, null, null, notificationData); | |
notification.Show(false); | |
} | |
} | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'), //подключаем необходимые зависимости | |
sourcemaps = require('gulp-sourcemaps'), | |
spsave = require('gulp-spsave'), | |
concat = require('gulp-concat'), | |
config = require('./gulpfile.conf'), | |
uglify = require('gulp-uglify'), | |
del = require('del'); | |
gulp.task('src', function () { //Задача сборки исходников | |
return gulp.src(['./src/**/*.js']) //возьмём все файлы js в папке src и подпапках | |
.pipe(sourcemaps.init()) //старт записи sourcemaps | |
.pipe(concat('myapp.js')) //собираем файлы в 1 | |
.pipe(uglify()) //минифицируем | |
.pipe(sourcemaps.write()) //пишем sourcemaps | |
.pipe(gulp.dest('./dist')) //возвращаем результат в dist | |
}); | |
gulp.task('other', function () { //задача копирования остальных файлов из папки src | |
return gulp.src(['!./src/**/*.js', './src/**/*']) | |
.pipe(gulp.dest('./dist')) | |
}); | |
gulp.task('clean', function(){ //стирает содержимое папки dist | |
return del(['./dist/**/*']); | |
}); | |
gulp.task("copyToSharePoint", ["clean", "src", "other"], function () { //Задача сборки и копирования файлов в SharePoint | |
return gulp.src("./dist/**/*") | |
.pipe(spsave({ //плагин позволяющий авторизовываться и записывать файлы в SharePoint - тут представлена версия для SharePoint online | |
username: config.username, //если нужно on premise - посмотрите пример из документации к spsave - https://github.com/s-KaiNet/spsave#samples | |
password: config.password, | |
siteUrl: config.siteUrl, | |
folder: config.folder | |
})); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch('./src/**/*', ['copyToSharePoint']); //при изменении файлов в src будет запускать copyToSharePoint | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment