Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-mock2easy

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-mock2easy - npm Package Compare versions

Comparing version 0.1.15 to 0.1.16

2

package.json
{
"name": "grunt-mock2easy",
"description": "mock接口,生成md文档",
"version": "0.1.15",
"version": "0.1.16",
"homepage": "",

@@ -6,0 +6,0 @@ "author": {

var createMock = angular.module('createMock', ['ui.bootstrap']);
createMock.controller('addMockListCtrl', function($scope,$http){
createMock.controller('addMockListCtrl', function($scope,$http,$filter,$modal){
$.extend($scope,{

@@ -58,4 +58,4 @@ data:{

kind:'string',
name:'***',
rule:'***',
name:'--',
rule:'--',
array:_array,

@@ -67,6 +67,32 @@ nameVerify:'name_'+Date.parse(new Date()),

removeResponseParameters:function(i){
$scope.data.responseParameters = $filter('orderBy')($scope.data.responseParameters,'id');
$scope.data.responseParameters.splice(i,1);
},
submit:function(){
$http.post('/modify',angular.fromJson($scope.data));
$http.post('/modify',angular.fromJson($scope.data)).then(function(){
window.location.href = '/';
});
},
//打开窗口
openWin:function(){
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ['$scope','$modalInstance',function($scope,$modalInstance){
$scope.importResponseParameters = function(json){
$modalInstance.close(json);
}
}]
});
modalInstance.result.then(function (json) {
var reData = [];
var _id = 0;
$.each(JSON.parse(json),function(i,o){
json2Data(i,o,_id,[],reData);
_id += 1;
});
console.log(reData);
$scope.data.responseParameters = reData;
});
}

@@ -79,3 +105,101 @@ });

/**
*
* @param json 需要处理的对象
* @param id 父节点的ID
* @param array 他的父级 如果为数组的话 将id传出数组
* @returns {data|*}
*/
var json2Data = function(key,value,id,array,reData){
if(typeof(value)==='string' || typeof(value)==='boolean' || typeof(value)==='number'){
reData.push({
id: (''+id).length%2!=0 ? '0' + id : id,
kind: typeof(value),
name: key,
rule: value,
array: array,
nameVerify:'name_'+Date.parse(new Date()),
ruleVerify:'rule_'+Date.parse(new Date())
});
}else if($.isArray(value)){ //如果是一个数组
id = (''+id).length%2!=0 ? '0' + id : id;
if(value.length){
if(typeof(value[0]) === 'object'){ //如果这是一个数组对象的话
reData.push({
id: id,
kind: 'array(object)',
name: key,
rule: '',
array: array,
nameVerify:'name_'+Date.parse(new Date()),
ruleVerify:'rule_'+Date.parse(new Date())
});
var _id = 0;
array.push(id);
$.each(value[0],function(i,o){
_id = parseInt(_id);
_id = 1 + _id;
_id = _id < 9 ? '0'+_id:_id;
console.log(_id);
json2Data(i,o,id+_id,array,reData);
});
}else{ //如果这是一个简单的数组的话
var _rule = '[';
$.each(value,function(i,o){
if(typeof(o) === 'string'){
_rule += '"'+ o + '"';
}else{
_rule += o ;
}
if(i !== value.length-1){
_rule += ',';
}
});
_rule +=']';
reData.push({
id: id,
kind: 'mock',
name: key,
rule: _rule,
array: array,
nameVerify:'name_'+Date.parse(new Date()),
ruleVerify:'rule_'+Date.parse(new Date())
});
}
}else{ //如果是一个空数组
reData.push({
id: id,
kind: 'mock',
name: key,
rule: "[]",
array: array,
nameVerify:'name_'+Date.parse(new Date()),
ruleVerify:'rule_'+Date.parse(new Date())
});
}
}else if($.isPlainObject(value)){ //这不是一个空对象
id = (''+id).length%2!=0 ? '0'+ id : id ;
reData.push({
id: id,
kind: 'object',
name: key,
rule: "",
array: array,
nameVerify:'name_'+Date.parse(new Date()),
ruleVerify:'rule_'+Date.parse(new Date())
});
var _id = 0;
$.each(value,function(i,o){
_id = parseInt(_id);
_id = 1 + _id;
_id = (''+ _id ).length%2!=0 ? '0'+_id:_id;
json2Data(i,o,id+_id,array,reData);
});
}
};
angular.bootstrap(document, ['createMock','directiveM','filterM']);

@@ -122,3 +122,2 @@

v.rule = _o[v.id] ? true : false;
console.log(v);
}else if(v.kind === 'object'){

@@ -125,0 +124,0 @@ _o[v.id] = {};

var mockList = angular.module('mockList', ['ui.bootstrap']);
mockList.controller('mockListCtrl', function($scope,$http){
mockList.controller('mockListCtrl', function($scope,$http,$filter,$timeout){
$.extend($scope,{
data:{},
suc: false,
render:function(){

@@ -18,3 +19,14 @@ $http.post('/getList',{url:'/console/domain/list.json'}).then(function(data){

}).then(function(data){
window.location.href = '/detail/' + $filter('url')($scope.url);
});
},
del:function(i){
$http.post('/del', {
interfaceUrl: $scope.data[i].url
}).then(function(data){
$scope.render();
$scope.suc = true;
$timeout(function(){
$scope.suc = false;
},1000);
});

@@ -21,0 +33,0 @@ }

@@ -59,3 +59,16 @@ var express = require('express');

//删除接口
router.post('/del',function(req,res){
grunt.log.error(path.resolve(global.options.database)+req.body.interfaceUrl);
fs.unlink(path.resolve(global.options.database)+req.body.interfaceUrl,function(e){
if(e){
grunt.log.error('删除文件夹错误');
}else{
res.json({success:1});
}
});
});
//获取已经生成的接口路径

@@ -68,3 +81,3 @@ router.post('/add',function(req,res){

if(e){
grunt.log.write('创建文件夹错误');
grunt.log.error('创建文件夹错误');
}else{

@@ -71,0 +84,0 @@ fs.open(path.resolve(global.options.database)+req.body.interfaceUrl,"w",0644,function(e,fd){

@@ -19,5 +19,4 @@ var fs = require('fs');

function inner(cur){
grunt.log.error(cur+':'+fs.existsSync(cur))
if(cur.length > 0 && !fs.existsSync(cur)){//不存在就创建一个
fs.mkdirSync(cur, mode)
fs.mkdirSync(cur, mode);
}

@@ -24,0 +23,0 @@ if(arr.length){

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc