1+ var gulp = require ( "gulp" ) ,
2+ fs = require ( "fs" ) ,
3+ clean = require ( "gulp-clean" ) ,
4+ concat = require ( "gulp-concat" ) ,
5+ uglify = require ( "gulp-uglify" ) ,
6+ wrap = require ( "gulp-wrap" ) ,
7+ minifyCSS = require ( "gulp-minify-css" ) ,
8+ htmlReplace = require ( "gulp-html-replace" ) ,
9+ header = require ( "gulp-header" ) ,
10+ replace = require ( "gulp-replace" ) ,
11+ pkg = require ( "./package.json" ) ,
12+ zip = require ( "gulp-zip" ) ,
13+ rename = require ( "gulp-rename" ) ;
14+
15+ var banner = [
16+ "/** <%= pkg.name %>" ,
17+ " ** <%= pkg.description %>" ,
18+ " ** @author <%= pkg.author %>" ,
19+ " ** @version <%= pkg.version %>" ,
20+ " ** @license <%= pkg.license %>" ,
21+ " ** @see https://github.com/ZitRos/CacheUMLExplorer" ,
22+ " **/" ,
23+ ""
24+ ] . join ( "\n" ) ;
25+
26+ gulp . task ( "clean" , function ( ) {
27+ return gulp . src ( "build" , { read : false } )
28+ . pipe ( clean ( ) ) ;
29+ } ) ;
30+
31+ gulp . task ( "gatherScripts" , [ "clean" ] , function ( ) {
32+ return gulp . src ( [
33+ "web/jsLib/joint.min.js" ,
34+ "web/jsLib/joint.shapes.uml.js" ,
35+ "web/jsLib/joint.layout.DirectedGraph.min.js" ,
36+ "web/js/*.js"
37+ ] )
38+ . pipe ( concat ( "CacheUMLExplorer.js" ) )
39+ . pipe ( replace ( / \/ \* \{ \{ r e p l a c e : v e r s i o n } } \* \/ / , "\"" + pkg [ "version" ] + "\"" ) )
40+ //.pipe(wrap("CacheUMLExplorer = (function(){<%= contents %> return CacheUMLExplorer;}());"))
41+ . pipe ( uglify ( {
42+ output : {
43+ ascii_only : true ,
44+ width : 30000 ,
45+ max_line_len : 30000
46+ }
47+ } ) )
48+ . pipe ( header ( banner , { pkg : pkg } ) )
49+ . pipe ( gulp . dest ( "build/web/js/" ) ) ;
50+ } ) ;
51+
52+ //gulp.task("concatScripts", ["gatherScripts"], function () {
53+ // return gulp.src([
54+ // "web/jsLib/joint.min.js",
55+ // "web/jsLib/joint.layout.DirectedGraph.min.js",
56+ // "web/jsLib/joint.shapes.uml.js",
57+ // "build/web/js/CacheUMLExplorer.js"
58+ // ])
59+ // .pipe(concat("CacheUMLExplorer.js"))
60+ // .pipe(gulp.dest("build/web/js/"));
61+ //});
62+
63+ gulp . task ( "gatherCSS" , [ "clean" ] , function ( ) {
64+ return gulp . src ( "web/css/*.css" )
65+ . pipe ( concat ( "CacheUMLExplorer.css" ) )
66+ . pipe ( minifyCSS ( ) )
67+ . pipe ( gulp . dest ( "build/web/css/" ) ) ;
68+ } ) ;
69+
70+ gulp . task ( "addHTMLFile" , [ "clean" ] , function ( ) {
71+ return gulp . src ( "web/index.html" )
72+ . pipe ( htmlReplace ( {
73+ "css" : "css/CacheUMLExplorer.css" ,
74+ "js" : "js/CacheUMLExplorer.js"
75+ } ) )
76+ . pipe ( gulp . dest ( "build/web/" ) ) ;
77+ } ) ;
78+
79+ gulp . task ( "addHTMLZIPFile" , [ "clean" , "gatherScripts" , "gatherCSS" ] , function ( ) {
80+ var jsRepl = "<script type='text/javascript'>" + fs . readFileSync ( "build/web/js/CacheUMLExplorer.js" , "utf-8" ) + "</script>" ,
81+ cssRepl = "<style type='text/css'>" + fs . readFileSync ( "build/web/css/CacheUMLExplorer.css" ) + "</style>" ;
82+ return gulp . src ( "web/index.html" )
83+ . pipe ( concat ( "ZIPindex.html" ) )
84+ . pipe ( replace ( / < ! \- \- b u i l d : j s \- \- > ( .| \r | \n ) * < ! \- \- e n d b u i l d \- \- > / , function ( ) { return jsRepl ; } ) )
85+ . pipe ( replace ( / < ! \- \- b u i l d : c s s \- \- > ( .| \r | \n ) * < ! \- \- e n d b u i l d \- \- > / , function ( ) { return cssRepl ; } ) )
86+ . pipe ( gulp . dest ( "build/web" ) ) ;
87+ } ) ;
88+
89+ gulp . task ( "copyLICENSE" , [ "clean" ] , function ( ) {
90+ return gulp . src ( "LICENSE" )
91+ . pipe ( gulp . dest ( "build/" ) ) ;
92+ } ) ;
93+
94+ gulp . task ( "copyREADME" , [ "clean" ] , function ( ) {
95+ return gulp . src ( "readme.md" )
96+ . pipe ( gulp . dest ( "build/" ) ) ;
97+ } ) ;
98+
99+ gulp . task ( "exportCacheXML" , [
100+ "clean" , "gatherCSS" , "addHTMLFile" , "addHTMLZIPFile" , "copyLICENSE" , "copyREADME"
101+ ] , function ( ) {
102+ return gulp . src ( "cache/projectTemplate.xml" )
103+ . pipe (
104+ replace ( / \{ \{ r e p l a c e : H T M L } } / ,
105+ fs . readFileSync ( "build/web/ZIPindex.html" , "utf-8" ) )
106+ )
107+ . pipe ( rename ( function ( path ) { path . basename += "-v" + pkg [ "version" ] ; } ) )
108+ . pipe ( gulp . dest ( "build/Cache" ) ) ;
109+ } ) ;
110+
111+ gulp . task ( "zipRelease" , [ "exportCacheXML" ] , function ( ) {
112+ return gulp . src ( "build/**/*" )
113+ . pipe ( zip ( "CacheUMLExplorer-v" + pkg [ "version" ] + ".zip" , {
114+ comment : "Cach? UML explorer v" + pkg [ "version" ] + " by Nikita Savchenko\n\n" +
115+ "+ WEBModule folder holds packed JS/CSS files to integrate CacheUMLExplorer to any WEB " +
116+ "application;\n" +
117+ "+ Cache folder holds XML file to import to InterSystems Cache.\n\n" +
118+ "For further information about installation and information, check README.md file."
119+ } ) )
120+ . pipe ( gulp . dest ( "build" ) ) ;
121+ } ) ;
122+
123+ gulp . task ( "desktop" , [ "default" ] , function ( ) {
124+ return gulp . src ( "build/Cache/*" )
125+ . pipe ( gulp . dest ( "C:/Users/ZitRo/Desktop" ) ) ;
126+ } ) ;
127+
128+ gulp . task ( "default" , [ "zipRelease" ] ) ;
0 commit comments