Epic-231:versioning, and backup the configuration
[sdnc/oam.git] / configbackuprestore / vnfconfigbackupservice / src / main / webapp / node_modules / angular-object-diff / gulpfile.js
1 (function () {
2     'use strict';
3
4     var gulp = require('gulp');
5     var less = require('gulp-less');
6     var sourcemaps = require('gulp-sourcemaps');
7     var uglify = require('gulp-uglify');
8     var csso = require('gulp-csso');
9     var jshint = require('gulp-jshint');
10     var stylish = require('jshint-stylish');
11     var jscs = require('gulp-jscs');
12     var mocha = require('gulp-spawn-mocha');
13     var mochaPhantomJS = require('gulp-mocha-phantomjs');
14     var tar = require('gulp-tar');
15     var gzip = require('gulp-gzip');
16     var bumper = require('gulp-bump');
17     var git = require('gulp-git');
18     var shell = require('gulp-shell');
19     var rename = require('gulp-rename');
20     var fs = require('fs');
21     var sequence = require('gulp-sequence');
22
23     gulp.task('less', function () {
24         return gulp.src('./*.less')
25             .pipe(sourcemaps.init())
26             .pipe(less())
27             .pipe(csso())
28             .pipe(sourcemaps.write('./'))
29             .pipe(gulp.dest('./dist'));
30     });
31
32     gulp.task('lint', function () {
33         return gulp.src('**/*.js')
34             .pipe(jshint())
35             .pipe(jshint.reporter(stylish));
36     });
37
38     /* gulp.task('style', function() {
39       return gulp.src('**/
40     /*.js')
41         .pipe(jscs());
42     });*/
43
44     gulp.task('unit', function () {
45         return gulp
46             .src('test/index.html')
47             .pipe(mochaPhantomJS());
48     });
49
50     gulp.task('bump-patch', bump('patch'));
51     gulp.task('bump-minor', bump('minor'));
52     gulp.task('bump-major', bump('major'));
53
54     gulp.task('bower', function () {
55         return gulp.src('./angular-object-diff.js')
56             .pipe(gulp.dest('./dist'));
57     });
58
59     gulp.task('js', ['lint' /*, 'style'*/ , 'bower'], function () {
60         return gulp.src('./angular-object-diff.js')
61             .pipe(rename('angular-object-diff.min.js'))
62             .pipe(sourcemaps.init())
63             .pipe(uglify())
64             .pipe(sourcemaps.write('./'))
65             .pipe(gulp.dest('./dist'));
66     });
67
68     gulp.task('build', function () {
69         return gulp.src(['dist/*', '!./dist/*.tar.gz'])
70             .pipe(tar('angular-object-diff.js.tar'))
71             .pipe(gzip({
72                 gzipOptions: {
73                     level: 9
74                 }
75             }))
76             .pipe(gulp.dest('dist/'));
77     });
78
79     gulp.task('update', function (cb) {
80         fs.readFile('./examples/index.template.html', 'utf8', function (err, file) {
81             if (err) return cb(err);
82             file = file.replace('<!-- version -->', version());
83             fs.writeFile('./examples/index.html', file, cb);
84         });
85     });
86
87     gulp.task('git-commit', function () {
88         var v = 'update to version ' + version();
89         gulp.src(['./dist/*', './examples/*', './test/*', './package.json', './bower.json', './angular-object-diff.js', './angular-object-diff.less'])
90             .pipe(git.add())
91             .pipe(git.commit(v));
92     });
93
94     gulp.task('git-push', function (cb) {
95         var v = 'v' + version();
96         git.push('origin', 'master', function (err) {
97             if (err) return cb(err);
98             git.tag(v, v, function (err) {
99                 if (err) return cb(err);
100                 git.push('origin', 'master', {
101                     args: '--tags'
102                 }, function(err){
103                     if (err) return cb(err);
104                     git.checkout('gh-pages', function (err) {
105                         if (err) return cb(err);
106                         git.reset('master', {
107                             args: '--hard'
108                         }, function (err) {
109                             if (err) return cb(err);
110                             git.push('origin', 'gh-pages', function (err) {
111                                 if (err) return cb(err);
112                                 git.checkout('master', cb);
113                             });
114                         });
115                     });
116                 });
117             });
118         });
119     });
120
121     gulp.task('git-demo', function (cb) {
122         var v = 'v' + version();
123         git.checkout('gh-pages', function (err) {
124             if (err) return cb(err);
125             git.reset('master', {
126                 args: '--hard'
127             }, function (err) {
128                 if (err) return cb(err);
129                 git.push('origin', 'gh-pages', function (err) {
130                     if (err) return cb(err);
131                     git.checkout('master', cb);
132                 });
133             });
134         });
135     });
136
137     gulp.task('npm', shell.task([
138         'npm publish'
139     ]));
140
141     gulp.task('watch', function () {
142         gulp.watch('./*.js', ['js']);
143         gulp.watch('./*.less', ['less']);
144         return true;
145     });
146
147     function bump(level) {
148         return function () {
149             return gulp.src(['./package.json', './bower.json'])
150                 .pipe(bumper({
151                     type: level
152                 }))
153                 .pipe(gulp.dest('./'));
154         };
155     }
156
157     function version() {
158         return JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
159     }
160
161     gulp.task('default', sequence('check', ['less', 'js'], 'build'));
162     gulp.task('test', sequence('unit' /*, 'integration'*/ ));
163     gulp.task('check', sequence(['lint' /*, 'style'*/ ], 'test'));
164     gulp.task('publish', sequence(['git-commit', 'git-push', 'npm']));
165     gulp.task('deploy-patch', sequence('default', 'bump-patch', /*'update',*/ 'publish'));
166     gulp.task('deploy-minor', sequence('default', 'bump-minor', /*'update',*/ 'publish'));
167     gulp.task('deploy-major', sequence('default', 'bump-major', /*'update',*/ 'publish'));
168
169 })();