Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 54aad2a

Browse files
committed
chore: cleanup
1 parent 7f53a44 commit 54aad2a

11 files changed

+167
-178
lines changed

doc/2. graphQl support.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const resolver = {
4040
products: (_, { search, filter, sort, currentPage, pageSize }, context, rootValue) =>
4141
list(filter, sort, currentPage, pageSize, search, context, rootValue)
4242
}
43-
};
43+
}
4444
```
4545

4646
For other entity types you can check schemas and resolvers in the /src/graphql/elasticsearch correspond subfolder

docker-compose.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
version: '3.0'
1+
version: '3'
22
services:
33
es1:
44
container_name: elasticsearch
5-
# image: divante/vue-storefront-elasticsearch:5.6.10
65
build: docker/elasticsearch/
76
volumes:
87
- ./docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
@@ -14,7 +13,6 @@ services:
1413
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
1514

1615
kibana:
17-
# image: divante/vue-storefront-kibana:5.6.10
1816
build: docker/kibana/
1917
volumes:
2018
- ./docker/kibana/config/:/usr/share/kibana/config:ro

docker/elasticsearch/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM docker.elastic.co/elasticsearch/elasticsearch:5.6.10
1+
FROM docker.elastic.co/elasticsearch/elasticsearch:5.6.11
22

33
RUN bin/elasticsearch-plugin remove x-pack --purge
44

docker/kibana/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM docker.elastic.co/kibana/kibana:5.6.10
1+
FROM docker.elastic.co/kibana/kibana:5.6.11
22

33
RUN bin/kibana-plugin remove x-pack && \
44
kibana 2>&1 | grep -m 1 "Optimization of .* complete"

migrations/.common.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
let config = require('config');
3-
let kue = require('kue');
4-
let queue = kue.createQueue(Object.assign(config.kue, { redis: config.redis }));
2+
let config = require('config')
3+
let kue = require('kue')
4+
let queue = kue.createQueue(Object.assign(config.kue, { redis: config.redis }))
55

66
let es = require('elasticsearch')
77
const esConfig = {
@@ -15,9 +15,9 @@ const esConfig = {
1515
keepAlive: false
1616
}
1717
if (config.elasticsearch.user) {
18-
esConfig.httpAuth = config.elasticsearch.user + ':' + config.elasticsearch.password
18+
esConfig.httpAuth = config.elasticsearch.user + ':' + config.elasticsearch.password
1919
}
2020
let client = new es.Client(esConfig)
2121

22-
exports.db = client
22+
exports.db = client
2323
exports.queue = queue

migrations/1513602868543-change_field_types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const common = require('./.common')
55
const putMappings = require('../src/lib/elastic').putMappings
66

77
module.exports.up = next => {
8-
putMappings(common.db, config.elasticsearch.indices[0], next);
8+
putMappings(common.db, config.elasticsearch.indices[0], next)
99
}
1010

1111
module.exports.down = next => {

migrations/1530101328854-local_es_config_fix.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
'use strict'
22

3-
const _set = require('lodash/set');
3+
const _set = require('lodash/set')
44

5-
const fs = require('fs');
6-
const path = require('path');
5+
const fs = require('fs')
6+
const path = require('path')
77

8-
const configDir = path.resolve('./config');
8+
const configDir = path.resolve('./config')
99

1010
var files = fs.readdirSync(configDir).filter(function(file) {
11-
if (file === 'default.json') return false;
11+
if (file === 'default.json') return false
1212

13-
if (file.startsWith('elastic.schema.')) return false;
13+
if (file.startsWith('elastic.schema.')) return false
1414

15-
return path.extname(file) === '.json';
16-
});
15+
return path.extname(file) === '.json'
16+
})
1717

1818
module.exports.up = next => {
1919
files.forEach(function(file) {
20-
var file = path.join(configDir, file);
20+
var file = path.join(configDir, file)
2121

2222
try {
23-
console.log("Searching for deprecated parameters in file '%s'...", file);
24-
let config = JSON.parse(fs.readFileSync(file));
23+
console.log(`Searching for deprecated parameters in file '${file}'...`)
24+
let config = JSON.parse(fs.readFileSync(file))
2525

2626
if ("esHost" in config) {
27-
console.log("Parameter 'esHost' found - rewriting...", file);
28-
let esHostPort = config.esHost.split(':');
29-
_set(config, 'elasticsearch.host', esHostPort[0]);
30-
_set(config, 'elasticsearch.port', esHostPort[1]);
31-
delete config.esHost;
27+
console.log("Parameter 'esHost' found - rewriting...", file)
28+
let esHostPort = config.esHost.split(':')
29+
_set(config, 'elasticsearch.host', esHostPort[0])
30+
_set(config, 'elasticsearch.port', esHostPort[1])
31+
delete config.esHost
3232
}
3333

3434
if ("esIndexes" in config) {
35-
console.log("Parameter 'esIndexes' found - rewriting...");
36-
_set(config, 'elasticsearch.indices', config.esIndexes);
37-
delete config.esIndexes;
35+
console.log("Parameter 'esIndexes' found - rewriting...")
36+
_set(config, 'elasticsearch.indices', config.esIndexes)
37+
delete config.esIndexes
3838
}
3939

40-
fs.writeFileSync(file, JSON.stringify(config, null, 2));
41-
console.log("File '%s' updated.", file);
40+
fs.writeFileSync(file, JSON.stringify(config, null, 2))
41+
console.log(`File '${file}' updated.`)
4242
} catch (e) {
43-
throw e;
43+
throw e
4444
}
45-
});
45+
})
4646

4747
next()
4848
}

scripts/db.js

+51-56
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use harmony'
2-
31
const CommandRouter = require('command-router')
42
const cli = CommandRouter()
53

@@ -8,77 +6,74 @@ const common = require('../migrations/.common')
86
const es = require('../src/lib/elastic')
97

108
cli.option({ name: 'indexName',
11-
alias: 'i',
12-
default: config.elasticsearch.indices[0],
13-
type: String
9+
alias: 'i',
10+
default: config.elasticsearch.indices[0],
11+
type: String
1412
})
1513

1614
cli.command('rebuild', () => { // TODO: add parallel processing
17-
console.log('** Hello! I am going to rebuild EXISTINT ES index to fix the schema')
18-
const originalIndex = cli.options.indexName
19-
const tempIndex = originalIndex + '_' + Math.round(+new Date()/1000)
20-
21-
console.log('** Creating temporary index' + tempIndex)
22-
es.createIndex(common.db, tempIndex, function(err) {
23-
if (err) {
24-
console.log(err)
25-
}
15+
console.log('** Hello! I am going to rebuild EXISTINT ES index to fix the schema')
16+
const originalIndex = cli.options.indexName
17+
const tempIndex = originalIndex + '_' + Math.round(+new Date()/1000)
2618

27-
console.log('** Putting the mappings on top of ' + tempIndex)
28-
es.putMappings(common.db, tempIndex, function(err) {
19+
console.log(`** Creating temporary index ${tempIndex}`)
20+
es.createIndex(common.db, tempIndex, function(err) {
21+
if (err) {
22+
console.log(err)
23+
}
2924

30-
console.log('** We will reindex ' + originalIndex + ' with the current schema')
31-
es.reIndex(common.db, originalIndex, tempIndex, function (err) {
32-
if (err) {
33-
console.log(err)
34-
}
35-
36-
console.log('** Removing the original index')
37-
es.deleteIndex(common.db, originalIndex, function (err) {
38-
if (err) {
39-
console.log(err)
40-
}
25+
console.log(`** Putting the mappings on top of ${tempIndex}`)
26+
es.putMappings(common.db, tempIndex, function(err) {
4127

42-
console.log('** Creating alias')
43-
es.putAlias(common.db, tempIndex, originalIndex, function (err) {
44-
console.log('Done! Bye!')
45-
process.exit(0)
46-
})
47-
})
48-
})
49-
})
50-
})
51-
})
52-
53-
cli.command('new', () => { // TODO: add parallel processing
54-
console.log('** Hello! I am going to create NE ES index')
55-
const indexName = cli.options.indexName
56-
es.createIndex(common.db, indexName, function (err) {
28+
console.log(`** We will reindex ${originalIndex} with the current schema`)
29+
es.reIndex(common.db, originalIndex, tempIndex, function (err) {
5730
if (err) {
58-
console.log(err)
31+
console.log(err)
5932
}
6033

61-
console.log('Done! Bye!')
34+
console.log('** Removing the original index')
35+
es.deleteIndex(common.db, originalIndex, function (err) {
36+
if (err) {
37+
console.log(err)
38+
}
39+
40+
console.log('** Creating alias')
41+
es.putAlias(common.db, tempIndex, originalIndex, function (err) {
42+
console.log('Done! Bye!')
43+
process.exit(0)
44+
})
45+
})
46+
})
6247
})
63-
})
48+
})
49+
})
6450

51+
cli.command('new', () => { // TODO: add parallel processing
52+
console.log('** Hello! I am going to create NE ES index')
53+
const indexName = cli.options.indexName
54+
es.createIndex(common.db, indexName, function (err) {
55+
if (err) {
56+
console.log(err)
57+
}
6558

59+
console.log('Done! Bye!')
60+
})
61+
})
6662

6763
cli.on('notfound', (action) => {
68-
console.error('I don\'t know how to: ' + action)
64+
console.error(`I don't know how to: ${action}`)
6965
process.exit(1)
7066
})
71-
72-
67+
7368
process.on('unhandledRejection', (reason, p) => {
74-
console.error('Unhandled Rejection at: Promise', p, 'reason:', reason);
75-
// application specific logging, throwing an error, or other logic here
76-
});
69+
console.error(`Unhandled Rejection at: Promise ${p}, reason: ${reason}`)
70+
// application specific logging, throwing an error, or other logic here
71+
})
7772

7873
process.on('uncaughtException', function (exception) {
79-
console.error(exception); // to see your exception details in the console
80-
// if you are on production, maybe you can send the exception details to your
81-
// email as well ?
82-
});
74+
console.error(exception) // to see your exception details in the console
75+
// if you are on production, maybe you can send the exception details to your
76+
// email as well ?
77+
})
8378

84-
cli.parse(process.argv);
79+
cli.parse(process.argv)

scripts/elastic.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
'use harmony'
2-
31
const CommandRouter = require('command-router')
42
const cli = CommandRouter()
53

6-
const util = require('util');
74
const config = require('config').elasticsearch
85
const spawnSync = require('child_process').spawnSync
96

@@ -33,36 +30,44 @@ cli.option({
3330

3431
function stdOutErr(stdout, stderr) {
3532
if (stdout.length > 0)
36-
console.log(stdout.toString('utf8'));
33+
console.log(stdout.toString('utf8'))
3734
if (stderr.length > 0)
38-
console.error(stderr.toString('utf8'));
35+
console.error(stderr.toString('utf8'))
3936
}
4037

4138
cli.command('dump', () => {
42-
var input = util.format('http://%s:%d/%s', config.host, config.port, cli.options['input-index']);
39+
const input = `http://${config.host}:${config.port}/${cli.options['input-index']}`
4340

44-
var child = spawnSync('node', ['node_modules/elasticdump/bin/elasticdump', '--input=' + input, '--output=' + cli.options['output-file']]);
45-
stdOutErr(child.stdout, child.stderr);
41+
const child = spawnSync('node', [
42+
'node_modules/elasticdump/bin/elasticdump',
43+
`--input=${input}`,
44+
`--output=${cli.options['output-file']}`
45+
])
46+
stdOutErr(child.stdout, child.stderr)
4647
})
4748

4849
cli.command('restore', () => {
49-
var output = util.format('http://%s:%d/%s', config.host, config.port, cli.options['output-index']);
50+
const output = `http://${config.host}:${config.port}/${cli.options['output-index']}`
5051

51-
var child = spawnSync('node', ['node_modules/elasticdump/bin/elasticdump', '--input=' + cli.options['input-file'], '--output=' + output]);
52-
stdOutErr(child.stdout, child.stderr);
52+
const child = spawnSync('node', [
53+
'node_modules/elasticdump/bin/elasticdump',
54+
`--input=${cli.options['input-file']}`,
55+
`--output=${output}`
56+
])
57+
stdOutErr(child.stdout, child.stderr)
5358
})
5459

5560
cli.on('notfound', (action) => {
56-
console.error('I don\'t know how to: ' + action)
61+
console.error(`I don't know how to: ${action}`)
5762
process.exit(1)
5863
})
5964

6065
process.on('unhandledRejection', (reason, p) => {
61-
console.log("Unhandled Rejection at: Promise ", p, " reason: ", reason);
62-
});
66+
console.log("Unhandled Rejection at: Promise ", p, " reason: ", reason)
67+
})
6368

6469
process.on('uncaughtException', function(exception) {
65-
console.log(exception);
66-
});
70+
console.log(exception)
71+
})
6772

68-
cli.parse(process.argv);
73+
cli.parse(process.argv)

scripts/kue.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
'use harmony'
2-
31
const CommandRouter = require('command-router')
42
const cli = CommandRouter()
53

6-
const util = require('util');
74
const config = require('config').redis
8-
const kue = require('kue');
5+
const kue = require('kue')
96

107
cli.option({
118
name: 'port',
@@ -30,22 +27,22 @@ cli.command('dashboard', () => {
3027
db: config.db
3128
},
3229
prefix: cli.options.prefix
33-
});
30+
})
3431

35-
kue.app.listen(cli.options.port);
32+
kue.app.listen(cli.options.port)
3633
})
3734

3835
cli.on('notfound', (action) => {
39-
console.error('I don\'t know how to: ' + action)
36+
console.error(`I don't know how to: ${action}`)
4037
process.exit(1)
4138
})
4239

4340
process.on('unhandledRejection', (reason, p) => {
44-
console.log("Unhandled Rejection at: Promise ", p, " reason: ", reason);
45-
});
41+
console.log(`Unhandled Rejection at: Promise ${p}, reason: ${reason}`)
42+
})
4643

4744
process.on('uncaughtException', function(exception) {
48-
console.log(exception);
49-
});
45+
console.log(exception)
46+
})
5047

51-
cli.parse(process.argv);
48+
cli.parse(process.argv)

0 commit comments

Comments
 (0)