Skip to content

Commit

Permalink
misc: bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
elcarim5efil committed Feb 6, 2017
1 parent 449cc2a commit 8cbe06c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 53 deletions.
132 changes: 80 additions & 52 deletions bin/fozy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,104 @@
'use strict';

const path = require('path');
if(!!!global.fozy) {
let root = path.join(process.cwd());
global.fozy = {
__root: root,
__dev: {},
}
try{
global.fozy.__config = require(path.join(root, 'fozy.config'));
} catch(e) {}
}

const pack = require('../package.json');
const Cli = require('../lib/cli');

let cli = new Cli();
let isReady2RunServer;

cli.on(['-v', '--version'], () => {
console.log(`v${pack.version}`);
});
setFozyObj();

cli.on(['-h', '--help'], () => {
console.log(
`Usage: fozy [options]
cli.on(['-v', '--version'], printVersion);
cli.on(['-h', '--help'], printHelp);
cli.on(['-w', '--watch'], runInWatchMode);
cli.on(['-p', '--proxy'], runInProxyMode);
cli.on(['--init'], initFozyConfigJSFile);
cli.on(['--nei'], runNeiSetup);

Options:
-v, --version\t\tprint version
-h, --help\t\tprint help
-w, --watch\t\tstart live-reload with browser-sync
-p, --proxy [proxyName], using proxy api, {proxyName} should be contained in de proxyMap
--init\t\tinitialize the project, so far, create fozy.config.js
cli.normal = function(){
readyToRunServer();
doRunServer();
};

Please visit Github repository https://github.com/elcarim5efil/fozy for more information.`);
});
cli.end = function runServer(){
doRunServer();
};

let runServer;
function doRunServer(){
if(isReady2RunServer) {
var app = require('../index');
app.run({});
}
}

cli.on(['-w', '--watch'], function(){
function setFozyObj(){
if(!!!global.fozy) {
let root = path.join(process.cwd());
global.fozy = {
__root: root,
__dev: {},
}
}
}

function runInWatchMode(){
readyToRunServer();
global.fozy.__dev.watch = true;
runServer = true;
});

cli.on(['-p', '--proxy'], (arg) => {
console.log(`using proxy config: ${arg}`);
let proxy = global.fozy.__config.mock.proxyMap[arg];
if(proxy){
console.log('proxy: ', arg);
global.fozy.__config.mock.proxy = proxy;
}

function runInProxyMode(arg){
readyToRunServer();
if(isReady2RunServer) {
console.log(`using proxy config: ${arg}`);
let proxy = global.fozy.__config.mock.proxyMap[arg];
if(proxy){
console.log('proxy: ', arg);
global.fozy.__config.mock.proxy = proxy;
}
}
runServer = true;
});
}

cli.on(['--init'], function(){
function initFozyConfigJSFile(){
var init = require('../lib/init');
isReady2RunServer = false;
init.run();
});
}

cli.on(['--nei'], function(arg){
function runNeiSetup(arg){
let nei = require('../lib/nei');
isReady2RunServer = false;
nei.build(arg);
});
}

cli.normal = function(){
runServer = true;
};
function printVersion(){
const pack = require('../package.json');
console.log(`v${pack.version}`);
}

cli.end = function(){
if(runServer) {
var app = require('../index');
app.run({});
function printHelp(){
console.log(
`Usage: fozy [options]
Options:
-v, --version\t\t\tprint version
-h, --help\t\t\tprint help
-w, --watch\t\t\tstart live-reload with browser-sync
-p, --proxy {proxyName}, \tusing proxy api, {proxyName} should be contained in de proxyMap
--init\t\t\tinitialize the project, so far, create fozy.config.js
Please visit Github repository https://github.com/elcarim5efil/fozy for more information.`);
}

function readyToRunServer(){
if(!!!global.fozy.__config){
try{
global.fozy.__config = require(path.join(global.fozy.__root, 'fozy.config'));
isReady2RunServer = true;
} catch(e) {
console.log('cannot find fozy.config.js, please make sure you make this file.');
return false;
}
}
};
return true;
}

cli.parse(process.argv.slice(2));
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fozy",
"version": "0.2.0",
"version": "0.2.1",
"description": "",
"main": "index.js",
"bin": {
Expand Down

0 comments on commit 8cbe06c

Please sign in to comment.