-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
convert.js
executable file
·51 lines (39 loc) · 1.44 KB
/
convert.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
#!/usr/bin/env node
/* eslint-disable quotes */
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const eslintRe = /\/. eslint.+\s+/g
function replaceStringsIn (file) {
fs.readFile(file, 'utf8', function (err, str) {
if (err) throw err
const replace = function (source, dest) {
str = str.split(source).join(dest)
}
replace('http://localhost:8080', 'https://example.cypress.io')
replace("to.eq('localhost:8080')", "to.eq('example.cypress.io')")
replace("to.eq('localhost')", "to.eq('example.cypress.io')")
replace("to.eq('8080')", "to.eq('')")
replace("to.eq('http:')", "to.eq('https:')")
replace(eslintRe, "")
replace("imgSrcToDataURL('/assets", "imgSrcToDataURL('https://example.cypress.io/assets")
// temporary for 5.0.0
// TODO: remove this
replace("whitelist: 'session_id'", "preserve: 'session_id'")
replace("server.whitelist", "server.ignore")
fs.writeFile(file, str, function (err) {
if (err) throw err
// eslint-disable-next-line no-console
console.log(`Converted ${path.relative(process.cwd(), file)} successfully.`)
})
})
}
glob('./app/**/*.html', { realpath: true }, (err, htmlFiles) => {
if (err) throw err
glob('./cypress/integration/examples/**/*', { realpath: true }, (err, specFiles) => {
if (err) throw err
htmlFiles.concat(specFiles).forEach(function (file) {
return replaceStringsIn(file)
})
})
})