Skip to content

Commit

Permalink
#77 feat(ui.router.js) disable or enable ui
Browse files Browse the repository at this point in the history
  • Loading branch information
hector-js committed Dec 18, 2020
1 parent 154cf9b commit 0a314be
Showing 1 changed file with 49 additions and 46 deletions.
95 changes: 49 additions & 46 deletions lib/app/components/ui/ui.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,61 @@ const express = require('express');
const router = new express.Router();
const path = require('path');
const shelljs = require('shelljs');
const args = require('minimist')(process.argv.slice(2));

router.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', './resources/index.html'));
});
if (args.ui && args.ui.enable) {
router.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', './resources/index.html'));
});

router.get('/favicon.ico', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', `./resources${req.url}`));
});
router.get('/favicon.ico', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', `./resources${req.url}`));
});

router.get('/_css/*.css', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', `./resources${req.url}`));
});
router.get('/_css/*.css', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', `./resources${req.url}`));
});

router.get('/_js/*.js', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', `./resources${req.url}`));
});
router.get('/_js/*.js', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', `./resources${req.url}`));
});

router.get('/_assets/*.png', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', `./resources${req.url}`));
});
router.get('/_assets/*.png', (req, res) => {
res.sendFile(path.join(__dirname, '../../..', `./resources${req.url}`));
});

router.get('/_test', (req, res) => {
const { stdout, code } = shelljs.exec(`npm run _test`);
res.json({ status: `${code===1?'ko':'ok'}`, content: stdout });
});

router.get('/_terminal', (req, res) => {
const command = req.get('command');
if (command && command.trim().startsWith('hjs')) {
const { stdout, code } = shelljs.exec(command.replace('hjs', 'npm run hjs -- '));
router.get('/_test', (req, res) => {
const { stdout, code } = shelljs.exec(`npm run _test`);
res.json({ status: `${code===1?'ko':'ok'}`, content: stdout });
} else {
const message = `
.------\\ /------.
| - |
| |
| |
| | .----------------------------.
_______________________ ¦ Sorry, ¦
===========.=========== ¦ You must add a hjs command ¦
/ ~~~~~ ~~~~~ \\ ¦ .--------------------------'
/| | |\\ ¦/
W --- / \\ --- W
\\. |o o| ./
| |
\\ ######### /
\\ ## ----- ## /
\\## ##/
\\_____v_____/
`;
res.json({ status: `ko`, content: message });
}
});
});

router.get('/_terminal', (req, res) => {
const command = req.get('command');
if (command && command.trim().startsWith('hjs')) {
const { stdout, code } = shelljs.exec(command.replace('hjs', 'npm run hjs -- '));
res.json({ status: `${code===1?'ko':'ok'}`, content: stdout });
} else {
const message = `
.------\\ /------.
| - |
| |
| |
| | .----------------------------.
_______________________ ¦ Sorry, ¦
===========.=========== ¦ You must add a hjs command ¦
/ ~~~~~ ~~~~~ \\ ¦ .--------------------------'
/| | |\\ ¦/
W --- / \\ --- W
\\. |o o| ./
| |
\\ ######### /
\\ ## ----- ## /
\\## ##/
\\_____v_____/
`;
res.json({ status: `ko`, content: message });
}
});
}

module.exports = router;

0 comments on commit 0a314be

Please sign in to comment.