forked from raineorshine/solidity-by-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
29 lines (24 loc) · 899 Bytes
/
build.js
File metadata and controls
29 lines (24 loc) · 899 Bytes
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
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const promisify = require('bluebird').promisify
const globAsync = promisify(glob)
const repoRoot = 'https://github.com/raineorshine/solidity-by-example/blob/master/'
const readmeTemplateFile = 'README-template.md'
const readmeFile = 'README.md'
const readmePlaceholder = '<%=examples%>'
function renderExamples(files) {
return files.map(file => {
const filename = path.basename(file)
const src = fs.readFileSync(file, 'utf-8')
return `### ${filename}\n\`\`\`js\n${src}\n\`\`\`\n`
}).join('\n')
}
function renderReadme(content) {
const readmeTemplate = fs.readFileSync(readmeTemplateFile, 'utf-8')
return readmeTemplate.replace(readmePlaceholder, content)
}
globAsync('**/*.sol')
.then(renderExamples)
.then(renderReadme)
.then(fileContent => fs.writeFileSync(readmeFile, fileContent))