-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
122 lines (105 loc) · 3.04 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const gulpStylelint = require('gulp-stylelint');
const runSequence = require('run-sequence');
const del = require('del');
const conventionalChangelog = require('gulp-conventional-changelog');
const conventionalGitHubReleaser = require('conventional-github-releaser');
const bump = require('gulp-bump');
const argv = require('yargs').argv;
const validBumpTypes = 'major|minor|patch|prerelease'.split('|');
const bumpType = (argv.bump || 'patch').toLowerCase();
const stylelintFormatter = require('stylelint-formatter-pretty');
if (validBumpTypes.indexOf(bumpType) === -1) {
throw new Error('Unrecognized bump "' + bumpType + '".');
}
const args = {
bump: bumpType,
depth: parseInt(argv.depth || '0', 10),
token: argv.token,
branch: argv.branch
};
const changelogOpts = {
preset: 'angular',
releaseCount: 1,
targetCommitish: args.branch
};
// utilizes the bump plugin to bump the
// semver for the repo
gulp.task('bump-version', () =>
gulp.src(['./package.json'])
.pipe(bump({type: args.bump}))
.pipe(gulp.dest('./'))
);
// generates the CHANGELOG.md file based on commit
// from git commit messages
gulp.task('changelog', () =>
gulp.src(`./CHANGELOG.md`)
.pipe(conventionalChangelog(changelogOpts))
.pipe(gulp.dest('./'))
);
// calls the listed sequence of tasks in order
gulp.task('prepare-release', callback =>
runSequence(
'build',
'lint',
'bump-version',
'changelog',
callback
)
);
gulp.task('release', callback => {
conventionalGitHubReleaser({
type: 'oauth',
token: args.token || process.env.CONVENTIONAL_GITHUB_RELEASER_TOKEN
}, changelogOpts, {}, {}, {}, {}, (err, data) => {
if (err) {
console.error(err.toString());
return callback();
}
if (!data.length) {
console.log('No GitHub releases created because no git tags available to work with.');
return callback();
}
let allRejected = true;
for (let i = data.length - 1; i >= 0; i--) {
if (data[i].state === 'fulfilled') {
allRejected = false;
break;
}
}
if (allRejected) {
console.error(data);
} else {
console.log(data);
}
return callback();
});
});
gulp.task('lint-sass', function() {
return gulp.src(['./*.scss', './*/*.scss', '!./utils/*.scss'])
.pipe(gulpStylelint({
reporters: [
{formatter: stylelintFormatter, console: true, fix: true}
]
}));
});
// This is only used to validate the code is able to compile
gulp.task('sass', () =>
gulp.src('./index.scss')
.pipe(sass().on('error', sass.logError))
);
gulp.task('default', gulp.parallel('sass', 'lint-sass'));
gulp.task('build:sass', () =>
gulp.src('./index.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./build'))
);
gulp.task('copy:fonts', () => {
return gulp.src('./fonts/*')
.pipe(gulp.dest('build/fonts/'))
});
gulp.task('clean:dist', () =>
del(['build/**'])
);
gulp.task('build:dist', gulp.series('clean:dist', 'lint-sass', 'copy:fonts','build:sass'));