-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
142 lines (116 loc) · 3.68 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
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
// generated on 2016-03-02 using generator-openmrs-owa 0.1.0
'use strict';
var fs = require('fs');
var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var del = require('del');
var mainBowerFiles = require('main-bower-files');
var wiredep = require('wiredep').stream;
var livereload = require('gulp-livereload');
var gutil = require('gulp-util');
var plugins = gulpLoadPlugins();
var THIS_APP_ID = 'SystemAdministration';
var THIS_APP_VERSION = '1.4.0-SNAPSHOT';
var htmlGlob = ['app/**/*.html'];
var resourcesGlob = ['app/**/*.{png,svg,jpg,gif}', 'app/**/*.{css,less}',
'app/**/*.js', 'app/**/*.{ttf,woff}', 'app/manifest.webapp', /* list extra resources here */ ];
var Server = require('karma').Server;
var getConfig = function () {
var config;
try {
// look for config file
config = require('./config.json');
} catch (err) {
// create file with defaults if not found
config = {
'LOCAL_OWA_FOLDER': 'C:\\\\Users\\\\user\\\\openmrs\\\\SystemAdministration\\\\owa\\\\'
};
fs.writeFile('config.json', JSON.stringify(config), function(err) {
if(err) {
return gutil.log(err);
}
gutil.log("Default config file created");
});
} finally {
return config;
}
}
/**
* Run test once and exit
*/
// gulp.task('test', function (done) {
// new Server({
// configFile: __dirname + '/test/karma.conf.js',
// singleRun: true
// }, done).start();
// });
// gulp.task('test-debug', function (done) {
// new Server({
// configFile: __dirname + '/test/karma.conf.js',
// singleRun: false
// }, done).start();
// });
gulp.task('copy-bower-packages', function() {
try {
fs.statSync('bower_components');
return gulp.src(mainBowerFiles(), {
base: 'bower_components'
}).pipe(gulp.dest('dist/lib'));
} catch (err) {
// Don't panic
}
});
gulp.task('html', ['copy-bower-packages'], function() {
try {
fs.statSync('bower_components');
// User wiredep to automagically link bower packages
return gulp.src(htmlGlob).pipe(wiredep({
ignorePath: '../bower_components/',
fileTypes: {
html: {
replace: {
js: '<script src="lib/{{filePath}}"></script>',
css: '<link rel="stylesheet" href="lib/{{filePath}}" />'
}
}
}
})).pipe(gulp.dest('dist'));
} catch (err) {
return gulp.src(htmlGlob)
.pipe(gulp.dest('dist'));
}
});
gulp.task('resources', function() {
return gulp.src(resourcesGlob)
.pipe(gulp.dest('dist'));
});
gulp.task('watch', function() {
livereload.listen();
gulp.watch('app/*', ['deploy-local']);
gulp.watch('app/**/*.*', ['deploy-local']);
});
gulp.task('deploy-local', ['build'], function() {
var config = getConfig();
return gulp.src(['dist/**/*', '!*.zip'])
.pipe(gulp.dest(config.LOCAL_OWA_FOLDER + THIS_APP_ID));
});
gulp.task('build', ['resources', 'html'], function() {
return gulp.src('dist/**/*')
.pipe(plugins.zip(THIS_APP_ID + '-' + THIS_APP_VERSION + '.zip'))
.pipe(gulp.dest('.'));
});
gulp.task('clean', del.bind(null, ['dist']));
gulp.task('default', ['clean'], function() {
gulp.start('build');
});