-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgenerate_demos.js
40 lines (33 loc) · 1.36 KB
/
generate_demos.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
const fs = require('fs')
const path = require('path')
const wrench = require('wrench')
const demos = require('./demos.json')
var template = fs.readFileSync(path.join('./template.html')).toString()
var content = ''
if (!fs.existsSync(path.join('./dist'))) {
fs.mkdirSync(path.join('./dist'))
}
for (var i in demos.demos) {
var item = demos.demos[i]
content += `
<div class="item-demo">
<h1 class="text-strong">${item.label}</h1>
<p>${item.description}</p>
<button class="border-blue blue radius small" onclick="runDemo('${item.key}')">Run demo</button>
<button class="border-blue text-blue radius small" onclick="openSource('${item.key}')">Source Code</button>
<div class="line margin-bottom"></div>
</div>
`
fs.writeFileSync(path.join(item.path, 'www', 'cordova.js'), fs.readFileSync(path.join(demos.mock_dir), { encoding: 'utf-8' }))
wrench.copyDirSyncRecursive(item.path, path.join('./dist', item.key), {
forceDelete: true
})
}
var index = template.replace(`<!-- SPACE-GENERATE-DOCS -->`, `<div class="content-list-demo padding">${content}</div>`)
fs.writeFileSync(path.join('./dist', 'index.html'), index)
if (!fs.existsSync(path.join(demos.site_dir, 'demos/'))) {
fs.mkdirSync(path.join(demos.site_dir, 'demos/'))
}
wrench.copyDirSyncRecursive('./dist', path.join(demos.site_dir, 'demos/'), {
forceDelete: true
})