-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathgulpfile.js
146 lines (132 loc) · 4.18 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
143
144
145
146
const { src, dest, watch, parallel, series, task } = require("gulp");
const zip = require("gulp-zip");
const replace = require("gulp-replace");
const sequence = require("run-sequence");
const git = require("gulp-git");
const conventionalChangelog = require("gulp-conventional-changelog");
const fs = require("fs");
const signAddon = require("sign-addon").default;
const APP_PATH = "./app/";
const DIST_PATH = "./dist/";
const OUTPUT_PATH = "./web-ext-artifacts/";
function changelog() {
return src("CHANGELOG.md", {
buffer: false
})
.pipe(
conventionalChangelog({
preset: "angular" // Or to any other commit message convention you use.
})
)
.pipe(dest("./"));
}
function commitChanges() {
return (
src(["./package.json", "./CHANGELOG.md", "./app/manifest.json"])
.pipe(git.add())
// to avoid issue https://github.com/stevelacy/gulp-git/issues/186
.pipe(
git.commit(undefined, {
args: '-m "build: release ' + process.env.NEW_VERSION + '"',
disableMessageRequirement: true,
disableAppendPaths: true
})
)
.on("error", function(error) {
console.log(error);
})
);
}
function pushChanges(done) {
git.push('origin', 'master', done);
return done();
}
function createNewTag(done) {
var version = getPackageJsonVersion();
git.tag(version, version, function(error) {
if (error) {
return done(error);
}
git.push('origin', 'master', {args: '--tags'}, done);
return done();
});
function getPackageJsonVersion() {
// We parse the json file instead of using require because require caches
// multiple calls so the version number won't be updated
return JSON.parse(fs.readFileSync("./package.json", "utf8")).version;
}
}
function manifestVersion() {
return src([DIST_PATH + "manifest.json"])
.pipe(replace(/(.*"version": ")(.*)(",.*)/g, "$1" + process.env.NEW_VERSION + "$3"))
.pipe(dest(DIST_PATH));
}
function manifestAppVersion() {
return src([APP_PATH + "manifest.json"])
.pipe(replace(/(.*"version": ")(.*)(",.*)/g, "$1" + process.env.NEW_VERSION + "$3"))
.pipe(dest(APP_PATH));
}
function packageVersion() {
return src(["./package.json"])
.pipe(replace(/(.*"version": ")(.*)(",.*)/g, "$1" + process.env.NEW_VERSION + "$3"))
.pipe(dest("./"));
}
function xpi() {
const manifest = require(DIST_PATH + "manifest.json");
const distFileName = manifest.name + "-" + manifest.version + ".xpi";
return src([DIST_PATH + "/**"])
.pipe(zip(distFileName))
.pipe(dest(OUTPUT_PATH));
}
function zipDist() {
const manifest = require(DIST_PATH + "manifest.json");
const distFileName = manifest.name + "-" + manifest.version + ".zip";
return src([DIST_PATH + "/**"])
.pipe(zip(distFileName))
.pipe(dest(OUTPUT_PATH));
}
function zipApp() {
const manifest = require(DIST_PATH + "manifest.json");
const distFileName = manifest.name + "-app-" + manifest.version + ".zip";
return src([APP_PATH + "/**"])
.pipe(zip(distFileName))
.pipe(dest(OUTPUT_PATH));
}
function sign() {
const manifest = require(DIST_PATH + "manifest.json");
const distFileName = manifest.name + "-" + manifest.version + ".xpi";
signAddon({
xpiPath: OUTPUT_PATH + distFileName,
version: manifest.version,
apiKey: process.env.AMO_API_KEY,
apiSecret: process.env.AMO_API_SECRET,
downloadDir: OUTPUT_PATH,
channel: "listed",
id: "{024f65fd-47e3-4556-bd93-4c0a1d08cd33}"
})
.then(function(result) {
if (result.success) {
console.log("The following signed files were downloaded:");
console.log(result.downloadedFiles);
console.log("Your extension ID is:");
console.log(result.id);
} else {
console.error("Your add-on could not be signed!");
console.error("Check the console for details.");
}
console.log(result.success ? "SUCCESS" : "FAIL");
})
.catch(function(error) {
console.error("Signing error:", error);
});
}
exports.changelog = changelog;
exports.release = series(
parallel(manifestVersion, manifestAppVersion, packageVersion),
changelog,
commitChanges,
pushChanges,
createNewTag,
parallel(xpi, zipDist, zipApp),
sign
);