-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
117 lines (103 loc) · 3.82 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
113
114
115
116
117
"use strict";
const babel = require( "gulp-babel" );
const changed = require( "gulp-changed" );
const debug = require( "gulp-debug" );
const gulp = require( "gulp" );
const plumber = require( "gulp-plumber" );
const rename = require( "gulp-rename" );
const replace = require( "gulp-replace" );
const sourcemap = require( "gulp-sourcemaps" );
const yargs = require( "yargs" );
const clientPattern = /\/\/\:\s*\@client\:(.+?|[^]+?)\/\/\:\s*\@end\-client/gm;
const negateClientPattern = /\/\/\:\s*\@\!client\:(.+?|[^]+?)\/\/\:\s*\@end\-client/gm;
const serverPattern = /\/\/\:\s*\@server\:(.+?|[^]+?)\/\/\:\s*\@end\-server/gm;
const negateServerPattern = /\/\/\:\s*\@\!server\:(.+?|[^]+?)\/\/\:\s*\@end\-server/gm;
const bridgePattern = /\/\/\:\s*\@bridge\:(.+?|[^]+?)\/\/\:\s*\@end\-bridge/gm;
const negateBridgePattern = /\/\/\:\s*\@\!bridge\:(.+?|[^]+?)\/\/\:\s*\@end\-bridge/gm;
const ignoreOpenPattern = /\/\/\:\s*\@ignore\:/gm;
const ignoreOpenCommentPattern = /\/\/\:\s*\@ignore\:\s*\n\s*\/\*/gm;
const ignoreClosePattern = /\/\/\:\s*\@end\-ignore/gm;
const ignoreCloseCommentPattern = /\*\/\s*\n\s*\/\/\:\s*\@end\-ignore/gm;
let parameter = yargs
.boolean( "client" )
.boolean( "server" )
.boolean( "bridge" )
.boolean( "all" )
.coerce( "module", ( name ) => name.split( /\,/ ) )
.argv
let list = parameter.module;
gulp.task( "server", function formatServer( ){
return gulp.src( list.map( ( name ) => `${ name }.module.js` ) )
.pipe( plumber( ) )
.pipe( debug( { "title": "Server File:" } ) )
.pipe( rename( ( path ) => {
path.basename = path.basename.replace( ".module", "" );
return path;
} ) )
.pipe( replace( negateServerPattern, "" ) )
.pipe( replace( clientPattern, "" ) )
.pipe( replace( bridgePattern, "" ) )
.pipe( changed( "./", {
"hasChanged": changed.compareContents
} ) )
.pipe( debug( { "title": "Server File Done:" } ) )
.pipe( gulp.dest( "./" ) );
} );
gulp.task( "client", function formatClient( ){
return gulp.src( list.map( ( name ) => `${ name }.module.js` ) )
.pipe( plumber( ) )
.pipe( debug( { "title": "Client File:" } ) )
.pipe( rename( ( path ) => {
path.basename = path.basename.replace( ".module", ".support" );
return path;
} ) )
.pipe( replace( negateClientPattern, "" ) )
.pipe( replace( serverPattern, "" ) )
.pipe( replace( bridgePattern, "" ) )
.pipe( sourcemap.init( ) )
.pipe( babel( ) )
.pipe( sourcemap.write( "./" ) )
.pipe( changed( "./", {
"hasChanged": changed.compareContents,
} ) )
.pipe( debug( { "title": "Client File Done:" } ) )
.pipe( gulp.dest( "./" ) );
} );
gulp.task( "bridge", function formatBridge( ){
return gulp.src( list.map( ( name ) => `${ name }.module.js` ) )
.pipe( plumber( ) )
.pipe( debug( { "title": "Bridge File:" } ) )
.pipe( rename( ( path ) => {
path.basename = path.basename.replace( ".module", ".bridge" );
return path;
} ) )
.pipe( replace( negateBridgePattern, "" ) )
.pipe( replace( serverPattern, "" ) )
.pipe( replace( clientPattern, "" ) )
.pipe( replace( ignoreOpenPattern, "//: @ignore:\n/*" ) )
.pipe( replace( ignoreClosePattern, "*/\n//: @end-ignore" ) )
.pipe( sourcemap.init( ) )
.pipe( babel( ) )
.pipe( sourcemap.write( "./" ) )
.pipe( replace( ignoreOpenCommentPattern, "//: @ignore:" ) )
.pipe( replace( ignoreCloseCommentPattern, "//: @end-ignore" ) )
.pipe( changed( "./", {
"hasChanged": changed.compareContents,
} ) )
.pipe( debug( { "title": "Bridge File Done:" } ) )
.pipe( gulp.dest( "./" ) );
} );
let defaultTask = [ ];
if( parameter.all ){
defaultTask.push( "server" );
defaultTask.push( "client" );
}else if( parameter.server ){
defaultTask.push( "server" );
}else if( parameter.client ){
defaultTask.push( "client" );
}else if( parameter.bridge ){
defaultTask.push( "bridge" );
}else{
throw new Error( "no task specified" );
}
gulp.task( "default", defaultTask );