UNPKG

nyx_server

Version:

Node内容发布

210 lines (169 loc) 5.16 kB
var projectLoader = require('../ProjectLoader'); var project = require('../Project'); var projectMatchService = require('../ProjectMatchService'); var getProject = function (name) { if (name === 'local') { return projectLoader.loadLoaclProject.bind(this)(); } else { return projectLoader.loadServerProject.bind(this)({name: name}) .then(results => results[0]); } }; // var getProjectInfo = function () { // return getProject.bind(this)() // .then(convertProject.bind(this)); // }; // var getTemplate = function () { // return getProject.bind(this)() // .then(loadTemplates.bind(this)) // .map(convertTemplate.bind(this)); // }; // var getChips = function () { // return getProject.bind(this)() // .then(loadChips.bind(this)) // .map(convertChip.bind(this)); // }; var loadTemplates = function (projectInfo) { return project.loadTemplates.bind(this)(projectInfo); }; var loadChips = function (projectInfo) { return project.loadChips.bind(this)(projectInfo); }; var convertProjects = function (projects) { return Object.keys(projects).map(key => { const obj = projects[key]; return { name: obj.name, description: obj.descr, version: obj.version, url: obj.gitRepo }; }); }; var convertProject = function (project) { return [ {key: 'basePath', value: project.basePath}, {key: 'name', value: project.name}, {key: 'version', value: project.config.version}, {key: 'description', value: project.config.description}, {key: 'url', value: project.config.repository.url} ]; }; var convertTemplate = function (template) { return { key: template.basePath, basePath: template.basePath, name: template.config.name, fileType: template.config.fileType, devices: template.config.devices, extra: template.config.extra, matchPath: template.config.matchPath, projectName: template._ownerProject.name, dataId: '' }; }; var convertChip = function (chip) { return { key: chip.basePath, basePath: chip.basePath, name: chip.config.name, projectName: chip._project.name, dataId: 'null' }; }; var getIps = function () { var os = require('os'); var interfaces = os.networkInterfaces(); var _interface; var ips = []; for (var key in interfaces) { _interface = interfaces[key]; _interface.forEach(function (item) { if (item.family === 'IPv4' && item.address.indexOf('172') >= 0) { ips.push(item.address); } }); } return ips; }; var getServerProjects = function () { return projectMatchService.getProjects.bind(this)(); }; module.exports = { convertProjects: convertProjects, convertProject: convertProject, convertTemplate: convertTemplate, convertChip: convertChip, loadTemplates: loadTemplates, loadChips: loadChips, getProject: getProject, getServerProjects: getServerProjects, getIps: getIps }; // var Log = require('../log'); // var cache = require("../Cache").cache; // var logger = Log.getLogger('test'); // var context = { // log: logger, // cache: cache, // extend: {} // }; // var show = function (result) { // console.log(JSON.stringify(result)); // }; // getServerProjects.bind(context)() // .then(show); // getProject.bind(context)() // .then(convertProject.bind(context)) // .then(show.bind(context)); // getProject.bind(context)({name:'nxy_gitclient_test'}) // .then(convertProject.bind(context)) // .then(show); // getProject.bind(context)() // .then(project.loadTemplates.bind(context)) // .map(convertTemplate.bind(context)) // .then(show); // getProject.bind(context)({name:'nxy_gitclient_test'}) // .then(project.loadTemplates.bind(context)) // .map(convertTemplate.bind(context)) // .then(show); // getProject.bind(context)() // .then(getTemplate.bind(context)()) // .then(show); // // 获取服务端指定项目的模板列表 // getServerTemplates.bind(context)( // getServerProject.bind(context)({name:'nxy_gitclient_test'}) // ).then(function (result) { // console.log(JSON.stringify(result)); // }); // // 获取服务端指定项目的碎片列表 // getServerChips.bind(context)( // getServerProject.bind(context)({name:'nxy_gitclient_test'}) // ).then(function (result) { // console.log(JSON.stringify(result)); // }); // // 获取服务端指定项目信息 // getServerProject.bind(context)({name:'nxy_gitclient_test'}) // .then(function (result) { // console.log(JSON.stringify(result)); // }); // // 获取服务端项目列表 // getServerProjects.bind(context)() // .then(function (result) { // console.log(JSON.stringify(result)); // }); // // 获取本地项目信息 // getProjectInfo.bind(context)().then(function (project) { // console.log(JSON.stringify(project)); // }); // // 获取本地项目 // getProject.bind(context)().then(function (project) { // console.log(JSON.stringify(project)); // }) // // 获取本地模板 // getTemplate.bind(context)() // .then(function (result) { // console.log(result); // }); // 获取本地碎片 // getChips.bind(context)();