Skip to content

Commit

Permalink
misc: update some structure
Browse files Browse the repository at this point in the history
  • Loading branch information
elcarim5efil committed Mar 9, 2017
1 parent 7ada591 commit e8c5148
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 53 deletions.
7 changes: 6 additions & 1 deletion lib/live_reload/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@

'use strict';

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _koaBrowserSync = require('koa-browser-sync');

var _koaBrowserSync2 = _interopRequireDefault(_koaBrowserSync);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var __root = fozy.__root;
Expand All @@ -15,7 +20,7 @@ files2Watch = files2Watch.concat(config.watch.map(function (item) {
return _path2.default.join(__root, item);
}));

module.exports = require('koa-browser-sync')({
module.exports = (0, _koaBrowserSync2.default)({
init: true,
files: files2Watch,
notify: false,
Expand Down
33 changes: 11 additions & 22 deletions lib/mock/modules/local_mock/async_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,55 +32,44 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var __root = fozy.__root;
var config = require(_path2.default.join(__root, 'fozy.config'));
var config = fozy.__config;

var AsyncData = function () {
function AsyncData(ctx) {
_classCallCheck(this, AsyncData);

this.files = {};
this.ctx = ctx;
this.filePath = this.getFilePath(ctx) || '';
this.data = {};
}

_createClass(AsyncData, [{
key: 'getData',
value: function getData() {
var files = this.files = this.getFiles(this.ctx);

var data = this.data = new _local_data2.default({
path: files.json
this.data = new _local_data2.default({
path: this.filePath
}).getData();

return this.processData(data);
return this.processData(this.data, this.ctx);
}
}, {
key: 'processData',
value: function processData(data) {
var ctx = this.ctx;
value: function processData(data, ctx) {
var proc = new _jsonProcessor2.default({
module: this.files.js + '.js',
module: this.filePath + '.js',
preStringify: false
});

return proc.process(data || {}, ctx.request.body, _querystring2.default.parse(ctx.url.split('?')[1]), ctx);
}
}, {
key: 'getFiles',
value: function getFiles(ctx) {
var files = {};
key: 'getFilePath',
value: function getFilePath(ctx) {
var url = _extend2.default.removePostfix(ctx.url.split('?')[0]);
var method = ctx.method.toLocaleLowerCase();
var root = _path2.default.join(__root, config.mock.api.root, method && config.mock.api[method]);
var fileName = config.mock.fileName;
if (!fileName) {
files.json = _path2.default.join(root, url);
files.js = _path2.default.join(root, url);
} else {
files.json = _path2.default.join(root, url, fileName);
files.js = _path2.default.join(root, url, fileName);
}
return files;
var fileName = config.mock.fileName || '';
return _path2.default.join(root, url, fileName);
}
}]);

Expand Down
2 changes: 1 addition & 1 deletion lib/mock/modules/template_engine/global_sync_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var __root = fozy.__root;
var config = require(_path2.default.join(__root, 'fozy.config'));
var config = fozy.__config;
var globalJsonPath = _path2.default.join(__root, config.template.mock, '__global/data');

var GlobalSyncData = function () {
Expand Down
2 changes: 1 addition & 1 deletion lib/mock/modules/template_engine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

var __root = fozy.__root;
var config = require(_path2.default.join(__root, 'fozy.config'));
var config = fozy.__config;
var templateRoot = _path2.default.join(__root, config.template.root || '');

var engine = void 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/mock/modules/template_engine/sync_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var __root = fozy.__root;
var config = require(_path3.default.join(__root, 'fozy.config'));
var config = fozy.__config;

var MockData = function () {
function MockData(option) {
Expand Down
10 changes: 7 additions & 3 deletions src/live_reload/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

'use strict';

import path from 'path';
import koaBrowserSync from 'koa-browser-sync';

const __root = fozy.__root;
const config = fozy.__config;

Expand All @@ -8,13 +13,12 @@ files2Watch = files2Watch.concat(config.watch.map(function(item){
return path.join(__root, item);
}));

module.exports = require('koa-browser-sync')({

module.exports = koaBrowserSync({
init: true,
files: files2Watch,
notify: false,
ui: false,
online: false,
open: config.autoOpen,
});


31 changes: 10 additions & 21 deletions src/mock/modules/local_mock/async_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,30 @@
import path from 'path';
import _ from '../../../util/extend';
const __root = fozy.__root;
const config = require(path.join(__root, 'fozy.config'));
const config = fozy.__config;

import qs from 'querystring';
import JSONProcessor from '../../../util/json.processor.js';
import LocalData from '../local_data';

export default class AsyncData {
constructor(ctx) {
this.files = {};
this.ctx = ctx;
this.filePath = this.getFilePath(ctx) || '';
this.data = {};
}

getData() {
let files = this.files = this.getFiles(this.ctx);

let data = this.data = new LocalData({
path: files.json,
this.data = new LocalData({
path: this.filePath,
}).getData();

return this.processData(data);
return this.processData(this.data, this.ctx);
}

processData(data) {
let ctx = this.ctx;
processData(data, ctx) {
let proc = new JSONProcessor({
module: this.files.js + '.js',
module: this.filePath + '.js',
preStringify: false,
});

Expand All @@ -42,20 +39,12 @@ export default class AsyncData {
);
}

getFiles(ctx){
let files = {};
getFilePath(ctx){
let url = _.removePostfix(ctx.url.split('?')[0]);
let method = ctx.method.toLocaleLowerCase();
let root = path.join(__root, config.mock.api.root, method && config.mock.api[method]);
let fileName = config.mock.fileName;
if(!fileName) {
files.json = path.join(root, url);
files.js = path.join(root, url);
} else {
files.json = path.join(root, url, fileName);
files.js = path.join(root, url, fileName);
}
return files;
let fileName = config.mock.fileName || '';
return path.join(root, url, fileName);
}
}

2 changes: 1 addition & 1 deletion src/mock/modules/template_engine/global_sync_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';
import LocalData from '../local_data';

const __root = fozy.__root;
const config = require(path.join(__root, 'fozy.config'));
const config = fozy.__config;
const globalJsonPath = path.join(__root, config.template.mock, '__global/data');

export default class GlobalSyncData {
Expand Down
2 changes: 1 addition & 1 deletion src/mock/modules/template_engine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import path from 'path';
import _ from '../../../util/extend';
const __root = fozy.__root;
const config = require(path.join(__root, 'fozy.config'));
const config = fozy.__config;
const templateRoot = path.join(__root, config.template.root || '');

import SyncData from './sync_data.js';
Expand Down
2 changes: 1 addition & 1 deletion src/mock/modules/template_engine/sync_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import _path from 'path';
import _ from '../../../util/extend';
const __root = fozy.__root;
const config = require(_path.join(__root, 'fozy.config'));
const config = fozy.__config;

import qs from 'querystring';
import LocalData from '../local_data';
Expand Down

0 comments on commit e8c5148

Please sign in to comment.