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

vap-builder

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vap-builder - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

define.d.ts

66

index.js

@@ -38,44 +38,42 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var title_loader_1 = require("./title-loader");
var template_loader_1 = require("./template-loader");
var _ = require("lodash");
var VapInfo = require('../vap/package.json');
function build(config) {
return __awaiter(this, void 0, void 0, function () {
var titleLoader, templateLoader, titleMap, VERSION_1;
var templateLoader, param_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
titleLoader = new title_loader_1.default(config);
;
templateLoader = new template_loader_1.default(config);
return [4 /*yield*/, titleLoader.load()];
case 1:
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 imports = {};
if (_.isString(page.links)) {
imports.links = [page.links];
}
else if (_.isEmpty(page.links)) {
imports.links = [];
}
if (_.isString(page.scripts)) {
imports.scripts = [page.scripts];
}
else if (_.isEmpty(page.scripts)) {
imports.scripts = [];
}
var data = _.assign({}, VERSION_1, { customHeader: config.site.customHeader || '/js/header.js', displayTheme: config.site.displayTheme, adminTheme: config.site.adminTheme }, { CDN: (config.site && config.site.cdn) || '' }, { title: titleMap.get(page.path) || '' }, page, imports);
templateLoader.write(data);
});
templateLoader = new template_loader_1.default(config);
try {
param_1 = {
nocache: (config.site && config.site.nocache) ? true : false,
CDN: (config.site && config.site.cdn) || '',
timestamp: (config.site && config.site.release) ? "?" + _.now() : '',
customHeader: config.site.customHeader || '/js/header.js',
displayTheme: config.site.displayTheme,
// 兼容,不具意义
VAP_RELEASE: '',
};
// console.log(param)
config.pages.map(function (page) {
var imports = {};
if (_.isString(page.links)) {
imports.links = [page.links];
}
catch (e) {
// console.error('Mysql 查询失败');
console.error(e);
else if (_.isEmpty(page.links)) {
imports.links = [];
}
return [2 /*return*/];
if (_.isString(page.scripts)) {
imports.scripts = [page.scripts];
}
else if (_.isEmpty(page.scripts)) {
imports.scripts = [];
}
var data = _.assign({}, param_1, page, imports);
templateLoader.write(data);
});
}
catch (e) {
console.error(e);
}
return [2 /*return*/];
});

@@ -82,0 +80,0 @@ });

{
"name": "vap-builder",
"version": "1.0.1",
"version": "1.0.2",
"description": "Fast VAP framework buider",

@@ -12,13 +12,12 @@ "main": "index.js",

"dependencies": {
"ejs": "^2.6.1",
"ejs": "^3.0.1",
"fs-path": "^0.0.24",
"lodash": "^4.17.11",
"mysql": "^2.16.0"
"lodash": "^4.17.15"
},
"devDependencies": {
"@types/lodash": "^4.14.119",
"@types/node": "^10.12.18",
"ts-loader": "^5.3.2",
"typescript": "^3.2.2"
"@types/lodash": "^4.14.149",
"@types/node": "^12.12.14",
"ts-loader": "^6.2.1",
"typescript": "3.5.3"
}
}
import { Config, Page } from '../define';
export default class {
private useName;
private templateDir;
private outputDir;
constructor(config: Config);
getPath(data: any): string;
/**
* 读取路径 (html目录)
*/
readPath(root: any): string;
/**
* 写入路径 (dist目录)
*/
writePath(data: any): string;
writeContext(path: any, context: any): void;

@@ -9,0 +15,0 @@ writeAdmin(data: Page): void;

@@ -21,3 +21,2 @@ "use strict";

function default_1(config) {
this.useName = false;
this.templateDir = '';

@@ -31,19 +30,33 @@ this.outputDir = '';

this.outputDir = path.resolve(outputDir);
this.useName = config.useName ? true : false;
console.log("\u5F00\u59CB\u751F\u6210html\u6587\u4EF6 \u8F93\u51FA\u6587\u4EF6\u5939" + this.outputDir + " \u6A21\u677F\u6587\u4EF6\u5939\uFF1A" + this.templateDir + " ");
}
default_1.prototype.getPath = function (data) {
if (this.useName) {
if (_.endsWith(data.path, '/')) {
return this.outputDir + data.path + 'index.html';
/**
* 读取路径 (html目录)
*/
default_1.prototype.readPath = function (root) {
var e_1, _a;
try {
for (var _b = __values(['.ejs', '.html', '.htm']), _c = _b.next(); !_c.done; _c = _b.next()) {
var sufx = _c.value;
var url = path.resolve(this.templateDir, "." + (root.endsWith('/') ? root.substr(0, root.length - 1) : root) + sufx);
if (fs.existsSync(url)) {
return url;
}
}
return this.outputDir + data.path + '.html';
}
else {
if (_.endsWith(data.path, '/')) {
return this.outputDir + data.path + 'index.html';
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
return this.outputDir + data.path + '/index.html';
finally { if (e_1) throw e_1.error; }
}
return '';
};
/**
* 写入路径 (dist目录)
*/
default_1.prototype.writePath = function (data) {
return path.resolve(this.outputDir, "." + data.path + (data.path.endsWith('/') ? '' : '/') + "index.html");
};
default_1.prototype.writeContext = function (path, context) {

@@ -59,56 +72,32 @@ console.log("\u5F00\u59CB\u5199\u5165 : " + path);

default_1.prototype.writeAdmin = function (data) {
var writePath = this.getPath(data);
var str = ejs.render(Templete_1.ADMIN, data);
var writePath = this.writePath(data);
var readPath = this.readPath('/admin');
var template = readPath ? fs.readFileSync(readPath).toString() : Templete_1.ADMIN;
var str = ejs.render(template, data);
this.writeContext(writePath, str);
};
default_1.prototype.writeDisplay = function (data) {
var writePath = this.getPath(data);
var str = ejs.render(Templete_1.DISPLAY, data);
var writePath = this.writePath(data);
var readPath = this.readPath('/display');
var template = readPath ? fs.readFileSync(readPath).toString() : Templete_1.DISPLAY;
var str = ejs.render(template, data);
this.writeContext(writePath, str);
};
default_1.prototype.writeScreen = function (data) {
var writePath = this.getPath(data);
var str = ejs.render(Templete_1.SCREEN, data);
var writePath = this.writePath(data);
var readPath = this.readPath('/screen');
var template = readPath ? fs.readFileSync(readPath).toString() : Templete_1.SCREEN;
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;
var readPath = this.readPath(data.realPath ? data.realPath : data.path);
if (readPath) {
var writePath = this.writePath(data);
var template = fs.readFileSync(readPath).toString();
var str = ejs.render(template, data);
this.writeContext(writePath, str);
return;
}
else {
if (data.path.length == 1) {
path = this.templateDir + '/index';
}
else {
path = this.templateDir + data.path;
}
}
var readPath = '';
try {
for (var _b = __values(['.ejs', '.html', '.htm']), _c = _b.next(); !_c.done; _c = _b.next()) {
var sufx = _c.value;
var stat = fs.existsSync(path + sufx);
if (stat) {
readPath = path + sufx;
break;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
if (readPath == '') {
throw new Error("File : " + data.path + " .ejs/.html/.htm not exists");
}
var template = fs.readFileSync(readPath).toString();
var str = ejs.render(template, data);
this.writeContext(writePath, str);
console.error(data.path + " \u5BF9\u5E94\u7684\u6A21\u677F\u4E0D\u5B58\u5728\uFF01");
};

@@ -115,0 +104,0 @@ default_1.prototype.write = function (data) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs");
var path = require("path");
var DEFAULT_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 <link href=\"<%=CDN %>/css/iconfont.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\" />\n</head>\n<body class=\"<%=GLOBAL_VERSION?'_vap_'+GLOBAL_VERSION:''%>\" <%-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<% if(displayTheme){ %>\n <link href=\"<%=CDN %>/css/theme-display-<%=displayTheme %>.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\" />\n<% } else{ %>\n <script src=\"<%=CDN %>/js/theme-display.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n<% } %>\n<% links.forEach(function(link){%><link href=\"<%=CDN %><%=link %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\" rel=\"stylesheet\" /><%})%>\n<script src=\"<%=CDN %><%=customHeader %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script><%})%>\n</body>\n</html>";
var DEFAULT_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/iconfont.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\">\n<script src=\"<%=CDN %>/js/references.admin.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n</head>\n<body class=\"<%=GLOBAL_VERSION?'_vap_'+GLOBAL_VERSION:''%>\" <%-GLOBAL_VERSION?'version=\"'+GLOBAL_VERSION+'\"':''-%> >\n<div id=\"root\"></div>\n<% if(adminTheme){ %>\n <link href=\"<%=CDN %>/css/theme-admin-<%=adminTheme %>.css<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\" rel=\"stylesheet\" />\n<% } else{ %>\n <script src=\"<%=CDN %>/js/theme-admin.js<%=VAP_RELEASE?'?'+VAP_RELEASE:''%>\"></script>\n<% } %>\n<% links.forEach(function(link){%><link href=\"<%=CDN %><%=link %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\" rel=\"stylesheet\" /><%})%>\n<script src=\"<%=CDN %>/js/admin.js<%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=GLOBAL_RELEASE?'?'+GLOBAL_RELEASE:''%>\"></script><%})%>\n</body>\n</html>";
var DEFAULT_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-default.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=\"<%=GLOBAL_VERSION?'_vap_'+GLOBAL_VERSION:''%>\" <%-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>";
if (fs.existsSync(path.resolve('../app-portal/html/display.ejs'))) {
DEFAULT_DISPLAY = fs.readFileSync(path.resolve('../app-portal/html/display.ejs')).toString();
}
if (fs.existsSync(path.resolve('../app-portal/html/admin.ejs'))) {
DEFAULT_ADMIN = fs.readFileSync(path.resolve('../app-portal/html/admin.ejs')).toString();
}
if (fs.existsSync(path.resolve('../app-portal/html/screen.ejs'))) {
DEFAULT_SCREEN = fs.readFileSync(path.resolve('../app-portal/html/screen.ejs')).toString();
}
exports.DISPLAY = DEFAULT_DISPLAY;
exports.ADMIN = DEFAULT_ADMIN;
exports.SCREEN = DEFAULT_SCREEN;
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 <% if(nocache){ %>\n <meta http-equiv=\"pragma\" content=\"no-cache\">\n <% } %>\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n <title></title>\n <link href=\"<%=CDN %>/css/iconfont.css<%=timestamp %>\" rel=\"stylesheet\" />\n</head>\n<body>\n<div id=\"__header\"></div><div id=\"root\"></div>\n<script src=\"<%=CDN %>/js/references.display.js<%=timestamp %>\"></script>\n<% if(displayTheme){ %>\n <link href=\"<%=CDN %>/css/theme-display-<%=displayTheme %>.css<%=timestamp %>\" rel=\"stylesheet\" />\n<% } else{ %>\n <script src=\"<%=CDN %>/js/theme-display.js<%=timestamp %>\"></script>\n<% } %>\n<% links.forEach(function(link){%><link href=\"<%=CDN %><%=link %><%=timestamp %>\" rel=\"stylesheet\" /><%})%>\n<script src=\"<%=CDN %><%=customHeader %><%=timestamp %>\"></script>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=timestamp %>\"></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<% if(nocache){ %>\n<meta http-equiv=\"pragma\" content=\"no-cache\">\n<% } %>\n<title></title>\n<link href=\"<%=CDN %>/css/iconfont.css<%=timestamp %>\" rel=\"stylesheet\">\n<script src=\"<%=CDN %>/js/references.admin.js<%=timestamp %>\"></script>\n</head>\n<body>\n<div id=\"root\"></div>\n<script src=\"<%=CDN %>/js/theme-admin.js<%=timestamp %>\"></script>\n<script src=\"<%=CDN %>/js/admin.js<%=timestamp %>\"></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 <% if(nocache){ %>\n <meta http-equiv=\"pragma\" content=\"no-cache\">\n <% } %>\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n <title><%=(locals.title?title:'')%></title>\n <link href=\"<%=CDN %>/css/theme-screen-default.css<%=timestamp %>\" rel=\"stylesheet\">\n <link href=\"<%=CDN %>/css/iconfont.css<%=timestamp %>\" rel=\"stylesheet\">\n <% links.forEach(function(link){%><link href=\"<%=CDN %><%=link %><%=timestamp %>\" rel=\"stylesheet\" /><%})%>\n <script src=\"<%=CDN %>/js/references.screen.js<%=timestamp %>\"></script>\n</head>\n<body>\n<div id=\"root\"></div> \n</body>\n<% scripts.forEach(function(script){%><script src=\"<%=CDN %><%=script %><%=timestamp %>\"></script><%})%>\n</html>";
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