-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
49 lines (42 loc) · 1 KB
/
cli.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
#!/usr/bin/env node
'use strict'
const fs = require('fs')
const render = require('./index.js')
const path = require('path')
const pkg = require('./package.json');
if(process.argv[2] === '-v'){
console.log('version', pkg.version)
return;
}
if(typeof process.argv[2] === 'undefined'){
console.log('no file')
return
}
let filepath = path.join(process.cwd(), process.argv[2])
const checkAccess = function(path){
return new Promise((resolve,reject)=>{
fs.access(path, fs.R_OK, (err, s) => {
if(err){
reject("unable to access file" + process.argv[2])
return
}
resolve()
})
})
}
const output = function(html,path) {
var out = fs.createWriteStream(path, {
flags: "w",
encoding: "utf8",
mode: parseInt('0644',8)
})
out.write(html)
out.end()
}
checkAccess(filepath).then(()=>{
var htmlPath = process.argv[2].replace('jsx','html')
output(render(filepath),htmlPath)
console.log('\n'+'Successfully created: '+htmlPath+'\n')
},(err)=>{
console.log(err)
})