0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

fix: eslint globally read all files, rename jsx to js. Reduce amount of repeated configuration

This commit is contained in:
Juan Picado @jotadeveloper 2017-07-13 23:28:45 +02:00
parent 2e5a1e7fd9
commit 2df4f7b628
No known key found for this signature in database
GPG key ID: 18AC54485952D158
24 changed files with 281 additions and 297 deletions

View file

@ -1,8 +1,4 @@
node_modules node_modules
lib/web/static
lib/web/ui/
lib/web/static
coverage/ coverage/
wiki/ wiki/
static/ static/

80
.eslintrc Normal file
View file

@ -0,0 +1,80 @@
{
"plugins": [
"react",
"flowtype"
],
"extends": [
"eslint:recommended",
"google",
"plugin:react/recommended",
"plugin:flowtype/recommended"
],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 7,
"ecmaFeatures": {
"impliedStrict": true,
"jsx": true
}
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"rules": {
"no-tabs": 0,
"keyword-spacing": 0,
"padded-blocks": 0,
"no-useless-escape": 0,
"handle-callback-err": 2,
"no-debugger": 2,
"no-fallthrough": 2,
"curly": 2,
"eol-last": 1,
"no-irregular-whitespace": 1,
"no-mixed-spaces-and-tabs": [
1,
"smart-tabs"
],
"no-trailing-spaces": 1,
"no-new-require": 2,
"no-undef": 2,
"no-unreachable": 2,
"no-unused-vars": [
2,
{
"vars": "all",
"args": "none"
}
],
"max-len": [
1,
160
],
"semi": [
2,
"always"
],
"camelcase": 0,
"require-jsdoc": 2,
"valid-jsdoc": 2,
"prefer-spread": 1,
"prefer-rest-params": 1,
"no-var": 2,
"no-constant-condition": 2,
"no-empty": 2,
"guard-for-in": 2,
"no-invalid-this": 2,
"new-cap": 2,
"one-var": 2,
"no-console": [
2,
{
"allow": [
"warn"
]
}
]
}
}

View file

@ -1,99 +0,0 @@
# vim: syntax=yaml
#
# List of very light restrictions designed to prevent obvious errors,
# not impose our own code style upon other contributors.
#
# This is supposed to be used with `eslint --reset`
#
# Created to work with eslint@0.18.0
#
plugins: ["react"]
extends: ["eslint:recommended", "google", "plugin:react/recommended"]
env:
node: true
browser: true
es6: true
parserOptions:
sourceType: "module"
ecmaVersion: 7
ecmaFeatures:
jsx: true
rules:
no-tabs: 0
keyword-spacing: 0
padded-blocks: 0
# useful to have in node.js,
# if you're sure you don't need to handle error, rename it to "_err"
handle-callback-err: 2
# just to make sure we don't forget to remove them when releasing
no-debugger: 2
# add "falls through" for those
no-fallthrough: 2
# enforce use curly always
# curly: 1
# just warnings about whitespace weirdness here
eol-last: 1
no-irregular-whitespace: 1
no-mixed-spaces-and-tabs: [1, smart-tabs]
no-trailing-spaces: 1
# probably always an error, tell me if it's not
no-new-require: 2
# single most important rule here, without it linting won't even
# make any sense
no-undef: 2
# in practice, those are always errors
no-unreachable: 2
# useful for code clean-up
no-unused-vars: [2, {"vars": "all", "args": "none"}]
max-len: [1, 160]
# camelcase is standard, but this should be 1 and then 2 soon
camelcase: 0
# jsdoc is mandatory
require-jsdoc: 2
valid-jsdoc: 2
# this feature is cool but not supported by Node 4, disable via comments
prefer-spread: 1
prefer-rest-params: 1
# encorage use es6
no-var: 2
# configuration that should be upgraded progresivelly
no-constant-condition: 2
no-empty: 2
# loop over objects http://eslint.org/docs/rules/guard-for-in
guard-for-in: 2
# this must be used within classes
no-invalid-this: 2
# All object must be uppercase
new-cap: 2
# readbility is important, no multiple inline declarations
one-var: 2
# console not allowed unless for testing
no-console: [2, {"allow": ["log", "warn"]}]

BIN
package-lock.json generated

Binary file not shown.

View file

@ -48,59 +48,59 @@
"unix-crypt-td-js": "^1.0.0" "unix-crypt-td-js": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"axios": "^0.16.2", "axios": "0.16.2",
"babel-cli": "^6.24.1", "babel-cli": "6.24.1",
"babel-core": "^6.25.0", "babel-core": "6.25.0",
"babel-eslint": "^7.2.3", "babel-eslint": "7.2.3",
"babel-loader": "^7.1.1", "babel-loader": "7.1.1",
"babel-plugin-flow-runtime": "^0.11.1", "babel-plugin-flow-runtime": "0.11.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-plugin-transform-runtime": "^6.23.0", "babel-plugin-transform-runtime": "6.23.0",
"babel-preset-env": "^1.5.2", "babel-preset-env": "1.5.2",
"babel-preset-flow": "^6.23.0", "babel-preset-flow": "6.23.0",
"babel-preset-react": "^6.24.1", "babel-preset-react": "6.24.1",
"babel-preset-stage-2": "^6.24.1", "babel-preset-stage-2": "6.24.1",
"babel-preset-stage-3": "^6.24.1", "babel-preset-stage-3": "6.24.1",
"babel-runtime": "^6.23.0", "babel-runtime": "6.23.0",
"codacy-coverage": "2.0.2", "codacy-coverage": "2.0.2",
"codecov": "2.2.0", "codecov": "2.2.0",
"coveralls": "^2.13.1", "coveralls": "2.13.1",
"css-loader": "^0.28.4", "css-loader": "0.28.4",
"element-react": "^1.0.16", "element-react": "1.0.16",
"element-theme-default": "^1.3.7", "element-theme-default": "1.3.7",
"eslint": "^4.1.0", "eslint": "4.2.0",
"eslint-config-google": "^0.8.0", "eslint-config-google": "0.8.0",
"eslint-loader": "^1.8.0", "eslint-loader": "1.8.0",
"eslint-plugin-babel": "^4.1.1", "eslint-plugin-babel": "4.1.1",
"eslint-plugin-flowtype": "^2.34.1", "eslint-plugin-flowtype": "2.35.0",
"eslint-plugin-import": "^2.6.1", "eslint-plugin-import": "2.6.1",
"eslint-plugin-react": "^7.1.0", "eslint-plugin-react": "7.1.0",
"extract-text-webpack-plugin": "^2.1.2", "extract-text-webpack-plugin": "3.0.0",
"file-loader": "^0.11.2", "file-loader": "0.11.2",
"flow-runtime": "^0.13.0", "flow-runtime": "0.13.0",
"friendly-errors-webpack-plugin": "^1.6.1", "friendly-errors-webpack-plugin": "1.6.1",
"html-webpack-plugin": "^2.29.0", "html-webpack-plugin": "2.29.0",
"in-publish": "2.0.0", "in-publish": "2.0.0",
"localstorage-memory": "^1.0.2", "localstorage-memory": "1.0.2",
"mocha": "^3.4.2", "mocha": "3.4.2",
"mocha-lcov-reporter": "1.3.0", "mocha-lcov-reporter": "1.3.0",
"node-sass": "^4.5.3", "node-sass": "4.5.3",
"normalize.css": "^7.0.0", "normalize.css": "7.0.0",
"nyc": "^11.0.3", "nyc": "11.0.3",
"ora": "^1.3.0", "ora": "1.3.0",
"prop-types": "^15.5.10", "prop-types": "15.5.10",
"react": "^15.6.1", "react": "15.6.1",
"react-dom": "^15.6.1", "react-dom": "15.6.1",
"react-hot-loader": "^3.0.0-beta.7", "react-hot-loader": "3.0.0-beta.7",
"react-router-dom": "^4.1.1", "react-router-dom": "4.1.1",
"rimraf": "^2.6.1", "rimraf": "2.6.1",
"sass-loader": "^6.0.6", "sass-loader": "6.0.6",
"source-map-loader": "^0.2.1", "source-map-loader": "0.2.1",
"style-loader": "^0.18.2", "style-loader": "0.18.2",
"styled-components": "^2.1.1", "styled-components": "2.1.1",
"url-loader": "^0.5.8", "url-loader": "0.5.8",
"webpack": "^3.0.0", "webpack": "3.2.0",
"webpack-dev-server": "^2.5.0" "webpack-dev-server": "2.5.0"
}, },
"keywords": [ "keywords": [
"private", "private",

View file

@ -1,5 +1,5 @@
# vim: syntax=yaml {
"rules": {
"no-useless-escape": 0
rules: }
no-useless-escape: 0 }

View file

@ -1,5 +1,5 @@
# vim: syntax=yaml {
"rules": {
"no-useless-escape": 0
rules: }
no-useless-escape: 0 }

27
src/webui/.eslintrc Normal file
View file

@ -0,0 +1,27 @@
{
"env": {
"browser": true,
"node": true,
"jest": true,
"es6": true
},
"rules": {
"require-jsdoc": 0,
"no-console": [
1,
{
"allow": [
"log"
]
}
],
"comma-dangle": 0,
"semi": 1,
"react/no-danger-with-children": 1,
"react/no-string-refs": 1,
"react/prefer-es6-class": [
2,
"always"
]
}
}

View file

@ -1,28 +0,0 @@
# vim: syntax=yaml
## rules for react components
extends:
- google
- eslint:recommended
- plugin:react/recommended
- plugin:flowtype/recommended
plugins:
- flowtype
parser: babel-eslint
env:
node: true
browser: true
jest: true
rules:
# jsdoc is mandatory
require-jsdoc: 0
# jsx rules
react/no-danger-with-children: 0
react/no-string-refs: 0

View file

@ -2,15 +2,15 @@ import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server'; import WebpackDevServer from 'webpack-dev-server';
import config from './webpack.dev.config.babel'; import config from './webpack.dev.config.babel';
import ora from 'ora'; import ora from 'ora';
import env from '../../config/env' import env from '../../config/env';
const compiler = webpack(config); const compiler = webpack(config);
const spinner = ora('Compiler is running...').start(); const spinner = ora('Compiler is running...').start();
compiler.plugin('done', () => { compiler.plugin('done', () => {
if (!global.rebuild) { if (!global.rebuild) {
spinner.stop(); spinner.stop();
console.log('Dev Server Listening at http://localhost:4872/') console.log('Dev Server Listening at http://localhost:4872/');
global.rebuild = true global.rebuild = true;
} }
}); });
@ -30,8 +30,8 @@ new WebpackDevServer(compiler, {
chunks: true, chunks: true,
chunkModules: false chunkModules: false
} }
}).listen(4872, 'localhost', function (err) { }).listen(4872, 'localhost', function(err) {
if (err) { if (err) {
return console.log(err); return console.log(err);
} }
}) });

View file

@ -1,11 +1,11 @@
import env from '../../config/env' import env from '../../config/env';
const isDev = process.env.NODE_ENV === 'development' const isDev = process.env.NODE_ENV === 'development';
export default { export default {
entry: `${env.SRC_ROOT}/webui/src/index.jsx`, entry: `${env.SRC_ROOT}/webui/src/index.js`,
output: { output: {
path: `${env.APP_ROOT}/static/`, path: `${env.APP_ROOT}/static/`,
filename: '[name].[hash].js' filename: '[name].[hash].js'
}, },
@ -58,7 +58,7 @@ export default {
} }
}, },
{ {
loader: "sass-loader" loader: 'sass-loader'
} }
] ]
}, },

View file

@ -1,8 +1,8 @@
import webpack from 'webpack'; import webpack from 'webpack';
import HTMLWebpackPlugin from 'html-webpack-plugin'; import HTMLWebpackPlugin from 'html-webpack-plugin';
import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin'; import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';
import baseConfig from './webpack.config' import baseConfig from './webpack.config';
import env from '../../config/env' import env from '../../config/env';
export default { export default {
...baseConfig, ...baseConfig,
@ -11,7 +11,7 @@ export default {
'react-hot-loader/patch', 'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:4872', 'webpack-dev-server/client?http://localhost:4872',
'webpack/hot/only-dev-server', 'webpack/hot/only-dev-server',
`${env.SRC_ROOT}/webui/src/index.jsx` `${env.SRC_ROOT}/webui/src/index.jss`
] ]
}, },
@ -22,7 +22,7 @@ export default {
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
__DEBUG__: true, '__DEBUG__': true,
'process.env.NODE_ENV': '"development"' 'process.env.NODE_ENV': '"development"'
}), }),
new HTMLWebpackPlugin({ new HTMLWebpackPlugin({
@ -37,4 +37,4 @@ export default {
new webpack.NoEmitOnErrorsPlugin(), new webpack.NoEmitOnErrorsPlugin(),
new FriendlyErrorsPlugin() new FriendlyErrorsPlugin()
] ]
} };

View file

@ -1,24 +1,24 @@
import webpack from 'webpack'; import webpack from 'webpack';
import HTMLWebpackPlugin from 'html-webpack-plugin'; import HTMLWebpackPlugin from 'html-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin'; import ExtractTextPlugin from 'extract-text-webpack-plugin';
import baseConfig from './webpack.config' import baseConfig from './webpack.config';
import env from '../../config/env' import env from '../../config/env';
import _ from 'lodash' import _ from 'lodash';
baseConfig.module.rules baseConfig.module.rules
.filter(loader => .filter((loader) =>
Array.isArray(loader.use) && loader.use.find(v => /css/.test(v.loader.split('-')[0])) Array.isArray(loader.use) && loader.use.find((v) => /css/.test(v.loader.split('-')[0]))
).forEach(loader => { ).forEach((loader) => {
loader.use = ExtractTextPlugin.extract({ loader.use = ExtractTextPlugin.extract({
fallback: 'style-loader', fallback: 'style-loader',
use: _.tail(loader.use) use: _.tail(loader.use)
}) });
}) });
export default { export default {
...baseConfig, ...baseConfig,
entry: { entry: {
main: `${env.SRC_ROOT}/webui/src/index.jsx` main: `${env.SRC_ROOT}/webui/src/index.js`
}, },
output: { output: {
@ -27,7 +27,7 @@ export default {
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
__DEBUG__: false, '__DEBUG__': false,
'process.env.NODE_ENV': '"production"' 'process.env.NODE_ENV': '"production"'
}), }),
new webpack.optimize.UglifyJsPlugin({ new webpack.optimize.UglifyJsPlugin({
@ -47,4 +47,4 @@ export default {
}), }),
new webpack.NoEmitOnErrorsPlugin() new webpack.NoEmitOnErrorsPlugin()
] ]
} };

View file

@ -1,18 +1,18 @@
import React from 'react'; import React from 'react';
import { HashRouter as Router, Route, Switch } from 'react-router-dom'; import {HashRouter as Router, Route, Switch} from 'react-router-dom';
import 'normalize.css' import 'normalize.css';
import 'element-theme-default' import 'element-theme-default';
import { i18n } from 'element-react' import {i18n} from 'element-react';
import locale from 'element-react/src/locale/lang/en' import locale from 'element-react/src/locale/lang/en';
i18n.use(locale); i18n.use(locale);
import Header from './components/Header' import Header from './components/Header';
import Home from './modules/home'; import Home from './modules/home';
import Detail from './modules/detail'; import Detail from './modules/detail';
import './styles/global.scss' import './styles/global.scss';
export default class App extends React.Component { export default class App extends React.Component {
render() { render() {

View file

@ -1,10 +1,10 @@
import React from 'react'; import React from 'react';
import { Button, Dialog, Input, MessageBox } from 'element-react'; import {Button, Dialog, Input, MessageBox} from 'element-react';
import styled from 'styled-components'; import styled from 'styled-components';
import API from '../../../utils/api'; import API from '../../../utils/api';
import storage from '../../../utils/storage'; import storage from '../../../utils/storage';
import _ from 'lodash'; import _ from 'lodash';
import { Link } from 'react-router-dom'; import {Link} from 'react-router-dom';
import classes from './header.scss'; import classes from './header.scss';
@ -16,7 +16,7 @@ const SetupGuide = styled.figure`
line-height: 18px; line-height: 18px;
padding: 8px 0; padding: 8px 0;
color: #f9f2f4; color: #f9f2f4;
` `;
export default class Header extends React.Component { export default class Header extends React.Component {
state = { state = {
@ -25,25 +25,25 @@ export default class Header extends React.Component {
password: '' password: ''
} }
constructor (props) { constructor(props) {
super(props); super(props);
this.toggleLoginModal = this.toggleLoginModal.bind(this); this.toggleLoginModal = this.toggleLoginModal.bind(this);
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
} }
toggleLoginModal () { toggleLoginModal() {
this.setState({ this.setState({
showLogin: !this.state.showLogin showLogin: !this.state.showLogin
}) });
} }
handleInput (name, e) { handleInput(name, e) {
this.setState({ this.setState({
[name]: e [name]: e
}) });
} }
async handleSubmit () { async handleSubmit() {
if (this.state.username === '' || this.state.password === '') { if (this.state.username === '' || this.state.password === '') {
return MessageBox.alert('Username or password can\'t be empty!'); return MessageBox.alert('Username or password can\'t be empty!');
} }
@ -68,7 +68,7 @@ export default class Header extends React.Component {
} }
} }
get isTokenExpire () { get isTokenExpire() {
let token = storage.getItem('token'); let token = storage.getItem('token');
if (!_.isString(token)) return true; if (!_.isString(token)) return true;
let payload = token.split('.')[1]; let payload = token.split('.')[1];
@ -90,12 +90,12 @@ export default class Header extends React.Component {
return expired; return expired;
} }
handleLogout () { handleLogout() {
storage.clear(); storage.clear();
location.reload(); location.reload();
} }
renderUserActionButton () { renderUserActionButton() {
if (!this.isTokenExpire) { // TODO: Check jwt token expire if (!this.isTokenExpire) { // TODO: Check jwt token expire
return ( return (
<div className={ classes.welcome }> <div className={ classes.welcome }>
@ -103,9 +103,9 @@ export default class Header extends React.Component {
&nbsp; &nbsp;
<Button type="danger" onClick={this.handleLogout}>Logout</Button> <Button type="danger" onClick={this.handleLogout}>Logout</Button>
</div> </div>
) );
} else { } else {
return <Button type="danger" style={ {marginLeft: 'auto'} } onClick={ this.toggleLoginModal }>Login</Button> return <Button type="danger" style={ {marginLeft: 'auto'} } onClick={ this.toggleLoginModal }>Login</Button>;
} }
} }

View file

@ -3,13 +3,13 @@ import PropTypes from 'prop-types';
import {Tag} from 'element-react'; import {Tag} from 'element-react';
import {Link} from 'react-router-dom'; import {Link} from 'react-router-dom';
import classes from './package.scss' import classes from './package.scss';
export default class Package extends React.Component { export default class Package extends React.Component {
static propTypes = { static propTypes = {
package: PropTypes.object package: PropTypes.object
} }
render () { render() {
let {package: pkg} = this.props; let {package: pkg} = this.props;
return ( return (

View file

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import styled from 'styled-components' import styled from 'styled-components';
import Package from '../Package'; import Package from '../Package';
@ -9,30 +9,30 @@ const NoPackage = styled.li`
line-height: 3; line-height: 3;
font-size: 20px; font-size: 20px;
color: lightgrey; color: lightgrey;
` `;
const PackageRow = styled.li` const PackageRow = styled.li`
border-bottom: 1px solid #e4e8f1; border-bottom: 1px solid #e4e8f1;
list-style: none; list-style: none;
` `;
const PackageContainer = styled.ul` const PackageContainer = styled.ul`
margin: 0; margin: 0;
padding: 0; padding: 0;
` `;
export default class PackageList extends React.Component { export default class PackageList extends React.Component {
static propTypes = { static propTypes = {
packages: PropTypes.array packages: PropTypes.array
} }
renderList () { renderList() {
return this.props.packages.map((pkg, i)=> ( return this.props.packages.map((pkg, i)=> (
<PackageRow key={i}><Package package={pkg} /></PackageRow> <PackageRow key={i}><Package package={pkg} /></PackageRow>
)) ));
} }
render () { render() {
return ( return (
<PackageContainer> <PackageContainer>
{ {
@ -41,6 +41,6 @@ export default class PackageList extends React.Component {
<NoPackage>No Package Available</NoPackage> <NoPackage>No Package Available</NoPackage>
} }
</PackageContainer> </PackageContainer>
) );
} }
} }

View file

@ -2,11 +2,11 @@ import '../utils/__setPublicPath__';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader' import {AppContainer} from 'react-hot-loader';
import App from './App' import App from './app';
let rootNode = document.getElementById('root') let rootNode = document.getElementById('root');
let renderApp = (Component) => { let renderApp = (Component) => {
ReactDOM.render( ReactDOM.render(
@ -14,13 +14,13 @@ let renderApp = (Component) => {
<Component/> <Component/>
</AppContainer>, </AppContainer>,
rootNode rootNode
) );
} };
renderApp(App); renderApp(App);
if (module.hot) { if (module.hot) {
module.hot.accept('./App', () => { module.hot.accept('./App', () => {
renderApp(App) renderApp(App);
}) });
} }

View file

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import API from '../../../utils/api'; import API from '../../../utils/api';
import { Loading } from 'element-react'; import {Loading} from 'element-react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classes from './detail.scss'; import classes from './detail.scss';
@ -28,15 +28,15 @@ export default class Detail extends React.Component {
} }
} }
renderReadMe () { renderReadMe() {
if (this.state.readMe) { if (this.state.readMe) {
return ( return (
<div className="markdown-body" dangerouslySetInnerHTML={{__html: this.state.readMe}}/> <div className="markdown-body" dangerouslySetInnerHTML={{__html: this.state.readMe}}/>
) );
} else { } else {
return ( return (
<Loading text="Loading..." /> <Loading text="Loading..." />
) );
} }
} }
@ -47,6 +47,6 @@ export default class Detail extends React.Component {
<hr/> <hr/>
{this.renderReadMe()} {this.renderReadMe()}
</div> </div>
) );
} }
} }

View file

@ -1,17 +1,17 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Loading, MessageBox } from 'element-react'; import {Loading, MessageBox} from 'element-react';
import API from '../../../utils/api'; import API from '../../../utils/api';
import PackageList from '../../components/PackageList' import PackageList from '../../components/PackageList';
import classes from './home.scss'; import classes from './home.scss';
export default class Home extends React.Component { export default class Home extends React.Component {
static propTypes = { static propTypes = {
children: PropTypes.element children: PropTypes.element
} }
state = { state = {
@ -19,16 +19,16 @@ export default class Home extends React.Component {
query: '' query: ''
} }
constructor (props) { constructor(props) {
super(props); super(props);
this.handleSearchInput = this.handleSearchInput.bind(this); this.handleSearchInput = this.handleSearchInput.bind(this);
} }
componentDidMount () { componentDidMount() {
this.loadPackages(); this.loadPackages();
} }
componentDidUpdate (prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (prevState.query !== this.state.query) { if (prevState.query !== this.state.query) {
if (this.req && this.req.abort) this.req.abort(); if (this.req && this.req.abort) this.req.abort();
this.setState({ this.setState({
@ -38,12 +38,12 @@ export default class Home extends React.Component {
if (prevState.query !== '' && this.state.query === '') { if (prevState.query !== '' && this.state.query === '') {
this.loadPackages(); this.loadPackages();
} else { } else {
this.searchPackage(this.state.query) this.searchPackage(this.state.query);
} }
} }
} }
async loadPackages () { async loadPackages() {
try { try {
this.req = await API.get('packages'); this.req = await API.get('packages');
@ -62,7 +62,7 @@ export default class Home extends React.Component {
} }
} }
async searchPackage (query) { async searchPackage(query) {
try { try {
this.req = await API.get(`/search/${query}`); this.req = await API.get(`/search/${query}`);
@ -78,29 +78,29 @@ export default class Home extends React.Component {
type: 'error', type: 'error',
title: 'Warning', title: 'Warning',
message: 'Unable to get search result, please try again later.' message: 'Unable to get search result, please try again later.'
}) });
} }
} }
handleSearchInput (e) { handleSearchInput(e) {
this.setState({ this.setState({
query: e.target.value query: e.target.value
}); });
} }
renderLoading () { renderLoading() {
return ( return (
<Loading text="Loading..." /> <Loading text="Loading..." />
) );
} }
renderPackageList () { renderPackageList() {
return ( return (
<div> <div>
<h1 className={ classes.listTitle }>Available Packages</h1> <h1 className={ classes.listTitle }>Available Packages</h1>
<PackageList packages={this.state.packages} /> <PackageList packages={this.state.packages} />
</div> </div>
) );
} }
render() { render() {
@ -114,6 +114,6 @@ export default class Home extends React.Component {
/> />
{ this.state.loading ? this.renderLoading() : this.renderPackageList() } { this.state.loading ? this.renderLoading() : this.renderPackageList() }
</div> </div>
) );
} }
} }

View file

@ -1,9 +1,9 @@
import storage from './storage'; import storage from './storage';
import axios from 'axios' import axios from 'axios';
class API { class API {
constructor () { constructor() {
['get', 'delete', 'post', 'put', 'patch'].map(method => { ['get', 'delete', 'post', 'put', 'patch'].map((method) => {
this[method] = (url, options = {}) => { this[method] = (url, options = {}) => {
if (!window.VERDACCIO_API_URL) { if (!window.VERDACCIO_API_URL) {
throw new Error('VERDACCIO_API_URL is not defined!'); throw new Error('VERDACCIO_API_URL is not defined!');
@ -16,7 +16,7 @@ class API {
options.headers.authorization = token; options.headers.authorization = token;
} }
if (!['http://', 'https://', '//'].some(prefix => url.startsWith(prefix))) { if (!['http://', 'https://', '//'].some((prefix) => url.startsWith(prefix))) {
url = window.VERDACCIO_API_URL + url; url = window.VERDACCIO_API_URL + url;
} }
@ -25,8 +25,8 @@ class API {
url, url,
...options ...options
}); });
} };
}) });
} }
} }

View file

@ -9,4 +9,4 @@ try {
storage = memoryStorage; storage = memoryStorage;
} }
export default storage export default storage;

View file

@ -1,15 +1,23 @@
# vim: syntax=yaml {
"extends": [
extends: ["eslint:recommended"] "eslint:recommended"
],
env: "env": {
node: true "node": true,
mocha: true "mocha": true,
es6: true "es6": true
},
rules: "rules": {
valid-jsdoc: 0 "valid-jsdoc": 0,
no-redeclare: 1 "no-redeclare": 1,
no-console: 1 "no-console": [
no-useless-escape: 0 2,
{
"allow": [
"log"
]
}
],
"no-useless-escape": 0
}
}

BIN
yarn.lock

Binary file not shown.