forked from AdguardTeam/AdguardBrowserExtension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser-firefox-amo.js
More file actions
133 lines (116 loc) · 4.04 KB
/
browser-firefox-amo.js
File metadata and controls
133 lines (116 loc) · 4.04 KB
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
/**
* Firefox AMO build is the same as Firefox-webext build but in this case
* remote scripts are not allowed.
* 1. Copying common scripts and htmls (pages, lib, locales)
* 2. Copying Firefox filters
* 3. Copying Webkit, Chrome and Firefox_webext scripts
* 4. Updating version of an extension in manifest and changing update_url if its a beta build
* 5. Change the extension name in localization files based on a type of a build (dev, beta or release)
* 6. Preprocessing files with the AMO param for prohibition of remote scripts
* 7. Creating firefox web-extension pack
*/
import fs from 'fs';
import path from 'path';
import gulp from 'gulp';
import webExt from 'web-ext';
import zip from 'gulp-zip';
import {
BUILD_DIR,
BRANCH_DEV,
BRANCH_BETA,
BRANCH_RELEASE,
FIREFOX_WEBEXT,
FIREFOX_EXTENSION_ID_BETA,
FIREFOX_EXTENSION_ID_RELEASE,
FIREFOX_EXTENSION_ID_DEV,
} from './consts';
import { version } from './parse-package';
import { updateLocalesMSGName, preprocessAll } from './helpers';
import copyCommonFiles from './copy-common';
import copyExternal from './copy-external';
// set current type of build
const BRANCH = process.env.NODE_ENV || '';
const paths = {
firefox_webext: path.join('Extension/browser/firefox_webext/**/*'),
filters: path.join('Extension/filters/firefox/**/*'),
chromeFiles: path.join('Extension/browser/chrome/**/*'),
webkitFiles: path.join('Extension/browser/webkit/**/*'),
dest: path.join(BUILD_DIR, BRANCH, (BRANCH === BRANCH_DEV)
? `firefox-amo-${version}`
: `firefox-amo-${BRANCH}-${version}-unsigned`),
};
const dest = {
filters: path.join(paths.dest, 'filters'),
inner: path.join(paths.dest, '**/*'),
buildDir: path.join(BUILD_DIR, BRANCH),
manifest: path.join(paths.dest, 'manifest.json'),
webext: path.join(BUILD_DIR, BRANCH, `firefox-amo-${BRANCH}-${version}-unsigned.zip`),
};
// copy common files
const copyCommon = () => copyCommonFiles(paths.dest);
// copy firefox filters
const copyFilters = () => gulp.src(paths.filters)
.pipe(gulp.dest(dest.filters));
// copy chromium, webkit files and firefox_webext files
const firefoxWebext = () => gulp.src([paths.webkitFiles, paths.chromeFiles, paths.firefox_webext])
.pipe(gulp.dest(paths.dest));
// preprocess with params
const preprocess = done => preprocessAll(paths.dest, {
browser: FIREFOX_WEBEXT,
remoteScripts: false,
}, done);
// change the extension name based on a type of a build (dev, beta or release)
const localesProcess = done => updateLocalesMSGName(BRANCH, paths.dest, done, FIREFOX_WEBEXT);
const updateManifest = (done) => {
const manifest = JSON.parse(fs.readFileSync(dest.manifest));
let extensionID = '';
switch (BRANCH) {
case BRANCH_BETA:
extensionID = FIREFOX_EXTENSION_ID_BETA;
break;
case BRANCH_RELEASE:
extensionID = FIREFOX_EXTENSION_ID_RELEASE;
break;
case BRANCH_DEV:
extensionID = FIREFOX_EXTENSION_ID_DEV;
break;
default:
throw new Error(`This is impossible branch: ${BRANCH}`);
}
manifest.version = version;
manifest.applications.gecko.id = extensionID;
fs.writeFileSync(dest.manifest, JSON.stringify(manifest, null, 4));
return done();
};
const createArtifactBuild = (done) => {
if (BRANCH !== BRANCH_BETA && BRANCH !== BRANCH_RELEASE) {
return done();
}
return gulp.src(dest.inner)
.pipe(zip('firefox.zip'))
.pipe(gulp.dest(BUILD_DIR));
};
const createWebExt = (done) => {
if (BRANCH !== BRANCH_BETA && BRANCH !== BRANCH_RELEASE) {
return done();
}
return webExt.cmd.build({
sourceDir: paths.dest,
artifactsDir: dest.buildDir,
overwriteDest: true,
}).then((file) => {
fs.renameSync(file.extensionPath, dest.webext);
done();
});
};
export default gulp.series(
copyExternal,
copyCommon,
copyFilters,
firefoxWebext,
updateManifest,
localesProcess,
preprocess,
createArtifactBuild,
createWebExt
);