Skip to content

Instantly share code, notes, and snippets.

@pyrsmk
Created June 13, 2019 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyrsmk/1d7d2290d8ff857f50df2c194782bc08 to your computer and use it in GitHub Desktop.
Save pyrsmk/1d7d2290d8ff857f50df2c194782bc08 to your computer and use it in GitHub Desktop.
Systèmes de build : taskr
const { CLIEngine } = require('eslint')
const rollup = require('rollup')
const typescript = require('rollup-plugin-typescript2')
const prepack = require('rollup-plugin-prepack-up')
exports.lint = function* () {
yield new Promise((resolve, reject) => {
const eslint = new CLIEngine()
const formatter = eslint.getFormatter()
const { results } = eslint.executeOnFiles(['src/**'])
if (results.reduce((value, item) => value + item.errorCount, 0)) {
console.log(formatter(results))
reject()
} else if (results.reduce((value, item) => value + item.warningCount, 0)) {
console.log(formatter(results))
}
resolve()
})
}
exports.bundle = function* () {
yield new Promise((resolve, reject) => {
rollup.rollup({
input: 'src/Toast.ts',
plugins: [
typescript({ useTsconfigDeclarationDir: true }),
prepack(),
],
}).then(bundler => {
bundler.write({
file: 'dist/toast.js',
format: 'umd',
name: 'toast',
}).then(
resolve
).catch(
reject
)
}).catch(
reject
)
})
}
exports.minify = function* (task) {
yield task
.source('dist/toast.js')
.uglify()
.rename({ basename: 'toast.min' })
.target('dist')
yield task
.source('dist/toast.js')
.uglify({
outSourceMap: 'toast.js.map',
sourceMapInline: true,
})
.rename({ basename: 'toast.min' })
.target('tests/lib/')
}
exports.build = function* (task) {
yield task.serial(['lint', 'bundle', 'minify'])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment