vap-builder
Advanced tools
Comparing version 0.1.3 to 0.1.4
import { Config } from './define'; | ||
export declare function testMysql(config: Config): Promise<void>; | ||
export declare function build(config: Config): Promise<void>; |
114
index.js
@@ -39,8 +39,8 @@ "use strict"; | ||
var title_loader_1 = require("./title-loader"); | ||
var yaml_loader_1 = require("./yaml-loader"); | ||
var template_loader_1 = require("./template-loader"); | ||
var _ = require("lodash"); | ||
function testMysql(config) { | ||
var VapInfo = require('../node_modules/vap/package.json'); | ||
function build(config) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var titleLoader, map; | ||
var titleLoader, templateLoader, titleMap, VERSION_1; | ||
return __generator(this, function (_a) { | ||
@@ -51,6 +51,18 @@ switch (_a.label) { | ||
; | ||
templateLoader = new template_loader_1.default(config); | ||
return [4 /*yield*/, titleLoader.load()]; | ||
case 1: | ||
map = _a.sent(); | ||
console.log(map.get('/sap/assetInfo')); | ||
titleMap = _a.sent(); | ||
try { | ||
VERSION_1 = { GLOBAL_VERSION: (config.site && config.site.version) || '', GLOBAL_RELEASE: (config.site && config.site.release) || _.now(), VAP_RELEASE: VapInfo.version }; | ||
config.pages.map(function (page) { | ||
var extra = {}; | ||
var data = _.assign({}, VERSION_1, { CDN: config.cdn || '' }, { title: titleMap.get(page.path) || '', links: [], scripts: [] }, page, extra); | ||
templateLoader.write(data); | ||
}); | ||
} | ||
catch (e) { | ||
// console.error('Mysql 查询失败'); | ||
console.error(e); | ||
} | ||
return [2 /*return*/]; | ||
@@ -61,94 +73,2 @@ } | ||
} | ||
exports.testMysql = testMysql; | ||
function build(config) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var titleLoader, yamlLoader, templateLoader, VERSION_1, map_1, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
titleLoader = new title_loader_1.default(config); | ||
; | ||
yamlLoader = new yaml_loader_1.YamlFileLoader(config); | ||
templateLoader = new template_loader_1.default(config); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
VERSION_1 = { GLOBAL_VERSION: yamlLoader.getVersion(), GLOBAL_RELEASE: yamlLoader.getRelease(), VAP_RELEASE: yamlLoader.getVapRelease() }; | ||
return [4 /*yield*/, titleLoader.load()]; | ||
case 2: | ||
map_1 = _a.sent(); | ||
config.pages.map(function (page) { | ||
var extra = {}; | ||
if (page.template == 'login') { | ||
extra = yamlLoader.getLogin(); | ||
} | ||
if (page.template == 'portal') { | ||
extra = yamlLoader.getPortal(); | ||
} | ||
var data = _.assign({}, VERSION_1, { CDN: config.cdn || '' }, { title: map_1.get(page.path) || '', links: [], scripts: [] }, page, extra); | ||
templateLoader.write(data); | ||
}); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
// console.error('Mysql 查询失败'); | ||
console.error(e_1); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.build = build; | ||
// export default class { | ||
// config: Config = null; | ||
// titleLoader: TitleLoader = null; | ||
// yamlLoader: YamlLoader = null; | ||
// templateLoader: TemplateLoader = null; | ||
// constructor(config: Config) { | ||
// this.config = config; | ||
// // if (config.yaml === false || config.mode !== 'vap') { | ||
// // this.yamlLoader = new NoFileLoader(config); | ||
// // } else { | ||
// this.yamlLoader = new YamlFileLoader(config); | ||
// // } | ||
// if (!_.has(config, 'mode') || config.mode == 'vap') { | ||
// this.titleLoader = new TitleLoader(config); | ||
// } | ||
// this.templateLoader = new TemplateLoader(config); | ||
// } | ||
// async build() { | ||
// try { | ||
// const VERSION = { GLOBAL_VERSION: this.yamlLoader.getVersion(), GLOBAL_RELEASE: this.yamlLoader.getRelease() }; | ||
// const map = await this.titleLoader.load(); | ||
// this.config.pages.map(page => { | ||
// var extra = {}; | ||
// if (page.template == 'login') { | ||
// extra = this.yamlLoader.getLogin(); | ||
// } | ||
// if (page.template == 'portal') { | ||
// extra = this.yamlLoader.getPortal(); | ||
// } | ||
// var data = _.assign({}, VERSION, { title: map.get(page.path) || '', links: [], scripts: [] }, page, extra); | ||
// this.templateLoader.write(data) | ||
// }); | ||
// } catch (e) { | ||
// // console.error('Mysql 查询失败'); | ||
// console.error(e); | ||
// } | ||
// // let exists = fs.existsSync(CONF_FILE); | ||
// // var CONF = _.extend({}, DEF); | ||
// // if (exists) { | ||
// // var reader = fs.readFileSync(CONF_FILE); | ||
// // _.extend(CONF, JSON.parse(reader.toString())); | ||
// // } else { | ||
// // fs.writeFileSync(CONF_FILE, JSON.stringify(DEF)) | ||
// // } | ||
// // console.log(p) | ||
// // this.dataManager | ||
// // console.log(this.dataManager); | ||
// // this.config.pages.map(item => { | ||
// // console.log(item); | ||
// // }) | ||
// } | ||
// } |
{ | ||
"name": "vap-builder", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Fast VAP framework buider", | ||
@@ -16,3 +16,3 @@ "main": "index.js", | ||
"mysql": "^2.16.0", | ||
"yaml": "^1.1.0" | ||
"vap": "^2.8.8" | ||
}, | ||
@@ -19,0 +19,0 @@ "devDependencies": { |
@@ -11,6 +11,4 @@ import { Config, Page } from '../define'; | ||
writeScreen(data: Page): void; | ||
writePortal(data: Page): void; | ||
writeLogin(data: Page): void; | ||
writeCustom(data: Page): void; | ||
write(data: Page): void; | ||
} |
@@ -23,3 +23,3 @@ "use strict"; | ||
this.outputDir = ''; | ||
var templateDir = config.template || './html'; | ||
var templateDir = config.input || './html'; | ||
var outputDir = config.output || '../dist'; | ||
@@ -33,7 +33,9 @@ templateDir = _.endsWith(templateDir, '/') ? templateDir.substr(0, templateDir.length - 1) : templateDir; | ||
default_1.prototype.getPath = function (data) { | ||
var writePath = this.outputDir + data.path + '/index.html'; | ||
console.log("\u5F00\u59CB\u5199\u5165 " + writePath); | ||
return writePath; | ||
if (_.endsWith(data.path, '/')) { | ||
return this.outputDir + data.path + 'index.html'; | ||
} | ||
return this.outputDir + data.path + '/index.html'; | ||
}; | ||
default_1.prototype.writeContext = function (path, context) { | ||
console.log("\u5F00\u59CB\u5199\u5165 : " + path); | ||
fsPath.writeFile(path, context, function (err) { | ||
@@ -61,22 +63,18 @@ if (err) { | ||
}; | ||
default_1.prototype.writePortal = function (data) { | ||
var writePath = this.getPath(data); | ||
// @ts-ignore | ||
var tempPath = this.templateDir + '/' + data.page + '.ejs'; | ||
var template = fs.readFileSync(tempPath).toString(); | ||
var str = ejs.render(template, data); | ||
this.writeContext(writePath, str); | ||
// fs.writeFileSync(writePath, str); | ||
}; | ||
default_1.prototype.writeLogin = function (data) { | ||
var writePath = this.getPath(data); | ||
// @ts-ignore | ||
var tempPath = this.templateDir + '/' + data.page + '.ejs'; | ||
var template = fs.readFileSync(tempPath).toString(); | ||
var str = ejs.render(template, data); | ||
this.writeContext(writePath, str); | ||
}; | ||
default_1.prototype.writeCustom = function (data) { | ||
var e_1, _a; | ||
var writePath = this.getPath(data); | ||
var path = ''; | ||
if (data.realPath) { | ||
var realPath = _.startsWith(data.realPath, '/') ? data.realPath.substr(1) : data.realPath; | ||
path = this.templateDir + '/' + realPath; | ||
} | ||
else { | ||
if (data.path.length == 1) { | ||
path = this.templateDir + '/index'; | ||
} | ||
else { | ||
path = this.templateDir + data.path; | ||
} | ||
} | ||
var readPath = ''; | ||
@@ -86,6 +84,5 @@ try { | ||
var sufx = _c.value; | ||
var path_1 = this.templateDir + data.path + sufx; | ||
var stat = fs.statSync(path_1); | ||
if (stat.isFile()) { | ||
readPath = path_1; | ||
var stat = fs.existsSync(path + sufx); | ||
if (stat) { | ||
readPath = path + sufx; | ||
break; | ||
@@ -120,8 +117,2 @@ } | ||
break; | ||
case 'login': | ||
this.writeLogin(data); | ||
break; | ||
case 'portal': | ||
this.writePortal(data); | ||
break; | ||
case 'custom': | ||
@@ -128,0 +119,0 @@ this.writeCustom(data); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DISPLAY = "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n <title><%=(locals.title?title:'')%></title>\n <script src=\"<%=CDN %>/js/theme.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n <link href=\"<%=CDN %>/css/iconfont.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\" />\n <link href=\"<%=CDN %>/css/vap.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\" />\n <% links.forEach(function(link){%><link href=\"<%=CDN %><%=link %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\" rel=\"stylesheet\" /><%})%>\n</head>\n<body <%=GLOBAL_VERSION?'version=\"'+GLOBAL_VERSION+'\"':''%> >\n<div id=\"__header\"></div><div id=\"root\"></div>\n<script src=\"<%=CDN %>/js/references.display.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n<script src=\"<%=CDN %>/js/header.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script><%})%>\n</body>\n</html>"; | ||
exports.ADMIN = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" wecontent=\"ie=edge\">\n<title><%=(locals.title?title:'')%></title>\n<link href=\"<%=CDN %>/css/theme-admin.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n<link href=\"<%=CDN %>/css/iconfont.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n<link href=\"<%=CDN %>/css/admin.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n<% links.forEach(function(link){%><link href=\"<%=CDN %><%=link %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\" rel=\"stylesheet\" /><%})%>\n<script src=\"<%=CDN %>/js/references.admin.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n</head>\n<body <%=GLOBAL_VERSION?'version=\"'+GLOBAL_VERSION+'\"':''%> >\n<div id=\"root\"></div>\n<script src=\"<%=CDN %>/js/admin.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script><%})%>\n</body>\n</html>"; | ||
exports.SCREEN = "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n <title><%=(locals.title?title:'')%></title>\n <link href=\"<%=CDN %>/css/theme-screen.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n <link href=\"<%=CDN %>/css/vap.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n <link href=\"<%=CDN %>/css/iconfont.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n <% links.forEach(function(link){%><link href=\"<%=link %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\" rel=\"stylesheet\" /><%})%>\n <script src=\"<%=CDN %>/js/references.screen.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n</head>\n<body class=\"vap-screen\" <%=GLOBAL_VERSION?'version=\"'+GLOBAL_VERSION+'\"':''%> >\n<div id=\"root\"></div> \n</body>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script><%})%>\n</html>"; | ||
exports.DISPLAY = "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\">\n <meta http-equiv=\"pragma\" content=\"no-cache\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n <title><%=(locals.title?title:'')%></title>\n <script src=\"<%=CDN %>/js/theme.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n <link href=\"<%=CDN %>/css/iconfont.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\" />\n <link href=\"<%=CDN %>/css/vap.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\" />\n <% links.forEach(function(link){%><link href=\"<%=CDN %><%=link %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\" rel=\"stylesheet\" /><%})%>\n</head>\n<body <%=GLOBAL_VERSION?'version=\"'+GLOBAL_VERSION+'\"':''%> >\n<div id=\"__header\"></div><div id=\"root\"></div>\n<script src=\"<%=CDN %>/js/references.display.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n<script src=\"<%=CDN %>/js/header.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script><%})%>\n</body>\n</html>"; | ||
exports.ADMIN = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\">\n<meta http-equiv=\"pragma\" content=\"no-cache\">\n<meta http-equiv=\"X-UA-Compatible\" wecontent=\"ie=edge\">\n<title><%=(locals.title?title:'')%></title>\n<link href=\"<%=CDN %>/css/theme-admin.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n<link href=\"<%=CDN %>/css/iconfont.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n<link href=\"<%=CDN %>/css/admin.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n<% links.forEach(function(link){%><link href=\"<%=CDN %><%=link %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\" rel=\"stylesheet\" /><%})%>\n<script src=\"<%=CDN %>/js/references.admin.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n</head>\n<body <%=GLOBAL_VERSION?'version=\"'+GLOBAL_VERSION+'\"':''%> >\n<div id=\"root\"></div>\n<script src=\"<%=CDN %>/js/admin.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script><%})%>\n</body>\n</html>"; | ||
exports.SCREEN = "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\">\n <meta http-equiv=\"pragma\" content=\"no-cache\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n <title><%=(locals.title?title:'')%></title>\n <link href=\"<%=CDN %>/css/theme-screen.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n <link href=\"<%=CDN %>/css/vap.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n <link href=\"<%=CDN %>/css/iconfont.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n <% links.forEach(function(link){%><link href=\"<%=link %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\" rel=\"stylesheet\" /><%})%>\n <script src=\"<%=CDN %>/js/references.screen.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n</head>\n<body class=\"vap-screen\" <%=GLOBAL_VERSION?'version=\"'+GLOBAL_VERSION+'\"':''%> >\n<div id=\"root\"></div> \n</body>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script><%})%>\n</html>"; |
@@ -54,2 +54,6 @@ "use strict"; | ||
return new Promise(function (resolve, reject) { | ||
if (_.isPlainObject(_this.config.mysql)) { | ||
resolve(_this.buildPath(paths)); | ||
return; | ||
} | ||
var connection = mysql.createConnection(_this.config.mysql); | ||
@@ -56,0 +60,0 @@ connection.query('SELECT id,title,path,parent FROM resource WHERE type< 3', function (err, rows, fields) { |
3
16751
9
315
+ Addedvap@^2.8.8
+ Addedvap@2.9.9(transitive)
- Removedyaml@^1.1.0
- Removedyaml@1.10.2(transitive)