forked from fdaciuk/ajax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
146 lines (132 loc) · 3.75 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
138
139
140
141
142
143
144
145
146
'use strict'
const fs = require('fs')
const gulp = require('gulp')
const Server = require('karma').Server
const concat = require('gulp-concat')
const uglify = require('gulp-uglify')
const header = require('gulp-header')
const standard = require('gulp-standardize')
const plato = require('plato')
const exec = require('child_process').exec
const pkg = require('./package.json')
const coreFiles = 'src/ajax.js'
const testFiles = 'test/**/*.js'
const apiFiles = 'api/**/*.js'
const allFiles = [coreFiles, testFiles, apiFiles]
const banner = () => {
return [
'/**!',
' * <%= pkg.name.replace("@fdaciuk/", "") %> - v<%= pkg.version %>',
' * <%= pkg.description %>',
' * <%= pkg.homepage %>',
'',
' * <%= new Date( Date.now() ) %>',
' * <%= pkg.license %> (c) <%= pkg.author %>',
'*/',
''
].join('\n')
}
gulp.task('lint', () => {
gulp.src(allFiles)
.pipe(standard())
.pipe(standard.reporter('snazzy'))
.pipe(standard.reporter('fail'))
})
gulp.task('uglify', () => {
gulp.src(coreFiles)
.pipe(concat('ajax.min.js'))
.pipe(uglify())
.pipe(header(banner(), { pkg: pkg }))
.pipe(gulp.dest('./dist'))
})
gulp.task('test', (done) => {
return new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, () => done()).start()
})
gulp.task('watch', [ 'test', 'lint' ], () => {
gulp.watch(allFiles, [ 'test', 'lint' ])
})
gulp.task('plato', done => {
const files = [ coreFiles ]
const outputDir = './plato'
const options = { title: '#Ajax' }
const callback = (report) => done()
plato.inspect(files, outputDir, options, callback)
})
gulp.task('update-readme', (done) => {
fs.readFile('README.md', 'utf8', (err, file) => {
const updateVersion = file.split('\n').reduce((acc, line) => {
const versionLine = line.includes('//cdn.rawgit.com/fdaciuk/ajax')
let newLine = line
if (versionLine) {
newLine = line.replace(/\/v([\d.]+)\//, `/v${pkg.version}/`)
}
return acc.concat(newLine)
}, [])
fs.writeFile('README.md', updateVersion.join('\n'), done)
})
})
gulp.task('deploy', done => {
const date = new Date(Date.now())
const execCommand = (command, message) => {
console.log(`- ${message}`)
return new Promise((resolve, reject) => {
exec(command.join(' && '), (err, stdout, stderr) => {
if (err) return reject(err)
return resolve(stdout)
})
})
}
const syncRepository = [
'git pull origin dev --force'
]
const createNewVersion = [
'gulp update-readme',
'gulp uglify',
'git add .',
'git commit -m "Minifying"',
'git tag -f v' + pkg.version
]
const generateReports = [
'gulp plato',
'rm -rf .tmp',
'mkdir .tmp',
'cd .tmp',
'git clone [email protected]:reportz/ajax.git ./',
'cp -R ../coverage ../plato ./',
'git add -A',
'git commit -m "Update reports at ' + date + ' "',
'git push origin gh-pages',
'cd ../',
'rm -rf .tmp'
]
const updateMainBranch = [
'git checkout master',
'git merge dev',
'git push origin master --tags'
]
const updateDevBranch = [
'git checkout dev',
'git push origin dev --tags'
]
const npmPublish = [
'npm run pub'
]
execCommand(syncRepository, 'Sync repository...')
.then(() => execCommand(createNewVersion, 'Create new Version...'))
.then(() => execCommand(generateReports, 'Generate reports...'))
.then(() => execCommand(updateMainBranch, 'Update master branch...'))
.then(() => execCommand(updateDevBranch, 'Update dev branch...'))
.then(() => execCommand(npmPublish, 'Publish on NPM...'))
.then(() => {
console.log('Done!')
process.exit(0)
})
.catch((err) => {
console.log(err)
process.exit(1)
})
})
gulp.task('default', [ 'watch' ])