-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·48 lines (43 loc) · 1.43 KB
/
index.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
#!/usr/bin/env node
"use strict";
var Cli = new require("n-cli");
var cli = new Cli({
silent: false,
handleUncaughtException : true,
});
cli.on("serve", function(){
var fs = require('fs');
var express = require('express');
var https = require('https');
var path = require('path');
var cors = require('cors')
var key = fs.readFileSync(path.join(__dirname,'/ssl/key.pem'));
var cert = fs.readFileSync(path.join(__dirname,'/ssl/cert.pem'));
var https_options = {
key: key,
cert: cert
};
var PORT = this.argv._[1] || 8081
var HOST = 'localhost';
var app = express();
app.use(cors());
app.use(express.static(process.cwd()));
app.get('/list', function (req, res) {
var dirs = fs.readdirSync(process.cwd()).filter(file => fs.statSync(path.join(process.cwd(), file)).isDirectory());
for(key in dirs){
if (!fs.existsSync(path.join(process.cwd(),dirs[key],"manifest.json"))) {
dirs.splice(key,1);
}
}
res.setHeader('Content-Type', 'application/json');
return res.send(JSON.stringify(dirs));
});
var server = https.createServer(https_options, app).listen(PORT, HOST);
console.log('HTTPS Server listening on %s:%s', HOST, PORT);
});
cli.on("create", function() {
var env = require('yeoman-environment').createEnv();
env.lookup(function() {
env.run('ekstep-content-plugin', {'name': cli.argv._[1]});
});
});