Commit 52c53448 by 王昆

gsb

parent e6271c96
var fs=require("fs"); var fs = require("fs");
var settings=require("../settings"); var settings = require("../settings");
async function asycReadFile(path){ var os = require("os");
var p=new Promise(function(reslv,reject){
fs.readFile(path,function(err,r){ async function asycReadFile(path) {
if(err){ var p = new Promise(function (reslv, reject) {
reject(err); fs.readFile(path, function (err, r) {
}else{ if (err) {
reslv(r); reject(err);
} } else {
}); reslv(r);
}); }
return p; });
});
return p;
} }
async function buildComponent(compname){ async function buildComponent(compname) {
var htmlpath=settings.basepath+"/app/front/vues/pages/"+compname+"/"+compname+".html"; var htmlpath = settings.basepath + "/app/front/vues/pages/" + compname + "/" + compname + ".html";
var jspath=settings.basepath+"/app/front/vues/pages/"+compname+"/"+compname+".js"; var jspath = settings.basepath + "/app/front/vues/pages/" + compname + "/" + compname + ".js";
var html= await asycReadFile(htmlpath); var html = await asycReadFile(htmlpath);
var tmpl=html.toString("utf-8"); var tmpl = html.toString("utf-8");
var js= await asycReadFile(jspath); var js = await asycReadFile(jspath);
var jsstr=js.toString("utf-8"); var jsstr = js.toString("utf-8");
jsstr=jsstr.replace("${tmpl}",tmpl); jsstr = jsstr.replace("${tmpl}", tmpl);
return jsstr; return jsstr;
} }
module.exports = function (app) { module.exports = function (app) {
app.get('/vue/comp/base',function(req,res){ app.get('/vue/comp/base', function (req, res) {
var vuePath=settings.basepath+"/app/front/vues/base"; var vuePath = settings.basepath + "/app/front/vues/base";
var baseComps=[]; var baseComps = [];
fs.readdir(vuePath,function(err,rs){ fs.readdir(vuePath, function (err, rs) {
if(rs){ if (rs) {
rs.forEach(function(r){ rs.forEach(function (r) {
delete require.cache[require.resolve(vuePath+"/"+r)]; delete require.cache[require.resolve(vuePath + "/" + r)];
var comp=require(vuePath+"/"+r).replace(/\n/g,""); var comp = require(vuePath + "/" + r).replace(/\n/g, "");
baseComps.push(comp); baseComps.push(comp);
}); });
res.end(JSON.stringify(baseComps)) res.end(JSON.stringify(baseComps))
} }
}); });
}); });
app.get('/vue/comp/:cname',function(req,res){ app.get('/vue/comp/:cname', function (req, res) {
var componentName=req.params.cname; var componentName = req.params.cname;
buildComponent(componentName).then(function(r){ buildComponent(componentName).then(function (r) {
let platform = os.platform(); let platform = os.platform();
console.log(platform, '----------------'); console.log(platform, '----------------');
// windows // windows
if(platform.startsWith('win')) { if (platform.toLocaleLowerCase().startsWith('win')) {
res.end(r.replace(/\n\r/g,"")); res.end(r.replace(/[\n\r]/g,""));
} else { } else {
res.end(r.replace(/\n/g,"")); res.end(r.replace(/\n/g, ""));
} }
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment