Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
durango authored Jul 19, 2017
2 parents 3dab27e + 35a1c25 commit 21c775b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Example for Sqlite3

Example for MSSQL

`npm install -g tedious`
`npm install -g mssql`

## Usage

Expand Down
21 changes: 14 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var dialects = require('./dialects');
var _ = Sequelize.Utils._;
var SqlString = require('./sql-string');
var tsHelper = require('./ts-helper');
var CLIEngine = require('eslint').CLIEngine;

function AutoSequelize(database, username, password, options) {
if (options && options.dialect === 'sqlite' && ! options.storage)
Expand Down Expand Up @@ -246,11 +247,11 @@ AutoSequelize.prototype.run = function(callback) {

if (_.isString(defaultVal)) {
var field_type = self.tables[table][field].type.toLowerCase();
if (field_type.indexOf('date') === 0 || field_type.indexOf('timestamp') === 0) {
if (_.endsWith(defaultVal, '()')) {
val_text = "sequelize.fn('" + defaultVal.replace(/\(\)$/, '') + "')"
}
else if (_.includes(['current_timestamp', 'current_date', 'current_time', 'localtime', 'localtimestamp'], defaultVal.toLowerCase())) {
if (_.endsWith(defaultVal, '()')) {
val_text = "sequelize.fn('" + defaultVal.replace(/\(\)$/, '') + "')"
}
else if (field_type.indexOf('date') === 0 || field_type.indexOf('timestamp') === 0) {
if (_.includes(['current_timestamp', 'current_date', 'current_time', 'localtime', 'localtimestamp'], defaultVal.toLowerCase())) {
val_text = "sequelize.literal('" + defaultVal + "')"
} else {
val_text = quoteWrapper + val_text + quoteWrapper
Expand Down Expand Up @@ -422,7 +423,12 @@ AutoSequelize.prototype.write = function(attributes, typescriptFiles, callback)

mkdirp.sync(path.resolve(self.options.directory));

async.each(tables, createFile, callback);
async.each(tables, createFile, !self.options.eslint ? callback : function() {
var engine = new CLIEngine({ fix: true });
var report = engine.executeOnFiles([self.options.directory]);
CLIEngine.outputFixes(report);
callback();
});

if(self.options.typescript){
if(typescriptFiles != null && typescriptFiles.length > 1){
Expand All @@ -432,7 +438,8 @@ AutoSequelize.prototype.write = function(attributes, typescriptFiles, callback)
}

function createFile(table, _callback) {
fs.writeFile(path.resolve(path.join(self.options.directory, table + (self.options.typescript ? '.ts' : '.js'))), attributes[table], _callback);
var fileName = self.options.camelCaseForFileName ? _.camelCase(table) : table;
fs.writeFile(path.resolve(path.join(self.options.directory, fileName + (self.options.typescript ? '.ts' : '.js'))), attributes[table], _callback);
}
}

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@
"license": "MIT",
"dependencies": {
"async": "^2.1.5",
"eslint": "^3.19.0",
"graceful-fs-extra": "^2.0.0",
"mkdirp": "^0.5.1",
"sequelize": "^3.30.2",
"yargs": "^8.0.1"
},
"devDependencies": {
"chai": "^3.5.0",
"cross-env": "^4.0.0",
"chai": "^4.0.1",
"cross-env": "^5.0.0",
"istanbul": "^0.4.5",
"lcov-result-merger": "^1.2.0",
"mkdirp": "^0.5.1",
"mocha": "^3.2.0",
"mysql": "^2.13.0",
"nyc": "^10.1.2",
"nyc": "^11.0.1",
"pg": "^6.1.5",
"pg-hstore": "^2.3.2",
"sqlite3": "^3.1.8",
Expand Down

0 comments on commit 21c775b

Please sign in to comment.