Skip to content

Commit

Permalink
chore: add prettier and precommit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
iamstarkov committed Apr 23, 2017
1 parent 7632eed commit 1f601b9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 32 deletions.
14 changes: 10 additions & 4 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ module.exports = class extends Generator {
type: String,
required: false,
defaults: '',
desc: 'Relocate the location of the generated files.'
desc: 'Relocate the location of the generated files.',
});
}

writing() {
var optional = this.options.config || {};
var existing = this.fs.exists(this.destinationPath(this.options.generateInto, '.travis.yml'))
? yaml.parse(this.fs.read(this.destinationPath(this.options.generateInto, '.travis.yml')))
var optional = this.options.config || {};
var existing = this.fs.exists(
this.destinationPath(this.options.generateInto, '.travis.yml')
)
? yaml.parse(
this.fs.read(
this.destinationPath(this.options.generateInto, '.travis.yml')
)
)
: {};
var defaults = yaml.parse(this.fs.read(this.templatePath('travisyml')));
var results = mergeAndConcat(existing, optional, defaults);
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"url": "https://iamstarkov.com"
},
"scripts": {
"precommit": "lint-staged",
"commit": "git-cz",
"commitmsg": "validate-commit-msg",
"test": "mocha",
Expand Down Expand Up @@ -41,6 +42,12 @@
"czConfig": {
"path": "cz-conventional-changelog"
},
"lint-staged": {
"*.js": [
"prettier --single-quote --trailing-comma es5 --write",
"git add"
]
},
"dependencies": {
"merge-and-concat": "^1.0.2",
"ramda": "^0.23.0",
Expand All @@ -53,7 +60,9 @@
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.0.0",
"husky": "^0.13.3",
"lint-staged": "^3.4.0",
"mocha": "^3.2.0",
"prettier": "^1.2.2",
"semantic-release": "^6.3.2",
"validate-commit-msg": "^2.12.1",
"yeoman-assert": "^3.0.0",
Expand Down
67 changes: 39 additions & 28 deletions test/test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,83 @@ var yaml = require('yamljs');

var existingConfig = {
language: 'node_js',
node_js: [ 'stable', 'iojs' ],
node_js: ['stable', 'iojs'],
before_script: ['bower install'],
};
var yamlExistingConfig = yaml.stringify(existingConfig, 3, 2)
var yamlExistingConfig = yaml.stringify(existingConfig, 3, 2);

describe('travis:app', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../generators/app'))
describe('travis:app', function() {
before(function(done) {
helpers
.run(path.join(__dirname, '../generators/app'))
.withOptions({
config: {
node_js: [ 'iojs' ],
after_script: ['npm run coveralls']
}
node_js: ['iojs'],
after_script: ['npm run coveralls'],
},
})
.on('ready', function (gen) {
gen.fs.write(gen.destinationPath('.travis.yml'), yamlExistingConfig);
}.bind(this))
.on(
'ready',
function(gen) {
gen.fs.write(gen.destinationPath('.travis.yml'), yamlExistingConfig);
}.bind(this)
)
.on('end', done);
});

it('creates config', function () {
it('creates config', function() {
assert.file('.travis.yml');
});

it('extends existing config', function () {
it('extends existing config', function() {
assert.fileContent('.travis.yml', /bower install/);
});

it('uses config from options', function () {
it('uses config from options', function() {
assert.fileContent('.travis.yml', /npm run coveralls/);
});

it('uses config with extra node versions from options', function () {
it('uses config with extra node versions from options', function() {
assert.fileContent('.travis.yml', /iojs/);
});
});

describe('travis:app with generate-into option', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../generators/app'))
describe('travis:app with generate-into option', function() {
before(function(done) {
helpers
.run(path.join(__dirname, '../generators/app'))
.withOptions({
config: {
node_js: [ 'iojs' ],
after_script: ['npm run coveralls']
node_js: ['iojs'],
after_script: ['npm run coveralls'],
},
generateInto: 'other/'
generateInto: 'other/',
})
.on('ready', function (gen) {
gen.fs.write(gen.destinationPath('other/.travis.yml'), yamlExistingConfig);
}.bind(this))
.on(
'ready',
function(gen) {
gen.fs.write(
gen.destinationPath('other/.travis.yml'),
yamlExistingConfig
);
}.bind(this)
)
.on('end', done);
});

it('creates config', function () {
it('creates config', function() {
assert.file('other/.travis.yml');
});

it('extends existing config', function () {
it('extends existing config', function() {
assert.fileContent('other/.travis.yml', /bower install/);
});

it('uses config from options', function () {
it('uses config from options', function() {
assert.fileContent('other/.travis.yml', /npm run coveralls/);
});

it('uses config with extra node versions from options', function () {
it('uses config with extra node versions from options', function() {
assert.fileContent('other/.travis.yml', /iojs/);
});
});

0 comments on commit 1f601b9

Please sign in to comment.