This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
forked from FilipePS/Traduzir-paginas-web
-
-
Notifications
You must be signed in to change notification settings - Fork 234
/
gulpfile.js
100 lines (89 loc) · 2.72 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
const gulp = require("gulp");
const zip = require("gulp-zip");
const fs = require("fs");
const babel = require("gulp-babel");
const sourcemaps = require("gulp-sourcemaps");
const manifest = require("./src/manifest.json");
const replace = require('gulp-replace');
const concat = require('gulp-concat');
gulp.task("clean", (cb) => {
fs.rmSync("dist", { recursive: true, force: true });
cb();
});
gulp.task("firefox-copy", () => {
return gulp.src(["src/**/**"]).pipe(gulp.dest("dist/firefox"));
});
gulp.task("firefox-babel", () => {
return gulp
.src(["dist/firefox/background/*.js"])
.pipe(sourcemaps.init())
.pipe(
babel({
presets: ["@babel/preset-env"],
})
)
.pipe(sourcemaps.write())
.pipe(gulp.dest("dist/firefox/background"));
});
gulp.task("firefox-zip", () => {
return gulp
.src(["dist/firefox/**/*"])
.pipe(zip("firefox.zip"))
.pipe(gulp.dest("dist"));
});
gulp.task("chrome-copy", () => {
return gulp.src(["src/**/**"]).pipe(gulp.dest("dist/chrome"));
});
gulp.task("chrome-rename", (cb) => {
fs.renameSync(
"dist/chrome/manifest.json",
"dist/chrome/firefox_manifest.json"
);
fs.renameSync(
"dist/chrome/chrome_manifest.json",
"dist/chrome/manifest.json"
);
cb();
});
gulp.task("chrome-babel", () => {
return gulp
.src(["dist/chrome/background/*.js"])
.pipe(sourcemaps.init())
.pipe(
babel({
presets: ["@babel/preset-env"],
})
)
.pipe(sourcemaps.write())
.pipe(gulp.dest("dist/chrome/background"));
});
gulp.task("chrome-concat-background",()=>{
return gulp.src(["/lib/languages.js", "/lib/config.js", "/lib/platformInfo.js","/lib/util.js", "/background/translationCache.js", "/background/translationService.js", "/background/chrome_background.js"].map(item=>"dist/chrome"+item))
.pipe(concat('background-entry.js'))
.pipe(gulp.dest('dist/chrome/background'));
})
gulp.task("chrome-zip", () => {
return gulp
.src(["dist/chrome/**/**"])
.pipe(zip("chrome.zip"))
.pipe(gulp.dest("dist"));
});
gulp.task("chrome-replace",()=>{
return gulp.src(["dist/chrome/**/*.html"])
.pipe(replace("__IMMERSIVE_TRANSLATE_VERSION__",manifest.version))
.pipe(gulp.dest("dist/chrome/"));
})
gulp.task("firefox-replace",()=>{
return gulp.src(["dist/firefox/**/*.html"])
.pipe(replace("__IMMERSIVE_TRANSLATE_VERSION__",manifest.version))
.pipe(gulp.dest("dist/firefox"));
})
gulp.task(
"firefox-build",
gulp.series("firefox-copy", "firefox-babel", "firefox-replace","firefox-zip")
);
gulp.task(
"chrome-build",
gulp.series("chrome-copy", "chrome-rename", "chrome-babel", "chrome-replace","chrome-concat-background","chrome-zip")
);
gulp.task("default", gulp.series("clean", "firefox-build", "chrome-build"));