-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
102 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist | ||
coverage | ||
coverage | ||
migrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ modules | |
.babelrc | ||
.gitignore | ||
circle.yml | ||
coverage | ||
coverage | ||
migrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#! /usr/bin/env node | ||
import fs from 'fs' | ||
|
||
let commands = { | ||
'make:migration': require('./migrations/make').default, | ||
'make:model': require('./models/make').default, | ||
} | ||
|
||
commands[process.argv[2]]({ | ||
args: process.argv.slice(3), | ||
cwd: process.cwd(), | ||
fs | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export default ({ args, cwd, fs }) => { | ||
let filePath = `${cwd}/models/${args[0].toLowerCase()}.js` | ||
|
||
const template = `import { Model } from 'relation' | ||
export default class ${args[0]} extends Model { | ||
} | ||
` | ||
try { | ||
fs.accessSync(`${cwd}/models`, fs.F_OK) | ||
} catch (e) { | ||
fs.mkdirSync(`${cwd}/models`) | ||
} | ||
|
||
fs.writeFile(filePath, template, err => { | ||
if (err) throw err; | ||
}) | ||
|
||
console.log('Created model: ', filePath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import pluralize from 'pluralize' | ||
|
||
|
||
module.exports = { | ||
module.exports = { | ||
getTableName: (model) => typeof model === 'string' ? pluralize(model).toLowerCase() : null, | ||
getFieldName: (model) => typeof model === 'string' ? `${model.toLowerCase()}_id` : null | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
require('dotenv').config() | ||
require('babel-polyfill') | ||
import { expect } from 'chai' | ||
import sinon from 'sinon' | ||
|
||
global.expect = expect | ||
|
||
global.sinon = sinon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
require('babel-polyfill') | ||
import { expect } from 'chai' | ||
import sinon from 'sinon' | ||
|
||
global.expect = expect | ||
global.expect = expect | ||
global.sinon = sinon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Make from '../../../../modules/cli/models/make' | ||
|
||
describe('Models', () => { | ||
it('makes a model', () => { | ||
|
||
let fs = { | ||
mkdirSync: sinon.spy(), | ||
writeFile: sinon.spy(), | ||
} | ||
|
||
Make({ args: ['Test'], cwd: 'blah', fs }) | ||
|
||
expect(fs.mkdirSync.calledOnce).to.equal(true) | ||
expect(fs.writeFile.calledOnce).to.equal(true) | ||
expect(fs.mkdirSync.args[0][0]).to.equal('blah/models') | ||
expect(fs.writeFile.args[0][0]).to.equal('blah/models/test.js') | ||
|
||
let error = new Error('failed creating file') | ||
try { | ||
fs.writeFile.args[0][2](error) | ||
} | ||
catch(e) { | ||
fs.writeFile.args[0][2]() | ||
expect(e.message).to.equal('failed creating file') | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters