-
Notifications
You must be signed in to change notification settings - Fork 3
/
fluid.js
executable file
·46 lines (41 loc) · 1.21 KB
/
fluid.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
#!/usr/bin/env node
const { program } = require('commander');
const fs = require('node:fs');
const webFS = require('fs').promises;
const filenameRegex = /\w+\.yml/ //may need to expand character set
const express = require('express');
const serve = require('express-static');
const app = express();
const host = '127.0.0.1';
const port = 8080;
program.command('load')
.arguments('<file>')
.action(function(file)
{
if (file.match(filenameRegex) != null)
{
try
{
//read data stream if file is large
//const data = fs.readFileSync(__dirname + "/" + file, 'utf8');
const data = fs.readFileSync(process.cwd() + "/" + file, 'utf8'); //assuming file is located at command line's current directory
console.log(data);
app.use(serve(__dirname + '/dist/article'));
const server = app.listen(port, host, function()
{
console.log("Server running: " + __dirname + '/dist/article\n' +
`Access on http://${host}:${port}`
);
})
}
catch (err)
{
console.error(err);
}
}
else
{
console.error("Invalid input file: Must be a .yml file.")
}
});
program.parse()