Skip to content

Commit

Permalink
release (#23)
Browse files Browse the repository at this point in the history
* chore(yarn): added dev-dependencies, hooks and npm init project

* chore(travis): added .travis.yml file

* chore(test): added test file and script

* chore(version): set version to 0.1.0

* chore(readme): update readme file. closes #3

* feat(package.json): made mslite a globally accessable module

* feat(bin): added sample cmd use case

* feat(yarn): added new dependencies

* feat(cli): 'mslite g model name ..names' now generates model files

* feat(replace): now replaces and 'model_name' within file

* chore(readme): updated readme.

* feat(default): added default files for generate

* feat(helper): created copy utility module

* feat(generate): added generate types for other components

* chore(yarn): added waterline and blob

* chore(refactor): models now created at src/models

* feat(yarn): added dotenv module

* feat(db): added config files for db setup

* feat(db): load models from /src/models

* feat(services): require all services

* fix(path): closes #15

* feat(index.js): for starting up project.
closes #17

* feat(cmd): now makes project with necessary dir and files included

* feat(.gitkeep): added .gitkeep to ensure dir(s) are tracked by git from creation

* feat(packgage.json): add package.json for project init

* test(*): updated tests to pass

* build(cote): added missing dependency

* chore(*): added tabs to log statement about generated files

* build(*): modified by semantic release

* ci(travis): modified by semantic release and me. Merged with some old changes

* docs(badge): added semantic release badge

* fix(model): now replacing sample name properly. Nits too

* fix(service): fixed recursive search of serices.

Global name for requester and publishers now CamelCase

* build(test): added mocha

* docs(readme): updated readme to show new features and guide
  • Loading branch information
robophil authored Oct 13, 2017
1 parent 85d4aa2 commit 6d0dfb1
Show file tree
Hide file tree
Showing 29 changed files with 4,584 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jspm_packages/

# Typescript v1 declaration files
typings/
typings.json
*.d.ts

# Optional npm cache directory
.npm
Expand All @@ -57,3 +59,6 @@ typings/
# dotenv environment variables file
.env

# Ide
.vscode/
.idea/
64 changes: 64 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/
typings.json
*.d.ts

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Ide
.vscode/
.idea/
36 changes: 36 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
language: node_js

sudo: false

install:
- yarn

cache:
yarn: true
directories:
- node_modules

notifications:
email: false

node_js:
- '7'
- '6'
- '4'

before_script:
- npm prune

script:
- npm test

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.27.5
- export PATH="$HOME/.yarn/bin:$PATH"

after_success:
- npm run semantic-release

branches:
except:
- /^v\d+\.\d+\.\d+$/
148 changes: 147 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,147 @@
# microservice-lite
# microservice-lite

[![Build Status](https://travis-ci.org/Robophil/microservice-lite.svg?branch=feat%2Fsetup-project-dev-dependencies)](https://travis-ci.org/Robophil/microservice-lite)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

Microservice-lite is a very small package for getting started with **microservices** on [node](htts://nodejs.org).
It covers everything a simple microservice should have.

1. Having it's own database (mysql, mongo, postgres, redis, and more)
2. Small footprint
3. Indepenent deployment
4. Zero-configuration
5. Zero-dependency
6. Auto-discovery, fault toleranct and scalable

This works, thanks to the effort of [@dashersw](https://github.com/dashersw/) and his wonderful project [cote.js](https://github.com/dashersw/cote)
and [@balderdashy](https://github.com/balderdashy) for writing [waterline](https://github.com/balderdashy/waterline)

## install

```bash
# for pre-release do npm i -g microservice-lite@next
npm i -g microservice-lite
```
or
```bash
# for pre-release do yarn global add microservice-lite@next
yarn global add microservice-lite
```

## cli commands

#### create a project
```bash
# creates new project
mslite new sample
```

#### responder
```bash
# New responder has been created as src/app/foo.responder.js
mslite g responder foo [...othernames]
```
#### requester
```bash
# New requester has been created as src/app/foo.requester.js
mslite g requester foo [...othernames]
```
Requesters are global and can be accessed from any location. The above can be accessed as `FooRequester` globally with the app
#### subscriber
```bash
# New subscriber has been created as src/app/foo.subscriber.js
mslite g subscriber foo [...othernames]
```
#### publisher
```bash
# New publisher has been created as src/app/foo.publisher.js
mslite g publisher foo [...othernames]
```
Publishers are global and can be accessed from any location. The above can be accessed as `FooPublisher` globally with the app
#### model
```bash
# New model has been created as src/models/foo.js
mslite g model foo [...othernames]
```
Models are global and can be accessed from any location. The above can be accessed as `Foo` globally with the app

## database and adapters
Each microservice should have it's own database and **mslite** helps you with that. You could have a different database for each service. Eg mysql, mongodb, pouchdb etc.

By default, each project created with **mslite** comes with a disk based databased called `sails-disk`. There are other adapters you can use to have a different database like

- `sails-mysql`
- `sails-postgresql`
- `sails-mongo`
- `sails-redis`
- `sails-orientdb`
- `sails-filemaker`

see [here](http://sailsjs.com/documentation/concepts/extending-sails/adapters/available-adapters) for more info about adapters.

To add a different adapter for your project, simply install the appropriate adapter and make sure you have the database on your current machine as the adapter would try to make connection.

#### configure adapters
1. Install required adapter eg.
```bash
npm i --save sails-mongo
```
2. open `config/adapters.js` and require intalled adapter, also passing it an object name of your pleasing eg
```js
module.exports = {
'sailsDisk': require('sails-disk'),
'sailsMongo': require('sails-mongo')
}
```
You can have any amount of adapters saved here for later use
3. Open `config/connections.js` create a connection object. Same as above, pass connection object to a name of your pleasing and specify the adapter from any defined in `step 1`
```js
module.exports = {
'diskDb': {
'adapter': 'sailsDisk'
},
myMongodbServer: {
adapter: 'sailsMongo',//adapter's name, as defined above
host: 'localhost',
port: 27017,
user: 'username', //optional
password: 'password', //optional
database: 'your_mongo_db_name_here' //optional
}
}
```
4. Open `cofig/models` Tell your models to use the connection you want.
```js
module.exports = {
'connection': 'myMongodbServer', //change from diskDb
'migrate': 'alter',
'schema': true
}
```
## test
NYD

## examples
NYD

## goal

The goal of the project is to make getting started with a microservice easy and painless, giving you basic features. The following features are on the roadmap

- CLI for generating necessary files. eg
```bash
# generates a db model
mslite g model name [names...]
```
- Easy connection to any database with the same api
- .... got a feature in mind ? create an issue [here](https://github.com/Robophil/microservice-lite/issues)

## development

This project uses the following to keep things a bit sane around the house

1. [standardjs](https://standardjs.com/)
2. [validate-commit-msg](https://github.com/conventional-changelog/validate-commit-msg) see http://conventionalcommits.org/
3. [Github flow](https://guides.github.com/introduction/flow/)

and is completly test driven [TDD](https://en.wikipedia.org/wiki/Test-driven_development)
21 changes: 21 additions & 0 deletions bin/cmd/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = (cmd, names, options) => {
switch (cmd) {
case 'model':
require('./types/model')(names, options)
break
case 'requester':
require('./types/requester')(names, options)
break
case 'responder':
require('./types/responder')(names, options)
break
case 'publisher':
require('./types/publisher')(names, options)
break
case 'subscriber':
require('./types/subscriber')(names, options)
break
default:
break
}
}
43 changes: 43 additions & 0 deletions bin/cmd/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const fs = require('fs-extra')
const path = require('path')
const replace = require('replace-in-file')
const cwd = process.cwd()

const postfixName = '-service'
const makeProject = (name) => {
const newDir = []
newDir.push(fs.ensureDir(`${cwd}/${name}/`))
newDir.push(fs.ensureFile(`${cwd}/${name}/src/models/.gitkeep`))
newDir.push(fs.ensureDir(`${cwd}/${name}/src/app/requester/.gitkeep`))
newDir.push(fs.ensureDir(`${cwd}/${name}/src/app/responder/.gitkeep`))
newDir.push(fs.ensureDir(`${cwd}/${name}/src/app/publisher/.gitkeep`))
newDir.push(fs.ensureDir(`${cwd}/${name}/src/app/subscriber/.gitkeep`))

return Promise.all(newDir)
}

module.exports = (name, options) => {
if (name === undefined) throw new Error(`No name passed\nRun 'mslite help'`)
if (options.postfix) {
name += postfixName
}
makeProject(name).then(() => {
const src = path.resolve(__dirname, '..', '..', 'files/action')
const dest = `${cwd}/${name}`

const configSrc = path.resolve(__dirname, '..', '..', 'files/config')
const configDest = `${cwd}/${name}/config`

return Promise.all([fs.copy(src, dest), fs.copy(configSrc, configDest)])
}).then(() => {
console.log(`\n\tNew Project has been created at '${name}'`)
const dest = `${cwd}/${name}/package.json`
return replace({
files: `${dest}`,
from: /microservice-lite/g,
to: `${name}`
}).then(() => {
console.log(`\tcd into ${name} and run 'npm install'\n\trun 'mslite help' for assistance and \n\trun 'npm start' to see your project up and running\n`)
})
})
}
16 changes: 16 additions & 0 deletions bin/cmd/types/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const copy = require('../../../helper/copy')

module.exports = (names, options) => {
const type = 'model'
const regex = /model_name/g
copy(names, type, regex).then(() => {
console.log('\n')
names.forEach(name => {
console.info(`\tNew ${type} has been created as src/models/${name}.js`)
})
console.log('\n')
}).catch(err => {
if (err instanceof Error) throw err
else throw new Error(err)
})
}
16 changes: 16 additions & 0 deletions bin/cmd/types/publisher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const copy = require('../../../helper/copy')

module.exports = (names, options) => {
const type = 'publisher'
const regex = /serviceName/g
copy(names, type, regex).then(() => {
console.log('\n')
names.forEach(name => {
console.info(`\tNew ${type} has been created as src/app/${name}.${type}.js`)
})
console.log('\n')
}).catch(err => {
if (err instanceof Error) throw err
else throw new Error(err)
})
}
16 changes: 16 additions & 0 deletions bin/cmd/types/requester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const copy = require('../../../helper/copy')

module.exports = (names, options) => {
const type = 'requester'
const regex = /serviceName/g
copy(names, type, regex).then(() => {
console.log('\n')
names.forEach(name => {
console.info(`\tNew ${type} has been created as src/app/${name}.${type}.js`)
})
console.log('\n')
}).catch(err => {
if (err instanceof Error) throw err
else throw new Error(err)
})
}
Loading

0 comments on commit 6d0dfb1

Please sign in to comment.