-
Notifications
You must be signed in to change notification settings - Fork 122
/
gulpfile.js
117 lines (102 loc) · 3.08 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
'use strict'
const del = require('del')
const gulp = require('gulp')
const uglify = require('gulp-uglify')
const concat = require('gulp-concat')
const path = require('path')
const shell = require('shelljs')
const rollup = require('rollup')
const dstDir = path.join(__dirname, 'release')
const srcDir = path.join(__dirname, 'src')
const docDir = path.join(dstDir, 'doc')
function exec(command, cb) {
shell
.exec(command, { async: true })
.on('exit', (code) => cb(code === 0 ? null : code))
}
gulp.task('clean', () => del(dstDir))
gulp.task('build:tsc', ['clean'], (cb) => {
exec('yarn run build', cb)
})
gulp.task('build:esm2015', ['clean'], (cb) => {
exec('yarn run build:esm2015', cb)
})
gulp.task('build:rollup', ['build:tsc'], () => {
const resolve = require('rollup-plugin-node-resolve')
const sourcemaps = require('rollup-plugin-sourcemaps')
const globals = {
'$': 'jquery',
}
return rollup.rollup({
amd: {id: `SpriteSpin`},
input: path.join(dstDir, 'src', 'index.js'),
onwarn: (warning, warn) => {
if (warning.code === 'THIS_IS_UNDEFINED') {return}
warn(warning);
},
plugins: [resolve(), sourcemaps()],
external: Object.keys(globals),
})
.then((bundle) => {
return bundle.write({
format: 'umd',
sourcemap: true,
file: path.join(dstDir, 'spritespin.js'),
name: 'SpriteSpin',
globals: globals,
exports: 'named',
})
})
})
gulp.task('build:uglify', ['build:rollup'], () => {
return gulp
.src(path.join(dstDir, 'spritespin.js'))
.pipe(uglify())
.pipe(concat('spritespin.min.js'))
.pipe(gulp.dest(dstDir))
})
gulp.task('build', ['build:tsc', 'build:esm2015', 'build:rollup', 'build:uglify'])
gulp.task('watch', ['build', 'api:json'], () => {
gulp.watch([ path.join('src', '**', '*.ts') ], ['build', 'api:json'])
})
gulp.task('publish', ['build'], (cb) => {
exec('npm publish --access=public', cb)
})
gulp.task('api:json', ['build'], (cb) => {
const ae = require('@microsoft/api-extractor')
const config = ae.ExtractorConfig.prepare({
configObject: {
compiler: {
tsconfigFilePath: path.join(__dirname, 'tsconfig.json'),
},
apiReport: {
enabled: false,
reportFileName: 'spritespin.api.md',
reportFolder: path.join(__dirname, 'doc'),
reportTempFolder: path.join(__dirname, 'tmp'),
},
docModel: {
enabled: true,
apiJsonFilePath: path.join(__dirname, 'doc', 'spritespin.api.json'),
},
dtsRollup: {
enabled: false,
},
projectFolder: path.join(dstDir, 'src'),
mainEntryPointFilePath: path.join(dstDir, 'src', 'index.d.ts'),
}
})
config.packageFolder = process.cwd()
config.packageJson = require('./package.json')
const result = ae.Extractor.invoke(config, {
// Equivalent to the "--local" command-line parameter
localBuild: true,
// Equivalent to the "--verbose" command-line parameter
showVerboseMessages: true
})
if (result.succeeded) {
exec('./node_modules/.bin/api-documenter markdown -i doc -o doc', cb)
} else {
cb(1)
}
})