-
Notifications
You must be signed in to change notification settings - Fork 19
/
.embed.js
33 lines (28 loc) · 879 Bytes
/
.embed.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
const fs = require('fs')
const path = require('path')
const b = path.join(__dirname, './build')
const contents = []
fs.readFileSync(path.join(b, './index.html'), 'utf-8')
.split(/<\/script>/g)
.forEach(v => {
const src = v.match(/<script.+src="(.+)">$/)?.[1]
if (src) {
contents.push(fs.readFileSync(path.join(b, src), 'utf-8'))
return
}
const content = v.match(/<script.*>(.+)$/)?.[1]
if (content) {
contents.push(content)
return
}
})
if (!contents.length) {
console.error('.embed.js error: can not find any script tag for embed api')
process.exit(1)
}
console.log(`.embed.js total script tags: ${contents.length}`)
fs.writeFileSync(path.join(b, 'webphone.js'), contents.join(';\n'))
const p = path.join(__dirname, './public')
fs.copyFileSync(
...[p, b].map(d => path.join(d, './webphone_embed_example.html')),
)