2016-03-18 11:12:50 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Node.js core.
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
// Public node modules.
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add options to a table
|
|
|
|
*/
|
|
|
|
|
2016-07-11 13:03:35 +02:00
|
|
|
module.exports = (models, modelName, value, option) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
|
|
|
|
// Template: add a specific option.
|
|
|
|
// This is only called when we create a new table.
|
|
|
|
// The option's template is included in the
|
|
|
|
// `./builder/tables/createTableIfNotExists` template.
|
|
|
|
const tplOption = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'tables', 'options', option + '.template'), 'utf8');
|
|
|
|
models[modelName][option] = _.unescape(_.template(tplOption)({
|
|
|
|
tableName: modelName,
|
|
|
|
option: option,
|
|
|
|
value: value
|
|
|
|
}));
|
|
|
|
};
|