]>
git.proxmox.com Git - mirror_xterm.js.git/blob - gulpfile.js
5 const browserify
= require('browserify');
6 const buffer
= require('vinyl-buffer');
7 const coveralls
= require('gulp-coveralls');
8 const fs
= require('fs-extra');
9 const path
= require('path');
10 const gulp
= require('gulp');
11 const istanbul
= require('gulp-istanbul');
12 const merge
= require('merge-stream');
13 const mocha
= require('gulp-mocha');
14 const sorcery
= require('sorcery');
15 const source
= require('vinyl-source-stream');
16 const sourcemaps
= require('gulp-sourcemaps');
17 const ts
= require('gulp-typescript');
18 const util
= require('gulp-util');
20 let buildDir
= process
.env
.BUILD_DIR
|| 'build';
21 let tsProject
= ts
.createProject('tsconfig.json');
22 let tsProjectSearchAddon
= ts
.createProject('./src/addons/search/tsconfig.json');
23 let srcDir
= tsProject
.config
.compilerOptions
.rootDir
;
24 let outDir
= tsProject
.config
.compilerOptions
.outDir
;
26 // Under some environments like TravisCI, this comes out at absolute which can
27 // break the build. This ensures that the outDir is absolute.
28 if (outDir
.indexOf(__dirname
) !== 0) {
29 outDir
= `${__dirname}/${outDir}`;
33 * Compile TypeScript sources to JavaScript files and create a source map file for each TypeScript
36 gulp
.task('tsc', function () {
37 // Remove the ${outDir}/ directory to prevent confusion if files were deleted in ${srcDir}/
38 fs
.emptyDirSync(`${outDir}`);
40 // Build all TypeScript files (including tests) to ${outDir}/, based on the configuration defined in
42 let tsResult
= tsProject
.src().pipe(sourcemaps
.init()).pipe(tsProject());
43 let tsc
= tsResult
.js
.pipe(sourcemaps
.write('.', {includeContent
: false, sourceRoot
: ''})).pipe(gulp
.dest(outDir
));
45 fs
.emptyDirSync(`${outDir}/addons/search`);
46 let tsResultSearchAddon
= tsProjectSearchAddon
.src().pipe(sourcemaps
.init()).pipe(tsProjectSearchAddon());
47 let tscSearchAddon
= tsResultSearchAddon
.js
.pipe(sourcemaps
.write('.', {includeContent
: false, sourceRoot
: ''})).pipe(gulp
.dest(`${outDir}/addons/search`));
49 // Copy all addons from ${srcDir}/ to ${outDir}/
50 let copyAddons
= gulp
.src([`${srcDir}/addons/**/*`, `!${srcDir}/addons/search`, `!${srcDir}/addons/search/**`]).pipe(gulp
.dest(`${outDir}/addons`));
52 // Copy stylesheets from ${srcDir}/ to ${outDir}/
53 let copyStylesheets
= gulp
.src(`${srcDir}/**/*.css`).pipe(gulp
.dest(outDir
));
55 return merge(tsc
, tscSearchAddon
, copyAddons
, copyStylesheets
);
59 * Bundle JavaScript files produced by the `tsc` task, into a single file named `xterm.js` with
62 gulp
.task('browserify', ['tsc'], function() {
63 // Ensure that the build directory exists
64 fs
.ensureDirSync(buildDir
);
66 let browserifyOptions
= {
69 entries
: [`${outDir}/xterm.js`],
70 standalone
: 'Terminal',
74 let bundleStream
= browserify(browserifyOptions
)
76 .pipe(source('xterm.js'))
78 .pipe(sourcemaps
.init({loadMaps
: true, sourceRoot
: '..'}))
79 .pipe(sourcemaps
.write('./'))
80 .pipe(gulp
.dest(buildDir
));
82 // Copy stylesheets from ${outDir}/ to ${buildDir}/
83 let copyStylesheets
= gulp
.src(`${outDir}/**/*.css`).pipe(gulp
.dest(buildDir
));
85 return merge(bundleStream
, copyStylesheets
);
88 gulp
.task('browserify-addons', ['tsc'], function() {
90 basedir
: `${buildDir}/addons/search`,
92 entries
: [`${outDir}/addons/search/search.js`],
96 let searchBundle
= browserify(searchOptions
)
97 .external(path
.join(outDir
, 'xterm.js'))
99 .pipe(source('./addons/search/search.js'))
101 .pipe(sourcemaps
.init({loadMaps
: true, sourceRoot
: ''}))
102 .pipe(sourcemaps
.write('./'))
103 .pipe(gulp
.dest(buildDir
));
105 // Copy all add-ons from outDir to buildDir
106 let copyAddons
= gulp
.src([
108 `${outDir}/addons/**/*`,
109 // Exclude TS addons from copy as they are being built via browserify
110 `!${outDir}/addons/search`,
111 `!${outDir}/addons/search/**`
112 ]).pipe(gulp
.dest(`${buildDir}/addons`));
114 return merge(searchBundle
, copyAddons
);
117 gulp
.task('instrument-test', function () {
118 return gulp
.src([`${outDir}/**/*.js`])
121 // Force `require` to return covered files
122 .pipe(istanbul
.hookRequire());
125 gulp
.task('mocha', ['instrument-test'], function () {
126 return gulp
.src([`${outDir}/*test.js`, `${outDir}/**/*test.js`], {read
: false})
128 .once('error', () => process
.exit(1))
129 .pipe(istanbul
.writeReports());
133 * Run single test file by file name(without file extension). Example of the command:
134 * gulp mocha-test --test InputHandler.test
136 gulp
.task('mocha-test', ['instrument-test'], function () {
137 let testName
= util
.env
.test
;
138 util
.log("Run test by Name: " + testName
);
139 return gulp
.src([`${outDir}/${testName}.js`, `${outDir}/**/${testName}.js`], {read
: false})
141 .once('error', () => process
.exit(1))
142 .pipe(istanbul
.writeReports());
146 * Use `sorcery` to resolve the source map chain and point back to the TypeScript files.
147 * (Without this task the source maps produced for the JavaScript bundle points into the
148 * compiled JavaScript files in ${outDir}/).
150 gulp
.task('sorcery', ['browserify'], function () {
151 let chain
= sorcery
.loadSync(`${buildDir}/xterm.js`);
156 gulp
.task('sorcery-addons', ['browserify-addons'], function () {
157 var chain
= sorcery
.loadSync(`${buildDir}/addons/search/search.js`);
163 * Submit coverage results to coveralls.io
165 gulp
.task('coveralls', function () {
166 gulp
.src('coverage/**/lcov.info')
170 gulp
.task('build', ['sorcery', 'sorcery-addons']);
171 gulp
.task('test', ['mocha']);
172 gulp
.task('default', ['build']);