-
Notifications
You must be signed in to change notification settings - Fork 0
/
prebuild.js
99 lines (76 loc) · 2.53 KB
/
prebuild.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
const fs = require('fs')
const CopyPlugin = require("copy-webpack-plugin")
const EventHooksPlugin = require('event-hooks-webpack-plugin')
const EnvPlugin = require('webpack').EnvironmentPlugin
const writeData = ()=>{
// Text data
const EN = JSON.parse(fs.readFileSync('./public/common/_locales/en/messages.json', 'utf8'))
const APP_DESC = EN['APP_DESC'].message
// Description for Extension and PWA manifests
const setDesc = path => {
const result = JSON.parse(fs.readFileSync(path, 'utf8'))
result.description = APP_DESC//updateValue(data.description)
fs.writeFileSync(path, JSON.stringify(result, undefined, 2))
}
setDesc('./src/manifest.json')
setDesc('./public/web/manifest.json')
// Types for messages
fs.writeFileSync(
'./src/messages.d.json.ts',
`export default ${JSON.stringify(EN,undefined,2)} as const`
)
// sets desc in index.html
const indexPath = './public/web/index.html'
fs.writeFileSync(indexPath,
fs.readFileSync(indexPath,'utf8').replace(/(<meta\s+name="description"\s+content=")(.*)(")/, '$1'+APP_DESC+'$3')
)
}
const getPlugins = (EXTENSION)=>[
new EventHooksPlugin({'environment': writeData}),
new EnvPlugin({
"REACT_APP_ENV": EXTENSION ? "" : "REACT_APP_ENV",
}),
new CopyPlugin({
patterns: EXTENSION ?
['../public/extention','../public/common'] :
[{from:'./public/common',to:'./static'}]
})
]
module.exports.EXT = getPlugins(true)
module.exports.WEB = getPlugins(false)
/* const updateValue = (value)=>{
const key = value?.trim().match(/^%(.*)%$/)?.[1]
return key !== undefined ? EN[key].message : value
}
const modifyJSON = (path, mod)=>{
const result = JSON.parse(fs.readFileSync(path, 'utf8'))
mod(result)
fs.writeFileSync(path, JSON.stringify(result, undefined, 2))
} */
/* /// EXT
let CopyPlugin = require("copy-webpack-plugin")
let EnvPlugin = require('webpack').EnvironmentPlugin
module.exports = {
packageTarget:'dist/extension/packages',
webpack: (config)=>{
config.plugins.push(new EnvPlugin({"REACT_APP_ENV":""}))
config.plugins.push(new CopyPlugin({
patterns:['../public/extention','../public/common']
}))
return config
}
}
/// WEB
let EnvPlugin = require('webpack').EnvironmentPlugin
let CopyPlugin = require("copy-webpack-plugin")
let
module.exports = (config, env)=>{
config.plugins = [
new EnvPlugin({
"REACT_APP_ENV":"REACT_APP_ENV"
"REACT_APP_APP_DESC":''
}),
new CopyPlugin({patterns:[{from:'./public/common',to:'./static'}]}),
...config.plugins]
return config
} */