]>
git.proxmox.com Git - mirror_xterm.js.git/blob - 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 mocha
= require('gulp-mocha');
7 const mochaPhantomJs
= require('gulp-mocha-phantomjs');
8 const sorcery
= require('sorcery');
9 const source
= require('vinyl-source-stream');
10 const sourcemaps
= require('gulp-sourcemaps');
11 const ts
= require('gulp-typescript');
14 let buildDir
= process
.env
.BUILD_DIR
|| 'build';
18 * Compile TypeScript sources to JavaScript files and create a source map file for each TypeScript
21 gulp
.task('tsc', function () {
22 // Remove the lib/ directory to prevent confusion if files were deleted in src/
23 fs
.emptyDirSync('lib');
25 // Build all TypeScript files (including tests) to lib/, based on the configuration defined in
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'));
31 // Copy all addons from src/ to lib/
32 let copyAddons
= gulp
.src('src/addons/**/*').pipe(gulp
.dest('lib/addons'));
34 // Copy stylesheets from src/ to lib/
35 let copyStylesheets
= gulp
.src('src/**/*.css').pipe(gulp
.dest('lib'));
37 return merge(tsc
, copyAddons
, copyStylesheets
);
41 * Bundle JavaScript files produced by the `tsc` task, into a single file named `xterm.js` with
44 gulp
.task('browserify', ['tsc'], function() {
45 // Ensure that the build directory exists
46 fs
.ensureDirSync(buildDir
);
48 let browserifyOptions
= {
51 entries
: ['../lib/xterm.js'],
52 standalone
: 'Terminal',
56 let bundleStream
= browserify(browserifyOptions
)
58 .pipe(source('xterm.js'))
60 .pipe(sourcemaps
.init({loadMaps
: true, sourceRoot
: '..'}))
61 .pipe(sourcemaps
.write('./'))
62 .pipe(gulp
.dest(buildDir
));
64 // Copy all add-ons from lib/ to buildDir
65 let copyAddons
= gulp
.src('lib/addons/**/*').pipe(gulp
.dest(`${buildDir}/addons`));
67 // Copy stylesheets from src/ to lib/
68 let copyStylesheets
= gulp
.src('lib/**/*.css').pipe(gulp
.dest(buildDir
));
70 return merge(bundleStream
, copyAddons
, copyStylesheets
);
73 gulp
.task('test-mocha', function () {
74 return gulp
.src(['lib/*test.js', 'lib/**/*test.js'], {read
: false})
78 gulp
.task('test-mocha-phantomjs', function () {
79 return gulp
.src('test-harness.html')
80 .pipe(mochaPhantomJs());
84 * Use `sorcery` to resolve the source map chain and point back to the TypeScript files.
85 * (Without this task the source maps produced for the JavaScript bundle points into the
86 * compiled JavaScript files in lib/).
88 gulp
.task('sorcery', ['browserify'], function () {
89 var chain
= sorcery
.loadSync(`${buildDir}/xterm.js`);
90 var map
= chain
.apply();
94 gulp
.task('build', ['sorcery']);
95 gulp
.task('test', ['test-mocha', 'test-mocha-phantomjs']);
96 gulp
.task('default', ['build']);