-
-
Save CesarBalzer/f390fad7c444f1c441edf4bc4beb8c89 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const Model = require( './model' ) | |
const createController = '../../helpers/createController' | |
module.exports = require( createController )( Model )( __dirname ) |
This file contains hidden or 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
const fs = require( 'fs' ) | |
const path = require( 'path' ) | |
const ACTIONS_PATH = '/actions/' | |
const forbiden = [ '.', '_' ] | |
const listFilesIn = require( './listFilesIn' ) | |
const filterHiddenFiles = require( './filterHiddenFiles' )( forbiden ) | |
const removeJSExtension = ( action ) => action.replace('.js', '') | |
const toObject = ( obj, action ) => Object.assign( obj, action ) | |
const createAction = ( Model, localPath ) => ( action ) => ( { | |
[ action ]: require( localPath + ACTIONS_PATH + action )( Model ) | |
} ) | |
const createController = ( Model ) => ( localPath ) => //console.log('localPath', localPath) | |
listFilesIn( localPath + ACTIONS_PATH ) | |
.filter( filterHiddenFiles ) | |
.map( removeJSExtension ) | |
.map( createAction( Model, localPath ) ) | |
.reduce( toObject, {} ) | |
module.exports = ( Model ) => ( localPath ) => createController( Model )( localPath ) |
This file contains hidden or 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
module.exports = ( path ) => require( 'fs' ).readdirSync( path ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment