-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove type and responsibilities
- Add release stage on heroku Procfile - Extract seed into separate file - Force latest dependencies & audit fix
- Loading branch information
Showing
14 changed files
with
531 additions
and
346 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
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 +1,2 @@ | ||
web: BASE_PATH=./examples node ./examples/app.js | ||
web: BASE_PATH=./examples node ./examples/app.js | ||
release: BASE_PATH=./examples node ./examples/seed.js |
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,60 @@ | ||
'use strict'; | ||
|
||
|
||
/* dependencies */ | ||
const _ = require('lodash'); | ||
const { waterfall } = require('async'); | ||
const { include } = require('@lykmapipo/include'); | ||
const { connect } = require('@lykmapipo/mongoose-common'); | ||
const { Permission } = require('@lykmapipo/permission'); | ||
const { Role } = include(__dirname, '..'); | ||
|
||
|
||
// naive logger | ||
const log = (stage, error, result) => { | ||
if (error) { | ||
console.error(`${stage} seed error`, error); | ||
} | ||
if (result) { | ||
const val = _.isArray(result) ? result.length : result; | ||
console.info(`${stage} seed result`, val); | ||
} | ||
}; | ||
|
||
|
||
// refs | ||
let seedStart; | ||
let seedEnd; | ||
|
||
// seed permissions | ||
const seedPermission = done => { | ||
Permission.seed((error, seeded) => { | ||
log('permissions', error, seeded); | ||
done(error); | ||
}); | ||
}; | ||
|
||
// seed roles | ||
const seedRole = done => { | ||
Role.seed((error, seeded) => { | ||
log('roles', error, seeded); | ||
done(error); | ||
}); | ||
}; | ||
|
||
// do seed | ||
const seed = done => { | ||
seedStart = Date.now(); | ||
connect(error => { | ||
if (error) { return done(error); } | ||
waterfall([seedPermission, seedRole], done); | ||
}); | ||
}; | ||
|
||
// do seeding | ||
seed((error, results = [true]) => { | ||
seedEnd = Date.now(); | ||
log('time', null, seedEnd - seedStart); | ||
log('final', error, results); | ||
process.exit(0); | ||
}); |
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
Oops, something went wrong.