forked from erikwett/qsVariable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
107 lines (95 loc) · 3.04 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
var gulp = require('gulp');
var cssnano = require('gulp-cssnano');
var runSequence = require('run-sequence');
var gutil = require('gulp-util');
var pkg = require('./package.json');
var DIST = './dist',
SRC = './src',
TMP = './tmp',
MAIN = pkg.main.substring(0,pkg.main.indexOf('.')),
NAME = pkg.name,
DEPLOY = process.env.HOMEDRIVE + process.env.HOMEPATH + '/Documents/Qlik/Sense/Extensions/' + NAME;
gulp.task('requirejs', function (ready) {
var requirejs = require('requirejs');
var replace = require('gulp-replace');
var DIRNAME = "extensions/" + MAIN + "/";
requirejs.optimize({
baseUrl: SRC,
paths: {
"qlik": "empty:"
},
include: [MAIN],
exclude: ['qlik'],
// optimize : 'uglify',
findNestedDependencies: true,
out: TMP + '/' + MAIN + '.js'
}, function () {
gulp.src(TMP + '/' + MAIN + '.js').
pipe(replace('define("' + MAIN + '",', 'define(')).
pipe(replace('define("', 'define("'+DIRNAME)).
pipe(gulp.dest(DIST));
ready();
}, function (error) {
console.error('requirejs task failed', JSON.stringify(error));
process.exit(1);
});
});
gulp.task('qext', function () {
var qext = {
name:pkg.name,
description: pkg.description,
version: pkg.version,
type: 'visualization',
author: pkg.author,
};
var src = require('stream').Readable({ objectMode: true })
src._read = function () {
this.push(new gutil.File({ cwd: "", base: "", path: MAIN+'.qext',
contents: new Buffer(JSON.stringify(qext,null,4)) }));
this.push(null);
}
return src.pipe(gulp.dest(DIST));
});
gulp.task('less', function () {
var less = require('gulp-less');
var LessPluginAutoPrefix = require('less-plugin-autoprefix');
var autoprefix = new LessPluginAutoPrefix({
browsers: ["last 2 versions"]
});
return gulp.src(SRC + '/**/*.less')
.pipe(less({
plugins: [autoprefix]
}))
.pipe(cssnano())
.pipe(gulp.dest(DIST));
});
gulp.task('css', function () {
return gulp.src(SRC + '/**/*.css')
.pipe(cssnano())
.pipe(gulp.dest(DIST));
});
gulp.task('clean', function (ready) {
var del = require('del');
del.sync([DIST, TMP]);
ready();
});
gulp.task('zip-build', ['qext', 'less', 'css', 'requirejs'], function () {
var zip = require('gulp-zip');
return gulp.src(DIST + '/**/*')
.pipe(zip(NAME + '.zip'))
.pipe(gulp.dest(DIST));
});
gulp.task('build', function () {
return runSequence('clean',
'zip-build'
);
});
gulp.task('debug', ['less','qext'], function () {
return gulp.src([DIST + '/**/*.qext', SRC + '/**/*.js', DIST + '/**/*.css'])
.pipe(gulp.dest(DEPLOY));
});
gulp.task('deploy', ['less','qext','css', 'requirejs'], function () {
return gulp.src([DIST + '/**/*.qext', DIST + '/**/*.js', DIST + '/**/*.css'])
.pipe(gulp.dest(DEPLOY));
});
gulp.task('default', ['build']);