forked from SC5/sc5-styleguide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
137 lines (118 loc) · 3.98 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
var gulp = require('gulp'),
concat = require('gulp-concat'),
plumber = require('gulp-plumber'),
bower = require('gulp-bower'),
mainBowerFiles = require('main-bower-files'),
ngAnnotate = require('gulp-ng-annotate'),
replace = require('gulp-replace'),
runSequence = require('run-sequence'),
toc = require('gulp-doctoc'),
styleguide = require('./lib/styleguide'),
distPath = 'lib/dist',
fs = require('fs'),
chalk = require('chalk'),
outputPath = 'demo-output';
require('./gulpfile-tests')(gulp);
gulp.task('js:app', function() {
return gulp.src([
'lib/app/js/app.js',
'lib/app/js/controllers/*.js',
'lib/app/js/directives/*.js',
'lib/app/js/services/*.js'
])
.pipe(plumber())
.pipe(ngAnnotate())
.pipe(concat('app.js'))
.pipe(gulp.dest(distPath + '/js'));
});
gulp.task('js:vendor', ['bower'], function() {
return gulp.src(['lib/app/js/vendor/**/*.js'].concat(mainBowerFiles({filter: /\.js/})))
.pipe(plumber())
.pipe(concat('vendor.js'))
.pipe(gulp.dest(distPath + '/js'));
});
gulp.task('bower', function() {
return bower();
});
gulp.task('sass', function() {
return gulp.src('lib/app/sass/**/*')
.pipe(gulp.dest(distPath + '/sass'));
});
gulp.task('html', function() {
return gulp.src('lib/app/**/*.html')
.pipe(gulp.dest(distPath + '/'));
});
gulp.task('assets', function() {
return gulp.src('lib/app/assets/**')
.pipe(gulp.dest(distPath + '/assets'));
});
// Copy test directives to output even when running gulp dev
gulp.task('dev:static', function() {
gulp.src(['lib/demo/**'])
.pipe(gulp.dest(outputPath + '/demo'));
});
gulp.task('dev:doc', function() {
return gulp.src('**/README.md')
.pipe(toc())
.pipe(replace(/[^\n]*Table of Contents[^\n]*\n/g, ''))
.pipe(gulp.dest('./'));
});
gulp.task('dev:generate', function() {
return gulp.src(['lib/app/sass/**/*.scss'])
.pipe(styleguide.generate({
title: 'SC5 Styleguide',
server: true,
rootPath: outputPath,
overviewPath: 'README.md',
styleVariables: 'lib/app/sass/_styleguide_variables.scss'
}))
.pipe(gulp.dest(outputPath));
});
gulp.task('dev:applystyles', function() {
if (!fs.existsSync(distPath)) {
process.stderr.write(chalk.red.bold('Error:') + ' Directory ' + distPath + ' does not exist. You probably installed library by cloning repository directly instead of NPM repository.\n');
process.stderr.write('You need to run ' + chalk.green.bold('gulp build') + ' first\n');
process.exit(1);
return 1;
}
return gulp.src([distPath + '/css/*.css'])
.pipe(styleguide.applyStyles())
.pipe(gulp.dest(outputPath));
});
gulp.task('dev', ['dev:doc', 'dev:static', 'dev:applystyles', 'dev:generate'], function() {
// Do intial full build and create styleguide
runSequence('build', 'dev:generate');
gulp.watch('lib/app/sass/**/*.scss', function() {
runSequence('sass', 'dev:applystyles', 'dev:generate');
});
gulp.watch(['lib/app/js/**/*.js', 'lib/app/views/**/*', 'lib/app/index.html', '!lib/app/js/vendor/**/*.js'], function() {
gulp.start('lint:js');
runSequence('js:app', 'dev:generate');
});
gulp.watch('lib/app/js/vendor/**/*.js', function() {
runSequence('js:vendor', 'dev:generate');
});
gulp.watch('lib/app/**/*.html', function() {
runSequence('html', 'dev:generate');
});
gulp.watch('README.md', ['dev:doc', 'dev:generate']);
gulp.watch('lib/styleguide.js', ['dev:generate']);
});
gulp.task('build', ['sass', 'js:app', 'js:vendor', 'html', 'assets']);
gulp.task('changelog', function() {
require('conventional-changelog')({
repository: 'https://github.com/SC5/sc5-styleguide',
version: require('./package.json').version,
file: ''
}, function(err, log) {
fs.writeFile('./CHANGELOG_LATEST.md', log, function(err) {
if (err) {
console.log(err);
} else {
console.log('The latest changelog was updated\n\n');
console.log(log);
}
});
});
});
gulp.task('publish', ['build', 'changelog']);