Skip to content

Commit

Permalink
Code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed May 1, 2017
1 parent c2cd5d7 commit 0a67fb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
13 changes: 6 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const babel = require('gulp-babel');
const child_process = require('child_process');
const {david} = require('@cedx/gulp-david');
const {spawn} = require('child_process');
const del = require('del');
const eslint = require('gulp-eslint');
const gulp = require('gulp');
const path = require('path');
const babel = require('gulp-babel');
const eslint = require('gulp-eslint');
const {normalize} = require('path');

/**
* Runs the default tasks.
Expand Down Expand Up @@ -69,7 +69,7 @@ gulp.task('lint', () => gulp.src(['*.js', 'src/**/*.js', 'test/**/*.js'])
gulp.task('test', () => _exec('node_modules/.bin/nyc', [
'--report-dir=var',
'--reporter=lcovonly',
path.normalize('node_modules/.bin/mocha'),
normalize('node_modules/.bin/mocha'),
'--compilers=js:babel-register',
'--recursive'
]));
Expand All @@ -82,8 +82,7 @@ gulp.task('test', () => _exec('node_modules/.bin/nyc', [
* @return {Promise} Completes when the command is finally terminated.
*/
async function _exec(command, args = [], options = {shell: true, stdio: 'inherit'}) {
return new Promise((resolve, reject) => child_process
.spawn(path.normalize(command), args, options)
return new Promise((resolve, reject) => spawn(normalize(command), args, options)
.on('close', code => code ? reject(new Error(`${command}: ${code}`)) : resolve())
);
}
12 changes: 6 additions & 6 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import EventEmitter from 'events';
import superagent from 'superagent';
import url from 'url';
import {parse} from 'url';

import {Blog} from './blog';
import * as pkg from '../package.json';
import {version} from '../package.json';

/**
* Submits comments to the [Akismet](https://akismet.com) service.
Expand Down Expand Up @@ -64,7 +64,7 @@ export class Client extends EventEmitter {
* If possible, the user agent string should always have the following format: `Application Name/Version | Plugin Name/Version`.
* @type {string}
*/
this.userAgent = `Node.js/${process.version.substr(1)} | Akismet/${pkg.version}`;
this.userAgent = `Node.js/${process.version.substr(1)} | Akismet/${version}`;
}

/**
Expand All @@ -73,7 +73,7 @@ export class Client extends EventEmitter {
* @return {Promise<boolean>} A boolean value indicating whether it is spam.
*/
async checkComment(comment) {
let serviceURL = url.parse(this.endPoint);
let serviceURL = parse(this.endPoint);
let endPoint = `${serviceURL.protocol}//${this.apiKey}.${serviceURL.host}/1.1/comment-check`;
return await this._fetch(endPoint, comment.toJSON()) == 'true';
}
Expand All @@ -84,7 +84,7 @@ export class Client extends EventEmitter {
* @return {Promise} Completes once the comment has been submitted.
*/
async submitHam(comment) {
let serviceURL = url.parse(this.endPoint);
let serviceURL = parse(this.endPoint);
let endPoint = `${serviceURL.protocol}//${this.apiKey}.${serviceURL.host}/1.1/submit-ham`;
return this._fetch(endPoint, comment.toJSON());
}
Expand All @@ -95,7 +95,7 @@ export class Client extends EventEmitter {
* @return {Promise} Completes once the comment has been submitted.
*/
async submitSpam(comment) {
let serviceURL = url.parse(this.endPoint);
let serviceURL = parse(this.endPoint);
let endPoint = `${serviceURL.protocol}//${this.apiKey}.${serviceURL.host}/1.1/submit-spam`;
return this._fetch(endPoint, comment.toJSON());
}
Expand Down

0 comments on commit 0a67fb4

Please sign in to comment.