2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00
books/server/init_models.js
2018-01-24 17:22:05 +05:30

24 lines
728 B
JavaScript

const frappe = require('frappejs');
const walk = require('walk');
const path = require('path');
module.exports = function(models_path) {
if (!models_path) {
return;
}
walk.walkSync(models_path, {
listeners: {
file: (basepath, file_data, next) => {
const doctype = path.basename(path.dirname(basepath));
const name = path.basename(basepath);
const file_path = path.resolve(basepath, file_data.name);
if (doctype==='doctype' && file_data.name.endsWith('.js')) {
frappe.modules[file_data.name.slice(0, -3)] = require(file_path);
}
next();
}
}
});
}