forked from AdguardTeam/AdguardBrowserExtension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser-opera.js
More file actions
79 lines (64 loc) · 2.45 KB
/
browser-opera.js
File metadata and controls
79 lines (64 loc) · 2.45 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
/*
* Opera build is the same as Chromium build but includes it own filters.
* This task is running after Chromium build, so we need to copy Chromium folder
* and include Opera filters files. To zip Opera build folder if release.
*/
import fs from 'fs';
import path from 'path';
import gulp from 'gulp';
import modifyFile from 'gulp-modify-file';
import zip from 'gulp-zip';
import Crx from 'crx';
import {
BUILD_DIR, BRANCH_RELEASE, PRIVATE_FILES,
} from './consts';
import { version } from './parse-package';
// set current type of build
const BRANCH = process.env.NODE_ENV || '';
const paths = {
filtersOpera: path.join('Extension/filters/opera/**/*'),
chromium: path.join(BUILD_DIR, BRANCH, `chrome-${version}`, '**/*'),
chromiumManifest: path.join(BUILD_DIR, BRANCH, `chrome-${version}`, 'manifest.json'),
cert: path.join(PRIVATE_FILES, 'certificate.pem'),
dest: path.join(BUILD_DIR, BRANCH, `opera-${version}`),
};
const dest = {
filters: path.join(paths.dest, 'filters'),
inner: path.join(paths.dest, '**/*'),
buildDir: path.join(BUILD_DIR, BRANCH),
};
// copy chromium build dir
const copyChromiumFiles = () => gulp.src(paths.chromium).pipe(gulp.dest(paths.dest));
// replace chromium filters by opera filters
const copyFiltersOpera = () => gulp.src(paths.filtersOpera).pipe(gulp.dest(dest.filters));
// copy chromium manifest, and update it
const modifyManifest = () => gulp
.src(paths.chromiumManifest)
.pipe(modifyFile((content, path, file) => {
const manifest = JSON.parse(content);
const updatedManifest = {
...manifest,
minimum_opera_version: '42',
};
return JSON.stringify(updatedManifest, null, 4);
}))
.pipe(gulp.dest(paths.dest));
const createArtifactBuild = () => gulp.src(dest.inner)
.pipe(zip('opera.zip'))
.pipe(gulp.dest(BUILD_DIR));
const crxPack = async (done) => {
if (BRANCH !== BRANCH_RELEASE) {
return done();
}
const privateKey = await fs.promises.readFile(paths.cert, 'utf-8');
const crx = new Crx({
privateKey,
});
await crx.load(paths.dest);
const crxBuffer = await crx.pack();
const crxBuildFilename = `opera-${BRANCH}-${version}.crx`;
const crxBuildPath = path.join(dest.buildDir, crxBuildFilename);
await fs.promises.writeFile(crxBuildPath, crxBuffer);
return done;
};
export default gulp.series(copyChromiumFiles, copyFiltersOpera, modifyManifest, createArtifactBuild, crxPack);