Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Commit

Permalink
New codestyle (#62)
Browse files Browse the repository at this point in the history
* update eslint config

* update eslint

* use latest yarn version

* add comment for travis config
  • Loading branch information
Alexander Ivantsov authored Oct 3, 2017
1 parent a3a7fe2 commit 767fdd5
Show file tree
Hide file tree
Showing 90 changed files with 2,641 additions and 2,487 deletions.
130 changes: 60 additions & 70 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,76 @@
const {resolve} = require('./webpack/base');

const INDENT = 4;

const base = {
// disabled
'max-len': 'off',
'arrow-parens': 'off',
'arrow-body-style': 'off',
'no-prototype-builtins': 'off',
'no-plusplus': 'off',
// disabled
'max-len': 'off',
'arrow-parens': 'off',
'arrow-body-style': 'off',
'no-prototype-builtins': 'off',
'no-plusplus': 'off',

// modified
indent: ['error', INDENT, {
SwitchCase: 1
}],
'brace-style': ['error', 'stroustrup', {
'allowSingleLine': false
}],
'object-curly-spacing': ['error', 'never'],
'one-var': ['error', {
initialized: 'never'
}],
'one-var-declaration-per-line': ['error', 'initializations'],
// modified
'object-curly-spacing': ['error', 'never'],
'one-var': ['error', {
initialized: 'never'
}],
'one-var-declaration-per-line': ['error', 'initializations'],
};

const react = {
// disabled
'react/forbid-prop-types': 'off',
'react/no-array-index-key': 'off',
// disabled
'react/forbid-prop-types': 'off',
'react/no-array-index-key': 'off',

// modified
'react/jsx-filename-extension': ['error', {extensions: ['.js']}],
'react/jsx-indent': ['error', INDENT],
'react/jsx-indent-props': ['error', INDENT],
'react/jsx-tag-spacing': ['error', {
closingSlash: 'never',
beforeSelfClosing: 'never',
afterOpening: 'never'
}],
'react/sort-comp': ['error', {
order: [
'static-methods',
'lifecycle',
'rendering',
'everything-else'
],
groups: {
rendering: [
'render',
'/^render.+$/'
]
}
}],
// modified
'react/jsx-filename-extension': ['error', {extensions: ['.js']}],
'react/jsx-tag-spacing': ['error', {
closingSlash: 'never',
beforeSelfClosing: 'never',
afterOpening: 'never'
}],
'react/sort-comp': ['error', {
order: [
'static-methods',
'lifecycle',
'rendering',
'everything-else'
],
groups: {
rendering: [
'render',
'/^render.+$/'
]
}
}],
};

const other = {
'jsx-a11y/no-static-element-interactions': 'off'
'jsx-a11y/no-static-element-interactions': 'off'
};

module.exports = {
parser: 'babel-eslint',
extends: 'airbnb',
env: {
webextensions: true,
browser: true,
jest: true
},
globals: {
__DEV__: false
},
settings: {
'import/resolver': {
webpack: {
config: {
resolve
}
}
parser: 'babel-eslint',
extends: 'airbnb',
env: {
webextensions: true,
browser: true,
jest: true
},
globals: {
__DEV__: false
},
settings: {
'import/resolver': {
webpack: {
config: {
resolve
}
},
rules: Object.assign({},
base,
react,
other
)
}
}
},
rules: {
...base,
...react,
...other,
}
};
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
language: node_js
node_js:
- 8
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.1.0 # otherwise Travis uses 0.27.*
- export PATH=$HOME/.yarn/bin:$PATH
script:
- set -e # fail the build if one of the scripts fails - https://github.com/travis-ci/travis-ci/issues/1066
- npm run lint
- npm run test:coverage
cache:
Expand All @@ -13,4 +17,4 @@ deploy:
script: npm run publish
skip_cleanup: true
on:
tags: true
tags: true
28 changes: 14 additions & 14 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module.exports = {
rootDir: './src',
clearMocks: true,
resetModules: true,
moduleDirectories: [
'node_modules',
'src/pages',
],
moduleNameMapper: {
'\\.(less)$': 'identity-obj-proxy',
},
testPathIgnorePatterns: [
'/node_modules/',
'fixtures.js',
],
rootDir: './src',
clearMocks: true,
resetModules: true,
moduleDirectories: [
'node_modules',
'src/pages',
],
moduleNameMapper: {
'\\.(less)$': 'identity-obj-proxy',
},
testPathIgnorePatterns: [
'/node_modules/',
'fixtures.js',
],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"copy-webpack-plugin": "^4.0.0",
"css-loader": "^0.28.7",
"date-fns": "^1.28.5",
"eslint": "^3.19.0",
"eslint": "^4.8.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-import-resolver-webpack": "^0.8.3",
"eslint-plugin-import": "^2.7.0",
Expand Down
104 changes: 52 additions & 52 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,73 @@ const clientId = process.env.CLIENT_ID;
const refreshToken = process.env.REFRESH_TOKEN;

function getError(text, err) {
throw new Error(`Failed to ${text}: ${(err.response && err.response.text) || err}`);
throw new Error(`Failed to ${text}: ${(err.response && err.response.text) || err}`);
}

function getToken() {
return request
.post('https://accounts.google.com/o/oauth2/token')
.type('form')
.send({
client_id: clientId,
refresh_token: refreshToken,
grant_type: 'refresh_token',
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
})
.then(res => {
const accessToken = res.body.access_token;
return request
.post('https://accounts.google.com/o/oauth2/token')
.type('form')
.send({
client_id: clientId,
refresh_token: refreshToken,
grant_type: 'refresh_token',
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
})
.then(res => {
const accessToken = res.body.access_token;

if (!accessToken) {
throw new Error(res.body);
}
if (!accessToken) {
throw new Error(res.body);
}

console.log('(1/3) Token received!');
console.log('(1/3) Token received!');

return accessToken;
})
.catch(err => getError('receive access token', err));
return accessToken;
})
.catch(err => getError('receive access token', err));
}

function upload(accessToken) {
return request
.put(`https://www.googleapis.com/upload/chromewebstore/v1.1/items/${appId}`)
.set({
Authorization: `Bearer ${accessToken}`,
'x-goog-api-version': 2,
})
.attach('file', filename)
.then(res => {
if (res.body.uploadState !== 'SUCCESS') {
throw new Error(res.body.itemError[0].error_detail);
}
return request
.put(`https://www.googleapis.com/upload/chromewebstore/v1.1/items/${appId}`)
.set({
Authorization: `Bearer ${accessToken}`,
'x-goog-api-version': 2,
})
.attach('file', filename)
.then(res => {
if (res.body.uploadState !== 'SUCCESS') {
throw new Error(res.body.itemError[0].error_detail);
}

console.log('(2/3) Uploaded!');
console.log('(2/3) Uploaded!');

return accessToken;
})
.catch(err => getError('upload package', err));
return accessToken;
})
.catch(err => getError('upload package', err));
}

function publish(accessToken) {
return request
.post(`https://www.googleapis.com/chromewebstore/v1.1/items/${appId}/publish`)
.set({
Authorization: `Bearer ${accessToken}`,
'x-goog-api-version': 2,
'Content-Length': 0,
// publishTarget: 'trustedTesters'
})
.then(res => {
if (res.body.status[0] !== 'OK') {
throw new Error(res.body);
}
return request
.post(`https://www.googleapis.com/chromewebstore/v1.1/items/${appId}/publish`)
.set({
Authorization: `Bearer ${accessToken}`,
'x-goog-api-version': 2,
'Content-Length': 0,
// publishTarget: 'trustedTesters'
})
.then(res => {
if (res.body.status[0] !== 'OK') {
throw new Error(res.body);
}

console.log('(3/3) Published!');
})
.catch(err => getError('publish package', err));
console.log('(3/3) Published!');
})
.catch(err => getError('publish package', err));
}

getToken()
.then(upload)
.then(publish)
.catch(console.log);
.then(upload)
.then(publish)
.catch(console.log);
4 changes: 2 additions & 2 deletions scripts/locales.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const i18n = require('webext-i18n');

i18n({
inputDir: './src/locales',
outputDir: './dist/_locales',
inputDir: './src/locales',
outputDir: './dist/_locales',
}).then(() => console.log('Locales are generated.'));
28 changes: 14 additions & 14 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ const {execSync} = require('child_process');
const fs = require('fs-extra');

const paths = [
'./package.json',
'./src/manifest/base.json',
'./package.json',
'./src/manifest/base.json',
];

function validate(newVersion) {
const semverRegex = /^\d+\.\d+\.\d+$/;
const semverRegex = /^\d+\.\d+\.\d+$/;

if (!newVersion || !semverRegex.test(newVersion)) {
throw new Error('The release version is not provided or is incorrect');
}
if (!newVersion || !semverRegex.test(newVersion)) {
throw new Error('The release version is not provided or is incorrect');
}
}

function updateVersion(newVersion) {
paths.forEach(path => {
const config = fs.readJsonSync(path);
config.version = newVersion;
fs.writeJsonSync(path, config, {spaces: 2});
});
paths.forEach(path => {
const config = fs.readJsonSync(path);
config.version = newVersion;
fs.writeJsonSync(path, config, {spaces: 2});
});
}

function makeCommit(newVersion) {
execSync(`git add ${paths.join(' ')}`);
execSync(`git commit -m "bump v${newVersion}" --no-verify`);
execSync(`git tag v${newVersion}`);
execSync(`git add ${paths.join(' ')}`);
execSync(`git commit -m "bump v${newVersion}" --no-verify`);
execSync(`git tag v${newVersion}`);
}

const newVersion = process.argv[2];
Expand Down
Loading

0 comments on commit 767fdd5

Please sign in to comment.