Compare commits

...

15 Commits

Author SHA1 Message Date
dependabot[bot]
df19033a1d Bump tmpl from 1.0.4 to 1.0.5
Bumps [tmpl](https://github.com/daaku/nodejs-tmpl) from 1.0.4 to 1.0.5.
- [Release notes](https://github.com/daaku/nodejs-tmpl/releases)
- [Commits](https://github.com/daaku/nodejs-tmpl/commits/v1.0.5)

---
updated-dependencies:
- dependency-name: tmpl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-22 03:12:36 +00:00
dependabot[bot]
62ac69f59c Bump y18n from 3.2.1 to 3.2.2 (#12)
Bumps [y18n](https://github.com/yargs/y18n) from 3.2.1 to 3.2.2.
- [Release notes](https://github.com/yargs/y18n/releases)
- [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md)
- [Commits](https://github.com/yargs/y18n/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-04-12 11:45:39 +02:00
39f045cbe4 chore(release): publish v2.0.0-alpha.17 2021-04-09 14:23:44 +02:00
280018112b chore(release): publish v2.0.0-alpha.16 2021-04-09 14:22:37 +02:00
52a6627e6b removed failing react-native-json-tree 2021-04-09 14:03:14 +02:00
ff8b95ce45 removed-signing 2020-10-19 11:19:52 +02:00
2c5b64695c update 2020-10-19 11:16:16 +02:00
2d076d3bb9 chore(release): publish v2.0.0-alpha.14 2020-10-19 11:09:12 +02:00
293bcbe4b8 publish 2020-10-19 11:03:27 +02:00
769c48b093 update 2020-10-19 10:58:35 +02:00
a1879f45ad Publish 2020-10-19 10:55:31 +02:00
daedd1a876 chore(release): publish v2.0.0-alpha.11 2020-10-19 10:39:40 +02:00
denissb
8abb3789a1 Fix unlisten in events.js (#7) 2020-10-19 10:36:08 +02:00
f60a24d908 Update README.md 2019-08-23 00:21:37 +02:00
fd3a2bc24f V2 (#1) 2019-08-23 00:12:49 +02:00
97 changed files with 14010 additions and 9273 deletions

24
.github/workflows/publish.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
run: yarn install
- name: Deploy 🚀
run: |
git config --global user.email "morten@olsen.pro"
git config --global user.name "Release action"
yarn prerelease
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

4
.gitignore vendored
View File

@@ -1 +1,5 @@
node_modules
/coverage
/packages/lib/lib
/.auth
*.log

96
CHANGELOG.md Normal file
View File

@@ -0,0 +1,96 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [2.0.0-alpha.17](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.16...v2.0.0-alpha.17) (2021-04-09)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.16](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.16) (2021-04-09)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.15](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.15) (2021-04-09)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.14](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.14) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.13](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.13) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.12](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.12) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.11](https://github.com/morten-olsen/react-native-debug-console/compare/2.0.0-alpha.5...2.0.0-alpha.11) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.7](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.6...v2.0.0-alpha.7) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.6](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.5...v2.0.0-alpha.6) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.5](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.4...v2.0.0-alpha.5) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.4](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.3...v2.0.0-alpha.4) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.3](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console

View File

@@ -1,5 +1,7 @@
# React Native Debug Console
[![Maintainability](https://api.codeclimate.com/v1/badges/649636926c23c40f2404/maintainability)](https://codeclimate.com/github/morten-olsen/react-native-debug-console/maintainability)
... and yes I am aware that it is a boring name
React Native Debug Console is an easy to use network and console debug component and modal for react native, written purely in JavaScript

1
__mocks__/fileMock.js Normal file
View File

@@ -0,0 +1 @@
module.exports = 'test-file-stub';

9
babel.config.js Normal file
View File

@@ -0,0 +1,9 @@
module.exports = function(api) {
api.cache(true);
return {
presets: [
'babel-preset-expo',
'@babel/preset-typescript',
],
};
};

View File

@@ -1,15 +0,0 @@
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
},
"plugins": [
["module-resolver", {
"alias": {
"react-native-debug-console": "../lib"
}
}]
]
}

17
demo/.gitignore vendored
View File

@@ -1,17 +0,0 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.
# expo
.expo/
# dependencies
/node_modules
# misc
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

View File

@@ -1,9 +0,0 @@
import React from 'react';
import App from './App';
import renderer from 'react-test-renderer';
it('renders without crashing', () => {
const rendered = renderer.create(<App />).toJSON();
expect(rendered).toBeTruthy();
});

View File

@@ -1,201 +0,0 @@
This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app).
Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md).
## Table of Contents
* [Updating to New Releases](#updating-to-new-releases)
* [Available Scripts](#available-scripts)
* [npm start](#npm-start)
* [npm test](#npm-test)
* [npm run ios](#npm-run-ios)
* [npm run android](#npm-run-android)
* [npm run eject](#npm-run-eject)
* [Writing and Running Tests](#writing-and-running-tests)
* [Environment Variables](#environment-variables)
* [Configuring Packager IP Address](#configuring-packager-ip-address)
* [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon)
* [Sharing and Deployment](#sharing-and-deployment)
* [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community)
* [Building an Expo "standalone" app](#building-an-expo-standalone-app)
* [Ejecting from Create React Native App](#ejecting-from-create-react-native-app)
* [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio)
* [Should I Use ExpoKit?](#should-i-use-expokit)
* [Troubleshooting](#troubleshooting)
* [Networking](#networking)
* [iOS Simulator won't open](#ios-simulator-wont-open)
* [QR Code does not scan](#qr-code-does-not-scan)
## Updating to New Releases
You should only need to update the global installation of `create-react-native-app` very rarely, ideally never.
Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies.
Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility.
## Available Scripts
If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing.
### `npm start`
Runs your app in development mode.
Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal.
Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script:
```
npm start --reset-cache
# or
yarn start --reset-cache
```
#### `npm test`
Runs the [jest](https://github.com/facebook/jest) test runner on your tests.
#### `npm run ios`
Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed.
#### `npm run android`
Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App:
##### Using Android Studio's `adb`
1. Make sure that you can run adb from your terminal.
2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location).
##### Using Genymotion's `adb`
1. Find Genymotions copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`.
2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)).
3. Make sure that you can run adb from your terminal.
#### `npm run eject`
This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project.
**Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up.
## Customizing App Display Name and Icon
You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key.
To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string.
To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency.
## Writing and Running Tests
This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/en/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/en/tutorial-react-native.html).
## Environment Variables
You can configure some of Create React Native App's behavior using environment variables.
### Configuring Packager IP Address
When starting your project, you'll see something like this for your project URL:
```
exp://192.168.0.2:19000
```
The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides.
In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable:
Mac and Linux:
```
REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start
```
Windows:
```
set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname'
npm start
```
The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`.
## Sharing and Deployment
Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service.
### Publishing to Expo's React Native Community
Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account.
Install the `exp` command-line tool, and run the publish command:
```
$ npm i -g exp
$ exp publish
```
### Building an Expo "standalone" app
You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself.
### Ejecting from Create React Native App
If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio.
This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html).
#### Should I Use ExpoKit?
If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option.
## Troubleshooting
### Networking
If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports.
Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see:
```
exp://192.168.0.1:19000
```
Try opening Safari or Chrome on your phone and loading
```
http://192.168.0.1:19000
```
and
```
http://192.168.0.1:19001
```
If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received.
If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager. If you are using a VPN you may need to disable it.
### iOS Simulator won't open
If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`:
* "non-zero exit code: 107"
* "You may need to install Xcode" but it is already installed
* and others
There are a few steps you may want to take to troubleshoot these kinds of errors:
1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store.
2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so.
3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`.
### QR Code does not scan
If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses.
If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually.

View File

@@ -1,9 +0,0 @@
{
"expo": {
"sdkVersion": "27.0.0"
},
"packagerOpts": {
"config": "./rn-cli.config.js",
"projectRoots": ""
}
}

View File

@@ -1,30 +0,0 @@
{
"name": "demo",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-plugin-module-resolver": "^3.1.1",
"jest-expo": "~27.0.0",
"react-native-scripts": "1.14.0",
"react-test-renderer": "16.3.1"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "jest"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^27.0.1",
"prop-types": "^15.6.2",
"react": "16.3.1",
"react-native": "~0.55.2",
"react-native-json-tree": "^1.2.0",
"styled-components": "^3.4.2"
}
}

View File

@@ -1,30 +0,0 @@
const path = require('path');
const blacklist = require('metro/src/blacklist');
module.exports = {
getProjectRoots() {
return [__dirname, path.resolve(__dirname, '../lib')];
},
getProvidesModuleNodeModules() {
return [
'react-native',
'react',
'prop-types',
'styled-components',
'react-native-json-tree',
];
},
getBlacklistRE() {
return blacklist([
new RegExp(
`^${escape(path.resolve(__dirname, '../lib', 'node_modules'))}\\/.*$`
),
new RegExp(
`^${escape(path.resolve(__dirname, 'node_modules/xdl'))}\\/.*$`
),
new RegExp(
`^${escape(path.resolve(__dirname, 'node_modules/react-google-maps'))}\\/.*$`
),
]);
},
};

File diff suppressed because it is too large Load Diff

9
jest.config.js Normal file
View File

@@ -0,0 +1,9 @@
const path = require('path');
module.exports = {
preset: 'react-native',
rootDir: path.join(__dirname, 'packages'),
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': path.join(__dirname, '__mocks__', 'fileMock.js'),
},
};

View File

@@ -1,7 +1,11 @@
{
"packages": [
"demo",
"lib"
],
"version": "0.0.0"
"npmClient": "yarn",
"useWorkspaces": true,
"version": "2.0.0-alpha.17",
"command": {
"publish": {
"conventionalCommits": true,
"yes": true
}
}
}

View File

@@ -1,19 +0,0 @@
{
"name": "react-native-debug-console",
"version": "1.0.0-beta.14",
"main": "src/index.js",
"repository": {
"url": "https://github.com/morten-olsen/react-native-debugger"
},
"license": "MIT",
"dependencies": {
"react-native-json-tree": "^1.2.0",
"styled-components": "^3.4.2"
},
"peerDependencies": {
"prop-types": "^15.6.2",
"react": "^16.4.2",
"react-native": "^0.56.0"
},
"devDependencies": {}
}

View File

@@ -1,112 +0,0 @@
import React from 'react';
import {
StyleSheet,
View,
Text,
TextInput,
} from 'react-native';
import styled from 'styled-components/native';
import State from '../../data/State';
import { context } from '../../../console';
import log from '../../../log';
import Icon from '../../base/Icon';
const Button = styled.TouchableOpacity`
padding: 12px 8px;
`;
const styles = StyleSheet.create({
container: {
borderColor: '#ccc',
borderTopWidth: 1,
flexDirection: 'row',
alignItems: 'center',
paddingLeft: 10,
paddingRight: 10,
},
input: {
flex: 1,
fontFamily: 'Menlo-Regular',
borderColor: '#ccc',
borderRadius: 5,
margin: 10,
padding: 5,
},
});
const Input = ({
logs,
}) => (
<State>
{({
text = '',
history = [],
historyOffset,
}, setState) => (
<View style={styles.container}>
<Button
onPress={() => {
let currentOffset = typeof historyOffset === 'undefined' ? -1 : historyOffset;
currentOffset += 1;
const index = history.length - 1 - currentOffset;
if (history[index]) {
setState({
text: history[index],
historyOffset: currentOffset,
});
}
}}
>
<Icon name="left" />
</Button>
<Button
title=">"
onPress={() => {
let currentOffset = typeof historyOffset === 'undefined' ? -1 : historyOffset;
currentOffset -= 1;
const index = history.length - 1 - currentOffset;
if (history[index]) {
setState({
text: history[index],
historyOffset: currentOffset,
});
}
}}
>
<Icon name="right" />
</Button>
<TextInput
multiline
placeholder="{your code here}"
autoCapitalize="none"
autoCorrect={false}
style={styles.input}
value={text}
onChangeText={text => setState({ text })}
/>
<Button
onPress={() => {
const newHistory = [...history, text];
const contextKeys = Object.keys(context);
const contextValues = Object.values(context);
const fn = new Function(...contextKeys, text);
try {
fn(...contextValues);
setState({
text: '',
history: newHistory,
historyOffset: undefined,
});
} catch (err) {
log.error([err]);
}
}}
>
<Icon name="play" />
</Button>
</View>
)}
</State>
);
export default Input;

View File

@@ -1,74 +0,0 @@
import React from 'react';
import {
StyleSheet,
View,
} from 'react-native';
import log from '../../../log';
import Log from '../../data/Log';
import State from '../../data/State';
import Toolbar, {
Button,
Selector,
Seperator,
} from '../../base/Toolbar';
import Output from './Output';
import Input from './Input';
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
const initFilters = [
'error',
'warn',
'info',
'debug',
].map(i => ({
name: i,
value: i,
selected: true,
}))
const Console = ({
includeStackTrace,
}) => (
<Log>
{({ logs }) => (
<State
initState={{
filters: initFilters,
}}
>
{({ filters }, setState) => (
<View style={styles.container}>
<Toolbar>
<Selector
name="Filter"
icon="filter"
options={filters}
multiSelect
onSelect={(selected) => {
setState({
filters: selected,
});
}}
/>
<Seperator />
<Button
name="Clear"
icon="trash"
onPress={() => log.clear()}
/>
</Toolbar>
<Output filter={filters.filter(f => f.selected).map(f => f.name)} logs={logs} includeStackTrace={includeStackTrace} />
<Input />
</View>
)}
</State>
)}
</Log>
);
export default Console;

View File

@@ -1,62 +0,0 @@
import React from 'react';
import {
StyleSheet,
View,
} from 'react-native';
import network from '../../../network';
import State from '../../data/State';
import Network from '../../data/Network';
import Toolbar, {
Button,
Seperator,
} from '../../base/Toolbar';
import Details from './Details';
import List from './List';
const styles = StyleSheet.create({
container: {
flex: 1,
},
list: {
flex: 1,
borderColor: '#ccc',
borderBottomWidth: 1,
},
details: {
flex: 1,
},
});
let i = 0;
const Console = () => (
<State>
{({
active,
}, setState) => (
<Network>
{({ requests }) => {
const selected = active >= 0 ? requests[active] : undefined;
return (
<View style={styles.container}>
<Toolbar>
<Seperator />
<Button
name="Clear"
icon="trash"
onPress={() => network.clear()}
/>
</Toolbar>
<List
selected={selected ? selected.id : undefined}
requests={requests}
onSelect={(i) => setState({ active: i })}
/>
{selected && <Details {...selected} />}
</View>
);
}}
</Network>
)}
</State>
);
export default Console;

View File

@@ -1,56 +0,0 @@
import React from 'react';
import styled from 'styled-components/native';
import Storage from '../../data/Storage';
import State from '../../data/State';
import Toolbar, {
Button,
Seperator,
} from '../../base/Toolbar';
import Keys from './Keys';
import Value from './Value';
const Wrapper = styled.View`
flex: 1;
`;
const StorageView = () => (
<State>
{({ selected }, setState) => (
<Storage>
{(data, update, removeItem, clear) => (
<Wrapper>
<Toolbar>
<Seperator />
<Button
name="Refresh"
icon="reload"
onPress={update}
/>
<Button
name="Clear"
icon="trash"
onPress={clear}
/>
<Button
name="Delete"
icon="remove"
disabled={!selected}
onPress={() => removeItem(selected)}
/>
</Toolbar>
<Keys
selected={selected}
onSelect={(key) => setState({ selected: key })}
keys={Object.keys(data)}
/>
{selected && data[selected] && (
<Value value={data[selected]} />
)}
</Wrapper>
)}
</Storage>
)}
</State>
);
export default StorageView;

View File

@@ -1,38 +0,0 @@
import { Component } from 'react';
import log from '../../log';
class Log extends Component {
constructor() {
super();
this.state = {
logs: [],
};
this.setLogs = this.setLogs.bind(this);
}
componentDidMount() {
log.listen(this.setLogs);
}
componentWillUnmount() {
log.unlisten(this.setLogs);
}
setLogs(logs) {
this.setState({
logs,
});
}
render() {
const {
children,
} = this.props;
const component = children(
this.state,
);
return component;
}
}
export default Log;

View File

@@ -1,38 +0,0 @@
import { Component } from 'react';
import network from '../../network';
class Network extends Component {
constructor() {
super();
this.state = {
requests: [],
};
this.setRequests = this.setRequests.bind(this);
}
componentDidMount() {
network.listen(this.setRequests);
}
componentWillUnmount() {
network.unlisten(this.setRequests);
}
setRequests(requests) {
this.setState({
requests,
});
}
render() {
const {
children,
} = this.props;
const component = children(
this.state,
);
return component;
}
}
export default Network;

View File

@@ -1,20 +0,0 @@
import React, { Component } from 'react';
class State extends Component {
constructor(props, ...others) {
super(props, ...others);
this.state = props.initState || {};
this.setState = this.setState.bind(this);
}
render() {
const { children } = this.props;
const component = children(
this.state,
this.setState,
);
return component;
}
}
export default State;

View File

@@ -1,58 +0,0 @@
import { Component } from 'react';
import { AsyncStorage } from 'react-native';
class Storage extends Component {
constructor() {
super();
this.state = {
data: {},
};
this.update = this.update.bind(this);
this.removeItem = this.removeItem.bind(this);
this.clear = this.clear.bind(this);
}
componentDidMount() {
this.update();
}
async removeItem(name) {
await AsyncStorage.removeItem(name);
await this.update();
}
async clear() {
await AsyncStorage.clear();
await this.update();
}
async update() {
try {
const keys = await AsyncStorage.getAllKeys();
const values = await Promise.all(keys.map(key => AsyncStorage.getItem(key)));
const data = {};
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = values[i];
data[key] = value;
}
this.setState({
data,
});
} catch (err) {
console.error(err);
}
}
render() {
const {
children,
} = this.props;
const {
data,
} = this.state;
return children(data, this.update, this.removeItem, this.clear);
}
}
export default Storage;

View File

@@ -1,8 +0,0 @@
import log from './log';
import { AsyncStorage } from 'react-native';
export const context = {
storage: AsyncStorage,
log: (...args) => console.log(...args),
clear: log.clear,
};

View File

@@ -1,221 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
almost-equal@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/almost-equal/-/almost-equal-1.1.0.tgz#f851c631138757994276aa2efbe8dfa3066cccdd"
asap@~2.0.3:
version "2.0.6"
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
base16@Dean177/base16-js:
version "1.0.1"
resolved "https://codeload.github.com/Dean177/base16-js/tar.gz/6c5e5f3b63990b580ffdc036bc672f8987d5b93d"
base64-js@^1.0.2:
version "1.3.0"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.0.tgz#cab1e6118f051095e58b5281aea8c1cd22bfc0e3"
buffer@^5.0.3:
version "5.2.0"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.2.0.tgz#53cf98241100099e9eeae20ee6d51d21b16e541e"
dependencies:
base64-js "^1.0.2"
ieee754 "^1.1.4"
color-space@^1.14.3:
version "1.16.0"
resolved "https://registry.yarnpkg.com/color-space/-/color-space-1.16.0.tgz#611781bca41cd8582a1466fd9e28a7d3d89772a2"
dependencies:
hsluv "^0.0.3"
mumath "^3.3.4"
core-js@^1.0.0:
version "1.2.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
css-color-keywords@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"
css-to-react-native@^2.0.3:
version "2.2.1"
resolved "https://registry.yarnpkg.com/css-to-react-native/-/css-to-react-native-2.2.1.tgz#7f3f4c95de65501b8720c87bf0caf1f39073b88e"
dependencies:
css-color-keywords "^1.0.0"
fbjs "^0.8.5"
postcss-value-parser "^3.3.0"
encoding@^0.1.11:
version "0.1.12"
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
dependencies:
iconv-lite "~0.4.13"
fbjs@^0.8.16, fbjs@^0.8.5:
version "0.8.17"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd"
dependencies:
core-js "^1.0.0"
isomorphic-fetch "^2.1.1"
loose-envify "^1.0.0"
object-assign "^4.1.0"
promise "^7.1.1"
setimmediate "^1.0.5"
ua-parser-js "^0.7.18"
has-flag@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
hoist-non-react-statics@^2.5.0:
version "2.5.5"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47"
hsluv@^0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/hsluv/-/hsluv-0.0.3.tgz#829107dafb4a9f8b52a1809ed02e091eade6754c"
iconv-lite@~0.4.13:
version "0.4.23"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.23.tgz#297871f63be507adcfbfca715d0cd0eed84e9a63"
dependencies:
safer-buffer ">= 2.1.2 < 3"
ieee754@^1.1.4:
version "1.1.12"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.12.tgz#50bf24e5b9c8bb98af4964c941cdb0918da7b60b"
is-stream@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
isomorphic-fetch@^2.1.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
dependencies:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"
"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
lodash.curry@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.curry/-/lodash.curry-4.1.1.tgz#248e36072ede906501d75966200a86dab8b23170"
lodash.flow@^3.3.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/lodash.flow/-/lodash.flow-3.5.0.tgz#87bf40292b8cf83e4e8ce1a3ae4209e20071675a"
loose-envify@^1.0.0, loose-envify@^1.3.1:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
dependencies:
js-tokens "^3.0.0 || ^4.0.0"
mumath@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/mumath/-/mumath-3.3.4.tgz#48d4a0f0fd8cad4e7b32096ee89b161a63d30bbf"
dependencies:
almost-equal "^1.1.0"
node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
dependencies:
encoding "^0.1.11"
is-stream "^1.0.1"
object-assign@^4.1.0, object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
postcss-value-parser@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-3.3.0.tgz#87f38f9f18f774a4ab4c8a232f5c5ce8872a9d15"
promise@^7.1.1:
version "7.3.1"
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
dependencies:
asap "~2.0.3"
prop-types@^15.5.4, prop-types@^15.6.0:
version "15.6.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
dependencies:
loose-envify "^1.3.1"
object-assign "^4.1.1"
pure-color@^1.2.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/pure-color/-/pure-color-1.3.0.tgz#1fe064fb0ac851f0de61320a8bf796836422f33e"
"react-base16-styling@github:dean177/react-base16-styling#fbc6593":
version "0.4.6"
resolved "https://codeload.github.com/dean177/react-base16-styling/tar.gz/fbc6593cc58c5f4662c40b85964c7f9fbcb3984d"
dependencies:
base16 Dean177/base16-js
color-space "^1.14.3"
lodash.curry "^4.0.1"
lodash.flow "^3.3.0"
pure-color "^1.2.0"
react-is@^16.3.1:
version "16.4.2"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.4.2.tgz#84891b56c2b6d9efdee577cc83501dfc5ecead88"
react-native-json-tree@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/react-native-json-tree/-/react-native-json-tree-1.2.0.tgz#4600310bff1934026edbe77fc621230866fe7182"
dependencies:
prop-types "^15.6.0"
react-base16-styling "github:dean177/react-base16-styling#fbc6593"
"safer-buffer@>= 2.1.2 < 3":
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
styled-components@^3.4.2:
version "3.4.2"
resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-3.4.2.tgz#8f518419932327e47fe9144824e3184b3e2da95d"
dependencies:
buffer "^5.0.3"
css-to-react-native "^2.0.3"
fbjs "^0.8.16"
hoist-non-react-statics "^2.5.0"
prop-types "^15.5.4"
react-is "^16.3.1"
stylis "^3.5.0"
stylis-rule-sheet "^0.0.10"
supports-color "^3.2.3"
stylis-rule-sheet@^0.0.10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stylis-rule-sheet/-/stylis-rule-sheet-0.0.10.tgz#44e64a2b076643f4b52e5ff71efc04d8c3c4a430"
stylis@^3.5.0:
version "3.5.3"
resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.5.3.tgz#99fdc46afba6af4deff570825994181a5e6ce546"
supports-color@^3.2.3:
version "3.2.3"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.2.3.tgz#65ac0504b3954171d8a64946b2ae3cbb8a5f54f6"
dependencies:
has-flag "^1.0.0"
ua-parser-js@^0.7.18:
version "0.7.18"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.18.tgz#a7bfd92f56edfb117083b69e31d2aa8882d4b1ed"
whatwg-fetch@>=0.10.0:
version "2.0.4"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"

View File

@@ -1,10 +1,22 @@
{
"name": "debugger",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"postinstall": "lerna bootstrap",
"demo:ios": "lerna run --scope=react-native-debug-console-demo --stream ios",
"demo:web": "lerna run --scope=react-native-debug-console-demo --stream web",
"test": "lerna run --stream test",
"prerelease": "lerna version prerelease --yes -m \"chore(release): publish %s\" --conventional-commits --create-release github --force-publish"
},
"devDependencies": {
"create-react-native-app": "^1.0.0",
"lerna": "^3.0.3"
"@babel/cli": "^7.5.0",
"@babel/plugin-proposal-class-properties": "^7.5.0",
"@babel/preset-typescript": "^7.3.3",
"jest": "^24.8.0",
"lerna": "^3.0.3",
"react-test-renderer": "^16.8.6",
"typescript": "^3.5.2"
}
}

10
packages/demo/.gitignore vendored Normal file
View File

@@ -0,0 +1,10 @@
node_modules/**/*
.expo/*
npm-debug.*
*.jks
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/
web-report/

View File

@@ -1,7 +1,6 @@
import React from 'react';
import {
StyleSheet,
Text,
View,
Button,
KeyboardAvoidingView,
@@ -14,12 +13,10 @@ import {
log,
network,
show,
context,
} from 'react-native-debug-console';
} from 'react-native-debug-console/src';
network.attach();
log.attach();
context.hello = () => 'earth';
log.attach(true);
console.log('fooo');
let xhr = new XMLHttpRequest();
@@ -29,6 +26,14 @@ xhr = new XMLHttpRequest();
xhr.open('GET', 'https://google.com/sdfsfsdfsfdf');
xhr.send();
console.log({
hello: {
world: 1,
earth: 2,
},
});
AsyncStorage.setItem('a', 'b');
AsyncStorage.setItem('b', 'c');
AsyncStorage.setItem('c', 'd');
@@ -107,12 +112,17 @@ export default class App extends React.Component {
/>
<View style={{ height: 10 }} />
</View>
{/* <DevTool
<DevTool
style={{
flex: 1,
}}
/> */}
<DevToolModal />
storageProvider={AsyncStorage}
context={global}
/>
<DevToolModal
storageProvider={AsyncStorage}
context={global}
/>
</KeyboardAvoidingView>
</SafeAreaView>
);

View File

@@ -0,0 +1,96 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [2.0.0-alpha.17](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.16...v2.0.0-alpha.17) (2021-04-09)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.16](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.16) (2021-04-09)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.15](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.15) (2021-04-09)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.14](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.14) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.13](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.13) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.12](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.11...v2.0.0-alpha.12) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console-demo
# 2.0.0-alpha.11 (2020-10-19)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.7](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.6...v2.0.0-alpha.7) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.6](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.5...v2.0.0-alpha.6) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.5](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.4...v2.0.0-alpha.5) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.4](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.3...v2.0.0-alpha.4) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console-demo
# [2.0.0-alpha.3](https://github.com/morten-olsen/react-native-debug-console/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console-demo

10
packages/demo/Entry.js Normal file
View File

@@ -0,0 +1,10 @@
import { registerRootComponent } from 'expo';
import { activateKeepAwake } from 'expo-keep-awake';
import App from './App';
if (__DEV__) {
activateKeepAwake();
}
registerRootComponent(App);

34
packages/demo/app.json Normal file
View File

@@ -0,0 +1,34 @@
{
"expo": {
"name": "react-native-debug-console",
"slug": "demo",
"privacy": "public",
"sdkVersion": "33.0.0",
"platforms": [
"ios",
"android",
"web"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"packagerOpts": {
"config": "./metro.js",
"projectRoots": ""
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@@ -0,0 +1,3 @@
const config = require('../../babel.config');
module.exports = config;

12
packages/demo/metro.js Normal file
View File

@@ -0,0 +1,12 @@
const { createMetroConfiguration } = require('expo-yarn-workspaces');
const path = require('path');
//module.exports = createMetroConfiguration(__dirname);
module.exports = {
watchFolders: [
__dirname,
path.join(__dirname, '..', 'lib'),
path.join(__dirname, '..', '..', 'node_modules'),
]
};

View File

@@ -0,0 +1,30 @@
{
"name": "react-native-debug-console-demo",
"version": "2.0.0-alpha.17",
"main": "./Entry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"postinstall": "expo-yarn-workspaces postinstall"
},
"dependencies": {
"expo": "^33.0.0",
"react": "16.8.3",
"react-dom": "^16.8.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
"react-native-debug-console": "^2.0.0-alpha.17",
"react-native-web": "0.11.4"
},
"devDependencies": {
"@babel/runtime": "^7.5.0",
"babel-plugin-module-resolver": "^3.2.0",
"babel-preset-expo": "^5.1.1",
"expo-cli": "^2.21.2",
"expo-yarn-workspaces": "^1.2.0",
"react-art": "^16.8.6"
},
"private": true
}

6
packages/lib/.npmignore Normal file
View File

@@ -0,0 +1,6 @@
/babel.config.js
/node_modules
/__mocks__
/test
/src
/jest.config.js

1
packages/lib/.npmrc Normal file
View File

@@ -0,0 +1 @@
@morten-olsen:registry=https://npm.pkg.github.com/

96
packages/lib/CHANGELOG.md Normal file
View File

@@ -0,0 +1,96 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [2.0.0-alpha.17](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.16...v2.0.0-alpha.17) (2021-04-09)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.16](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.11...v2.0.0-alpha.16) (2021-04-09)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.15](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.11...v2.0.0-alpha.15) (2021-04-09)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.14](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.11...v2.0.0-alpha.14) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.13](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.11...v2.0.0-alpha.13) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.12](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.11...v2.0.0-alpha.12) (2020-10-19)
**Note:** Version bump only for package react-native-debug-console
# 2.0.0-alpha.11 (2020-10-19)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.7](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.6...v2.0.0-alpha.7) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.6](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.5...v2.0.0-alpha.6) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.5](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.4...v2.0.0-alpha.5) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.4](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.3...v2.0.0-alpha.4) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console
# [2.0.0-alpha.3](https://github.com/morten-olsen/react-native-debugger/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2019-07-05)
**Note:** Version bump only for package react-native-debug-console

2
packages/lib/__mocks__/react.js vendored Normal file
View File

@@ -0,0 +1,2 @@
const React = require('react')
module.exports = { ...React, useEffect: React.useLayoutEffect }

View File

@@ -0,0 +1,3 @@
const config = require('../../babel.config');
module.exports = config;

View File

@@ -0,0 +1,3 @@
const config = require('../../jest.config');
module.exports = config;

24
packages/lib/package.json Normal file
View File

@@ -0,0 +1,24 @@
{
"name": "react-native-debug-console",
"version": "2.0.0-alpha.17",
"main": "lib/index.js",
"react-native": "lib/native.js",
"repository": {
"url": "https://github.com/morten-olsen/react-native-debugger"
},
"scripts": {
"test": "jest",
"bundle": "babel --copy-files --extensions '.ts,.tsx,.js' -d lib src",
"prepublish": "yarn run bundle"
},
"license": "MIT",
"dependencies": {
"styled-components": "^5.0.0-beta.8"
},
"peerDependencies": {
"prop-types": "^15.6.0",
"react": "^16.8.3",
"react-native": "^0.59.8",
"react-native-webview": "^6.9.0"
}
}

View File

@@ -0,0 +1,114 @@
import React, { useState } from 'react';
import {
StyleSheet,
View,
TextInput,
Platform,
} from 'react-native';
import styled from 'styled-components/native';
import { createContext } from '../../../console';
import Icon from '../../base/Icon';
const Button = styled.TouchableOpacity`
padding: 12px 8px;
`;
const styles = StyleSheet.create({
container: {
borderColor: '#ccc',
borderTopWidth: 1,
flexDirection: 'row',
alignItems: 'center',
paddingLeft: 10,
paddingRight: 10,
},
input: {
flex: 1,
fontFamily: 'Menlo-Regular',
borderColor: '#ccc',
borderRadius: 5,
margin: 10,
padding: 5,
},
});
const Input = ({
provider,
context: baseContext,
}) => {
const [text, setText] = useState('');
const [history, setHistory] = useState([]);
const [historyOffset, setHistoryOffset] = useState();
const send = () => {
const newHistory = [...history, text];
const context = createContext({
logProvider: provider,
}, baseContext);
const contextKeys = Object.keys(context);
const contextValues = Object.values(context);
const fn = new Function(...contextKeys, text);
try {
fn(...contextValues);
setText('');
setHistoryOffset(undefined);
setHistory(newHistory);
} catch (err) {
provider.error([err]);
}
};
return (
<View style={styles.container}>
<Button
onPress={() => {
let currentOffset = typeof historyOffset === 'undefined' ? -1 : historyOffset;
currentOffset += 1;
const index = history.length - 1 - currentOffset;
if (history[index]) {
setText(history[index]);
setHistoryOffset(currentOffset);
}
}}
>
<Icon name="left" />
</Button>
<Button
title=">"
onPress={() => {
let currentOffset = typeof historyOffset === 'undefined' ? -1 : historyOffset;
currentOffset -= 1;
const index = history.length - 1 - currentOffset;
if (history[index]) {
setText(history[index]);
setHistoryOffset(currentOffset);
}
}}
>
<Icon name="right" />
</Button>
<TextInput
multiline
placeholder="{your code here}"
autoCapitalize="none"
autoCorrect={false}
style={styles.input}
value={text}
onChangeText={text => setText(text)}
onKeyPress={(evt) => {
global.proxyConsole.log(Platform.OS === 'web' && evt.key === 'Enter' && evt.shiftKey);
if (Platform.OS === 'web' && evt.key === 'Enter' && !evt.shiftKey) {
send();
return false;
}
}}
/>
<Button
onPress={() => send()}
>
<Icon name="play" />
</Button>
</View>
);
};
export default Input;

View File

@@ -1,6 +1,6 @@
import React, { Fragment } from 'react';
import React, { Fragment, createRef } from 'react';
import styled from 'styled-components/native';
import JSONTree from 'react-native-json-tree';
import JSONTree from '../../JSON';
import {
ScrollView
} from 'react-native';
@@ -32,12 +32,12 @@ const theme = {
};
const Wrapper = styled.View``;
const List = styled.View`
export const List = styled.View`
padding-left: 10px;
border-left-width: 10px;
border-color: ${props => props.color || 'black' }
`;
const Row = styled.View`
export const Row = styled.View`
margin: 10px;
`;
@@ -102,28 +102,32 @@ const Console = ({
logs,
includeStackTrace,
filter = [],
}) => (
<ScrollView
ref={ref => this.scrollView = ref}
onContentSizeChange={(contentWidth, contentHeight)=>{
this.scrollView.scrollToEnd({animated: true});
}}
>
<Wrapper>
{logs.filter(l => filter.includes(l.type)).map((log, i) => (
<Row key={i}>
<Emphasis color={getColor(log.type)}>
{log.type}
</Emphasis>
<OutputList
items={log.data}
includeStackTrace={includeStackTrace}
color={getColor(log.type)}
/>
</Row>
))}
</Wrapper>
</ScrollView>
);
}) => {
// const ref = createRef();
return (
<ScrollView
onContentSizeChange={(contentWidth, contentHeight)=>{
/*if (ref.current) {
ref.current.scrollView.scrollToEnd({animated: true});
}*/
}}
>
<Wrapper>
{logs.filter(l => filter.includes(l.type)).map((log, i) => (
<Row key={i}>
<Emphasis color={getColor(log.type)}>
{log.type}
</Emphasis>
<OutputList
items={log.data}
includeStackTrace={includeStackTrace}
color={getColor(log.type)}
/>
</Row>
))}
</Wrapper>
</ScrollView>
);
};
export default Console;

View File

@@ -0,0 +1,64 @@
import React, { useState } from 'react';
import {
StyleSheet,
View,
} from 'react-native';
import useLog from '../../data/log';
import Toolbar, {
Button,
Selector,
Seperator,
} from '../../base/Toolbar';
import Output from './Output';
import Input from './Input';
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
const initFilters = [
'error',
'warn',
'info',
'debug',
].map(i => ({
name: i,
value: i,
selected: true,
}))
const Console = ({
includeStackTrace,
provider,
context,
}) => {
const logs = useLog(provider);
const [filters, setFilters] = useState(initFilters);
return (
<View style={styles.container}>
<Toolbar>
<Selector
name="Filter"
icon="filter"
options={filters}
multiSelect
onSelect={(selected) => {
setFilters([...selected]);
}}
/>
<Seperator />
<Button
name="Clear"
icon="trash"
onPress={() => provider.clear()}
/>
</Toolbar>
<Output filter={filters.filter(f => f.selected).map(f => f.name)} logs={logs} includeStackTrace={includeStackTrace} />
<Input provider={provider} context={context} />
</View>
);
};
export default Console;

View File

@@ -1,12 +1,11 @@
import React, { Component } from 'react';
import {
Button,
Modal,
SafeAreaView,
KeyboardAvoidingView,
} from 'react-native';
import events from '../../events';
import DevTool from './index';
import Modal from '../base/Modal';
class Events extends Component {
@@ -54,7 +53,7 @@ class Events extends Component {
}}
>
<SafeAreaView
forceInset={{ top: 'always', vertical: 'always' }}
forceInset={{ top: 'always', vertical: 'always', bottom: 'always' }}
style={{flex: 1}}
>
<KeyboardAvoidingView

View File

@@ -4,18 +4,16 @@ import {
View,
} from 'react-native';
import styled from 'styled-components/native';
import { WebView } from 'react-native-webview';
import {
Emphasis,
Fixed,
} from '../../base/text';
import JSONTree from 'react-native-json-tree';
import JSONTree from '../../JSON';
import Cell from '../../base/Cell';
import CellHeader from '../../base/CellHeader';
import Tab from '../Tab';
const WebView = styled.WebView`
`;
const theme = {
scheme: 'bright',
author: 'chris kempson (http://chriskempson.com)',
@@ -42,6 +40,9 @@ const Indented = styled.View`
`;
const getResponse = (contentType, request) => {
if (!contentType) {
return null;
}
if (request.responseType == 'blob' || request.responseType == 'ArrayBuffer') {
return <Emphasis>🤖 Binary</Emphasis>
}
@@ -72,11 +73,19 @@ const Data = ({
<Cell left="Method" right={method} />
<Cell left="Url" right={url} />
<CellHeader>Response Headers</CellHeader>
<Indented><Fixed>{requestHeaders}</Fixed></Indented>
{headerInfo && (
<Indented>
<Fixed>
{requestHeaders}
</Fixed>
</Indented>
{headerInfo.length > 0 && (
<Fragment>
<CellHeader>Request Headers</CellHeader>
<Indented><Fixed selectable={true}>{headerInfo}</Fixed></Indented>
<Indented>
<Fixed selectable={true}>
{headerInfo}
</Fixed>
</Indented>
</Fragment>
)}
{args[0] && (
@@ -103,7 +112,7 @@ const Response = ({
const getPreview = (contentType, request, url) => {
if (request.responseType == 'blob' || request.responseType == 'ArrayBuffer') {
if (!contentType || request.responseType == 'blob' || request.responseType == 'ArrayBuffer' || !contentType) {
return [];
}
const contentTypes = contentType.split(';').map(c => c.trim());

View File

@@ -0,0 +1,55 @@
import React, { useState } from 'react';
import {
StyleSheet,
View,
} from 'react-native';
import network from '../../../network';
import useRequests from '../../data/requests';
import Toolbar, {
Button,
Seperator,
} from '../../base/Toolbar';
import Details from './Details';
import List from './List';
const styles = StyleSheet.create({
container: {
flex: 1,
},
list: {
flex: 1,
borderColor: '#ccc',
borderBottomWidth: 1,
},
details: {
flex: 1,
},
});
let i = 0;
const Console = ({
provider,
}) => {
const requests = useRequests(provider);
const [active, setActive] = useState();
const selected = active >= 0 ? requests[active] : undefined;
return (
<View style={styles.container}>
<Toolbar>
<Seperator />
<Button
name="Clear"
icon="trash"
onPress={() => network.clear()}
/>
</Toolbar>
<List
selected={selected ? selected.id : undefined}
requests={requests}
onSelect={(i) => setActive(i)}
/>
{selected && <Details {...selected} />}
</View>
);
}
export default Console;

View File

@@ -0,0 +1,60 @@
import React, { useState } from 'react';
import styled from 'styled-components/native';
import useStorage from '../../data/storage';
import Toolbar, {
Button,
Seperator,
} from '../../base/Toolbar';
import Keys from './Keys';
import Value from './Value';
const Wrapper = styled.View`
flex: 1;
`;
const StorageView = ({
provider,
}) => {
const [selected, setSelected] = useState();
const {
data,
update,
removeItem,
clear,
} = useStorage(provider);
return (
<Wrapper>
<Toolbar>
<Seperator />
<Button
name="Refresh"
icon="reload"
onPress={update}
/>
<Button
name="Clear"
icon="trash"
onPress={clear}
/>
<Button
name="Delete"
icon="remove"
disabled={!selected}
onPress={() => removeItem(selected)}
/>
</Toolbar>
<Keys
selected={selected}
onSelect={(key) => {
setSelected(key);
}}
keys={Object.keys(data)}
/>
{selected && data[selected] && (
<Value value={data[selected]} />
)}
</Wrapper>
);
};
export default StorageView;

View File

@@ -1,13 +1,11 @@
import React, { Fragment } from 'react';
import React, { Fragment, useState } from 'react';
import styled from 'styled-components/native';
import PropTypes from 'prop-types';
import {
Text,
StyleSheet,
TouchableOpacity,
View,
} from 'react-native';
import State from '../data/State';
import Icon from '../base/Icon';
const styles = StyleSheet.create({
@@ -67,52 +65,45 @@ const Console = ({
tabs,
onClose,
onDownload,
}) => (
<View style={styles.container}>
<State
initState={{
active: 0,
}}
>
{({ active }, setState) => (
<Fragment>
<Header>
<TabScroll horizontal>
<TabWrapper>
{tabs.map(({ name }, i) => (
<Tab
key={name}
style={active === i ? styles.tabActive : styles.tabInactive}
onPress={() => {
setState({ active: i });
}}
>
<Text>{name}</Text>
</Tab>
))}
</TabWrapper>
</TabScroll>
{onDownload && (
<Button
onPress={onDownload}
>
<Icon name="download" />
</Button>
)}
{onClose && (
<Button
onPress={onClose}
>
<Icon name="close" />
</Button>
)}
</Header>
{tabs[active] && tabs[active].view}
</Fragment>
)}
</State>
</View>
);
}) => {
const [active, setActive] = useState(0);
return (
<View style={styles.container}>
<Header>
<TabScroll horizontal>
<TabWrapper>
{tabs.map(({ name }, i) => (
<Tab
key={name}
style={active === i ? styles.tabActive : styles.tabInactive}
onPress={() => {
setActive(i);
}}
>
<Text>{name}</Text>
</Tab>
))}
</TabWrapper>
</TabScroll>
{onDownload && (
<Button
onPress={onDownload}
>
<Icon name="download" />
</Button>
)}
{onClose && (
<Button
onPress={onClose}
>
<Icon name="close" />
</Button>
)}
</Header>
{tabs[active] && tabs[active].view}
</View>
);
};
Console.propTypes = {
tabs: PropTypes.arrayOf(PropTypes.shape({

View File

@@ -22,33 +22,40 @@ const DevTool = ({
style,
includeStackTrace,
onClose,
showNetwork = true,
showStorage = true,
showConsole = true,
logProvider = log,
storageProvider,
context = {},
requestProvider = network,
additionalTools = [],
}) => {
const views = [];
if (showConsole) {
if (logProvider) {
views.push({
name: 'Console',
view: <Console includeStackTrace={includeStackTrace} />,
view: (
<Console
includeStackTrace={includeStackTrace}
provider={logProvider}
context={context}
/>
),
getData: log.get,
});
}
if (showNetwork) {
if (requestProvider) {
views.push({
name: 'Network',
view: <Requests />,
view: <Requests provider={requestProvider} />,
getData: network.get,
});
}
if (showStorage) {
if (storageProvider) {
views.push({
name: 'Storage',
view: <Storage />,
view: <Storage provider={storageProvider} />,
});
}

View File

@@ -0,0 +1,13 @@
import React from 'react';
import {
Fixed,
} from '../base/text';
const JSONTree = ({ data }) => (
<Fixed>
{ JSON.stringify(data, null, ' ') }
</Fixed>
);
export default JSONTree;

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@@ -0,0 +1,5 @@
import {
Modal
} from 'react-native';
export default Modal;

View File

@@ -0,0 +1,41 @@
import React, { useEffect, useState } from 'react';
import { createPortal } from 'react-dom';
import styled from 'styled-components';
const Wrapper = styled.div`
position: fixed;
background: #fff;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
`;
const Modal = ({
visible,
children
}) => {
const [root, setRoot] = useState();
useEffect(() => {
const elm = document.createElement('div');
document.body.appendChild(elm);
setRoot(elm);
}, []);
const elm = visible ? (
<Wrapper>{children}</Wrapper>
) : null;
if (!root) {
return null;
}
return createPortal(
elm,
root,
);
};
export default Modal;

View File

@@ -5,6 +5,9 @@ import {
} from '../base/text';
const getColor = (code) => {
if (code === 'Error') {
return '#c0392b';
}
if (code >= 500) {
return '#c0392b';
}
@@ -34,7 +37,7 @@ const Status = ({
}) => (
<Wrapper>
<Body>{code}</Body>
<Icon code={code} />
{code !== 'Waiting' && <Icon code={code} />}
</Wrapper>
)

View File

@@ -1,33 +1,29 @@
import React, { Fragment } from 'react';
import React, { Fragment, useState } from 'react';
import {
SafeAreaView,
TouchableOpacity,
} from 'react-native';
import styled from 'styled-components/native';
import State from '../../data/State';
import Button from './Button';
import Row from '../Row';
import Icon from '../Icon';
import Modal from '../Modal';
import {
Body,
} from '../text';
const Modal = styled.Modal`
`;
const Selector = ({
multiSelect = false,
onSelect,
options = [],
...others
}) => (
<State>
{({ open }, setState) => (
}) => {
const [open, setOpen] = useState(false);
return (
<Fragment>
<Button
{...others}
onPress={() => {
setState({ open: true })
setOpen(true);
}}
/>
<Modal
@@ -35,7 +31,7 @@ const Selector = ({
transparent={false}
visible={!!open}
onRequestClose={() => {
setState({ open: false })
setOpen(false);
}}
>
<SafeAreaView
@@ -46,11 +42,12 @@ const Selector = ({
name="Close"
icon="close"
onPress={() => {
setState({ open: false })
setOpen(false);
}}
/>
{options.map((option) => (
<TouchableOpacity
key={option.name}
onPress={() => {
if (!multiSelect) {
options.forEach(o => o.selected = false);
@@ -71,8 +68,7 @@ const Selector = ({
</SafeAreaView>
</Modal>
</Fragment>
)}
</State>
);
);
};
export default Selector;

View File

@@ -0,0 +1,18 @@
import { useEffect, useState } from 'react';
const useLog = (provider) => {
const [logs, setLogs] = useState([]);
useEffect(() => {
const update = (newLogs) => {
setLogs([...newLogs]);
}
provider.listen(update);
return () => {
provider.unlisten(update);
}
}, []);
return logs;
};
export default useLog;

View File

@@ -0,0 +1,18 @@
import { useState, useEffect } from 'react';
const useRequests = (provider) => {
const [requests, setRequests] = useState([]);
useEffect(() => {
const update = (newRequests) => {
setRequests(newRequests);
};
provider.listen(update);
return () => {
provider.unlisten(update);
};
}, []);
return requests;
};
export default useRequests;

View File

@@ -0,0 +1,40 @@
import { useState, useEffect } from 'react';
const useStorage = (provider) => {
const [data, setData] = useState({});
const update = async () => {
const keys = await provider.getAllKeys();
const values = await Promise.all(keys.map(key => provider.getItem(key)));
const data = {};
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = values[i];
data[key] = value;
}
setData(data);
};
const removeItem = async (name) => {
await provider.removeItem(name);
await update();
}
const clear = async () => {
await provider.clear();
await update();
}
useEffect(() => {
update().catch(err => console.error(err));
}, []);
return {
data,
update,
removeItem,
clear,
}
}
export default useStorage;

View File

@@ -0,0 +1,9 @@
export const createContext = ({
logProvider,
}, baseContext = {}) => ({
log: (...args) => logProvider.log(...args),
clear: logProvider.clear,
window: baseContext,
global: baseContext,
context: baseContext,
});

View File

@@ -8,7 +8,7 @@ class Events {
}
unlisten(fn) {
this.listeners = this.listeners(l => l !== fn);
this.listeners = this.listeners.filter(l => l !== fn);
}
publish(type, data) {

View File

@@ -3,7 +3,6 @@ import DevToolModal from './components/DevTool/Modal';
import log from './log';
import network from './network';
import events from './events';
import { context } from './console';
const show = () => events.publish('SHOW_DEVTOOLS');
const hide = () => events.publish('HIDE_DEVTOOLS');
@@ -13,7 +12,6 @@ export {
DevToolModal,
log,
network,
context,
show,
hide,
};

View File

@@ -1,4 +1,4 @@
export const proxyConsole = window.console;
export const proxyConsole = global.console;
class Log {
constructor() {
@@ -6,6 +6,7 @@ class Log {
this.listeners = [];
this.clear = this.clear.bind(this);
this.get = this.get.bind(this);
this.handleError = this.handleError.bind(this);
}
listen(fn) {
@@ -27,6 +28,9 @@ class Log {
}
log(type, data, keep) {
if (data && data[0] && data[0].indexOf && data[0].indexOf('Warning: Using the "className" prop on') === 0) {
return;
}
const entry = {
type,
data,
@@ -54,12 +58,18 @@ class Log {
this.log('debug', data, keep);
}
handleError(err) {
if (err && err.error) {
this.error([err.error]);
}
}
attach(keep) {
const redirected = Object.keys(proxyConsole).reduce((output, key) => ({
...output,
[key]: keep ? (...args) => proxyConsole[key](...args) : () => {},
}), {});
window.console = {
global.console = {
...redirected,
error: (...data) => this.error(data, keep),
warn: (...data) => this.warn(data, keep),
@@ -68,15 +78,24 @@ class Log {
debug: (...data) => this.debug(data, keep),
verbose: (...data) => this.debug(data, keep),
};
ErrorUtils.setGlobalHandler((err, fatal) => {
this.error([err], keep);
});
/*if (global.ErrorUtils) {
global.ErrorUtils.setGlobalHandler((err, fatal) => {
this.error([err], keep);
});
}*/
if (global.addEventListener) {
global.addEventListener('error', this.handleError);
}
}
detach() {
overrides.forEach((key) => {
window.console[key] = proxies[key];
});
if (global.removeEventListener) {
global.removeEventListener('error', this.handleError);
}
}
}

View File

@@ -0,0 +1,17 @@
import DevTool from './components/DevTool/index';
import DevToolModal from './components/DevTool/Modal';
import log from './log';
import network from './network';
import events from './events';
const show = () => events.publish('SHOW_DEVTOOLS');
const hide = () => events.publish('HIDE_DEVTOOLS');
export {
DevTool,
DevToolModal,
log,
network,
show,
hide,
};

View File

@@ -1,10 +1,10 @@
const proxied = window.XMLHttpRequest.prototype.open;
const proxied = global.XMLHttpRequest ? global.XMLHttpRequest.prototype.open : () => {};
let currentId = 0;
class Network {
constructor() {
this.requests = [];
this.listeners = [];
this.currentId = 0;
// this.clear = this.clear.bind(this);
this.get = this.get.bind(this);
}
@@ -27,37 +27,46 @@ class Network {
this.listeners.forEach(l => l(this.requests));
}
addRequest(request) {
this.requests.push({
id: this.currentId++,
...request,
});
addRequest(id, request) {
const index = this.requests.findIndex(req => req.id === id);
if (index >= 0) {
this.requests[index] = {
id,
...request,
};
} else {
this.requests.push({
id,
...request,
});
}
this.listeners.forEach(l => l(this.requests));
}
attach() {
const me = this;
const headers = {};
window.XMLHttpRequest.prototype.open = function proxyOpen (...args) {
global.XMLHttpRequest.prototype.open = function proxyOpen (...args) {
let sendArgs;
const [
method,
url,
] = args;
const id = currentId++;
this.addEventListener('load', () => {
me.addRequest({
me.addRequest(id, {
url,
method,
args: sendArgs,
headers,
requestHeaders: this.getAllResponseHeaders(),
contentType: this.getResponseHeader('content-type') || '',
contentType: (this.getResponseHeader('content-type') || ''),
request: this,
status: this.status,
status: this.status || null,
});
})
this.addEventListener('error', (error) => {
me.addRequest({
me.addRequest(id, {
url,
method,
error,
@@ -65,13 +74,21 @@ class Network {
headers,
requestHeaders: this.getAllResponseHeaders(),
request: this,
status: this.status || 'CONN ERR',
status: this.status || 'Error',
});
})
const proxiedSend = this.send;
const proxiedSetRequestHeader = this.setRequestHeader;
this.send = function proxySend (...sendargs) {
sendArgs = sendargs;
me.addRequest(id, {
url,
method,
args: sendArgs,
headers,
request: this,
status: 'Waiting',
});
return proxiedSend.apply(this, [].slice.call(arguments));
}
this.setRequestHeader = function (name, value) {
@@ -83,7 +100,7 @@ class Network {
}
detach() {
window.XMLHttpRequest.prototype.open = proxied;
global.XMLHttpRequest.prototype.open = proxied;
}
}

View File

@@ -0,0 +1,47 @@
import getDevTools from './getDevTools';
import renderer from 'react-test-renderer';
describe('Console', () => {
describe('output', () => {
let devTool;
beforeEach(() => {
devTool = getDevTools();
});
it('should render an emptry list', () => {
expect(devTool.console.output().props.logs).toEqual([
]);
});
it('should render one item', () => {
renderer.act(() => {
devTool.log.add('test');
});
expect(devTool.console.output().props.logs).toEqual([
'test',
]);
});
it('should render multible items item', () => {
renderer.act(() => {
devTool.log.add('1');
devTool.log.add('2');
devTool.log.add('3');
devTool.log.add('4');
devTool.log.add('5');
devTool.log.add('6');
devTool.log.add('7');
});
expect(devTool.console.output().props.logs).toEqual([
'1',
'2',
'3',
'4',
'5',
'6',
'7',
]);
});
});
})

View File

@@ -0,0 +1,61 @@
import React from 'react';
import renderer from 'react-test-renderer';
import {
DevTool,
} from '../src';
import Console from '../src/components/DevTool/Console';
import ConsoleOutput, { Row as OutputRow} from '../src/components/DevTool/Console/Output';
import ConsoleInput from '../src/components/DevTool/Console/Input';
import Requests from '../src/components/DevTool/Requests';
import RequestsDetails from '../src/components/DevTool/Requests/Details';
import RequestsList from '../src/components/DevTool/Requests/List';
import Storage from '../src/components/DevTool/Storage';
import StorageKeys from '../src/components/DevTool/Storage/Keys';
import StorageValues from '../src/components/DevTool/Storage/Value';
const createLog = () => {
const listeners = [];
const logs = [];
return {
listen: (l) => listeners.push(l),
unlisten: (l) => listeners = listeners.filter(nl => nl !== l),
add: (log) => {
logs.push(log);
listeners.forEach(l => l(logs));
}
}
}
const getDevTools = () => {
const log = createLog();
const instance = renderer.create(
<DevTool
logProvider={log}
/>
);
const result = {
instance,
console: {
main: () => instance.root.findByType(Console),
output: () => instance.root.findByType(ConsoleOutput),
rows: () => instance.root.findAllByType(OutputRow),
input: () => instance.root.findByType(ConsoleInput),
},
requests: {
main: () => instance.root.findByType(Requests),
output: () => instance.root.findByType(RequestsDetails),
input: () => instance.root.findByType(RequestsList),
},
storage: {
main: () => instance.root.findByType(Storage),
output: () => instance.root.findByType(StorageKeys),
input: () => instance.root.findByType(StorageValues),
},
log,
};
return result;
};
export default getDevTools;

63
tsconfig.json Normal file
View File

@@ -0,0 +1,63 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
}

27
wallaby.js Normal file
View File

@@ -0,0 +1,27 @@
module.exports = function (wallaby) {
return {
files: [
'babel.config.js',
'packages/**/*.js',
'__mocks__/**/*.js',
'!packages/**/*.spec.js',
'!packages/demo/node_modules/**/*'
],
tests: [
'packages/lib/test/*.spec.js',
],
env: {
type: 'node',
runner: 'node'
},
compilers: {
'**/*.js': wallaby.compilers.babel()
},
testFramework: 'jest'
};
};

13407
yarn.lock

File diff suppressed because it is too large Load Diff