-
Notifications
You must be signed in to change notification settings - Fork 11
/
script.js
34 lines (31 loc) · 914 Bytes
/
script.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
/*
* The AGPL License (AGPL)
* Copyright (c) 2022 hans000
*/
const path = require('path')
const fs = require('fs')
const configList = [
{
filename: './src/components/MainEditor/index.tsx',
mark: 'loadConfig',
isLocal: true,
code: `
import { loadLocalMocano } from './local';
if (! import.meta.env.DEV) {
loadLocalMocano()
}`,
},
]
configList.forEach(config => {
handle(config)
})
function handle(config) {
const filename = path.resolve(config.filename)
const text = fs.readFileSync(filename).toString()
const reg = new RegExp(`//#region ${config.mark}(\\s|\\S)*?//#endregion`)
const code = process.env.VITE_LOCAL + '' === config.isLocal + ''
? `//#region ${config.mark}${config.code}\n//#endregion`
: `//#region ${config.mark}\n//#endregion`
const newText = text.replace(reg, code)
fs.writeFileSync(filename, newText)
}