mm_os
Version:
MM_OS服务端架构,用于快速构建应用程序,支持网站建设、小程序后台、AI应用、物联网(IOT/AIOT)、游戏服务端等多种场景。
82 lines (71 loc) • 1.76 kB
JavaScript
const compressing = require('compressing');
const Item = require('mm_machine').Item;
/**
* 主题模板驱动类
* @class
*/
class Drive extends Item {
static config = {
name: '',
title: '',
description: '',
version: '1.0.0',
preview: '',
preview_large: '',
git: ''
};
/**
* 主题模板驱动类
* @param {object} config 主题模板配置
* @param {object} parent 父项
*/
constructor(config, parent) {
super({ ...Drive.config, ...config }, parent);
// this.default_file = "./template.json";
// dir, "/static/template".fullname()
}
}
/**
* 压缩主题模板
* @param {string} zip_dir 压缩目录
* @returns {object} 压缩后的文件对象
*/
Drive.prototype.zip = async function (zip_dir = '/static/file/zip/') {
var file = ('./' + this.config.name + '.zip').fullname(zip_dir);
file.addDir();
await compressing.zip.compressDir(this.getDir(), file);
if (file.hasFile()) {
return file;
}
return null;
};
/**
* 下载主题模板包
*/
Drive.prototype.download = async function () {
};
/**
* 更新主题模板
*/
Drive.prototype.update = async function () {
};
/**
* 获取模型
* @param {string} type 模型类型
* @returns {object} 返回获取到的模型
*/
Drive.prototype.getModel = function (type) {
let model = { ...this.config };
let dir = this.getDir();
let l = $.slash;
let app_name = dir.between('app' + l, l);
let plugin_name = dir.between('plugin' + l, l);
let name = dir.basename();
model.app = app_name;
model.plugin = plugin_name;
model.name = model.name || app_name + '_' + name;
return model;
};
module.exports = {
Drive
};