-
Notifications
You must be signed in to change notification settings - Fork 1
/
markdown.config.js
173 lines (138 loc) · 4.67 KB
/
markdown.config.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* CLI markdown.config.js file */
var fs = require('fs')
var path = require('path')
var markdownMagic = require('markdown-magic')
var readline = require('readline')
var pkg = fs.readFileSync('package.json', 'utf8')
var ver = JSON.parse(pkg).version
var git_branch = JSON.parse(pkg).git_branch
var c = [
`[![npm package](https://img.shields.io/badge/npm-${ver}-blue.svg)](https://www.npmjs.com/package/keet)`,
`[![browser build](https://img.shields.io/badge/rawgit-${ver}-ff69b4.svg)](https://cdn.rawgit.com/syarul/keet/${git_branch}/keet-min.js)`,
`[![npm module downloads](https://img.shields.io/npm/dt/keet.svg)](https://www.npmjs.com/package/keet)`,
`[![Build Status](https://travis-ci.org/syarul/keet.svg?branch=${git_branch})](https://travis-ci.org/syarul/keet)`,
`[![Coverage Status](https://coveralls.io/repos/github/syarul/keet/badge.svg?branch=${git_branch})](https://coveralls.io/github/syarul/keet?branch=${git_branch})`,
`[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)`
]
var files = ['hello', 'counter', 'conditional-nodes','model', 'sub-component']
var parse = {}
var config = {
transforms: {
/* Match <!-- AUTO-GENERATED-CONTENT:START (SHEILDS) --> */
SHEILDS (content, options) {
return c.join(' ')
},
VER () {
return `# Keet v${ver}`
},
EXAMPLES () {
return `For more usage cases visit the [examples](https://github.com/syarul/keet/tree/${git_branch}/examples) directory`
},
HELLO () {
return `\`\`\`js\n${parse['hello']}\`\`\``
},
COUNTER () {
return `\`\`\`js\n${parse['counter']}\`\`\``
},
CONDITIONAL_NODES () {
return `\`\`\`js\n${parse['conditional-nodes']}\`\`\``
},
MODEL () {
return `\`\`\`js\n${parse['model']}\`\`\``
},
SUB_COMPONENT () {
return `\`\`\`js\n${parse['sub-component']}\`\`\``
}
}
}
var markdownPath = path.join(__dirname, 'README.md')
function next(i, files){
if(i < files.length){
var file = files[i]
var rd = readline.createInterface({
input: fs.createReadStream(`examples/${file}.js`),
output: process.stdout,
terminal: false
})
parse[file] = ''
rd.on('line', function (line) {
if(!line.match('// rem')){
if(line.match(/\.\.\/\'/g)){
line = line.replace(/\.\.\/\'/, 'keet\'')
} else if(line.match(/\.\.\/utils/g)){
line = line.replace(/\.\.\/utils/, 'keet\/utils')
if(line.match(', getId '))
line = line.replace(', getId ', ' ')
}
parse[file] += line + '\n'
}
})
rd.on('close', function(){
i++
next(i, files)
})
} else {
markdownMagic(markdownPath, config)
}
}
next(0, files)
String.prototype.replaceAt = function (index, replacement) {
return this.substr(0, index) + replacement + this.substr(index + replacement.length)
}
function ReadLine2 (file) {
var rd = readline.createInterface({
input: fs.createReadStream(file),
output: process.stdout,
terminal: false
})
var c = 0
file = file.replace(/([^:]\/)\/+/g, '$1')
console.log('\nparsing ' + file + '...')
var info = ''
rd.on('line', function (line) {
c++
if (c > 0 && c < 11) {
info += line + '\n'
if (c === 10) {
console.log(info)
var data = fs.readFileSync('./keet-min.js'); //read existing contents into data
var fd = fs.openSync('./keet-min.js', 'w+');
var buffer = new Buffer(info);
fs.writeSync(fd, buffer, 0, buffer.length, 0); //write new data
fs.writeSync(fd, data, 0, data.length, buffer.length); //append old data
fs.close(fd);
}
}
})
}
function ReadLine (file) {
var rd = readline.createInterface({
input: fs.createReadStream(file),
output: process.stdout,
terminal: false
})
var c = 0
file = file.replace(/([^:]\/)\/+/g, '$1')
console.log('\nparsing ' + file + '...')
rd.on('line', function (line) {
c++
if (c === 3) {
var newLine = line.replaceAt(11, ver)
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
return console.log(err)
}
line = line.substr(3)
newLine = newLine.substr(3)
var re = new RegExp(line, 'g')
var result = data.replace(re, newLine)
console.log(re, newLine)
fs.writeFile(file, result, 'utf8', function (err) {
if (err) return console.log(err)
ReadLine2('./keet.js')
})
})
}
})
}
ReadLine('./keet.js')