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