-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
67 lines (57 loc) · 1.87 KB
/
build.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
/* eslint-disable no-console */
const fs = require('fs-extra')
const glob = require('glob')
const { execSync } = require('child_process')
const os = require('os')
const path = require('path')
const moveCommand = os.platform() === 'win32' ? 'move' : 'mv'
const sourcePath = 'out/_next'
const destinationPath = 'out/next'
try {
execSync(`${moveCommand} ${sourcePath} ${destinationPath}`)
console.log('Moved _next directory to next.')
} catch (error) {
console.error('Move operation failed:', error)
}
const main = () => {
const extensionPath = 'extension'
fs.ensureDirSync(extensionPath)
if (fs.existsSync(extensionPath)) {
// Get a list of all files and directories in 'extensionPath'
const files = fs.readdirSync(extensionPath)
// Loop through all files and directories
for (const file of files) {
// Get the full path of the file/directory
const filePath = path.join(extensionPath, file)
// Remove the file/directory
fs.removeSync(filePath)
}
}
// Replace content in HTML and JS files
const files = glob.sync('out/**/*.{html,js}', { nodir: true })
for (const file of files) {
let content = fs.readFileSync(file, 'utf-8')
content = content.replace(/\/_next\//g, '/next/')
fs.writeFileSync(file, content, 'utf-8')
}
// Perform related operations
fs.moveSync(
path.join('out', 'index.html'),
path.join(extensionPath, 'index.html'),
)
fs.moveSync(
path.join('out', 'favicon.png'),
path.join(extensionPath, 'favicon.png'),
)
fs.copySync(path.join('out', 'next'), path.join(extensionPath, 'next'))
fs.copySync(path.join('_locales'), path.join(extensionPath, '_locales'))
fs.removeSync('out')
fs.copySync('background.js', path.join(extensionPath, 'background.js'))
fs.copySync('manifest.json', path.join(extensionPath, 'manifest.json'))
console.log('Processing completed.')
}
try {
main()
} catch (error) {
console.error('An error occurred:', error)
}