mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-22 17:08:55 +00:00
reformat everything
This commit is contained in:
parent
bd531c91fc
commit
12fa008755
@ -1,4 +1,4 @@
|
||||
export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE'
|
||||
export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
|
||||
// I'm not sure, but I guess that if you use redux-devtools extension your APP_INIT should be look like:
|
||||
// export const APP_INIT = '@@INIT'
|
||||
export const APP_INIT = '@@redux/INIT'
|
||||
export const APP_INIT = '@@redux/INIT';
|
||||
|
@ -3,41 +3,45 @@
|
||||
export type NOTIFICATION_LEVEL = 'danger' | 'warning' | 'success' | 'info';
|
||||
|
||||
export type Notification = {
|
||||
level: NOTIFICATION_LEVEL,
|
||||
msg: string,
|
||||
duration?: number
|
||||
level: NOTIFICATION_LEVEL,
|
||||
msg: string,
|
||||
duration?: number
|
||||
};
|
||||
|
||||
export type ShowNotificationAction = {
|
||||
type: 'SHOW_NOTIFICATION',
|
||||
payload: Notification
|
||||
type: 'SHOW_NOTIFICATION',
|
||||
payload: Notification
|
||||
};
|
||||
|
||||
export type CloseNotificationAction = {
|
||||
type: 'CLOSE_NOTIFICATION',
|
||||
payload: Notification
|
||||
type: 'CLOSE_NOTIFICATION',
|
||||
payload: Notification
|
||||
};
|
||||
|
||||
export type NotificationsAction = ShowNotificationAction | CloseNotificationAction;
|
||||
export type NotificationsAction =
|
||||
| ShowNotificationAction
|
||||
| CloseNotificationAction;
|
||||
|
||||
export function showNotification(
|
||||
level: NOTIFICATION_LEVEL = 'info',
|
||||
msg: string,
|
||||
duration?: number
|
||||
level: NOTIFICATION_LEVEL = 'info',
|
||||
msg: string,
|
||||
duration?: number
|
||||
): ShowNotificationAction {
|
||||
return {
|
||||
type: 'SHOW_NOTIFICATION',
|
||||
payload: {
|
||||
level,
|
||||
msg,
|
||||
duration
|
||||
}
|
||||
};
|
||||
return {
|
||||
type: 'SHOW_NOTIFICATION',
|
||||
payload: {
|
||||
level,
|
||||
msg,
|
||||
duration
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function closeNotification(notification: Notification): CloseNotificationAction {
|
||||
return {
|
||||
type: 'CLOSE_NOTIFICATION',
|
||||
payload: notification
|
||||
};
|
||||
export function closeNotification(
|
||||
notification: Notification
|
||||
): CloseNotificationAction {
|
||||
return {
|
||||
type: 'CLOSE_NOTIFICATION',
|
||||
payload: notification
|
||||
};
|
||||
}
|
||||
|
@ -2,55 +2,55 @@
|
||||
// feel free to replace with your code
|
||||
// (get, post are used in ApiServices)
|
||||
|
||||
import { getLocalToken } from 'api/AuthSvc';
|
||||
import config from 'config';
|
||||
|
||||
import {getLocalToken} from 'api/AuthSvc';
|
||||
import config from 'config'
|
||||
|
||||
window.BASE_API = config.BASE_API
|
||||
window.BASE_API = config.BASE_API;
|
||||
|
||||
function requestWrapper(method) {
|
||||
return async function (url, data = null, params = {}) {
|
||||
if (method === 'GET') {
|
||||
// is it a GET?
|
||||
// GET doesn't have data
|
||||
params = data;
|
||||
data = null;
|
||||
} else if (data === Object(data)) {
|
||||
// (data === Object(data)) === _.isObject(data)
|
||||
data = JSON.stringify(data)
|
||||
} else {
|
||||
throw new Error(`XHR invalid, check ${method} on ${url}`)
|
||||
}
|
||||
|
||||
// default params for fetch = method + (Content-Type)
|
||||
let defaults = {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8'
|
||||
}
|
||||
}
|
||||
|
||||
// check that req url is relative and request was sent to our domain
|
||||
if (url.match(/^https?:\/\//gi) > -1) {
|
||||
let token = getLocalToken();
|
||||
if (token) {
|
||||
defaults.headers['Authorization'] = `JWT ${token}`;
|
||||
}
|
||||
url = window.BASE_API + url;
|
||||
}
|
||||
|
||||
if (data) {
|
||||
defaults.body = data;
|
||||
}
|
||||
|
||||
let paramsObj = {...defaults, headers: {...params, ...defaults.headers}}
|
||||
|
||||
return await fetch(url, paramsObj)
|
||||
.then(parseJSON)
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
});
|
||||
return async function(url, data = null, params = {}) {
|
||||
if (method === 'GET') {
|
||||
// is it a GET?
|
||||
// GET doesn't have data
|
||||
params = data;
|
||||
data = null;
|
||||
} else if (data === Object(data)) {
|
||||
// (data === Object(data)) === _.isObject(data)
|
||||
data = JSON.stringify(data);
|
||||
} else {
|
||||
throw new Error(`XHR invalid, check ${method} on ${url}`);
|
||||
}
|
||||
|
||||
// default params for fetch = method + (Content-Type)
|
||||
let defaults = {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8'
|
||||
}
|
||||
};
|
||||
|
||||
// check that req url is relative and request was sent to our domain
|
||||
if (url.match(/^https?:\/\//gi) > -1) {
|
||||
let token = getLocalToken();
|
||||
if (token) {
|
||||
defaults.headers['Authorization'] = `JWT ${token}`;
|
||||
}
|
||||
url = window.BASE_API + url;
|
||||
}
|
||||
|
||||
if (data) {
|
||||
defaults.body = data;
|
||||
}
|
||||
|
||||
let paramsObj = {
|
||||
...defaults,
|
||||
headers: { ...params, ...defaults.headers }
|
||||
};
|
||||
|
||||
return await fetch(url, paramsObj).then(parseJSON).catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// middlewares
|
||||
@ -64,28 +64,27 @@ function requestWrapper(method) {
|
||||
* @return {Object} response result with "ok" property
|
||||
*/
|
||||
async function parseJSON(res) {
|
||||
let json;
|
||||
try {
|
||||
json = await res.json()
|
||||
} catch (e) {
|
||||
return {data: {}, ok: false}
|
||||
}
|
||||
let json;
|
||||
try {
|
||||
json = await res.json();
|
||||
} catch (e) {
|
||||
return { data: {}, ok: false };
|
||||
}
|
||||
|
||||
// simplest validation ever, ahah :)
|
||||
if (!res.ok) {
|
||||
return {data: json, ok: false}
|
||||
}
|
||||
// resultOK - is a function with side effects
|
||||
// It removes ok property from result object
|
||||
return {data: json, ok: true}
|
||||
// simplest validation ever, ahah :)
|
||||
if (!res.ok) {
|
||||
return { data: json, ok: false };
|
||||
}
|
||||
// resultOK - is a function with side effects
|
||||
// It removes ok property from result object
|
||||
return { data: json, ok: true };
|
||||
}
|
||||
|
||||
|
||||
export const get = requestWrapper('GET')
|
||||
export const post = requestWrapper('POST')
|
||||
export const put = requestWrapper('PUT')
|
||||
export const patch = requestWrapper('PATCH')
|
||||
export const del = requestWrapper('DELETE')
|
||||
export const get = requestWrapper('GET');
|
||||
export const post = requestWrapper('POST');
|
||||
export const put = requestWrapper('PUT');
|
||||
export const patch = requestWrapper('PATCH');
|
||||
export const del = requestWrapper('DELETE');
|
||||
|
||||
// USAGE:
|
||||
// get('https://www.google.com', {
|
||||
@ -108,11 +107,11 @@ export const del = requestWrapper('DELETE')
|
||||
* @return {bool} - indicates was request successful or not
|
||||
*/
|
||||
export function resultOK(result) {
|
||||
if (result) {
|
||||
let ok = result.ok
|
||||
delete result.ok
|
||||
return ok //look at parseJSON
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
if (result) {
|
||||
let ok = result.ok;
|
||||
delete result.ok;
|
||||
return ok; //look at parseJSON
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
import React, {Component} from 'react'
|
||||
import {Provider} from 'react-redux'
|
||||
import {Router} from 'react-router'
|
||||
import React, { Component } from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
import { Router } from 'react-router';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
export default class Root extends Component {
|
||||
static propTypes = {
|
||||
store: PropTypes.object,
|
||||
history: PropTypes.object,
|
||||
routes: PropTypes.func
|
||||
};
|
||||
static propTypes = {
|
||||
store: PropTypes.object,
|
||||
history: PropTypes.object,
|
||||
routes: PropTypes.func
|
||||
};
|
||||
|
||||
render() {
|
||||
const {store, history, routes} = this.props;
|
||||
// key={Math.random()} = hack for HMR from https://github.com/webpack/webpack-dev-server/issues/395
|
||||
return (
|
||||
<Provider store={store} key={Math.random()}>
|
||||
<Router history={history} key={Math.random()}>
|
||||
{routes()}
|
||||
</Router>
|
||||
</Provider>
|
||||
);
|
||||
}
|
||||
render() {
|
||||
const { store, history, routes } = this.props;
|
||||
// key={Math.random()} = hack for HMR from https://github.com/webpack/webpack-dev-server/issues/395
|
||||
return (
|
||||
<Provider store={store} key={Math.random()}>
|
||||
<Router history={history} key={Math.random()}>
|
||||
{routes()}
|
||||
</Router>
|
||||
</Provider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,74 +5,74 @@ import { closeNotification } from 'actions/notifications';
|
||||
import type { Notification } from 'actions/notifications';
|
||||
|
||||
class NotificationRow extends React.Component {
|
||||
props: {
|
||||
notification: Notification,
|
||||
onClose: (n: Notification) => void
|
||||
};
|
||||
render() {
|
||||
const { msg, level } = this.props.notification;
|
||||
let className = '';
|
||||
props: {
|
||||
notification: Notification,
|
||||
onClose: (n: Notification) => void
|
||||
};
|
||||
render() {
|
||||
const { msg, level } = this.props.notification;
|
||||
let className = '';
|
||||
|
||||
switch (level) {
|
||||
case 'danger':
|
||||
className = 'alert-danger';
|
||||
break;
|
||||
case 'success':
|
||||
className = 'alert-success';
|
||||
break;
|
||||
case 'warning':
|
||||
className = 'alert-warning';
|
||||
break;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`alert popup ${className} animated-show-hide`}
|
||||
role="alert"
|
||||
aria-live="assertive"
|
||||
>
|
||||
<span className="sr-only">{level}</span>
|
||||
<div className="container" dangerouslySetInnerHTML={{ __html: msg }} />
|
||||
<i
|
||||
tabIndex="0"
|
||||
aria-label="dismiss"
|
||||
className="icon-close"
|
||||
onClick={this.onClose}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
switch (level) {
|
||||
case 'danger':
|
||||
className = 'alert-danger';
|
||||
break;
|
||||
case 'success':
|
||||
className = 'alert-success';
|
||||
break;
|
||||
case 'warning':
|
||||
className = 'alert-warning';
|
||||
break;
|
||||
}
|
||||
|
||||
onClose = () => {
|
||||
this.props.onClose(this.props.notification);
|
||||
};
|
||||
return (
|
||||
<div
|
||||
className={`alert popup ${className} animated-show-hide`}
|
||||
role="alert"
|
||||
aria-live="assertive"
|
||||
>
|
||||
<span className="sr-only">{level}</span>
|
||||
<div className="container" dangerouslySetInnerHTML={{ __html: msg }} />
|
||||
<i
|
||||
tabIndex="0"
|
||||
aria-label="dismiss"
|
||||
className="icon-close"
|
||||
onClick={this.onClose}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
onClose = () => {
|
||||
this.props.onClose(this.props.notification);
|
||||
};
|
||||
}
|
||||
|
||||
export class Notifications extends React.Component {
|
||||
props: {
|
||||
notifications: Notification[],
|
||||
closeNotification: (n: Notification) => void
|
||||
};
|
||||
render() {
|
||||
if (!this.props.notifications.length) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div className="alerts-container">
|
||||
{this.props.notifications.map((n, i) =>
|
||||
<NotificationRow
|
||||
key={`${n.level}-${i}`}
|
||||
notification={n}
|
||||
onClose={this.props.closeNotification}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
props: {
|
||||
notifications: Notification[],
|
||||
closeNotification: (n: Notification) => void
|
||||
};
|
||||
render() {
|
||||
if (!this.props.notifications.length) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div className="alerts-container">
|
||||
{this.props.notifications.map((n, i) =>
|
||||
<NotificationRow
|
||||
key={`${n.level}-${i}`}
|
||||
notification={n}
|
||||
onClose={this.props.closeNotification}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
notifications: state.notifications
|
||||
notifications: state.notifications
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, { closeNotification })(Notifications);
|
||||
|
@ -1,27 +1,47 @@
|
||||
import React from 'react';
|
||||
|
||||
const Help = () => (
|
||||
<section className="container" style={{minHeight: '50%'}}>
|
||||
<div className="tab-content">
|
||||
<article className="tab-pane help active">
|
||||
<h1 translate="NAV_Help">Help</h1>
|
||||
<article className="collapse-container">
|
||||
<div>
|
||||
<ul>
|
||||
<li><h3><a
|
||||
href="https://www.reddit.com/r/ethereum/comments/47nkoi/psa_check_your_ethaddressorg_wallets_and_any/d0eo45o"
|
||||
target="_blank"><span className="text-danger" translate="HELP_Warning">If you created a wallet -or- downloaded the repo before <strong>Dec. 31st, 2015</strong>, please check your wallets &
|
||||
download a new version of the repo. Click for details.</span></a></h3></li>
|
||||
<li><h3>This
|
||||
page is deprecated. Please check out our more up-to-date and
|
||||
searchable <a href="https://myetherwallet.groovehq.com/help_center" target="_blank">Knowledge
|
||||
Base. </a></h3></li>
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
const Help = () =>
|
||||
<section className="container" style={{ minHeight: '50%' }}>
|
||||
<div className="tab-content">
|
||||
<article className="tab-pane help active">
|
||||
<h1 translate="NAV_Help">Help</h1>
|
||||
<article className="collapse-container">
|
||||
<div>
|
||||
<ul>
|
||||
<li>
|
||||
<h3>
|
||||
<a
|
||||
href="https://www.reddit.com/r/ethereum/comments/47nkoi/psa_check_your_ethaddressorg_wallets_and_any/d0eo45o"
|
||||
target="_blank"
|
||||
>
|
||||
<span className="text-danger" translate="HELP_Warning">
|
||||
If you created a wallet -or- downloaded the repo before{' '}
|
||||
<strong>Dec. 31st, 2015</strong>, please check your
|
||||
wallets &
|
||||
download a new version of the repo. Click for details.
|
||||
</span>
|
||||
</a>
|
||||
</h3>
|
||||
</li>
|
||||
<li>
|
||||
<h3>
|
||||
This
|
||||
page is deprecated. Please check out our more up-to-date and
|
||||
searchable{' '}
|
||||
<a
|
||||
href="https://myetherwallet.groovehq.com/help_center"
|
||||
target="_blank"
|
||||
>
|
||||
Knowledge
|
||||
Base.{' '}
|
||||
</a>
|
||||
</h3>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
</article>
|
||||
</div>
|
||||
</section>;
|
||||
|
||||
export default Help
|
||||
export default Help;
|
||||
|
@ -15,7 +15,8 @@ export default class GasField extends React.Component {
|
||||
return (
|
||||
<div className="row form-group">
|
||||
<div className="col-sm-11 clearfix">
|
||||
<label>{translate('TRANS_gas')}{' '}
|
||||
<label>
|
||||
{translate('TRANS_gas')}{' '}
|
||||
</label>
|
||||
<input
|
||||
className={`form-control ${isFinite(parseFloat(value)) &&
|
||||
|
@ -1 +1 @@
|
||||
export App from './App'
|
||||
export App from './App';
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -5,46 +5,53 @@ const BOLD_REGEXP = /(\*\*)(.*?)\1/;
|
||||
const LINK_REGEXP = /\[([^\[]+)\]\(([^\)]+)\)/;
|
||||
|
||||
function decodeHTMLEntities(text) {
|
||||
var entities = [['amp', '&'], ['lt', '<'], ['gt', '>']];
|
||||
var entities = [['amp', '&'], ['lt', '<'], ['gt', '>']];
|
||||
|
||||
for (var i = 0, max = entities.length; i < max; ++i)
|
||||
text = text.replace(new RegExp('&' + entities[i][0] + ';', 'g'), entities[i][1]);
|
||||
for (var i = 0, max = entities.length; i < max; ++i)
|
||||
text = text.replace(
|
||||
new RegExp('&' + entities[i][0] + ';', 'g'),
|
||||
entities[i][1]
|
||||
);
|
||||
|
||||
return text;
|
||||
return text;
|
||||
}
|
||||
|
||||
function linkify(mdString: string) {
|
||||
const parts = mdString.split(LINK_REGEXP);
|
||||
if (parts.length === 1) {
|
||||
return decodeHTMLEntities(parts[0]);
|
||||
}
|
||||
const result = [];
|
||||
let key = 0;
|
||||
let i = 0;
|
||||
while (i + 1 < parts.length) {
|
||||
result.push(decodeHTMLEntities(parts[i]));
|
||||
result.push(<a key={'linkify-' + key} href={parts[i + 2]} target="_blank">{parts[i + 1]}</a>);
|
||||
key++;
|
||||
i += 3;
|
||||
}
|
||||
result.push(decodeHTMLEntities(parts[parts.length - 1]));
|
||||
return result.filter(Boolean);
|
||||
const parts = mdString.split(LINK_REGEXP);
|
||||
if (parts.length === 1) {
|
||||
return decodeHTMLEntities(parts[0]);
|
||||
}
|
||||
const result = [];
|
||||
let key = 0;
|
||||
let i = 0;
|
||||
while (i + 1 < parts.length) {
|
||||
result.push(decodeHTMLEntities(parts[i]));
|
||||
result.push(
|
||||
<a key={'linkify-' + key} href={parts[i + 2]} target="_blank">
|
||||
{parts[i + 1]}
|
||||
</a>
|
||||
);
|
||||
key++;
|
||||
i += 3;
|
||||
}
|
||||
result.push(decodeHTMLEntities(parts[parts.length - 1]));
|
||||
return result.filter(Boolean);
|
||||
}
|
||||
|
||||
export function markupToReact(mdString: string) {
|
||||
const parts = mdString.split(BOLD_REGEXP);
|
||||
if (parts.length === 1) {
|
||||
return linkify(parts[0]);
|
||||
}
|
||||
let result = [];
|
||||
let key = 0;
|
||||
let i = 0;
|
||||
while (i + 1 < parts.length) {
|
||||
result = result.concat(linkify(parts[i]));
|
||||
result.push(<b key={'boldify-' + key}>{parts[i + 2]}</b>);
|
||||
key++;
|
||||
i += 3;
|
||||
}
|
||||
result = result.concat(linkify(parts.pop()));
|
||||
return result.filter(Boolean);
|
||||
const parts = mdString.split(BOLD_REGEXP);
|
||||
if (parts.length === 1) {
|
||||
return linkify(parts[0]);
|
||||
}
|
||||
let result = [];
|
||||
let key = 0;
|
||||
let i = 0;
|
||||
while (i + 1 < parts.length) {
|
||||
result = result.concat(linkify(parts[i]));
|
||||
result.push(<b key={'boldify-' + key}>{parts[i + 2]}</b>);
|
||||
key++;
|
||||
i += 3;
|
||||
}
|
||||
result = result.concat(linkify(parts.pop()));
|
||||
return result.filter(Boolean);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -2,74 +2,86 @@ import React from 'react';
|
||||
import { markupToReact } from 'translations/markup';
|
||||
|
||||
describe('markupToReact', () => {
|
||||
it('passes plain string as is', () => {
|
||||
const value = 'string';
|
||||
const expected = 'string';
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
});
|
||||
it('passes plain string as is', () => {
|
||||
const value = 'string';
|
||||
const expected = 'string';
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('transforms bold syntax', () => {
|
||||
let value = '**foo**';
|
||||
let expected = [<b key="boldify-0">foo</b>];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
it('transforms bold syntax', () => {
|
||||
let value = '**foo**';
|
||||
let expected = [<b key="boldify-0">foo</b>];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
|
||||
value = '**foo** bar';
|
||||
expected = [<b key="boldify-0">foo</b>, ' bar'];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
value = '**foo** bar';
|
||||
expected = [<b key="boldify-0">foo</b>, ' bar'];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
|
||||
value = 'bar **foo**';
|
||||
expected = ['bar ', <b key="boldify-0">foo</b>];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
value = 'bar **foo**';
|
||||
expected = ['bar ', <b key="boldify-0">foo</b>];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
|
||||
value = 'bar **foo** baz';
|
||||
expected = ['bar ', <b key="boldify-0">foo</b>, ' baz'];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
value = 'bar **foo** baz';
|
||||
expected = ['bar ', <b key="boldify-0">foo</b>, ' baz'];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
|
||||
value = '**foo****bar**';
|
||||
expected = [<b key="boldify-0">foo</b>, <b key="boldify-1">bar</b>];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
});
|
||||
value = '**foo****bar**';
|
||||
expected = [<b key="boldify-0">foo</b>, <b key="boldify-1">bar</b>];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('transforms link syntax', () => {
|
||||
let value = '[foo](http://google.com)';
|
||||
let expected = [<a key="linkify-0" href="http://google.com" target="_blank">foo</a>];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
it('transforms link syntax', () => {
|
||||
let value = '[foo](http://google.com)';
|
||||
let expected = [
|
||||
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>
|
||||
];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
|
||||
value = '[foo](http://google.com) bar';
|
||||
expected = [<a key="linkify-0" href="http://google.com" target="_blank">foo</a>, ' bar'];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
value = '[foo](http://google.com) bar';
|
||||
expected = [
|
||||
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>,
|
||||
' bar'
|
||||
];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
|
||||
value = 'bar [foo](http://google.com)';
|
||||
expected = ['bar ', <a key="linkify-0" href="http://google.com" target="_blank">foo</a>];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
value = 'bar [foo](http://google.com)';
|
||||
expected = [
|
||||
'bar ',
|
||||
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>
|
||||
];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
|
||||
value = 'bar [foo](http://google.com) baz';
|
||||
expected = ['bar ', <a key="linkify-0" href="http://google.com" target="_blank">foo</a>, ' baz'];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
value = 'bar [foo](http://google.com) baz';
|
||||
expected = [
|
||||
'bar ',
|
||||
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>,
|
||||
' baz'
|
||||
];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
|
||||
value = '[foo](http://google.com)[bar](http://google.ca)';
|
||||
expected = [
|
||||
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>,
|
||||
<a key="linkify-1" href="http://google.ca" target="_blank">bar</a>
|
||||
];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
});
|
||||
value = '[foo](http://google.com)[bar](http://google.ca)';
|
||||
expected = [
|
||||
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>,
|
||||
<a key="linkify-1" href="http://google.ca" target="_blank">bar</a>
|
||||
];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('converts mixed syntax', () => {
|
||||
let value = 'Bold **foo** link [foo](http://google.com) text';
|
||||
let expected = [
|
||||
'Bold ',
|
||||
<b key="boldify-0">foo</b>,
|
||||
' link ',
|
||||
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>,
|
||||
' text'
|
||||
];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
});
|
||||
it('converts mixed syntax', () => {
|
||||
let value = 'Bold **foo** link [foo](http://google.com) text';
|
||||
let expected = [
|
||||
'Bold ',
|
||||
<b key="boldify-0">foo</b>,
|
||||
' link ',
|
||||
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>,
|
||||
' text'
|
||||
];
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('converts html entities', () => {
|
||||
let value = '&&';
|
||||
let expected = '&&';
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
})
|
||||
it('converts html entities', () => {
|
||||
let value = '&&';
|
||||
let expected = '&&';
|
||||
expect(markupToReact(value)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
@ -1,18 +1,24 @@
|
||||
'use strict'
|
||||
const path = require('path')
|
||||
'use strict';
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
port: 3000,
|
||||
title: 'MEW',
|
||||
publicPath: process.env.BUILD_GH_PAGES ? '/react-semantic.ui-starter/' : '/',
|
||||
publicPath: process.env.BUILD_GH_PAGES ? '/react-semantic.ui-starter/' : '/',
|
||||
srcPath: path.join(__dirname, './../common'),
|
||||
// add these dependencies to a standalone vendor bundle
|
||||
vendor: [
|
||||
'react', 'react-dom', 'react-router', 'redux', 'react-router-redux', 'redux-thunk', 'whatwg-fetch'
|
||||
'react',
|
||||
'react-dom',
|
||||
'react-router',
|
||||
'redux',
|
||||
'react-router-redux',
|
||||
'redux-thunk',
|
||||
'whatwg-fetch'
|
||||
],
|
||||
// enable babelrc
|
||||
babel: {
|
||||
babelrc: true
|
||||
},
|
||||
cssModules: false
|
||||
}
|
||||
};
|
||||
|
@ -1,15 +1,17 @@
|
||||
'use strict'
|
||||
const chalk = require('chalk')
|
||||
'use strict';
|
||||
const chalk = require('chalk');
|
||||
|
||||
// this plugin if for loggin url after each time the compilation is done.
|
||||
module.exports = class LogPlugin {
|
||||
constructor(port) {
|
||||
this.port = port
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.plugin('done', () => {
|
||||
console.log(`> App is running at ${chalk.yellow(`http://localhost:${this.port}`)}\n`)
|
||||
})
|
||||
console.log(
|
||||
`> App is running at ${chalk.yellow(`http://localhost:${this.port}`)}\n`
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,57 +1,59 @@
|
||||
'use strict'
|
||||
const path = require('path')
|
||||
const express = require('express')
|
||||
const webpack = require('webpack')
|
||||
const webpackConfig = require('./webpack.dev')
|
||||
const config = require('./config')
|
||||
const LogPlugin = require('./log-plugin')
|
||||
'use strict';
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const webpack = require('webpack');
|
||||
const webpackConfig = require('./webpack.dev');
|
||||
const config = require('./config');
|
||||
const LogPlugin = require('./log-plugin');
|
||||
|
||||
const app = express()
|
||||
const app = express();
|
||||
|
||||
const port = config.port
|
||||
const port = config.port;
|
||||
webpackConfig.entry.client = [
|
||||
'react-hot-loader/patch',
|
||||
'webpack-hot-middleware/client?reload=true',
|
||||
'webpack/hot/only-dev-server',
|
||||
webpackConfig.entry.client
|
||||
]
|
||||
'react-hot-loader/patch',
|
||||
'webpack-hot-middleware/client?reload=true',
|
||||
'webpack/hot/only-dev-server',
|
||||
webpackConfig.entry.client
|
||||
];
|
||||
|
||||
webpackConfig.plugins.push(new LogPlugin(port))
|
||||
webpackConfig.plugins.push(new LogPlugin(port));
|
||||
|
||||
let compiler
|
||||
let compiler;
|
||||
|
||||
try {
|
||||
compiler = webpack(webpackConfig)
|
||||
compiler = webpack(webpackConfig);
|
||||
} catch (err) {
|
||||
console.log(err.message)
|
||||
process.exit(1)
|
||||
console.log(err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const devMiddleWare = require('webpack-dev-middleware')(compiler, {
|
||||
publicPath: webpackConfig.output.publicPath,
|
||||
quiet: true,
|
||||
inline: true,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': '*',
|
||||
'Access-Control-Allow-Headers': '*'
|
||||
}
|
||||
})
|
||||
app.use(devMiddleWare)
|
||||
app.use(require('webpack-hot-middleware')(compiler, {
|
||||
publicPath: webpackConfig.output.publicPath,
|
||||
quiet: true,
|
||||
inline: true,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': '*',
|
||||
'Access-Control-Allow-Headers': '*'
|
||||
}
|
||||
});
|
||||
app.use(devMiddleWare);
|
||||
app.use(
|
||||
require('webpack-hot-middleware')(compiler, {
|
||||
log: console.log
|
||||
}))
|
||||
})
|
||||
);
|
||||
|
||||
const mfs = devMiddleWare.fileSystem
|
||||
const file = path.join(webpackConfig.output.path, 'index.html')
|
||||
const mfs = devMiddleWare.fileSystem;
|
||||
const file = path.join(webpackConfig.output.path, 'index.html');
|
||||
|
||||
devMiddleWare.waitUntilValid()
|
||||
devMiddleWare.waitUntilValid();
|
||||
|
||||
app.get('*', (req, res) => {
|
||||
devMiddleWare.waitUntilValid(() => {
|
||||
const html = mfs.readFileSync(file)
|
||||
res.end(html)
|
||||
})
|
||||
})
|
||||
devMiddleWare.waitUntilValid(() => {
|
||||
const html = mfs.readFileSync(file);
|
||||
res.end(html);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(port)
|
||||
app.listen(port);
|
||||
|
@ -1,28 +1,28 @@
|
||||
'use strict'
|
||||
const path = require('path')
|
||||
const config = require('./config')
|
||||
'use strict';
|
||||
const path = require('path');
|
||||
const config = require('./config');
|
||||
|
||||
const _ = module.exports = {}
|
||||
const _ = (module.exports = {});
|
||||
|
||||
_.cwd = (file) => {
|
||||
return path.join(process.cwd(), file || '')
|
||||
}
|
||||
_.cwd = file => {
|
||||
return path.join(process.cwd(), file || '');
|
||||
};
|
||||
|
||||
_.outputPath = path.join(__dirname, '../dist')
|
||||
_.outputPath = path.join(__dirname, '../dist');
|
||||
|
||||
_.outputIndexPath = path.join(__dirname, '../dist/index.html')
|
||||
_.outputIndexPath = path.join(__dirname, '../dist/index.html');
|
||||
|
||||
_.target = 'web'
|
||||
_.target = 'web';
|
||||
|
||||
_.loadersOptions = () => {
|
||||
const isProd = process.env.NODE_ENV === 'production'
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
|
||||
return {
|
||||
minimize: isProd,
|
||||
options: {
|
||||
// css-loader relies on context
|
||||
context: process.cwd(),
|
||||
babel: config.babel
|
||||
}
|
||||
return {
|
||||
minimize: isProd,
|
||||
options: {
|
||||
// css-loader relies on context
|
||||
context: process.cwd(),
|
||||
babel: config.babel
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -1,31 +1,33 @@
|
||||
'use strict'
|
||||
process.env.NODE_ENV = 'development'
|
||||
'use strict';
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
const webpack = require('webpack')
|
||||
const base = require('./webpack.base')
|
||||
const FriendlyErrors = require('friendly-errors-webpack-plugin')
|
||||
const webpack = require('webpack');
|
||||
const base = require('./webpack.base');
|
||||
const FriendlyErrors = require('friendly-errors-webpack-plugin');
|
||||
|
||||
base.devtool = 'source-map'
|
||||
base.module.loaders.push({
|
||||
test: /\.css$/,
|
||||
loaders: ['style-loader', 'css-loader', 'resolve-url-loader']
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loaders: ['style-loader', 'css-loader', 'resolve-url-loader', 'sass-loader']
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
loaders: ['style-loader', 'css-loader', 'resolve-url-loader', 'less-loader']
|
||||
})
|
||||
base.devtool = 'source-map';
|
||||
base.module.loaders.push(
|
||||
{
|
||||
test: /\.css$/,
|
||||
loaders: ['style-loader', 'css-loader', 'resolve-url-loader']
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loaders: ['style-loader', 'css-loader', 'resolve-url-loader', 'sass-loader']
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
loaders: ['style-loader', 'css-loader', 'resolve-url-loader', 'less-loader']
|
||||
}
|
||||
);
|
||||
|
||||
base.plugins.push(
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify('development')
|
||||
}),
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
new FriendlyErrors()
|
||||
)
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify('development')
|
||||
}),
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
new FriendlyErrors()
|
||||
);
|
||||
|
||||
module.exports = base
|
||||
module.exports = base;
|
||||
|
@ -1,94 +1,86 @@
|
||||
'use strict'
|
||||
process.env.NODE_ENV = 'production'
|
||||
'use strict';
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
const webpack = require('webpack')
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||||
const ProgressPlugin = require('webpack/lib/ProgressPlugin')
|
||||
const webpack = require('webpack');
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
|
||||
// const OfflinePlugin = require('offline-plugin')
|
||||
const base = require('./webpack.base')
|
||||
const config = require('./config')
|
||||
const fs = require('fs')
|
||||
const base = require('./webpack.base');
|
||||
const config = require('./config');
|
||||
const fs = require('fs');
|
||||
const distFolder = 'dist/';
|
||||
|
||||
if (fs.existsSync(distFolder)) fs.rmdirSync(distFolder);
|
||||
|
||||
if (fs.existsSync(distFolder))
|
||||
fs.rmdirSync(distFolder)
|
||||
|
||||
base.devtool = 'cheap-source-map'
|
||||
base.devtool = 'cheap-source-map';
|
||||
base.module.loaders.push(
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ExtractTextPlugin.extract(
|
||||
{
|
||||
fallback: 'style-loader',
|
||||
use: 'css-loader'
|
||||
}
|
||||
)
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: ExtractTextPlugin.extract(
|
||||
{
|
||||
fallback: 'style-loader',
|
||||
use: ['css-loader', 'sass-loader']
|
||||
}
|
||||
)
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
use: ExtractTextPlugin.extract(
|
||||
{
|
||||
fallback: 'style-loader',
|
||||
use: ['css-loader', 'less-loader']
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
use: 'css-loader'
|
||||
})
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
use: ['css-loader', 'sass-loader']
|
||||
})
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
use: ['css-loader', 'less-loader']
|
||||
})
|
||||
}
|
||||
);
|
||||
// a white list to add dependencies to vendor chunk
|
||||
base.entry.vendor = config.vendor
|
||||
base.entry.vendor = config.vendor;
|
||||
// use hash filename to support long-term caching
|
||||
base.output.filename = '[name].[chunkhash:8].js'
|
||||
base.output.filename = '[name].[chunkhash:8].js';
|
||||
// add webpack plugins
|
||||
base.plugins.push(
|
||||
new ProgressPlugin(),
|
||||
new ExtractTextPlugin('[name].[chunkhash:8].css'),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify('production')
|
||||
}),
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
sourceMap: true,
|
||||
compress: {
|
||||
warnings: false
|
||||
},
|
||||
output: {
|
||||
comments: false
|
||||
}
|
||||
}),
|
||||
// extract vendor chunks
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: 'vendor',
|
||||
filename: 'vendor.[chunkhash:8].js'
|
||||
})
|
||||
// For progressive web apps
|
||||
// new OfflinePlugin({
|
||||
// relativePaths: false,
|
||||
// AppCache: false,
|
||||
// ServiceWorker: {
|
||||
// events: true
|
||||
// }
|
||||
// })
|
||||
)
|
||||
new ProgressPlugin(),
|
||||
new ExtractTextPlugin('[name].[chunkhash:8].css'),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify('production')
|
||||
}),
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
sourceMap: true,
|
||||
compress: {
|
||||
warnings: false
|
||||
},
|
||||
output: {
|
||||
comments: false
|
||||
}
|
||||
}),
|
||||
// extract vendor chunks
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: 'vendor',
|
||||
filename: 'vendor.[chunkhash:8].js'
|
||||
})
|
||||
// For progressive web apps
|
||||
// new OfflinePlugin({
|
||||
// relativePaths: false,
|
||||
// AppCache: false,
|
||||
// ServiceWorker: {
|
||||
// events: true
|
||||
// }
|
||||
// })
|
||||
);
|
||||
|
||||
// minimize webpack output
|
||||
base.stats = {
|
||||
// Add children information
|
||||
children: false,
|
||||
// Add chunk information (setting this to `false` allows for a less verbose output)
|
||||
chunks: false,
|
||||
// Add built modules information to chunk information
|
||||
chunkModules: false,
|
||||
chunkOrigins: false,
|
||||
modules: false
|
||||
}
|
||||
// Add children information
|
||||
children: false,
|
||||
// Add chunk information (setting this to `false` allows for a less verbose output)
|
||||
chunks: false,
|
||||
// Add built modules information to chunk information
|
||||
chunkModules: false,
|
||||
chunkOrigins: false,
|
||||
modules: false
|
||||
};
|
||||
|
||||
module.exports = base
|
||||
module.exports = base;
|
||||
|
Loading…
x
Reference in New Issue
Block a user