ghost-service-loader
v1.0.1
Published
NPM for standard ghost creative services
Downloads
5
Readme
Ghost Service Loader
| Doc Sections | |--------------| | Getting Started | | Making Changes | | Included Services |
Get the Code
- https://github.com/ghostcreative/ghost-service-loader
Usage
1. Require
const GhostServiceLoader = require('ghost-service-loader');
// Easy enough
2. Init
const serviceLoader = GhostServiceLoader(config);
// see README.md in config folder
3. Usage
const myService = new MyService();
serviceLoader.setService('myService', myService);
// later on in another file
const serviceLoader = require('ghost-service-loader')(); // no need to pass config in again after init
const myService = serviceLoader.getService('myService');
Included Services
Authorization
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const authorizationService = serviceLoader.getAuthorizationService();
// use the service
authorizationService.findById(authId)
.then(authorization => { /** do something */ })
.catch(err => { /** handle error */ });
ElasticSearch Client
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const elasticSearchClient = serviceLoader.getElasticSearchClient();
// use the service
return new Promise((resolve, reject) => {
elasticSearchClient.indices.create({
index: 'myIndexName'
}, (err, result) => {
if (err) reject(err);
else resolve(result);
})
})
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const emailService = serviceLoader.getEmailService();
// use the service
emailService.send(emailData)
.then(authorization => { /** do something */ })
.catch(err => { /** handle error */ });
Logger
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const logger = serviceLoader.getLogger();
// use the service
logger.info('My info log', { data })
ModelScope
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const modelScopeService = serviceLoader.getModelScopeService();
// use the service
modelScopeService.findById(id)
.then(result => { /** do something */ })
.catch(err => { /** handle error */ });
Permission
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const permissionService = serviceLoader.getPermissionService();
// use the service
permissionService.findById(id)
.then(result => { /** do something */ })
.catch(err => { /** handle error */ });
Profile
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const profileService = serviceLoader.getProfileService();
// use the service
profileService.findById(id)
.then(result => { /** do something */ })
.catch(err => { /** handle error */ });
ResetToken
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const resetTokenService = serviceLoader.getResetTokenService();
// use the service
resetTokenService.findById(id)
.then(result => { /** do something */ })
.catch(err => { /** handle error */ });
Role
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const roleService = serviceLoader.getRoleService();
// use the service
roleService.findById(id)
.then(result => { /** do something */ })
.catch(err => { /** handle error */ });
RolePermission
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const rolePermissionService = serviceLoader.getRolePermissionService();
// use the service
rolePermissionService.findById(id)
.then(result => { /** do something */ })
.catch(err => { /** handle error */ });
User
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const userService = serviceLoader.getUserService();
// use the service
userService.findById(id)
.then(result => { /** do something */ })
.catch(err => { /** handle error */ });
UserPermission
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const userPermissionService = serviceLoader.getUserPermissionService();
// use the service
userPermissionService.findById(id)
.then(result => { /** do something */ })
.catch(err => { /** handle error */ });
UserRole
const Config = require('config');
const GhostServiceLoader = require('ghost-service-loader');
const serviceLoader = GhostServiceLoader(Config.get('services'))
const userRoleService = serviceLoader.getUserRoleService();
// use the service
userRoleService.findById(id)
.then(result => { /** do something */ })
.catch(err => { /** handle error */ });
Making Changes
If you have never used Git, search around online to get a grounding. But here are the basic commands you will need to use to actually push code to our repository, with a little bit of Git theory to explain what's going on.
- First make sure you have the most current version of the codebase. In your terminal window, navigate to the project root. Type
git checkout master
to checkout the master branch. git pull origin master
will update master with any new changes.git checkout -b feature/[NEW_FEATURE_NAME]
this will create a new branch (called feature/NEW_FEATURE_NAME, or whatever you want). Your branch names should be descriptive, but short. For example, if I want to create a cart on my branch, I might call it "feature/cart" (after the object) or "feature/checkout" (after the functionality).- You can run
git branch
at any time to see which branch you're on and what branches you have locally. - Write some code. If you ever want to see which files you've changed, added, or deleted you can run
git status
- When you are satisfied with your changes, make a commit by executing
git commit -am [YOUR_COMMIT_MESSAGE]
. The -a attribute tells Git to commit all changed files. If you don't want to commit all of them, you'll have to type the names of the files. The -m is required; Git needs commit messages. Try to be descriptive, maybe your first commit message will be "store skeleton", the next will be "product page", etc. NOTEgit commit -a
will not commit any new files since they are not part of Git yet. If you have new files you will need to rungit add .
before the above commands ("." means "all"). - Once the code is committed to your branch, your branch is ready to go. Now we just need to release it into the internet and tell everyone else that we want to combine this branch with the master branch. Execute
git push origin [BRANCH_NAME]
. Here, origin represents our Bitbucket repository. Rungit remote -v
to see your repository aliases. - Now we create a pull request on github - in other words, a request to the other developers that we want our code to be merged into the application. In the left sidebar, click Pull Requests > Create Pull Request. The branch on the left should be the branch you were just working on i.e. the one we want to merge into the app. The branch on the right should be master. Make a descriptive title so we know what the pull request is for, and add the necessary reviewers.
- Click "Create Pull Request" and wait for us to review your code.
We follow the git branching model outlined in this blog post
.