-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
70 lines (62 loc) · 2.23 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
'use strict';
// IMPORTS
// ================================================================================================
const gulp = require('gulp');
const del = require('del');
const exec = require('child_process').exec;
const mocha = require('gulp-mocha');
// TASKS
// ================================================================================================
function clean(cb) {
del(['bin']).then(() => { cb(); });
}
function compile(cb) {
exec('tsc -p .', function (err, stdout, stderr) {
if (stdout.length > 0) console.log(stdout);
if (stderr.length > 0) console.error(stderr);
cb(err);
});
}
function asbuild(cb) {
const source = 'lib/assembly/prime128.as';
const target = '/bin/lib/assembly/prime128.wasm';
exec(`npx asc ${source} -b ${target} --sourceMap --validate --importMemory --enable bulk-memory -O3`, function (err, stdout, stderr) {
if (stdout.length > 0) console.log(stdout);
if (stderr.length > 0) console.error(stderr);
cb(err);
});
}
function copyFiles(cb) {
gulp.src('./package.json').pipe(gulp.dest('./bin'));
gulp.src('./package-lock.json').pipe(gulp.dest('./bin'));
gulp.src('./galois.d.ts').pipe(gulp.dest('./bin'));
gulp.src('./.npmignore').pipe(gulp.dest('./bin'));
gulp.src('./README.md').pipe(gulp.dest('./bin'));
cb();
}
function publish(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);
});
}
function runTests(cb) {
gulp.src('./bin/tests/**/*.spec.js')
.pipe( mocha({reporter: 'spec', bail: false}))
.on('error', err => {
if (err && (!err.message || err.message !== 'There were test failures')) {
console.error(JSON.stringify(err, null, 2));
}
} )
.once('error', () => process.exit(1))
.on('end', () => process.exit(0));
cb();
}
const build = gulp.series(clean, asbuild, compile, copyFiles);
// EXPORTS
// ================================================================================================
exports.build = build;
exports.publish = gulp.series(build, publish);
exports.test = gulp.series(build, runTests);
exports.default = build;