express-cmd 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e61b3e17045f0ce4d5a57cdb52a6908238098c3
4
- data.tar.gz: 73eecef6373661be94c2af70f84c28ca3a722c6e
3
+ metadata.gz: 08bc2c1db119896d78c2afbad2ffa8f6b8c47071
4
+ data.tar.gz: e663d753bd60f5950421b1d386febba7eb4e78d1
5
5
  SHA512:
6
- metadata.gz: 2c06642f95a0cef50d0cf5da3b56f56991e997a68c2dad005709d7f249ef979deb9435b455bcd6b674acb48cfdf38b21ae6b7f206807cf7b73e92b4da7adbcc4
7
- data.tar.gz: ac66e6773ec7138987d236cdf560cf71ad58e5b57af7e060fc9eed92211bdecec1c1915ea2d129e706e5828f20d83ab690ae8f086456fd64d1962a657108d574
6
+ metadata.gz: 235db8b1e75cc2d5e2a46b13df3f6c4bfa849838449c21d19e36dbbc912fb3ed24d53d40fec82ddd822d5f82d26163562e260d8300b7bf92ed5e96014ed3bfad
7
+ data.tar.gz: b512c1b15c55c6861ddbff2c44da4af8a9efff746188ae8d260225453436ebc0a0b742ab949535f1db61a7bbf63735b212399f242fc9c6cc16a23c51335378a3
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # ExpressCmd
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/express/cmd`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
@@ -22,7 +18,22 @@ Or install it yourself as:
22
18
 
23
19
  ## Usage
24
20
 
25
- TODO: Write usage instructions here
21
+ I choose `mongodb` as my datastore, and I perfer to use `mongoose`.
22
+
23
+ ```bash
24
+ # make sure you have installed node-inspector (debug tool) and nodemon (node auto reload after saved).
25
+ npm install -g node-inspector
26
+ npm install -g nodemon
27
+
28
+ gem install express-cmd
29
+
30
+ express project-name
31
+ ```
32
+
33
+ ## Test
34
+
35
+ I choose `mocha` and `chai`, and use `Makefile` to run test. Run `make jenkins` to generate test report.
36
+
26
37
 
27
38
  ## Development
28
39
 
@@ -18,6 +18,8 @@ module ExpressCmd
18
18
 
19
19
  def setup_config
20
20
  keep_file "#{app_name}/config"
21
+ copy_file "config/mongo.js", "#{app_name}/config/mongo.js"
22
+ copy_file "config/mongo.yml", "#{app_name}/config/mongo.yml"
21
23
  end
22
24
 
23
25
  def setup_middleware
@@ -1,3 +1,3 @@
1
1
  module ExpressCmd
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,58 @@
1
+ var yaml = require('js-yaml');
2
+ var ejs = require('ejs');
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var queryString = require('query-string');
6
+ var mongoose = require('mongoose');
7
+
8
+ var logger = require('../lib/logger');
9
+
10
+ var dbURI = 'mongodb://';
11
+
12
+ // CONNECTION EVENTS
13
+ // When successfully connected
14
+ mongoose.connection.on('connected', function (aaa, bbb, ccc) {
15
+ logger.info('Mongoose default connection open to ' + dbURI);
16
+ });
17
+
18
+ // If the connection throws an error
19
+ mongoose.connection.on('error',function (err) {
20
+ logger.error('Mongoose default connection error: ' + err);
21
+ });
22
+
23
+ // When the connection is disconnected
24
+ mongoose.connection.on('disconnected', function () {
25
+ logger.info('Mongoose default connection disconnected');
26
+ });
27
+
28
+ // When the connection is open
29
+ mongoose.connection.on('open', function () {
30
+ logger.info('Mongoose default connection is open');
31
+ });
32
+
33
+ // If the Node process ends, close the Mongoose connection
34
+ process.on('SIGINT', function() {
35
+ mongoose.connection.close(function () {
36
+ logger.info('Mongoose default connection disconnected through app termination');
37
+ process.exit(0);
38
+ });
39
+ });
40
+
41
+ module.exports.connect = function (env) {
42
+ var dbFile = yaml.safeLoad(ejs.render(fs.readFileSync(path.resolve(__dirname, '../config/mongo.yml'), 'UTF-8')));
43
+ var dbcf = dbFile[env];
44
+
45
+ // Build the connection string
46
+ if (dbcf.username && dbcf.password) {
47
+ dbURI += encodeURIComponent(dbcf.username) + ':' + encodeURIComponent(dbcf.password) + '@';
48
+ }
49
+
50
+ dbURI += dbcf.host + ':' + dbcf.port + '/' + dbcf.database + '?v=1&';
51
+
52
+ if (dbcf.options) {
53
+ dbURI += queryString.stringify(dbcf.options);
54
+ }
55
+
56
+ // Create the database connection
57
+ mongoose.connect(dbURI);
58
+ }
@@ -0,0 +1,23 @@
1
+ development:
2
+ host: localhost
3
+ port: 27017
4
+ database: demo-dev
5
+
6
+ test:
7
+ host: localhost
8
+ port: 27017
9
+ database: demo-test
10
+
11
+ production:
12
+ host: <%= process.env.MONGO_HOST %>
13
+ port: <%= process.env.MONGO_PORT %>
14
+ database: <%=process.env.MONGO_DBNAME %>
15
+ username: <%= process.env.MONGO_USERNAME %>
16
+ password: <%= process.env.MONGO_PASSWORD %>
17
+
18
+ staging:
19
+ host: <%= process.env.MONGO_HOST %>
20
+ port: <%= process.env.MONGO_PORT %>
21
+ database: <%= process.env.MONGO_DBNAME %>
22
+ username: <%= process.env.MONGO_USERNAME %>
23
+ password: <%= process.env.MONGO_PASSWORD %>
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "keywords": [
12
12
  ],
13
- "author": "CB",
13
+ "author": "",
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
16
  "async": "^1.2.1",
@@ -24,6 +24,7 @@
24
24
  "mocha": "^2.2.5",
25
25
  "mocha-jenkins-reporter": "^0.1.8",
26
26
  "moment": "^2.10.3",
27
+ "mongoose": "^4.0.8",
27
28
  "morgan": "^1.5.2",
28
29
  "multer": "^0.1.8",
29
30
  "path": "^0.11.14",
@@ -4,6 +4,8 @@ var bodyParser = require('body-parser');
4
4
  var multer = require('multer');
5
5
  var cookieParser = require('cookie-parser');
6
6
 
7
+ // mongo connect
8
+ var mongo = require('./config/mongo');
7
9
  var logger = require('./lib/logger');
8
10
 
9
11
  // MiddleWare
@@ -40,6 +42,8 @@ app.use('/api', apiRouter);
40
42
 
41
43
  app.listen(app.get('port'), function() {
42
44
  logger.info('Server started, listened on ' + app.get('port') + '.');
45
+ // connect with mongodb.
46
+ mongo.connect(app.get('env'));
43
47
  });
44
48
 
45
49
  module.exports = app;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express-cmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - wluo
@@ -133,6 +133,8 @@ files:
133
133
  - templates/.gitignore
134
134
  - templates/Makefile
135
135
  - templates/README.md.erb
136
+ - templates/config/mongo.js
137
+ - templates/config/mongo.yml
136
138
  - templates/lib/errors.js
137
139
  - templates/lib/logger.js
138
140
  - templates/middlewares/before-filter.js
@@ -165,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
167
  version: '0'
166
168
  requirements: []
167
169
  rubyforge_project:
168
- rubygems_version: 2.4.8
170
+ rubygems_version: 2.4.6
169
171
  signing_key:
170
172
  specification_version: 4
171
173
  summary: Command for generating express project