Commit 52c53448 by 王昆

gsb

parent e6271c96
var fs=require("fs");
var settings=require("../settings");
async function asycReadFile(path){
var p=new Promise(function(reslv,reject){
fs.readFile(path,function(err,r){
if(err){
reject(err);
}else{
reslv(r);
}
});
});
return p;
var fs = require("fs");
var settings = require("../settings");
var os = require("os");
async function asycReadFile(path) {
var p = new Promise(function (reslv, reject) {
fs.readFile(path, function (err, r) {
if (err) {
reject(err);
} else {
reslv(r);
}
});
});
return p;
}
async function buildComponent(compname){
var htmlpath=settings.basepath+"/app/front/vues/pages/"+compname+"/"+compname+".html";
var jspath=settings.basepath+"/app/front/vues/pages/"+compname+"/"+compname+".js";
var html= await asycReadFile(htmlpath);
var tmpl=html.toString("utf-8");
var js= await asycReadFile(jspath);
var jsstr=js.toString("utf-8");
jsstr=jsstr.replace("${tmpl}",tmpl);
return jsstr;
async function buildComponent(compname) {
var htmlpath = settings.basepath + "/app/front/vues/pages/" + compname + "/" + compname + ".html";
var jspath = settings.basepath + "/app/front/vues/pages/" + compname + "/" + compname + ".js";
var html = await asycReadFile(htmlpath);
var tmpl = html.toString("utf-8");
var js = await asycReadFile(jspath);
var jsstr = js.toString("utf-8");
jsstr = jsstr.replace("${tmpl}", tmpl);
return jsstr;
}
module.exports = function (app) {
app.get('/vue/comp/base',function(req,res){
var vuePath=settings.basepath+"/app/front/vues/base";
var baseComps=[];
fs.readdir(vuePath,function(err,rs){
if(rs){
rs.forEach(function(r){
delete require.cache[require.resolve(vuePath+"/"+r)];
var comp=require(vuePath+"/"+r).replace(/\n/g,"");
app.get('/vue/comp/base', function (req, res) {
var vuePath = settings.basepath + "/app/front/vues/base";
var baseComps = [];
fs.readdir(vuePath, function (err, rs) {
if (rs) {
rs.forEach(function (r) {
delete require.cache[require.resolve(vuePath + "/" + r)];
var comp = require(vuePath + "/" + r).replace(/\n/g, "");
baseComps.push(comp);
});
res.end(JSON.stringify(baseComps))
}
});
});
app.get('/vue/comp/:cname',function(req,res){
var componentName=req.params.cname;
buildComponent(componentName).then(function(r){
app.get('/vue/comp/:cname', function (req, res) {
var componentName = req.params.cname;
buildComponent(componentName).then(function (r) {
let platform = os.platform();
console.log(platform, '----------------');
// windows
if(platform.startsWith('win')) {
res.end(r.replace(/\n\r/g,""));
if (platform.toLocaleLowerCase().startsWith('win')) {
res.end(r.replace(/[\n\r]/g,""));
} 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