Created
June 13, 2019 12:12
-
-
Save pyrsmk/1d7d2290d8ff857f50df2c194782bc08 to your computer and use it in GitHub Desktop.
Systèmes de build : taskr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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