forked from bywatersolutions/dev-koha-plugin-kitchen-sink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
146 lines (134 loc) · 5.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const gulp = require('gulp');
const release = require('gulp-github-release');
const fs = require('fs');
const run = require('gulp-run');
const dateTime = require('node-datetime');
const Vinyl = require('vinyl');
const path = require('path');
const stream = require('stream');
const dt = dateTime.create();
const today = dt.format('Y-m-d');
const package_json = JSON.parse(fs.readFileSync('./package.json'));
const release_filename = `${package_json.name}-v${package_json.version}.kpz`;
const pm_name = 'KitchenSink';
const pm_file = pm_name+'.pm';
const pm_file_path = path.join('Koha', 'Plugin', 'Com', 'ByWaterSolutions');
const pm_file_path_full = path.join(pm_file_path, pm_file);
const pm_file_path_dist = path.join('dist', pm_file_path);
const pm_file_path_full_dist = path.join(pm_file_path_dist, pm_file);
const pm_bundle_path = path.join(pm_file_path, pm_name);
/**
*
* Array of directories relative to pm_bundle_path where static files will be served
*
* If no static files need to be served, set static_relative_path = []
*
*/
const static_relative_path = ['static_files', 'datepicker'];
var static_absolute_path = [];
if(static_relative_path.length) {
static_absolute_path = static_relative_path.map(dir=>path.join(pm_bundle_path, dir)+'/**/*');
}
console.log(release_filename);
console.log(pm_file_path_full_dist);
gulp.task('static', ()=>{
if(static_absolute_path.length) {
let spec_body = JSON.stringify({
get: {
'x-mojo-to': 'Static#get',
tags: ['pluginStatic'],
responses: {
200: {
description: 'File found',
schema: {
type: 'file'
}
},
404: {
description: 'File not found',
schema: {
type: 'object',
properties: {
error: {
description: "An explanation for the error",
type: "string"
}
}
}
},
400: {
description: 'Bad request',
schema: {
type: 'object',
properties: {
error: {
description: "An explanation for the error",
type: "string"
}
}
}
},
500: {
description: 'Internal server error',
schema: {
type: 'object',
properties: {
error: {
description: "An explanation for the error",
type: "string"
}
}
}
}
}
}
}, null, 2);
return gulp.src(static_absolute_path)
.pipe(new stream.Transform({
objectMode: true,
transform: (file, unused, cb) => {
if(file.stat.isDirectory()) return cb();
let path_name = path.join('/', path.relative(pm_bundle_path, file.base), file.relative);
console.log('creating '+path_name);
let endpoint_spec = '"'+path_name+'": '+ spec_body;
file.contents = Buffer.from(endpoint_spec);
cb(null, file);
}
}))
.pipe(new stream.Transform({
objectMode: true,
transform: function(file, unused, cb) {
!this.bufArray && (this.bufArray = []);
this.bufArray.push(file.contents);
cb();
}
}))
.on('finish', function() {
let file = new Vinyl({
path: 'staticapi.json',
contents: Buffer.from('{\n'+this.bufArray.map(buf=>buf.toString()).join(',\n')+'\n}')
});
this.emit('data', file);
this.end();
})
.pipe(gulp.dest(pm_bundle_path));
}
});
gulp.task('build', ['static'], () => {
run(`
mkdir dist ;
cp -r Koha dist/. ;
sed -i -e "s/{VERSION}/${package_json.version}/g" ${pm_file_path_full_dist} ;
sed -i -e "s/1900-01-01/${today}/g" ${pm_file_path_full_dist} ;
cd dist ;
zip -r ../${release_filename} ./Koha ;
cd .. ;
rm -rf dist ;
`).exec();
});
gulp.task('release', () => {
gulp.src(release_filename)
.pipe(release({
manifest: require('./package.json') // package.json from which default values will be extracted if they're missing
}));
});