datamax-cli
Version:
datamax plugin cli
136 lines (123 loc) • 3.04 kB
JavaScript
const render = require("json-templater/string");
module.exports = function buildInstall(config) {
let menuconfig = {
parent: "icon_other_all",
img: "img_time_selector",
desc: config.desc || "默认测试插件",
type: config.pluginName,
type_parent: "other",
icon: "iconimg_time_selector",
};
if (!config.menuconfig) {
config.menuconfig = menuconfig;
}
let INSTALL_TEMPLATE = `
// 导入颜色选择器组件
import {{pluginName}} from './{{pluginName}}/{{pluginName}}.vue'
class configClass {
constructor(type, name, content) {
this.content = content;
this.type = type;
this.name = name;
}
}
let base_attr = [
{
type: "max_num",
name: "图表尺寸",
num_begin: 0,
num_end: 0,
content: "300|180",
color: "",
firstLabel: "宽度",
secondLabel: "高度",
},
{
type: "max_num",
name: "图表位置",
num_begin: 0,
num_end: 0,
content: "0|0",
color: "",
firstLabel: "横坐标",
secondLabel: "纵坐标",
},
{
type: "max_num",
name: "其他",
num_begin: 0,
num_end: 0,
content: "0|1",
color: "",
firstLabel: "旋转角度",
secondLabel: "透明度",
},
];
// 存储组件列表
const components = [
{{pluginName}}
]
// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
const install = function (Vue) {
// 判断是否安装
if (install.installed) return
// 遍历注册全局组件
components.map(component => Vue.component(component.name, component))
}
let menusConfig = {{menuconfig}}
let config = base_attr;
let selfDefineCOnfig = new configClass(
"max_scope_num",
"测试数字属性",
"0|65|100"
);
config.push(selfDefineCOnfig);
let dxconfig = adaptDatamaxConfig(config, {{pluginName}})
export default {
// 导出的对象必须具有 install,才能被 Vue.use() 方法安装
install,
// 以下是具体的组件列表
{{pluginName}},
menusConfig,
config,
dxconfig
}
function guid(code) { //获取随机ID,组件拖到预览视图后就会被设置个ID
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return code + s4() + '-'+ s4() + '-' + s4();
}
function adaptDatamaxConfig(cfg,type) {
let config = {}
config["shapes"] = {
degree:0,
height:202,
positionX:170,
positionY:172,
width:201,
z_index:55
}
config["details"] = cfg
config["dropdown"] = []
config["id"] = guid(type)
return config
}
`;
//preview命令
let buildDir = [config.root, config.pluginName, "packages"];
if (config.hasOwnProperty("preview") && config["preview"] == true) {
buildDir = [config.root, "packages"];
}
let install_template = render(INSTALL_TEMPLATE, {
pluginName: config.pluginName,
menuconfig: JSON.stringify(config.menuconfig),
});
return {
template: install_template,
dir: buildDir,
file: `index.js`,
};
};