Skip to content

Commit bd7c489

Browse files
author
Tom Kirkpatrick
committed
style: lint the code
1 parent 26274b7 commit bd7c489

File tree

6 files changed

+45
-32
lines changed

6 files changed

+45
-32
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git/
2+
node_modules/
3+
coverage
4+
.nyc_output

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "fullcube",
3+
"root": true
4+
}

index.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
/* eslint global-require: 0 */
2+
13
'use strict'
24

35
const kebabCase = require('lodash.kebabcase')
4-
const fs = require('fs')
56
const path = require('path')
67
const debug = require('debug')('loopback:component:model-extender')
78
const appRoot = require('app-root-path')
9+
const requireAll = require('require-all')
810

911
module.exports = (app, options) => {
1012
options = options || {}
@@ -23,27 +25,24 @@ module.exports = (app, options) => {
2325

2426
// Set up logging class.
2527
let log = options.log || console
28+
2629
if (typeof log === 'string') {
2730
log = require(log)
2831
}
2932

3033
// Apply models customisations.
31-
function customizeModel(sourcePath) {
32-
fs.readdirSync(sourcePath).forEach(sourceFile => {
33-
const filePath = path.join(sourcePath, sourceFile)
34-
35-
if (path.extname(sourceFile) === '.js') {
36-
debug('Loading customization script %s', filePath)
37-
const code = require(filePath)
38-
34+
function customizeModel(dirname) {
35+
requireAll({
36+
dirname,
37+
resolve: code => {
38+
debug('Loading customization script %s', code)
3939
if (typeof code === 'function') {
4040
debug('Customizing model %s', Model.modelName)
41-
code(Model)
42-
}
43-
else {
44-
debug('Skipping model file %s - `module.exports` is not a function', sourceFile)
41+
return code(Model)
4542
}
46-
}
43+
debug('Skipping model file %s - `module.exports` is not a function', code)
44+
return code
45+
},
4746
})
4847
}
4948

@@ -60,7 +59,7 @@ module.exports = (app, options) => {
6059
// anything other than 'file not found' should be a hard fail.
6160
if (err.code !== 'ENOENT') {
6261
log.error(`Failure loading component path: ${requirePath}`, err.stack)
63-
process.exit(1)
62+
throw err
6463
}
6564
}
6665
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"description": "Loopback Component Model Extender",
55
"main": "index.js",
66
"scripts": {
7+
"lint": "eslint .",
8+
"pretest": "npm run lint",
79
"test": "nyc --reporter=lcov --reporter=text --reporter=text-summary mocha test/*test.js",
810
"test:watch": "npm run test -- -w"
911
},
@@ -28,10 +30,13 @@
2830
"devDependencies": {
2931
"chai": "3.5.0",
3032
"cors": "2.8.3",
33+
"eslint": "3.19.0",
34+
"eslint-config-fullcube": "2.0.35-latest-20170602-0428.0",
3135
"loopback": "3.8.0",
3236
"loopback-boot": "2.24.0",
3337
"mocha": "3.1.2",
3438
"nyc": "11.0.2",
39+
"require-all": "2.2.0",
3540
"strong-error-handler": "2.1.0"
3641
}
3742
}

test/.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "fullcube/mocha",
3+
"root": true
4+
}

test/test-server/server/server.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
'use strict';
1+
'use strict'
22

3-
var loopback = require('loopback');
4-
var boot = require('loopback-boot');
3+
const loopback = require('loopback')
4+
const boot = require('loopback-boot')
55

6-
var app = module.exports = loopback();
6+
const app = module.exports = loopback()
77

88
app.start = function() {
99
// start the web server
1010
return app.listen(function() {
11-
app.emit('started');
12-
var baseUrl = app.get('url').replace(/\/$/, '');
13-
console.log('Web server listening at: %s', baseUrl);
14-
if (app.get('loopback-component-explorer')) {
15-
var explorerPath = app.get('loopback-component-explorer').mountPath;
16-
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
17-
}
18-
});
19-
};
11+
app.emit('started')
12+
})
13+
}
2014

2115
// Bootstrap the application, configure models, datasources and middleware.
2216
// Sub-apps like REST API are mounted via boot scripts.
2317
boot(app, __dirname, function(err) {
24-
if (err) throw err;
18+
if (err) {
19+
throw err
20+
}
2521

2622
// start the server if `$ node server.js`
27-
if (require.main === module)
28-
app.start();
29-
});
23+
if (require.main === module) {
24+
app.start()
25+
}
26+
})

0 commit comments

Comments
 (0)