This repository has been archived by the owner on Mar 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathgulpfile.js
112 lines (104 loc) · 2.87 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
/* global require process Buffer */
var gulp = require('gulp');
var cssnano = require('gulp-cssnano');
var gutil = require('gulp-util');
var replace = require('gulp-replace');
var dest = require('gulp-dest');
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', ['less'], function (ready) {
var requirejs = require('requirejs');
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(replace('"./', '"' + 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
};
if (pkg.contributors) {
qext.contributors = pkg.contributors;
}
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(replace(/^/,
'define([], function () {var style = document.createElement("style");style.innerHTML = "'))
.pipe(replace(/$/, '";document.head.appendChild(style);});'))
.pipe(dest('', {
ext: '.js'
}))
.pipe(gulp.dest(SRC));
});
gulp.task('clean', function (ready) {
var del = require('del');
del.sync([DIST, TMP]);
ready();
});
gulp.task('build',['clean', 'requirejs', 'qext'], function () {
var zip = require('gulp-zip');
setTimeout(function () {
gulp.src([DIST + '/**/*.qext', DIST + '/**/*.js'])
.pipe(zip(NAME + '.zip'))
.pipe(gulp.dest(DIST));
}, 1000);
});
gulp.task('debug', ['less', 'qext'], function () {
return gulp.src([DIST + '/**/*.qext', SRC + '/**/*.js'])
.pipe(gulp.dest(DEPLOY));
});
gulp.task('deploy', ['less', 'qext', 'requirejs'], function () {
return gulp.src([DIST + '/**/*.qext', DIST + '/**/*.js'])
.pipe(gulp.dest(DEPLOY));
});
gulp.task('default', ['build']);