-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sal Niro
committed
Jun 1, 2017
1 parent
3150e52
commit 409ceb1
Showing
9 changed files
with
154 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
.idea | ||
node_modules | ||
demo/bundle.js | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
let express = require('express'); | ||
let app = express(); | ||
import express from 'express'; | ||
import webpack from 'webpack'; | ||
import path from 'path'; | ||
import config from './webpack.config.js'; | ||
import open from 'open'; | ||
|
||
app.set('port', 5000); | ||
const app = express(); | ||
const compiler = webpack(config); | ||
|
||
app.use(express.static('.')); | ||
app.set('port', 8000); | ||
|
||
app.use(function (req, res, next) { | ||
if (req.path.substr(-1) === '/' && req.path.length > 1) { | ||
let query = req.url.slice(req.path.length); | ||
res.redirect(301, req.path.slice(0, -1) + query); | ||
} else { | ||
next(); | ||
} | ||
}); | ||
app.use(require('webpack-dev-middleware')(compiler, { | ||
noInfo: true, | ||
publicPath: config.output.publicPath | ||
})); | ||
|
||
app.all('/*', function (req, res, next) { | ||
res.sendFile(`${__dirname}/index.html`) | ||
app.use(require('webpack-hot-middleware')(compiler)); | ||
|
||
app.all('/*', function (req, res) { | ||
res.sendFile(path.join(__dirname, './index.html')); | ||
}); | ||
|
||
app.listen(app.get('port'), function () { | ||
console.log(`react-codemirror2 demo listening on port ${app.get('port')}`); | ||
app.listen(app.get('port'), function (err) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log(`react-codemirror2 demo listening on port ${app.get('port')}`); | ||
open(`http://localhost:${app.get('port')}`); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
let codemirror = require('codemirror'); | ||
|
||
export default class CodeMirror extends React.Component { | ||
|
||
componentDidMount() { | ||
|
||
this.editor = codemirror(this.ref); | ||
this.editor.on('change', () => this.props.onChange(this.editor.getValue())); | ||
|
||
this.hydrate(this.props); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
|
||
this.hydrate(nextProps); | ||
} | ||
|
||
hydrate(props) { | ||
|
||
Object.keys(props.options || {}).forEach(key => this.editor.setOption(key, props.options[key])); | ||
this.editor.setValue(props.value || ''); | ||
} | ||
|
||
render() { | ||
return React.createElement('div', { ref: self => this.ref = self }); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const fs = require('fs'); | ||
const babel = require('babel-core'); | ||
const path = require('path'); | ||
const root = path.resolve(__dirname, '..'); | ||
const {Transform} = require('stream'); | ||
|
||
const transpile = new Transform({ | ||
transform(chunk, encoding, cb) { | ||
|
||
let transformed = babel.transform(chunk.toString(), {plugins: ['transform-react-jsx']}) | ||
|
||
this.push(transformed.code) | ||
cb(); | ||
} | ||
}); | ||
|
||
let rs = fs.createReadStream(`${root}/src/react-codemirror2.jsx`); | ||
let ws = fs.createWriteStream(`${root}/index.js`); | ||
|
||
rs.pipe(transpile).pipe(ws); | ||
|
File renamed without changes.