forked from agracio/ts-react-json-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
112 lines (97 loc) · 3.09 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const gulp = require('gulp');
const del = require('del');
const webpack = require('webpack-stream');
const sequence = require('run-sequence');
const tsb = require('gulp-tsb');
const chalk = require('chalk');
const minify = require('gulp-minify');
const run = require('gulp-run');
let buildDone = false;
const paths = {
src: ['src/**', 'test/**', './*.ts', 'node_modules/@types/**/*.d.ts'],
out: './dist',
test: './dist/test/**/*.js',
webpack: './build/',
webpackEntry: './dist/grid.js',
webpackName: 'ts-react-json-table.js'
};
function handleBuildError (error) {
console.log(chalk.red(error.toString()));
buildDone = false;
}
function createCompilation(){
return tsb.create('tsconfig.json', false, null, function(error){handleBuildError(error)});
//return tsb.create(tsconfig.compilerOptions, false, null, function(error){handleBuildError(error)});
}
function logBuildResult(){
console.log(buildDone ? chalk.green('Build succeeded.') : chalk.red('Build failed.'));
}
gulp.task('build', function() {
console.log(chalk.blue('Typescript compile.'));
buildDone = true;
return gulp.src(paths.src, {base: '.'})
.pipe(createCompilation()())
// .pipe(compilation())
.pipe(gulp.dest(paths.out));
});
gulp.task('clean', function() {
console.log(chalk.blue('Cleaning'));
return del([paths.out + '/**/*', paths.webpack + '/**/*']);
});
gulp.task('clean_webpack', function() {
console.log(chalk.blue('Cleaning webpack output in ' + paths.webpack));
return del([paths.webpack + '/**/*']);
});
gulp.task('webpack', ['clean_webpack', 'build'], function() {
logBuildResult();
if(!buildDone){ return;}
console.log(chalk.blue('Creating webpack in', paths.webpack));
return gulp.src(paths.webpackEntry)
.pipe(webpack({
output: {
libraryTarget: 'umd',
filename: paths.webpackName,
library: 'JsonTable',
//libraryExport: 'JsonTable',
},
module: {
rules: [
{test: /\.js$/, loader: "source-map-loader"}
],
},
externals: {
react: {
commonjs: null,
commonjs2: null,
//amd: "React",
root: 'React'
}
},
devtool: "#source-map"
}))
.pipe(gulp.dest(paths.webpack));
});
gulp.task('minify',['webpack'], function() {
gulp.src(paths.webpack + paths.webpackName)
.pipe(minify({
ext:{
min:'.min.js'
}
}))
.pipe(gulp.dest(paths.webpack))
});
gulp.task('copy-css', function() {
return gulp.src('./src/**/*.css').pipe(gulp.dest(paths.webpack))
});
gulp.task('publish_npm', function () {
return run('npm publish').exec();
});
gulp.task('publish', function () {
sequence('clean', 'minify','copy-css', 'publish_pack', 'publish_npm');
});
gulp.task('publish_pack', function () {
return run('npm pack').exec();
});
gulp.task('pack', function () {
sequence('clean', 'minify', 'copy-css', 'publish_pack');
});