2018-01-31 10:13:33 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const utils = require('frappejs/utils');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
make_model_files(name) {
|
|
|
|
|
|
|
|
// [doctype].json
|
|
|
|
fs.mkdirSync(`./models/doctype/${utils.slug(name)}`);
|
|
|
|
fs.writeFileSync(`./models/doctype/${utils.slug(name)}/${utils.slug(name)}.json`, `{
|
2018-01-31 12:56:21 +00:00
|
|
|
"name": "${name}",
|
|
|
|
"doctype": "DocType",
|
|
|
|
"is_single": 0,
|
|
|
|
"istable": 0,
|
|
|
|
"keyword_fields": [],
|
|
|
|
"fields": [
|
|
|
|
{
|
|
|
|
"fieldname": "name",
|
|
|
|
"label": "Name",
|
|
|
|
"fieldtype": "Data",
|
|
|
|
"reqd": 1
|
|
|
|
}
|
|
|
|
]
|
2018-01-31 10:13:33 +00:00
|
|
|
}`);
|
|
|
|
|
|
|
|
// [doctype].js
|
|
|
|
let thinname = name.replace(/ /g, '');
|
|
|
|
fs.writeFileSync(`./models/doctype/${utils.slug(name)}/${utils.slug(name)}.js`, `const BaseMeta = require('frappejs/model/meta');
|
|
|
|
const BaseDocument = require('frappejs/model/document');
|
|
|
|
|
|
|
|
class ${thinname}Meta extends BaseMeta {
|
2018-01-31 12:56:21 +00:00
|
|
|
setup_meta() {
|
|
|
|
Object.assign(this, require('./${utils.slug(name)}.json'));
|
|
|
|
}
|
2018-01-31 10:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ${thinname} extends BaseDocument {
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2018-01-31 12:56:21 +00:00
|
|
|
Document: ${thinname},
|
|
|
|
Meta: ${thinname}Meta
|
2018-01-31 10:13:33 +00:00
|
|
|
};`);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|