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