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

Commit

Permalink
add circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
HsuTing committed Sep 17, 2017
1 parent 071d661 commit 86afcf1
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 31 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ node_js:
script:
- yarn lint
- yarn test
branches:
only:
- master
yarn: true
38 changes: 22 additions & 16 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,27 @@ const testWebsite = ({website, ...config}) => {
};

describe('app', () => {
testWebsite({
website: false,
otherTest: []
});
testWebsite({
website: true,
subject: 'subject',
url: 'http://hsuting.com',
otherSettings: [],
otherTest: [
normalize,
component,
testPublic,
webpack,
template
]
[true, false].forEach(isPrivate => {
describe(`private: ${isPrivate}`, () => {
testWebsite({
private: isPrivate,
website: false,
otherTest: []
});
testWebsite({
private: isPrivate,
website: true,
subject: 'subject',
url: 'http://hsuting.com',
otherSettings: [],
otherTest: [
normalize,
component,
testPublic,
webpack,
template
]
});
});
});
});
11 changes: 10 additions & 1 deletion __tests__/files/app/readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const checkContent = (status, content) => (

export default ({
npm,
server
server,
private: isPrivate
}) => {
it('README.md', () => {
assert.file('README.md');
Expand All @@ -21,5 +22,13 @@ export default ({

checkContent(server, '- `start`: Run the prodiction version server.');
checkContent(server, '- `test-server`: Run the test server with `nodemon`.');

checkContent(isPrivate, '[![Build Status][circleci-image]][circleci-url]');
checkContent(!isPrivate, '[![Build Status][travis-image]][travis-url]');

checkContent(isPrivate, '[circleci-image]: https://circleci.com/gh/HsuTing/test.svg?style=svg&circle-token=token');
checkContent(isPrivate, '[circleci-url]: https://circleci.com/gh/HsuTing/test');
checkContent(!isPrivate, '[travis-image]: https://travis-ci.org/HsuTing/test.svg?branch=master');
checkContent(!isPrivate, '[travis-url]: https://travis-ci.org/HsuTing/test');
});
};
25 changes: 25 additions & 0 deletions __tests__/files/test/circleci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

import assert from 'yeoman-assert';

const checkContent = (status, content) => (
status ?
assert.fileContent('.circleci/config.yml', content) :
assert.noFileContent('.circleci/config.yml', content)
);

export default ({
website,
graphql,
mobileApp
}) => {
it('.circleci/config.yml', () => {
checkContent(website && graphql, '- image: jotadrilo/watchman');

checkContent(!mobileApp, '- run:');
checkContent(!mobileApp, 'name: Build');
checkContent(!mobileApp, 'command: yarn build');
checkContent(!mobileApp, 'name: Prod');
checkContent(!mobileApp, 'command: yarn prod');
});
};
9 changes: 7 additions & 2 deletions __tests__/utils/testPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import npmignore from './../files/npm/npmignore';
// test
import jest from './../files/test/jest';
import travis from './../files/test/travis';
import circleci from './../files/test/circleci';
import testGraphql from './../files/add/jest/graphql';
import testPages from './../files/add/jest/pages';
import testComponent from './../files/add/jest/component';
Expand All @@ -36,7 +37,7 @@ const checkPlugins = plugins => ({
});

const runDefaultTest = config => {
const {website, graphql, chooseType, plugins, otherTest} = config;
const {private: isPrivate, website, graphql, chooseType, plugins, otherTest} = config;
const server = chooseType === 'server';

editorconfig();
Expand Down Expand Up @@ -64,12 +65,16 @@ const runDefaultTest = config => {
});
readme({
server,
private: isPrivate,
...checkPlugins(plugins)
});

/* test */
jest(config);
travis(config);
if(isPrivate)
circleci(config);
else
travis(config);

if(website)
testComponent();
Expand Down
9 changes: 9 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ module.exports = class extends Base {
message: 'Package keywords (comma to split)',
when: !this.getPkg.keywords,
filter: /* istanbul ignore next */ words => words.split(/\s*,\s*/g)
}, {
type: 'confirm',
name: 'private',
message: 'Is a private project',
default: false,
store: true
}, {
type: 'confirm',
name: 'website',
Expand Down Expand Up @@ -97,6 +103,9 @@ module.exports = class extends Base {
}]).then(function(state) {
const {website, chooseType, graphql, plugins} = state;

if(state.private)
plugins.push('private');

if(chooseType !== 'none')
plugins.push(chooseType);

Expand Down
3 changes: 2 additions & 1 deletion generators/app/readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = class extends Base {
license: this.getPkg.license,
author: this.getAuthor,
npm: this.checkPlugins('npm'),
server: this.checkPlugins('server')
server: this.checkPlugins('server'),
private: this.checkPlugins('private')
}]
});
}
Expand Down
7 changes: 6 additions & 1 deletion generators/app/templates/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <%= name[0].toUpperCase() + name.slice(1).toLowerCase() %><% if(npm) { %> [![NPM version][npm-image]][npm-url]<% } %>[![Build Status][travis-image]][travis-url]
# <%= name[0].toUpperCase() + name.slice(1).toLowerCase() %><% if(npm) { %> [![NPM version][npm-image]][npm-url]<% } %><% if(private) { %> [![Build Status][circleci-image]][circleci-url]<% } else { %> [![Build Status][travis-image]][travis-url] <% } %>
<%= description %>

## Getting Started
Expand Down Expand Up @@ -26,5 +26,10 @@ yarn install && yarn build
[npm-image]: https://badge.fury.io/js/<%= name %>.svg
[npm-url]: https://npmjs.org/package/<%= name %>
<% } -%>
<% if(private) { -%>
[circleci-image]: https://circleci.com/gh/<%= author.name %>/<%= name %>.svg?style=svg&circle-token=token
[circleci-url]: https://circleci.com/gh/<%= author.name %>/<%= name %>
<% } else { -%>
[travis-image]: https://travis-ci.org/<%= author.name %>/<%= name %>.svg?branch=master
[travis-url]: https://travis-ci.org/<%= author.name %>/<%= name %>
<% } -%>
20 changes: 16 additions & 4 deletions generators/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@ module.exports = class extends Base {
'jest.config.js': ['jest.config.js', {
react: this.checkPlugins('react'),
mobile_app: this.checkPlugins('mobile app')
}],
'travis.yml': ['.travis.yml', {
relay: this.checkPlugins('relay'),
mobile_app: this.checkPlugins('mobile app')
}]
});

if(this.checkPlugins('private')) {
this.writeFiles({
'circleci.yml': ['.circleci/config.yml', {
relay: this.checkPlugins('relay'),
mobile_app: this.checkPlugins('mobile app')
}]
});
} else {
this.writeFiles({
'travis.yml': ['.travis.yml', {
relay: this.checkPlugins('relay'),
mobile_app: this.checkPlugins('mobile app')
}]
});
}
}

default() {
Expand Down
31 changes: 31 additions & 0 deletions generators/test/templates/circleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 2
jobs:
build:
working_directory: ~/repo
docker:
- image: node:latest
<% if(relay) { -%>
- image: jotadrilo/watchman
<% } -%>
steps:
- checkout
- run:
name: Install packages
command: yarn install
- run:
name: Check code style
command: yarn lint
<% if(!mobile_app) { -%>
- run:
name: Build
command: yarn build
- run:
name: Prod
command: yarn prod
<% } -%>
- run:
name: Test
command: yarn test
- store_artifacts:
path: coverage
prefix: coverage
3 changes: 0 additions & 3 deletions generators/test/templates/travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@ script:
- yarn prod
<% } -%>
- yarn test
branches:
only:
- master
yarn: true

0 comments on commit 86afcf1

Please sign in to comment.