express-cmd 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08bc2c1db119896d78c2afbad2ffa8f6b8c47071
4
- data.tar.gz: e663d753bd60f5950421b1d386febba7eb4e78d1
3
+ metadata.gz: a73377e3082ce9abb9e910c7d74789a5184f6b11
4
+ data.tar.gz: 7b364ad9da3eb258800bd6985edc929274504c7a
5
5
  SHA512:
6
- metadata.gz: 235db8b1e75cc2d5e2a46b13df3f6c4bfa849838449c21d19e36dbbc912fb3ed24d53d40fec82ddd822d5f82d26163562e260d8300b7bf92ed5e96014ed3bfad
7
- data.tar.gz: b512c1b15c55c6861ddbff2c44da4af8a9efff746188ae8d260225453436ebc0a0b742ab949535f1db61a7bbf63735b212399f242fc9c6cc16a23c51335378a3
6
+ metadata.gz: bd714075d15db5718792f258f3434b25c99160172262aa7cc96136e1dcdbfccc8d2ad82dd8dd737ba976d99b1511dfed50e6bef88760f65028a6bed15822c729
7
+ data.tar.gz: 7289bf3608b1559ffad6484121e9f3d63d3274dba3ab86b23d2b6f7c8dd17000900f93a75133062916856fd31dc90f04b3c25faa22ae2a95026c693b0cfd56d0
data/README.md CHANGED
@@ -20,15 +20,16 @@ Or install it yourself as:
20
20
 
21
21
  I choose `mongodb` as my datastore, and I perfer to use `mongoose`.
22
22
 
23
+ 1. make sure you have installed node-inspector (debug tool) and nodemon (node auto reload after saved).
24
+
23
25
  ```bash
24
- # make sure you have installed node-inspector (debug tool) and nodemon (node auto reload after saved).
25
26
  npm install -g node-inspector
26
27
  npm install -g nodemon
28
+ ```
27
29
 
28
- gem install express-cmd
30
+ 2. `express app_name`, and you can specify an option, for example `express my-project --skip_npm_install`.
29
31
 
30
- express project-name
31
- ```
32
+ **supported options**: `--skip_npm_install`.
32
33
 
33
34
  ## Test
34
35
 
@@ -5,6 +5,7 @@ module ExpressCmd
5
5
  include Thor::Actions
6
6
 
7
7
  argument :app_name
8
+ class_option :skip_npm_install, :type => :boolean
8
9
 
9
10
  def self.source_root
10
11
  File.join(File.dirname(__FILE__), "../../", "templates")
@@ -54,7 +55,9 @@ module ExpressCmd
54
55
  end
55
56
 
56
57
  def bundle_install
57
- system "cd #{app_name} && npm install && cd ../"
58
+ unless options[:skip_npm_install]
59
+ system "cd #{app_name} && npm install && cd ../"
60
+ end
58
61
  end
59
62
 
60
63
  protected
@@ -1,3 +1,3 @@
1
1
  module ExpressCmd
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  describe ExpressCmd do
2
2
  it "Generator express" do
3
3
  bin_path = File.join(File.expand_path('../../bin', __FILE__))
4
- system("#{bin_path}/express test-project")
4
+ system("#{bin_path}/express test-project --skip_npm_install")
5
5
  end
6
6
  end
data/templates/.gitignore CHANGED
@@ -4,3 +4,5 @@
4
4
  /log
5
5
  /test/reporter/*.xml
6
6
  .npm-debug.log
7
+
8
+ /*.gem
@@ -7,41 +7,12 @@ var mongoose = require('mongoose');
7
7
 
8
8
  var logger = require('../lib/logger');
9
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) {
10
+ module.exports.connect = function (env, connectedCallback) {
42
11
  var dbFile = yaml.safeLoad(ejs.render(fs.readFileSync(path.resolve(__dirname, '../config/mongo.yml'), 'UTF-8')));
43
12
  var dbcf = dbFile[env];
44
13
 
14
+ var dbURI = 'mongodb://';
15
+
45
16
  // Build the connection string
46
17
  if (dbcf.username && dbcf.password) {
47
18
  dbURI += encodeURIComponent(dbcf.username) + ':' + encodeURIComponent(dbcf.password) + '@';
@@ -53,6 +24,38 @@ module.exports.connect = function (env) {
53
24
  dbURI += queryString.stringify(dbcf.options);
54
25
  }
55
26
 
27
+ // CONNECTION EVENTS
28
+ // When successfully connected
29
+ mongoose.connection.on('connected', function (aaa, bbb, ccc) {
30
+ logger.info('Mongoose default connection open to ' + dbURI);
31
+ });
32
+
33
+ // If the connection throws an error
34
+ mongoose.connection.on('error',function (err) {
35
+ logger.error('Mongoose default connection error: ' + err);
36
+ });
37
+
38
+ // When the connection is disconnected
39
+ mongoose.connection.on('disconnected', function () {
40
+ logger.info('Mongoose default connection disconnected');
41
+ });
42
+
43
+ // When the connection is open
44
+ mongoose.connection.on('open', function () {
45
+ logger.info('Mongoose default connection is open');
46
+ if (typeof connectedCallback === 'function') {
47
+ connectedCallback();
48
+ }
49
+ });
50
+
51
+ // If the Node process ends, close the Mongoose connection
52
+ process.on('SIGINT', function() {
53
+ mongoose.connection.close(function () {
54
+ logger.info('Mongoose default connection disconnected through app termination');
55
+ process.exit(0);
56
+ });
57
+ });
58
+
56
59
  // Create the database connection
57
60
  mongoose.connect(dbURI);
58
61
  }
@@ -1,5 +1,5 @@
1
1
  var hasProp = {}.hasOwnProperty;
2
- var extend = function(child, parent) {
2
+ var extend = function (child, parent) {
3
3
  for (var key in parent) {
4
4
  if (hasProp.call(parent, key))
5
5
  child[key] = parent[key];
@@ -13,7 +13,7 @@ var extend = function(child, parent) {
13
13
  return child;
14
14
  };
15
15
 
16
- var AuthError = (function(superClass) {
16
+ var AuthError = (function (superClass) {
17
17
  extend(AuthError, superClass);
18
18
 
19
19
  function AuthError(message) {
@@ -25,7 +25,7 @@ var AuthError = (function(superClass) {
25
25
  return AuthError;
26
26
  })(Error);
27
27
 
28
- var ReqError = (function(superClass) {
28
+ var ReqError = (function (superClass) {
29
29
  extend(ReqError, superClass);
30
30
 
31
31
  function ReqError(message) {
@@ -1,7 +1,7 @@
1
1
  var AuthError = require('../lib/errors').AuthError;
2
2
 
3
3
  module.exports = function(app) {
4
- return app.use(function(req, res, next) {
4
+ return app.use(function (req, res, next) {
5
5
  var origin = req.get('origin');
6
6
  if (origin) {
7
7
  res.header('Access-Control-Allow-Origin', origin);
@@ -1,8 +1,8 @@
1
1
  var logger = require('../lib/logger');
2
2
 
3
3
  // definded error handler.
4
- module.exports = function(app, apiRouter) {
5
- return app.use(function(err, req, res, next) {
4
+ module.exports = function (app, apiRouter) {
5
+ return app.use(function (err, req, res, next) {
6
6
  var statusCode = err.status || 500;
7
7
  logger.error(statusCode + ": " + err.message + ", \n " + (err.stack || ''));
8
8
 
@@ -2,7 +2,7 @@ var morgan = require('morgan');
2
2
  var path = require('path');
3
3
  var fs = require('fs');
4
4
 
5
- module.exports = function(app) {
5
+ module.exports = function (app) {
6
6
  var accessLogStream, env, logDirectory;
7
7
 
8
8
  logDirectory = path.join(__dirname, '../log');
@@ -1,5 +1,5 @@
1
- module.exports = function(router) {
2
- router.route('/').get(function(req, res, next) {
1
+ module.exports = function (router) {
2
+ router.route('/').get(function (req, res, next) {
3
3
  res.status(204).end();
4
4
  });
5
5
  };
@@ -1,9 +1,9 @@
1
- module.exports = function(router) {
2
- router.route('/').get(function(req, res, next) {
1
+ module.exports = function (router) {
2
+ router.route('/').get(function (req, res, next) {
3
3
  res.json({instances: []});
4
4
  });
5
5
 
6
- router.route('/:hostname').get(function(req, res, next) {
6
+ router.route('/:hostname').get(function (req, res, next) {
7
7
  res.json({hostname: req.params.hostname});
8
8
  });
9
9
  };
@@ -1,5 +1,5 @@
1
- module.exports = function(router) {
2
- router.route('/').get(function(req, res, next) {
1
+ module.exports = function (router) {
2
+ router.route('/').get(function (req, res, next) {
3
3
  res.status(204).end();
4
4
  });
5
5
  };
data/templates/server.js CHANGED
@@ -19,28 +19,29 @@ app.set('env', process.env.NODE_ENV || 'development');
19
19
 
20
20
  // Before Filter
21
21
  require('./middlewares/before-filter')(app);
22
- // Error handler
23
- require('./middlewares/error-handler')(app);
24
22
  // Access Log
25
23
  require('./middlewares/morgan-log')(app);
26
24
 
27
25
  // Routes Example
28
- var apiRouter = express.Router();
26
+ var rootRouter = express.Router();
29
27
  var instanceRouter = express.Router();
30
28
  var configurationRouter = express.Router({ mergeParams: true });
31
29
  var translationRouter = express.Router({ mergeParams: true });
32
30
 
33
31
  instanceRouter.use('/:hostname/configurations', configurationRouter);
34
32
  instanceRouter.use('/:hostname/translations', translationRouter);
35
- apiRouter.use('/instances', instanceRouter);
33
+ rootRouter.use('/instances', instanceRouter);
36
34
 
37
35
  require('./routes/configuration')(configurationRouter);
38
36
  require('./routes/translation')(translationRouter);
39
37
  require('./routes/instance')(instanceRouter);
40
38
 
41
- app.use('/api', apiRouter);
39
+ app.use('/1', rootRouter);
40
+
41
+ // Error handler (should be here)
42
+ require('./middlewares/error-handler')(app);
42
43
 
43
- app.listen(app.get('port'), function() {
44
+ app.listen(app.get('port'), function () {
44
45
  logger.info('Server started, listened on ' + app.get('port') + '.');
45
46
  // connect with mongodb.
46
47
  mongo.connect(app.get('env'));
@@ -1,5 +1,5 @@
1
- describe('Demo Test', function(){
2
- it("#Chai should sample example", function(done) {
1
+ describe('Demo Test', function () {
2
+ it("#Chai should sample example", function (done) {
3
3
  var user = {
4
4
  name: 'tj',
5
5
  pets: ['tobi', 'loki', 'jane', 'bandit']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express-cmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - wluo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-24 00:00:00.000000000 Z
11
+ date: 2015-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler