express-cmd 0.2.0 → 0.3.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 +4 -4
- data/README.md +5 -4
- data/lib/express_cmd/generator.rb +4 -1
- data/lib/express_cmd/version.rb +1 -1
- data/spec/generate_spec.rb +1 -1
- data/templates/.gitignore +2 -0
- data/templates/config/mongo.js +35 -32
- data/templates/lib/errors.js +3 -3
- data/templates/middlewares/before-filter.js +1 -1
- data/templates/middlewares/error-handler.js +2 -2
- data/templates/middlewares/morgan-log.js +1 -1
- data/templates/routes/configuration.js +2 -2
- data/templates/routes/instance.js +3 -3
- data/templates/routes/translation.js +2 -2
- data/templates/server.js +7 -6
- data/templates/test/units/demo_test.js +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a73377e3082ce9abb9e910c7d74789a5184f6b11
|
4
|
+
data.tar.gz: 7b364ad9da3eb258800bd6985edc929274504c7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
30
|
+
2. `express app_name`, and you can specify an option, for example `express my-project --skip_npm_install`.
|
29
31
|
|
30
|
-
|
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
|
-
|
58
|
+
unless options[:skip_npm_install]
|
59
|
+
system "cd #{app_name} && npm install && cd ../"
|
60
|
+
end
|
58
61
|
end
|
59
62
|
|
60
63
|
protected
|
data/lib/express_cmd/version.rb
CHANGED
data/spec/generate_spec.rb
CHANGED
data/templates/.gitignore
CHANGED
data/templates/config/mongo.js
CHANGED
@@ -7,41 +7,12 @@ var mongoose = require('mongoose');
|
|
7
7
|
|
8
8
|
var logger = require('../lib/logger');
|
9
9
|
|
10
|
-
|
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
|
}
|
data/templates/lib/errors.js
CHANGED
@@ -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
|
|
@@ -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
|
};
|
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
|
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
|
-
|
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('/
|
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'));
|
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.
|
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-
|
11
|
+
date: 2015-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|