forked from OBKoro1/stop-mess-around
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
56 lines (49 loc) · 1.72 KB
/
deploy.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
/*
* Author : OBKoro1
* Date : 2021-06-18 11:08:23
* LastEditors : OBKoro1
* LastEditTime : 2021-07-30 01:50:19
* FilePath : deploy.js
* Description : 同步package.json的配置到manifest.json中
* koroFileheader插件
* Copyright (c) ${now_year} by OBKoro1, All Rights Reserved.
*/
const path = require('path')
const fs = require('fs')
// 插件版本与描述
const VERSION = process.env.npm_package_version
let DESCRIPTION = '防摸鱼插件: 通过强制的手段禁止大家浪费时间摸鱼:在上班/学习期间下意识的打开摸鱼网站, 自动检测摸鱼网站, 提示激励信息后, 关闭摸鱼网站, 滚去学习,滚去做对未来有益的事情!'
let PLUGINNAME = 'stop-mess-around'
const { argv } = process
const env = argv[2]
if (env !== 'production') {
PLUGINNAME = 'stop-mess-around-file'
DESCRIPTION = `file: ${DESCRIPTION}`
}
const templateOption = {
DESCRIPTION,
VERSION,
PLUGINNAME,
}
updateFillBuilderYAML(templateOption)
// 修改manifest.template.json配置,替换manifest.production.json
function updateFillBuilderYAML(option) {
const ELECTRON_BUILDER_TEMPLATE = path.resolve(
__dirname,
'src',
'manifest.template.json',
)
const ELECTRON_BUILDER_OUTPUT = path.resolve(__dirname, 'src', 'manifest.production.json')
let content = fs.readFileSync(ELECTRON_BUILDER_TEMPLATE).toString()
// 替换匹配到的每个变量
Object.entries(option).forEach(
([key, val]) => {
content = content.replace(createReg(key), val)
},
)
fs.writeFileSync(ELECTRON_BUILDER_OUTPUT, content)
}
// 根据变量名构建一个正则,匹配对应模板中的变量表示
function createReg(variable) {
return new RegExp(`{{${variable}}}`, 'g')
}