-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ESLint and fixes coding style #6
- Loading branch information
Showing
8 changed files
with
293 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "airbnb/legacy", | ||
"rules": { | ||
"comma-dangle": [2, "never"], | ||
"func-names": 0, | ||
"no-console": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
xml | ||
.env | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,60 @@ | ||
var | ||
gulp = require('gulp'), | ||
cheerio = require('gulp-cheerio'), | ||
gimporter = require('./lib/gimporter'), | ||
indexer = require('./lib/indexer'), | ||
elastic = require('./lib/elastic'), | ||
Q = require('q'); | ||
var gulp = require('gulp'); | ||
var cheerio = require('gulp-cheerio'); | ||
var gimporter = require('./lib/gimporter'); | ||
var indexer = require('./lib/indexer'); | ||
var elastic = require('./lib/elastic'); | ||
var eslint = require('gulp-eslint'); | ||
|
||
gulp.task('import', function () { | ||
return gulp | ||
.src(['xml/**/*.*','!xml/**/{POPUP,POPUP/**}']) | ||
.src(['xml/**/*.*', '!xml/**/{POPUP,POPUP/**}']) | ||
.pipe(cheerio({ | ||
parserOptions: { | ||
xmlMode: true | ||
}, | ||
run: function ($, file, done) { | ||
console.log('Processing: ' + file.path); | ||
gimporter.processFile($, file) | ||
.then(function(){ | ||
.then(function () { | ||
done(); | ||
}); | ||
} | ||
})); | ||
} })); | ||
}); | ||
|
||
gulp.task('process_template', function() { | ||
gulp.task('process_template', function () { | ||
elastic.setTemplate(); | ||
}); | ||
|
||
gulp.task('index', function() { | ||
gulp.task('index', function () { | ||
indexer.perform(); | ||
}); | ||
|
||
gulp.task('reindex', function () { | ||
indexer.reindex(); | ||
}); | ||
|
||
gulp.task('run', ['import', 'process_template', 'index']); | ||
gulp.task('lint', function () { | ||
return gulp.src(['**/*.js', '!node_modules/**']) | ||
.pipe(eslint()) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()); | ||
}); | ||
|
||
gulp.task('lint-watch', function () { | ||
var lintAndPrint = eslint(); | ||
|
||
lintAndPrint.pipe(eslint.formatEach()); | ||
|
||
return gulp.watch('./lib/**/*.js', function (event) { | ||
if (event.type !== 'deleted') { | ||
gulp.src(event.path) | ||
.pipe(lintAndPrint, { | ||
end: false | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
gulp.task('default', ['import'], function() { | ||
gulp.task('default', ['import'], function () { | ||
process.exit(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,47 @@ | ||
var elastic = {}, | ||
elasticsearch = require('elasticsearch'), | ||
Q = require('q'), | ||
TEMPLATE_NAME = "template_gaceta", | ||
template_mapping = require("./template/template_mapping.json"), | ||
client = new elasticsearch.Client({ | ||
host: 'localhost:9200' | ||
}); | ||
var elasticsearch = require('elasticsearch'); | ||
var templateMapping = require('./template/template_mapping.json'); | ||
var Q = require('q'); | ||
var client = {}; | ||
var elastic = {}; | ||
var TEMPLATE_NAME = 'template_gaceta'; | ||
|
||
client = new elasticsearch.Client({ | ||
host: 'localhost:9200' | ||
}); | ||
|
||
elastic.deleteTemplate = function() { | ||
var deferred = Q.defer(); | ||
elastic.deleteTemplate = function () { | ||
var deferred = Q.defer(); | ||
|
||
client.indices.existsTemplate({ | ||
client.indices.existsTemplate({ | ||
name: TEMPLATE_NAME | ||
}, function () { | ||
client.indices.deleteTemplate({ | ||
name: TEMPLATE_NAME | ||
}, function() { | ||
client.indices.deleteTemplate({ | ||
name: TEMPLATE_NAME | ||
}, function(err) { | ||
if (err) { | ||
err; | ||
} | ||
deferred.resolve(); | ||
}); | ||
}, function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
deferred.resolve(); | ||
}); | ||
}); | ||
|
||
return deferred.promise; | ||
return deferred.promise; | ||
}; | ||
|
||
elastic.setTemplate = function() { | ||
this.deleteTemplate().then(function() { | ||
client.indices.putTemplate({ | ||
create: true, | ||
name: TEMPLATE_NAME, | ||
body: template_mapping | ||
}, function(err) { | ||
if (err) { | ||
throw err; | ||
} | ||
console.log('Template added:', TEMPLATE_NAME); | ||
}); | ||
elastic.setTemplate = function () { | ||
this.deleteTemplate().then(function () { | ||
client.indices.putTemplate({ | ||
create: true, | ||
name: TEMPLATE_NAME, | ||
body: templateMapping | ||
}, function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
console.log('Template added:', TEMPLATE_NAME); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = elastic; | ||
module.exports = elastic; |
Oops, something went wrong.