-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
49 lines (37 loc) · 1.14 KB
/
common.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
import path from "path"
import { fileURLToPath } from 'url'
import {readFile, writeFile} from 'fs'
let folderName = 'dist-'
let zipName
const isProduction = process.env.NODE_ENV === 'production'
const browser = process.env.BROWSER
if (! isProduction) {
folderName += 'dev-'
} else if (process.env.STAGING) {
folderName += 'staging-'
}
if (browser) {
folderName += browser
if (isProduction) {
zipName=browser+'.zip'
}
} else {
folderName += 'unknown'
}
export const __filename = fileURLToPath(import.meta.url)
export const __dirname = path.dirname(__filename)
export const distPath = path.join(__dirname, folderName)
export const zipFile = zipName ? path.join(__dirname, zipName) : ''
const background_file = path.join(distPath, 'background.js')
export const replaceBackgroundFile = () => {
readFile(background_file, 'utf-8', function (err, contents) {
if (err) {
console.log(err);
return;
}
const replaced = contents.replace(/ *document.baseURI *\|\|/g, '');
writeFile(background_file, replaced, 'utf-8', function (err) {
console.log(err);
});
});
}