-
Notifications
You must be signed in to change notification settings - Fork 25
/
md-to-js.js
executable file
·56 lines (51 loc) · 1.54 KB
/
md-to-js.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
// @ts-check
const shell = require('shelljs')
const path = require('path')
const globby = require('globby')
const pluralize = require('pluralize')
const { findCypressVersion } = require('./src/utils')
// converts Markdown fiddle specs into JavaScript specs
let baseUrl = process.argv[2]
if (!baseUrl) {
const DEFAULT_BASE_URL = `http://localhost:5000/cypress-examples`
console.log('Setting empty baseUrl to %s', DEFAULT_BASE_URL)
baseUrl = DEFAULT_BASE_URL
}
console.log(
'Each spec file will visit %s before tests in each spec',
baseUrl,
)
const rootFolder = 'docs'
const markdownFiles = globby.sync([
`${rootFolder}/**/*.md`,
// we skip the recipes Markdown files,
// let's not make JavaScript spec out of it
`!${rootFolder}/recipes/**/*.md`,
// also skip the root index file
`!${rootFolder}/index.md`,
])
console.log(
'%d Markdown %s',
markdownFiles.length,
pluralize('file', markdownFiles.length, false),
)
console.log(markdownFiles.join('\n'))
markdownFiles.forEach((filename) => {
const inRoot = path.relative(rootFolder, filename)
const pagePath = inRoot.replace(/\.md$/, '')
// navigation spec is a little different - it will navigate to its page itself
const beforeVisitUrl = filename.endsWith('navigation.md')
? baseUrl
: `${baseUrl}/${pagePath}`
shell.exec(
`npx export-fiddles ${filename} --before ${beforeVisitUrl}`,
)
})
shell.exec('ls -lAR docs/**/*.js')
console.log(
'You can run these specs against %s with command',
baseUrl,
)
console.log(
'npx cypress open --config-file cypress-dist.config.js',
)