Skip to content

Commit 9c207ba

Browse files
committed
gulp builder
1 parent d48a428 commit 9c207ba

8 files changed

Lines changed: 297 additions & 11 deletions

File tree

Blocks/BlocksInstaller.cls.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ This method is invoked when a class is compiled.</Description>
4343
write !, "Creating WEB application """_..#CSPAPP_"""..."
4444
$$$ThrowOnError(##class(Security.Applications).Create(..#CSPAPP, .cspProperties))
4545
write !, "WEB application """_..#CSPAPP_""" created."
46+
if ##class(%Studio.General).GetWebServerPort(,,,.url) {
47+
write !, "You can now open it with a link: "_url_$p(..#CSPAPP,"/",2,*)_"/"
48+
}
4649
} else {
4750
write !, "WEB application """_..#CSPAPP_""" already exists, so it is ready to use."
4851
}

Blocks/Router.cls.xml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,28 @@
3232
}
3333
set xdata = ##class(%Dictionary.XDataDefinition).%OpenId(..%ClassName(1)_"||"_tName)
3434
if $isobject(xdata) {
35-
quit xdata.Data.OutputToDevice()
35+
set status=##class(%XML.TextReader).ParseStream(xdata.Data, .textreader)
36+
set isBase64=xdata.Description["*base64*"
37+
if $isobject(textreader) {
38+
set data=""
39+
while textreader.Read() {
40+
if (textreader.NodeType="chars") {
41+
if isBase64 {
42+
set data=data_textreader.Value
43+
set data=$translate(data,$char(13,10))
44+
set data4Decode=$extract(data,1,$length(data)\4*4)
45+
write $system.Encryption.Base64Decode(data4Decode)
46+
set data=$extract(data,$length(data4Decode)+1,*)
47+
} else {
48+
write textreader.Value
49+
}
50+
}
51+
}
52+
write $system.Encryption.Base64Decode(data)
53+
quit $$$OK
54+
} else {
55+
quit xdata.Data.OutputToDevice()
56+
}
3657
}
3758
3859
set tName = %request.GetCgiEnv("SCRIPT_FILENAME")

BlocksExplorer.prj.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Export generator="Cache" version="25">
3-
<Project name="BlocksExplorer" LastModified="2015-09-20 17:14:55.040791">
3+
<Project name="BlocksExplorer" LastModified="2015-11-20 09:31:52.586313">
44
<Items>
55
<ProjectItem name="Blocks.BlocksInstaller" type="CLS"></ProjectItem>
66
<ProjectItem name="Blocks.Router" type="CLS"></ProjectItem>
77
<ProjectItem name="Blocks.WebSocket" type="CLS"></ProjectItem>
8-
<ProjectItem name="csp/blocks/index.html" type="CSP"></ProjectItem>
9-
<ProjectItem name="csp/blocks/css/main.css" type="CSP"></ProjectItem>
10-
<ProjectItem name="csp/blocks/css/joint.all.min.css" type="CSP"></ProjectItem>
11-
<ProjectItem name="csp/blocks/js/mapViewer.js" type="CSP"></ProjectItem>
12-
<ProjectItem name="csp/blocks/js/main.js" type="CSP"></ProjectItem>
13-
<ProjectItem name="csp/blocks/js/joint.shapes.blocks.js" type="CSP"></ProjectItem>
14-
<ProjectItem name="csp/blocks/js/joint.all.min.js" type="CSP"></ProjectItem>
15-
<ProjectItem name="csp/blocks/js/blocksViewer.js" type="CSP"></ProjectItem>
168
</Items>
179
</Project>
1810
</Export>

gulp-cachebuild/index.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
var through = require('through2')
2+
var gutil = require('gulp-util')
3+
var PluginError = gutil.PluginError
4+
var File = gutil.File
5+
var fs = require('fs')
6+
var xml2js = require('xml2js')
7+
var parser = new xml2js.Parser({
8+
attrKey: '$',
9+
preserveChildrenOrder: true,
10+
async: true,
11+
explicitCharkey: true,
12+
explicitRoot: false,
13+
explicitArray: true
14+
})
15+
var builder = new xml2js.Builder({
16+
cdata: true,
17+
rootName: 'Export'
18+
})
19+
20+
var types = {
21+
'Class': 'CLS',
22+
'CSP': 'CSP',
23+
'CSPBase64': 'CSP'
24+
}
25+
26+
module.exports = function(file, options) {
27+
options = options || {}
28+
29+
var xml = {
30+
'$': {}
31+
}
32+
var project = {
33+
'$': {},
34+
'Items': [{
35+
ProjectItem: []
36+
}]
37+
}
38+
39+
if (typeof file === 'string') {
40+
fileName = file
41+
} else if (typeof file.path === 'string') {
42+
fileName = path.basename(file.path)
43+
} else {
44+
throw new PluginError('gulp-cachebuild', 'Missing path in file options for gulp-cachebuild')
45+
}
46+
47+
function bufferContents(file, enc, cb) {
48+
if (file.isNull()) {
49+
cb()
50+
return
51+
}
52+
53+
if (file.isStream()) {
54+
cb()
55+
return
56+
}
57+
58+
var data = String(file.contents).replace(/\r/g, '')
59+
parser.parseString(data, function(err, result) {
60+
var exportData = result
61+
if (!xml.$.generator && exportData.$.generator) xml.$.generator = exportData.$.generator
62+
if (!xml.$.version && exportData.$.version) xml.$.version = exportData.$.version
63+
var keys = Object.keys(exportData)
64+
keys.forEach(function(key) {
65+
if (key == '$') {
66+
return
67+
}
68+
var items = exportData[key]
69+
items.forEach(function(exportItem) {
70+
var type = key === 'Routine' ? exportItem.$.type : types[key]
71+
console.log(key, file.path)
72+
if (key == 'Project') {
73+
project.$.name = exportItem.$.name
74+
} else if (type) {
75+
var name = exportItem.$.name
76+
console.log(type, name)
77+
if (type == 'CSP' && options.cspApplication) {
78+
exportItem.$.application = options.cspApplication
79+
}
80+
xml[key] = xml[key] || []
81+
xml[key].push(exportItem)
82+
83+
var name = exportItem.$.name
84+
if (exportItem.$.application) {
85+
name = exportItem.$.application + name
86+
}
87+
88+
project.Items[0].ProjectItem.push({
89+
'$': {
90+
name: name,
91+
type: type
92+
}
93+
})
94+
}
95+
})
96+
})
97+
cb()
98+
})
99+
}
100+
101+
function endStream(cb) {
102+
if (!xml) {
103+
cb()
104+
return
105+
}
106+
107+
xml.Project = [project]
108+
109+
var cacheFile = new File({
110+
cwd: '',
111+
base: '',
112+
path: fileName,
113+
contents: new Buffer(builder.buildObject(xml))
114+
})
115+
this.push(cacheFile)
116+
cb()
117+
}
118+
119+
return through.obj(bufferContents, endStream)
120+
}

gulp-cachebuild/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "gulp-cachebuild",
3+
"version": "0.0.1",
4+
"description": "Concat Cache project in one file",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "MIT",
11+
"dependencies": {
12+
"fs": "0.0.2",
13+
"gulp-util": "^3.0.7",
14+
"through2": "^2.0.0",
15+
"xml2js": "^0.4.15"
16+
}
17+
}

gulpfile.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
var gulp = require('gulp')
2+
var clean = require('gulp-clean')
3+
var concat = require('gulp-concat')
4+
var uglify = require('gulp-uglify')
5+
var cheerio = require('gulp-cheerio')
6+
var htmlReplace = require('gulp-html-replace')
7+
var fs = require('fs')
8+
var cacheBuilder = require('./gulp-cachebuild')
9+
10+
gulp.task('default', ['build'])
11+
12+
gulp.task('build', ['xml'])
13+
14+
gulp.task('clean', function() {
15+
return gulp.src([
16+
'./build/'
17+
], {
18+
read: false
19+
})
20+
.pipe(clean())
21+
})
22+
23+
gulp.task('html', ['clean'], function() {
24+
return gulp.src('index.html')
25+
.pipe(htmlReplace({
26+
js: 'js/app.min.js',
27+
css: 'css/styles.min.css'
28+
}))
29+
.pipe(gulp.dest('./build/'))
30+
})
31+
32+
gulp.task('js', ['clean'], function() {
33+
return gulp.src([
34+
'js/joint.all.min.js',
35+
'js/joint.shapes.blocks.js',
36+
'js/blocksViewer.js',
37+
'js/mapViewer.js',
38+
'js/wsEventDispatcher.js',
39+
'js/main.js'
40+
])
41+
.pipe(concat('app.min.js'))
42+
.pipe(uglify({
43+
44+
}))
45+
.pipe(gulp.dest('./build/js/'))
46+
})
47+
48+
gulp.task('css', ['clean'], function() {
49+
return gulp.src([
50+
'css/joint.all.min.css',
51+
'css/main.css'
52+
])
53+
.pipe(concat('styles.min.css'))
54+
.pipe(gulp.dest('./build/css/'))
55+
})
56+
57+
58+
gulp.task('xml', ['clean', 'css', 'js', 'html'], function() {
59+
return gulp.src([
60+
'./BlocksExplorer.prj.xml',
61+
'./Blocks/**/*.xml'
62+
])
63+
.pipe(cacheBuilder('CacheBlocksExplorer.xml', {
64+
cspApplication: ''
65+
}))
66+
.pipe(cheerio({
67+
run: function($, file) {
68+
var staticFiles = [{
69+
name: 'index.html',
70+
file: './build/index.html'
71+
}, {
72+
name: 'js/app.min.js',
73+
file: './build/js/app.min.js'
74+
}, {
75+
name: 'css/styles.min.css',
76+
file: './build/css/styles.min.css'
77+
}]
78+
79+
staticFiles.map(function(fileInfo) {
80+
try {
81+
$('Class[name="Blocks.Router"]').append($('<XData>')
82+
.attr('name', fileInfo.name.replace(/\./g, '_'))
83+
.append('<Description>*base64*</Description>')
84+
.append(
85+
$('<Data><![CDATA[ <data>' + (fs.readFileSync(fileInfo.file, {
86+
encoding: 'base64'
87+
})).replace(/[\n\r]/g, '') + '</data> ]]> </Data>')
88+
)
89+
)
90+
} catch (err) {
91+
console.log(err)
92+
}
93+
})
94+
95+
},
96+
parserOptions: {
97+
xmlMode: true,
98+
prettify: true
99+
}
100+
}))
101+
.pipe(gulp.dest('./build/'))
102+
})

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
<head lang="en">
55
<meta charset="UTF-8">
66
<title>Cache Blocks explorer</title>
7+
<!-- build:css -->
78
<link rel="stylesheet" href="css/joint.all.min.css">
89
<link rel="stylesheet" href="css/main.css">
10+
<!-- endbuild -->
911
<link id="favicon" rel="shortcut icon" href="#" />
1012
</head>
1113

@@ -52,12 +54,14 @@
5254
<div class='blockInfo item'>
5355
</div>
5456
</div>
57+
<!-- build:js -->
5558
<script src="js/joint.all.min.js"></script>
5659
<script src="js/joint.shapes.blocks.js"></script>
5760
<script src="js/blocksViewer.js"></script>
5861
<script src="js/mapViewer.js"></script>
5962
<script src="js/wsEventDispatcher.js"></script>
6063
<script src="js/main.js"></script>
64+
<!-- endbuild-->
6165
</body>
6266

6367
</html>

package.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,32 @@
33
"version": "0.0.1",
44
"description": "Cache Blocks Explorer",
55
"author": "daimor",
6-
"license": "MIT"
6+
"license": "MIT",
7+
"dependencies": {},
8+
"devDependencies": {
9+
"fs": "0.0.2",
10+
"gulp": "^3.9.0",
11+
"gulp-bower-src": "^0.1.0",
12+
"gulp-cheerio": "^0.6.2",
13+
"gulp-clean": "^0.3.1",
14+
"gulp-concat": "^2.6.0",
15+
"gulp-html-replace": "^1.5.4",
16+
"gulp-minify-css": "^1.2.1",
17+
"gulp-postcss": "^6.0.1",
18+
"gulp-replace": "^0.5.4",
19+
"gulp-uglify": "^1.4.2",
20+
"inspect": "0.0.2",
21+
"main-bower-files": "^2.9.0"
22+
},
23+
"scripts": {
24+
"test": "echo \"Error: no test specified\" && exit 1"
25+
},
26+
"repository": {
27+
"type": "git",
28+
"url": "https://github.com/daimor/CacheBlocksExplorer.git"
29+
},
30+
"bugs": {
31+
"url": "https://github.com/daimor/CacheBlocksExplorer/issues"
32+
},
33+
"homepage": "https://github.com/daimor/CacheBlocksExplorer"
734
}

0 commit comments

Comments
 (0)