You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.5 KiB
JavaScript

const { src, dest, watch, series, task } = require('gulp')
const ts = require('gulp-typescript')
const del = require('delete')
const eslint = require('gulp-eslint')
const nodemon = require('gulp-nodemon')
4 years ago
/**
* Clears the dist folder by deleting all files inside.
* @param cb
*/
function clearDist (cb) {
del('dist/*', cb)
4 years ago
}
/**
* Typescript compilation task.
* @returns {*}
*/
function compileTypescript () {
const tsProject = ts.createProject('tsconfig.json')
const tsResult = tsProject.src().pipe(tsProject())
4 years ago
return tsResult
// .pipe(minify())
.pipe(dest('dist'))
4 years ago
}
/**
* Task for moving all remaining file from source to dist that don't need procession.
* @returns {*}
*/
function moveRemaining () {
4 years ago
return src(['src/**/*', '!src/**/*.ts'])
.pipe(dest('dist'))
4 years ago
}
function runEslint () {
return src(['src/**/*.ts'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint({ fix: true }))
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError())
4 years ago
}
task('eslint', () => {
return src(['src/**/*.ts'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint({ fix: true }))
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError())
})
4 years ago
task('default', series(clearDist, compileTypescript, moveRemaining))
4 years ago
task('watch', () => {
runEslint()
compileTypescript()
watch('**/*.ts', runEslint)
watch('**/*.ts', compileTypescript)
// watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
nodemon({
script: 'dist/index.js',
watch: ['dist/**/*.js'],
ext: 'js'
})
})
4 years ago
task('watchnolint', () => {
watch('**/*.ts', compileTypescript)
// watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
nodemon({
script: 'dist/index.js',
watch: ['dist/**/*.js'],
ext: 'js'
})
})