-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.cjs
105 lines (99 loc) · 3.38 KB
/
gulpfile.cjs
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
const { src, dest } = require("gulp");
const tar = require('gulp-tar');
const gzip = require('gulp-gzip');
const modifyFile = require('gulp-modify-file');
const jsonModify = require('gulp-json-modify')
const path = require('path')
function addKnownUserExports(content) {
content = "var exportObject = {};\n" + content;
content += `
var Utils = exportObject.Utils;
var KnownUser = exportObject.KnownUser;
export { KnownUser, Utils };`;
const lastPropertyDefinition = content.lastIndexOf('Object.defineProperty(');
const newLine = content.indexOf('\n', lastPropertyDefinition);
const firstPart = content.substring(0, newLine);
const secondPart = content.substring(newLine + 1);
return firstPart + `
exportObject.KnownUser = KnownUser_1.KnownUser;
exportObject.Utils = QueueITHelpers_1.Utils;
` + secondPart;
}
function addQueueTokenExports(content) {
content = "var exportObject = {};\n" + content;
content += `
var Token = exportObject.Token;
var Payload = exportObject.Payload;
export { Payload, Token };`;
const tokenPropertyDefinition = content.indexOf('Object.defineProperty(exports, "Token"');
const newLine = content.indexOf('},', tokenPropertyDefinition);
const firstPart = content.substring(0, newLine - 2);
const secondPart = content.substring(newLine - 1);
return firstPart + `
exportObject.Payload = Payload_1.Payload;
exportObject.Token = Token_1.Token;
` + secondPart;
}
exports.packageArtifacts = () => {
return src([
'bundle.json',
'dist/*.js',
'dist/**/*.js'
])
.pipe(modifyFile((content, filePath, _) => {
let filename = path.basename(filePath);
if (filename === 'queueit-knownuserv3-sdk.js') {
content = addKnownUserExports(content);
}
if (filename === 'queueToken.js') {
content = addQueueTokenExports(content);
}
return content;
}))
.pipe(tar('kuedge.tar'))
.pipe(gzip())
.pipe(dest('dist'));
}
exports.prepare = () => {
return src([
'sdk/*.js'
])
.pipe(modifyFile((content, filePath, _) => {
let filename = path.basename(filePath);
if (filename === 'queueit-knownuserv3-sdk.js') {
content = addKnownUserExports(content);
}
if (filename === 'queueToken.js') {
content = addQueueTokenExports(content);
}
return content;
}))
.pipe(dest('dist/sdk'));
}
exports.stripPackage = () => {
return src(['./package.json'])
.pipe(jsonModify({ key: 'devDependencies', value: {} }))
.pipe(jsonModify({ key: 'scripts', value: {} }))
.pipe(dest('./'))
}
exports.packageForDeployment = () => {
return src([
'bundle.json',
'edgegrid.edgerc',
'dist/*.js',
'dist/**/*.js'
])
.pipe(modifyFile((content, filePath, _) => {
let filename = path.basename(filePath);
if (filename === 'queueit-knownuserv3-sdk.js') {
content = addKnownUserExports(content);
}
if (filename === 'queueToken.js') {
content = addQueueTokenExports(content);
}
return content;
}))
.pipe(tar('kuedge.deployment.tar'))
.pipe(gzip())
.pipe(dest('dist'));
}