This repository has been archived by the owner on Jun 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathgulpfile.js
99 lines (80 loc) · 3.38 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
const gulp = require('gulp');
const zip = require('gulp-zip');
const exec = require('child_process').exec;
const fs = require('fs');
const src_dir = 'extension';
const dest_dir = 'build';
const dest_dir2 = 'build\\source';
const dest_dir3 = 'build\\toolbox\\edgeextension\\manifest\\';
const package_dir = 'build/toolbox/edgeextension/package';
const output_dir = 'build/output';
const assets = 'edgeAssets';
function execute(execCommand, callback) {
exec(execCommand, function (err, stdout, stderr) {
console.log('stdout:', stdout);
console.log('stderr:', stderr);
console.log('err:', err);
let success = stderr ? false : true;
callback(success);
});
}
// Tasks
gulp.task('zip', function() {
console.log(process.cwd());
let ignores = fs.readFileSync(src_dir+'/.chromeignore').toString().split("\n");
for (let i = 0; i < ignores.length; i++) {
if (ignores[i].startsWith("/")) {
ignores[i] = "!"+src_dir+ignores[i];
}
else {
ignores[i] = "!"+ignores[i];
}
}
return gulp.src([src_dir+'/**'].concat(ignores))
.pipe(zip('chrome-moderator-toolbox.zip'))
.pipe(gulp.dest(output_dir));
});
gulp.task('manifoldJS', function() {
console.log(process.cwd());
let ignores = fs.readFileSync(src_dir+'/.chromeignore').toString().split("\n");
for (let i = 0; i < ignores.length; i++) {
if (ignores[i].startsWith("/")) {
ignores[i] = "!"+src_dir+ignores[i];
}
else {
ignores[i] = "!"+ignores[i];
}
}
gulp.src([src_dir+'/**'].concat(ignores))
.pipe(gulp.dest(dest_dir2));
// Hacky? Yes, very much but it seems to work
execute(`manifoldjs -l error -p edgeextension -f edgeextension -m ${dest_dir2}\\manifest.json -d ${dest_dir}`, function(result) {
if(result) {
gulp.src([assets+'/**'])
.pipe(gulp.dest(dest_dir3+'\\Assets'));
let appxManifestXML = fs.readFileSync(`${dest_dir3}/appxmanifest.xml`).toString();
appxManifestXML = appxManifestXML.replace('INSERT-YOUR-PACKAGE-IDENTITY-NAME-HERE', '2471toolboxTeam.moderatortoolboxforreddit');
appxManifestXML = appxManifestXML.replace('CN=INSERT-YOUR-PACKAGE-IDENTITY-PUBLISHER-HERE', 'CN=8F6C891B-BA96-48EA-AFFE-227374B8192B');
appxManifestXML = appxManifestXML.replace('INSERT-YOUR-PACKAGE-PROPERTIES-PUBLISHERDISPLAYNAME-HERE', 'toolboxTeam');
appxManifestXML = appxManifestXML.replace(/Version="\d\.(\d\.\d\.\d)" \/>/, 'Version="$1.0" />');
fs.writeFileSync(`${dest_dir3}/appxmanifest.xml`, appxManifestXML, 'utf8', function(err) {
if (err) {
throw err;
}
console.log('The file has been saved!');
});
execute(`manifoldjs -l debug -p edgeextension package ${dest_dir3} -d ${dest_dir}`, function(result) {
if(result) {
gulp.src([package_dir+'/**'])
.pipe(gulp.dest(output_dir));
console.log('edge package build');
} else {
console.log('problem executing second manifoldJS round');
}
});
} else {
console.log('problem executing first manifoldJS round');
}
});
});
gulp.task('default', ['zip', 'manifoldJS']);