]> git.proxmox.com Git - mirror_xterm.js.git/blob - gulpfile.js
Add PhantomJS test support and CharMeasure tests
[mirror_xterm.js.git] / gulpfile.js
1 const browserify = require('browserify');
2 const buffer = require('vinyl-buffer');
3 const fs = require('fs-extra');
4 const gulp = require('gulp');
5 const merge = require('merge-stream');
6 const mochaPhantom = require('gulp-mocha-phantomjs');
7 const sorcery = require('sorcery');
8 const source = require('vinyl-source-stream');
9 const sourcemaps = require('gulp-sourcemaps');
10 const ts = require('gulp-typescript');
11 const tsify = require('tsify');
12
13
14 let buildDir = process.env.BUILD_DIR || 'build';
15
16
17 /**
18 * Compile TypeScript sources to JavaScript files and create a source map file for each TypeScript
19 * file compiled.
20 */
21 gulp.task('tsc', function () {
22 // Remove the lib/ directory to prevent confusion if files were deleted in src/
23 fs.emptyDirSync('lib');
24
25 // Build all TypeScript files (including tests) to lib/, based on the configuration defined in
26 // `tsconfig.json`.
27 let tsProject = ts.createProject('tsconfig.json');
28 let tsResult = tsProject.src().pipe(sourcemaps.init()).pipe(tsProject());
29 let tsc = tsResult.js.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: ''})).pipe(gulp.dest('lib'));
30
31 // Copy all addons from src/ to lib/
32 let copyAddons = gulp.src('src/addons/**/*').pipe(gulp.dest('lib/addons'));
33
34 // Copy stylesheets from src/ to lib/
35 let copyStylesheets = gulp.src('src/**/*.css').pipe(gulp.dest('lib'));
36
37 return merge(tsc, copyAddons, copyStylesheets);
38 });
39
40 /**
41 * Bundle JavaScript files produced by the `tsc` task, into a single file named `xterm.js` with
42 * Browserify.
43 */
44 gulp.task('browserify', ['tsc'], function() {
45 // Ensure that the build directory exists
46 fs.ensureDirSync(buildDir);
47
48 let browserifyOptions = {
49 basedir: buildDir,
50 debug: true,
51 entries: ['../lib/xterm.js'],
52 standalone: 'Terminal',
53 cache: {},
54 packageCache: {}
55 };
56 let bundleStream = browserify(browserifyOptions)
57 .plugin(tsify)
58 .bundle()
59 .pipe(source('xterm.js'))
60 .pipe(buffer())
61 .pipe(sourcemaps.init({loadMaps: true, sourceRoot: '..'}))
62 .pipe(sourcemaps.write('./'))
63 .pipe(gulp.dest(buildDir));
64
65 // Copy all add-ons from lib/ to buildDir
66 let copyAddons = gulp.src('lib/addons/**/*').pipe(gulp.dest(`${buildDir}/addons`));
67
68 // Copy stylesheets from src/ to lib/
69 let copyStylesheets = gulp.src('lib/**/*.css').pipe(gulp.dest(buildDir));
70
71 return merge(bundleStream, copyAddons, copyStylesheets);
72 });
73
74 gulp.task('test-phantom', function () {
75 return gulp.src('test-harness.html')
76 .pipe(mochaPhantom());
77 });
78
79 /**
80 * Use `sorcery` to resolve the source map chain and point back to the TypeScript files.
81 * (Without this task the source maps produced for the JavaScript bundle points into the
82 * compiled JavaScript files in lib/).
83 */
84 gulp.task('sorcery', ['browserify'], function () {
85 var chain = sorcery.loadSync(`${buildDir}/xterm.js`);
86 var map = chain.apply();
87 chain.writeSync();
88 });
89
90 gulp.task('build', ['sorcery']);
91
92 gulp.task('default', ['build']);