Skip to content

Commit

Permalink
Implement ESLint and fixes coding style #6
Browse files Browse the repository at this point in the history
  • Loading branch information
asumaran committed Feb 2, 2016
1 parent c6395ae commit 08856f6
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 230 deletions.
Binary file removed .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .eslintrc
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
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
xml
.env
.DS_Store
48 changes: 33 additions & 15 deletions gulpfile.js
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();
});
71 changes: 37 additions & 34 deletions lib/elastic.js
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;
Loading

0 comments on commit 08856f6

Please sign in to comment.