Skip to content

Commit 6c11e55

Browse files
committed
cli ratelimit and code maintainence 2
1 parent 40c69c1 commit 6c11e55

File tree

11 files changed

+1347
-644
lines changed

11 files changed

+1347
-644
lines changed

.eslintrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
env: {
3+
es6: true,
4+
node: true
5+
},
6+
extends: 'eslint:recommended',
7+
parserOptions: {
8+
ecmaVersion: 2015
9+
},
10+
rules: {
11+
indent: [ 'error', 2 ],
12+
'linebreak-style': [ 'error', 'unix'],
13+
quotes: [ 'error', 'single' ],
14+
semi: [ 'error', 'always' ]
15+
}
16+
};

bin/index.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ var messages = [
2222
'\t \x1b[33m**'
2323
, ' \x1b[33m***'
2424
, ' \x1b[33m****'
25-
, '\x1b[33m***** \x1b[31m** \x1b[36m.----------------------.'
26-
, ' \x1b[33m**** \x1b[31m*** \x1b[36m| Contentstack |'
27-
, ' \x1b[33m*** \x1b[31m**** \x1b[36m\'----------------------\''
28-
, ' \x1b[33m** \x1b[31m***** '
25+
, '\x1b[33m***** \x1b[31m**'
26+
, ' \x1b[33m**** \x1b[31m*** Contentstack'
27+
, ' \x1b[33m*** \x1b[31m****'
28+
, ' \x1b[33m** \x1b[31m*****'
2929
, ' \x1b[31m****'
3030
, ' \x1b[31m***'
3131
, ' \x1b[31m**'
@@ -90,19 +90,22 @@ program
9090
setImmediate(function () {
9191
//creating the domain to execute in safe mode
9292
var context = domain.create();
93-
9493
// error handling in domain
9594
context.on('error', errorHandler);
9695

9796
// running the connect in domain
9897
context.run(function() {
99-
var connect = require('./../lib/connect'),
100-
args = {
101-
directory: directory || options.dir,
102-
api_key: api_key || options.api_key,
103-
access_token: access_token || options.token,
104-
template: "basic" || options.template
105-
};
98+
try {
99+
var connect = require('../lib/connect');
100+
} catch (error) {
101+
console.error(error)
102+
}
103+
var args = {
104+
directory: directory || options.dir,
105+
api_key: api_key || options.api_key,
106+
access_token: access_token || options.token,
107+
template: 'basic' || options.template
108+
};
106109
new connect(args);
107110
});
108111
});
@@ -180,7 +183,11 @@ program
180183
context.run(function() {
181184
var _options = optionConversion(options);
182185
_options = helper.merge(getDefaultOptions(options, options._events), _options);
183-
var publish = require('./../lib/publish');
186+
try {
187+
var publish = require('./../lib/publish');
188+
} catch (error) {
189+
console.error(error)
190+
}
184191
new publish('publish', _options);
185192
});
186193
});
@@ -238,7 +245,6 @@ if (program.args.length == 0) {
238245
, ' -V, --version output the version number'
239246
, '\nDocumentation can be found at https://contentstackdocs.built.io/'
240247
].join('\n');
241-
console.log(message);
242248
process.exit(1);
243249
}
244250
/*

lib/config/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,32 @@
1111
*/
1212
var fs = require('fs');
1313
var path = require('path');
14+
var chalk = require('chalk');
1415
var resolve = require('resolve');
1516
var folderPath;
16-
17+
var log = console.log;
18+
var error = chalk.red;
1719
/**
1820
* Load config from contentstack-express
1921
* @return {Object} contentstack-express config
2022
*/
2123
exports.config = function() {
2224
try {
23-
var frameworkPath, contentstack, config, rootPath = process.cwd();
25+
var frameworkPath, contentstack, rootPath = process.cwd();
2426
frameworkPath = resolve.sync('contentstack-express', {
2527
paths: [],
2628
basedir: rootPath
2729
});
2830
folderPath = frameworkPath.replace('contentstack.js', '');
2931
contentstack = require(frameworkPath);
3032
return contentstack.config;
31-
} catch (error) {
32-
console.error(
33-
`contentstack-express module could not be resolved!\n${error.message || error}`
34-
);
35-
console.error(
36-
`Please run the command from the contentstack-express application directory`
37-
);
33+
} catch (err) {
34+
log(error(
35+
`contentstack-express module could not be resolved!\n${err.message || err}`
36+
));
37+
log(error(
38+
'Please run the command from the contentstack-express application directory'
39+
));
3840
process.exit(0);
3941
}
4042
};

0 commit comments

Comments
 (0)