kdesign-ui
Version:
kd is from company of klx, it provide quickly genarator company inner business front structure
75 lines (74 loc) • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var index_1 = require("./index");
var babel = require('../babel');
var GenerateComTpl = /** @class */ (function (_super) {
tslib_1.__extends(GenerateComTpl, _super);
function GenerateComTpl(name, props) {
var _this = _super.call(this) || this;
_this.CODE = "";
_this.COMPOSE = {};
//生成组件
_this.CODE = _this.composeCode(_this.generate(name, props));
return _this;
}
GenerateComTpl.prototype.generate = function (name, props) {
var _this = this;
return this.baseGenerate(name, props, {
before: function () { },
executing: function (isString, props, key) {
if (!isString) {
_this.COMPOSE[key] = props[key];
}
},
after: function () { }
});
};
return GenerateComTpl;
}(index_1.GenerateTpl));
var GenerateComJs = /** @class */ (function (_super) {
tslib_1.__extends(GenerateComJs, _super);
function GenerateComJs(options) {
var _this = _super.call(this) || this;
_this.CODE = '';
_this.TPL = "\n import TreeList from '@/page/business/inline-tree-list'\n export default {\n data () {\n return {}\n },\n components: {\n TreeList\n },\n methods: {}\n }";
_this.CODE = _this.composeCode(_this.generate(options));
return _this;
}
GenerateComJs.prototype.generate = function (options) {
return babel(this.TPL, {
visitor: function (t, babylon) {
return {
ReturnStatement: function (path) {
if (path.node.leadingComments)
return;
var newBlockStatement = t.returnStatement(babylon.parseExpression(JSON.stringify(options.data)));
path.replaceWith(newBlockStatement);
}
};
},
lintCode: function (code) {
return code.replace(/data\(\) \{/, 'data () {').replace(/\"/g, '\'');
}
});
};
return GenerateComJs;
}(index_1.GenerateJs));
var GenerateComStyle = /** @class */ (function (_super) {
tslib_1.__extends(GenerateComStyle, _super);
function GenerateComStyle(name) {
return _super.call(this) || this;
}
return GenerateComStyle;
}(index_1.GenerateStyle));
module.exports = function (props) {
if (props === void 0) { props = {}; }
var name = 'TreeList';
var tpl = new GenerateComTpl(name, props);
var js = new GenerateComJs({
data: tpl.COMPOSE
});
var style = new GenerateComStyle(name);
return tpl.CODE + js.CODE + style.CODE;
};