-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
59 lines (49 loc) · 1.86 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
'use strict';
// IMPORTS
// ================================================================================================
const gulp = require( 'gulp' );
const del = require( 'del' );
const exec = require( 'child_process' ).exec;
const gulpsync = require( 'gulp-sync' )( gulp );
const mocha = require( 'gulp-mocha' );
// TASKS
// ================================================================================================
gulp.task( 'default', [ 'build' ] );
gulp.task( 'build', gulpsync.sync( [ 'clean', 'compile', 'copy:files' ] ) );
gulp.task( 'clean', cb => {
del( [ 'bin' ] ).then( () => cb() );
} );
gulp.task( 'copy:files', () => {
return gulp.src( [ './package.json', './README.md', './pohlig-hellman.d.ts' ], { base: '.' } )
.pipe( gulp.dest( './bin' ) );
} );
gulp.task( 'compile', cb => compile( false, cb ) );
// publish to npm
gulp.task( 'publish', [ 'build' ], function ( cb ) {
exec( 'npm publish bin --access=public', function ( err, stdout, stderr ) {
if ( stdout.length > 0 ) console.log( stdout );
if ( stderr.length > 0 ) console.error( stderr );
cb( err );
} );
} );
gulp.task( 'test', [ 'build' ], () => {
return gulp.src( './bin/tests/*.spec.js', { read: false } )
.pipe( mocha() )
.once( 'error', () => process.exit( 1 ) )
.once( 'end', () => process.exit( 0 ) );
} );
// define default task
gulp.task( 'default', [ 'build' ] );
// HELPER FUNCTIONS
// ================================================================================================
function compile ( watch, cb ) {
let command = 'tsc --project .';
if ( watch ) {
command += ' --watch';
}
exec( command, function ( err, stdout, stderr ) {
if ( stdout.length > 0 ) console.log( stdout );
if ( stderr.length > 0 ) console.error( stderr );
cb( err );
} );
}