Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurvr committed May 17, 2015
1 parent c6362f3 commit 3eafc63
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 96 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ node_js:
before_script:
- git config --global user.name "Travis-CI"
- git config --global user.email "[email protected]"

2 changes: 0 additions & 2 deletions app/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* WSK dependencies check module
*/
'use strict';

var exec = require('child_process').exec;
var events = require('events');
var iniparser = require('iniparser');
Expand Down Expand Up @@ -101,4 +100,3 @@ module.exports = {
checkGit: checkGit,
checkGcloud: checkGcloud
};

8 changes: 3 additions & 5 deletions app/download.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

var request = require('request');
var Download = require('download');

Expand All @@ -21,7 +20,6 @@ function getLatestRelease(cb) {
cb(err || new Error(body || 'web-starter-kit/releases replied with ' + res.statusCode));
return;
}
/*jshint camelcase:false */
var release = {tag_name: ''};
for (var i = 0, r; (r = body[i]); i++) {
if (release.tag_name < r.tag_name) {
Expand All @@ -31,7 +29,7 @@ function getLatestRelease(cb) {
if (!release.tag_name) {
err = new Error('could not fetch WSK release version');
}
/*jshint camelcase:true */

cb(err, release);
});
}
Expand All @@ -42,9 +40,9 @@ function createDownloader(opts, cb) {
cb(err);
return;
}
/*jshint camelcase:false */

var url = WSK_ZIP_URL + ver.tag_name + '.zip';
/*jshint camelcase:true */

cb(null, new Download(opts).get(url), url, ver);
});
}
Expand Down
7 changes: 1 addition & 6 deletions app/hosting.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

var request = require('request');


Expand Down Expand Up @@ -38,12 +37,8 @@ function fetchConfig(provider, callback) {
});
}

//function deployTaskFilename(provider, tool) {
//}

module.exports = {
config: config,
isSupported: isSupported,
fetchConfig: fetchConfig,
//deployTaskFilename: deployTaskFilename
fetchConfig: fetchConfig
};
88 changes: 46 additions & 42 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

var exec = require('child_process').exec;
var path = require('path');
var yeoman = require('yeoman-generator');
Expand Down Expand Up @@ -76,9 +75,9 @@ module.exports = yeoman.generators.Base.extend({
var self = this,
done = this.async();

/*jshint expr:true */
this.verbose && this.log.write().info('Getting latest WSK release version ...');
/*jshint expr:false */
if (this.verbose) {
this.log.write().info('Getting latest WSK release version ...');
}

download({extract: true, strip: 1}, function (err, downloader, url, ver) {
if (err) {
Expand All @@ -87,11 +86,9 @@ module.exports = yeoman.generators.Base.extend({
}

if (self.verbose) {
/*jshint camelcase:false */
self.log.info('Found release %s', ver.tag_name)
.info('Fetching %s ...', url)
.info(chalk.yellow('This might take a few moments'));
/*jshint camelcase:true */
.info('Fetching %s ...', url)
.info(chalk.yellow('This might take a few moments'));
downloader.use(function (res) {
res.on('data', function () { self.log.write('.'); });
});
Expand All @@ -112,9 +109,10 @@ module.exports = yeoman.generators.Base.extend({

checks.on('passed', function (res) {
self.checks[res.what] = {data: res.data};
/*jshint expr:true */
self.verbose && self.log.ok(res.what + ' ' + (res.result || ''));
/*jshint expr:false */

if (self.verbose) {
self.log.ok(res.what + ' ' + (res.result || ''));
}
});

checks.on('failed', function (res) {
Expand All @@ -129,9 +127,9 @@ module.exports = yeoman.generators.Base.extend({

writing: {
gulpfile: function () {
/*jshint expr:true */
this.verbose && this.log.info('Configuring gulpfile.js');
/*jshint expr:false */
if (this.verbose) {
this.log.info('Configuring gulpfile.js');
}

var filepath = path.join(this.destinationRoot(), 'gulpfile.js'),
gulpfile = this.readFileAsString(filepath);
Expand Down Expand Up @@ -183,9 +181,9 @@ module.exports = yeoman.generators.Base.extend({
// },

packagejson: function () {
/*jshint expr:true */
this.verbose && this.log.info('Configuring package.json');
/*jshint expr:false */
if (this.verbose) {
this.log.info('Configuring package.json');
}

var filepath = path.join(this.destinationRoot(), 'package.json'),
pkg = JSON.parse(this.readFileAsString(filepath));
Expand All @@ -203,9 +201,9 @@ module.exports = yeoman.generators.Base.extend({
},

webmanifest: function () {
/*jshint expr:true */
this.verbose && this.log.info('Configuring manifest.webapp');
/*jshint expr:false */
if (this.verbose) {
this.log.info('Configuring manifest.webapp');
}

var filepath = path.join(this.destinationRoot(), 'app', 'manifest.webapp'),
manifest = JSON.parse(this.readFileAsString(filepath));
Expand All @@ -221,9 +219,9 @@ module.exports = yeoman.generators.Base.extend({
},

layout: function () {
/*jshint expr:true */
this.verbose && this.log.info('Configuring layout and contents');
/*jshint expr:false */
if (this.verbose) {
this.log.info('Configuring layout and contents');
}

var basic = path.join(this.destinationRoot(), 'app', 'basic.html'),
index = path.join(this.destinationRoot(), 'app', 'index.html'),
Expand Down Expand Up @@ -303,9 +301,10 @@ module.exports = yeoman.generators.Base.extend({
'git remote add origin [email protected]:' + this.prompts.githubTarget
];
exec(cmd.join(' && '), {cwd: path.join('dist')}, function (err, stdout) {
/*jshint expr:true */
log && log.write().info(stdout);
/*jshint expr:false */
if (log) {
log.write().info(stdout);
}

done();
});
}
Expand All @@ -315,14 +314,15 @@ module.exports = yeoman.generators.Base.extend({
install: {
npminstall: function () {
if (!this.skipInstall) {
/*jshint expr:true */
this.verbose && this.log.write()
.info('Running ' + chalk.yellow('npm install') + ' ' +
'to install the required dependencies. ' +
'If this fails, try running the command yourself.')
.info(chalk.yellow('This might take a few moments'))
.write();
/*jshint expr:false */
if (this.verbose) {
this.log.write()
.info('Running ' + chalk.yellow('npm install') + ' ' +
'to install the required dependencies. ' +
'If this fails, try running the command yourself.')
.info(chalk.yellow('This might take a few moments'))
.write();
}

this.npmInstall();
}
},
Expand All @@ -341,20 +341,25 @@ module.exports = yeoman.generators.Base.extend({
];

exec(cmd.join(' && '), function (err, stdout) {
/*jshint expr:true */
err && self.log.error(err);
self.verbose && self.log.write(stdout);
/*jshint expr:false */
if (err) {
self.log.error(err);
}

if (self.verbose) {
self.log.write(stdout);
}

done();
});
}
},

end: function () {
if (this.messages.length === 0) {
/*jshint expr:true */
this.verbose && this.log.write().ok('You are all set now. Happy coding!');
/*jshint expr:false */
if (this.verbose) {
this.log.write().ok('You are all set now. Happy coding!');
}

return;
}

Expand All @@ -365,4 +370,3 @@ module.exports = yeoman.generators.Base.extend({
}
}
});

21 changes: 7 additions & 14 deletions app/prompt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

var path = require('path');
var iniparser = require('iniparser');

Expand Down Expand Up @@ -78,9 +77,8 @@ function questions(defaults) {
if (!url || RE_URL.test(url)) {
return true;
}
/*jshint quotmark:false */
return "That doesn't look like a valid URL";
/*jshint quotmark:single */

return 'That doesn\'t look like a valid URL';
}
},
{
Expand Down Expand Up @@ -116,9 +114,7 @@ function questions(defaults) {
{value: 'paas', name: 'PaaS (GAE, Heroku)'},
{value: 'static', name: 'Static (GitHub, GCS, S3)'},
{value: 'server', name: 'Server (Apache, Nginx, etc.)'},
/*jshint quotmark:false */
{value: 'none', name: "Nowhere, don't worry about it"}
/*jshint quotmark:single */
{value: 'none', name: 'Nowhere, don\'t worry about it'}
],
default: function (answers) {
return defaults.hostingCat ||
Expand Down Expand Up @@ -191,10 +187,8 @@ function questions(defaults) {
// -------------- Heroku (PaaS hosting) ------------------

{
/*jshint quotmark:false */
message: ("What is your Heroku app name?\n "+
"(just hitting enter is OK, we'll create one for you)\n "),
/*jshint quotmark:single */
message: ('What is your Heroku app name?\n ' +
'(just hitting enter is OK, we\'ll create one for you)\n '),
name: 'herokuApp',
default: defaults.herokuApp,
when: function (answers) {
Expand Down Expand Up @@ -245,9 +239,8 @@ function questions(defaults) {
if (RE_GITHUB_TARGET.test(v)) {
return true;
}
/*jshint quotmark:false */
return "It's either 'owner' or 'owner/repo'";
/*jshint quotmark:single */

return 'It\'s either \'owner\' or \'owner/repo\'';
},
filter: function (v) {
if (v && v.indexOf('/') === -1) {
Expand Down
1 change: 0 additions & 1 deletion app/templates/deploy_gae.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

var spawn = require('child_process').spawn;
var gulp = require('gulp');

Expand Down
5 changes: 1 addition & 4 deletions app/templates/deploy_github.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

var path = require('path');
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
Expand All @@ -20,9 +19,7 @@ gulp.task('deploy:commit', function (done) {
msg = process.argv.slice(im, im + 2)[1];
}
msg = msg || 'Production build';
/*jshint quotmark:false */
var cmd = ["git add .", "git commit -m '" + msg + "'", "git status"];
/*jshint quotmark:true */
var cmd = ['git add .', 'git commit -m \'' + msg + '\'', 'git status'];
exec(cmd.join(' && '), {cwd: path.join(process.cwd(), 'dist')}, function (err, stdout, stderr) {
if (!/working directory clean/m.test(stdout)) {
console.log('--- ERROR log ---\n' + stderr);
Expand Down
2 changes: 1 addition & 1 deletion docs/deploy-gae.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ID, which is also how you'll be able to access the published website.
What the generator does when using 'deploy to GAE' option is the following:

1. Creates a `.gcloud/properties` file with the specified Project ID.
2. Copies `app.yaml` from [H5BP GAE server-config](https://github.com/h5bp/server-configs-gae)
2. Copies `app.yaml` from [H5BP GAE server configs](https://github.com/h5bp/server-configs-gae)
to `app/app.yaml`.
3. Modifies `app/app.yaml` to use correct Project ID, the one you specified.

Expand Down
1 change: 0 additions & 1 deletion test/test-app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*global describe, before, it*/
'use strict';

var fs = require('fs');
var assert = require('yeoman-generator').assert;
var testUtil = require('./util');
Expand Down
5 changes: 0 additions & 5 deletions test/test-download.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*global describe, before, after, afterEach, it*/
'use strict';

var assert = require('yeoman-generator').assert;
var nock = require('nock');
var download = require('../app/download');
Expand All @@ -11,21 +10,17 @@ describe('download module', function () {
after(function () { nock.enableNetConnect(); });

it('fetches latest release version and creates downloader', function (done) {
/*jshint camelcase:false */
var scope = nock('https://api.github.com')
.get('/repos/google/web-starter-kit/releases')
.reply(200, [
{tag_name: 'v1'},
{tag_name: 'v2'},
{tag_name: 'v2.5.2'}
]);
/*jshint camelcase:true */

download({}, function (err, d, url, ver) {
assert(!err, err);
/*jshint camelcase:false */
assert.deepEqual(ver, {tag_name: 'v2.5.2'});
/*jshint camelcase:false */
assert.equal(url, download.WSK_ZIP_URL + 'v2.5.2.zip');
assert(d);

Expand Down
1 change: 0 additions & 1 deletion test/test-gae.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*global describe, before, it*/
'use strict';

var assert = require('yeoman-generator').assert;
var testUtil = require('./util');

Expand Down
1 change: 0 additions & 1 deletion test/test-github.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*global describe, before, it*/
'use strict';

var fs = require('fs');
var exec = require('child_process').exec;

Expand Down
Loading

0 comments on commit 3eafc63

Please sign in to comment.