Skip to content

Commit

Permalink
release: v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jan 6, 2020
1 parent 43b35fa commit 1312645
Show file tree
Hide file tree
Showing 14 changed files with 816 additions and 847 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
env: {
browser: true,
es6: true,
commonjs: true
},
extends: 'eslint:recommended',
rules: {
quotes: ['error', 'single']
},
parserOptions: {
sourceType: 'module'
}
}

22 changes: 0 additions & 22 deletions .eslintrc.json

This file was deleted.

6 changes: 4 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/src/
.eslintignore
.eslintrc.json
.eslintrc.js
prettier.config.js
.gitignore
.npmignore
.travis.yml
index.html
webpack.config.js
webpack.config.js
.prettierignore
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eruda-code.js
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## v2.0.0 (6 Jan 2020)

* feat: theme support
34 changes: 22 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Eruda-code</title>
</head>
<body>
<script src="node_modules/eruda/eruda.min.js"></script>
<script>eruda.init({tool: 'console'});</script>
<script src="assets/eruda-code.js"></script>
<script>eruda.add(erudaCode).show('code').show();</script>
</body>
</html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
/>
<title>Eruda-code</title>
</head>
<body>
<script src="node_modules/eruda/eruda.js"></script>
<script>
eruda.init({ tool: 'console' })
</script>
<script src="assets/eruda-code.js"></script>
<script>
eruda
.add(erudaCode)
.show('code')
.show()
</script>
</body>
</html>
44 changes: 24 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "eruda-code",
"version": "1.0.0",
"version": "2.0.0",
"description": "Eruda plugin for running JavaScript code",
"main": "eruda-code.js",
"scripts": {
"dev": "webpack-dev-server --host 0.0.0.0",
"build": "webpack && webpack -p",
"build": "webpack -p",
"ci": "npm run lint && npm run build",
"lint": "eslint src/**/*.js"
"lint": "eslint src/**/*.js",
"format": "prettier src/**/*.js src/**/*.scss *.js index.html --write"
},
"repository": {
"type": "git",
Expand All @@ -29,23 +30,26 @@
},
"homepage": "https://github.com/liriliri/eruda-code#readme",
"devDependencies": {
"autoprefixer": "^7.2.2",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"codemirror": "^5.33.0",
"css-loader": "^0.28.7",
"eruda": "^1.4.0",
"eslint": "^4.12.1",
"handlebars": "^4.0.11",
"handlebars-loader": "^1.6.0",
"node-sass": "^4.7.2",
"postcss": "^6.0.14",
"@babel/core": "^7.7.2",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.7.1",
"@babel/runtime": "^7.7.2",
"autoprefixer": "^9.7.1",
"babel-loader": "^8.0.6",
"codemirror": "^5.50.2",
"css-loader": "^3.4.1",
"eruda": "^2.0.0",
"eslint": "^6.6.0",
"handlebars": "^4.5.1",
"handlebars-loader": "^1.7.1",
"node-sass": "^4.13.0",
"postcss": "^7.0.21",
"postcss-class-prefix": "^0.3.0",
"postcss-loader": "^2.0.9",
"sass-loader": "^6.0.6",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7"
"postcss-loader": "^3.0.0",
"prettier": "^1.18.2",
"sass-loader": "^8.0.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
}
}
5 changes: 5 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
singleQuote: true,
tabWidth: 2,
semi: false
}
43 changes: 32 additions & 11 deletions src/CodeMirror.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
.CodeMirror {
height: 100%;
height: 100%;
}

/* Sync style with chrome dev-tool */
.cm-keyword {color: hsl(310, 86%, 36%);}
.cm-number {color: hsl(248, 100%, 41%);}
.cm-comment {color: hsl(120, 100%, 23%) !important; font-style: italic;}
.cm-string {color: hsl(1, 80%, 43%) !important;}
.cm-string-2 {color: hsl(1, 99%, 39%) !important;}
.cm-atom {color: hsl(310, 86%, 36%);}
.cm-def {color: hsl(240, 73%, 38%);}
.cm-operator {color: hsl(27, 100%, 30%);}
.cm-meta {color: hsl(27, 100%, 30%);}
.cm-variable-2 {color: hsl(240, 73%, 38%);}
.cm-keyword {
color: hsl(310, 86%, 36%);
}
.cm-number {
color: hsl(248, 100%, 41%);
}
.cm-comment {
color: hsl(120, 100%, 23%) !important;
font-style: italic;
}
.cm-string {
color: hsl(1, 80%, 43%) !important;
}
.cm-string-2 {
color: hsl(1, 99%, 39%) !important;
}
.cm-atom {
color: hsl(310, 86%, 36%);
}
.cm-def {
color: hsl(240, 73%, 38%);
}
.cm-operator {
color: hsl(27, 100%, 30%);
}
.cm-meta {
color: hsl(27, 100%, 30%);
}
.cm-variable-2 {
color: hsl(240, 73%, 38%);
}
85 changes: 85 additions & 0 deletions src/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import CodeMirror from 'codemirror'
import 'codemirror/mode/javascript/javascript'
import { nextTick, copy } from './util'

export default function(eruda) {
let { evalCss, beautify } = eruda.util

class Code extends eruda.Tool {
constructor() {
super()
this.name = 'code'
this._style = evalCss(require('./style.scss'))
this._CodeMirrorStyle = evalCss(require('codemirror/lib/codemirror.css'))
this._CodeMirrorCustomStyle = evalCss(require('./CodeMirror.css'))
this._editor = null
}
init($el, container) {
super.init($el, container)

$el.html(require('./template.hbs')())
this._bindEvent()
}
show() {
super.show()
if (!this._editor) {
let container = this._$el.find('.eruda-editor').get(0)
this._editor = CodeMirror.fromTextArea(container, {
lineNumbers: 'true',
mode: 'javascript'
})
nextTick(() => this._editor.refresh())
}
}
hide() {
super.hide()
}
run() {
try {
evalJs(this._editor.getValue())
} catch (e) {
/* eslint-disable no-console */
console.error(e)
}
}
beautify() {
let editor = this._editor

let value = editor.getValue()
editor.setValue(beautify(value))
}
copy() {
copy(this._editor.getValue())
}
clear() {
this._editor.setValue('')
}
destroy() {
super.destroy()
evalCss.remove(this._style)
evalCss.remove(this._CodeMirrorStyle)
evalCss.remove(this._CodeMirrorCustomStyle)
}
_bindEvent() {
this._$el
.on('click', '.eruda-run', () => this.run())
.on('click', '.eruda-beautify', () => this.beautify())
.on('click', '.eruda-clear', () => this.clear())
.on('click', '.eruda-copy', () => this.copy())
}
}

let evalJs = code => {
let ret

try {
ret = eval.call(window, `(${code})`)
} catch (e) {
ret = eval.call(window, code)
}

return ret
}

return new Code()
}
Loading

0 comments on commit 1312645

Please sign in to comment.