Skip to content

Commit

Permalink
monorepo using yarn workspaces
Browse files Browse the repository at this point in the history
problem: create-react-app does not support compiling files outside 'src'. Building draft-js*-plugin everytime it changes in development is not a good flow, so holding this for now
facebook/create-react-app#1107
  • Loading branch information
guilhermecvm committed Nov 28, 2017
1 parent 7b77110 commit ba879ac
Show file tree
Hide file tree
Showing 28 changed files with 156 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules
node_modules

# testing
/coverage
Expand Down
24 changes: 5 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
{
"name": "dolphino",
"version": "0.2.0",
"private": true,
"homepage": "https://guilhermecvm.github.io/dolphino",
"dependencies": {
"draft-js": "^0.10.4",
"draft-js-buttons": "^2.0.1",
"draft-js-markdown-plugin": "^1.1.0",
"draft-js-plugins-editor": "^2.0.1",
"draft-js-prism": "^1.0.5",
"draft-js-static-toolbar-plugin": "^2.0.1",
"prismjs": "^1.8.4",
"react": "^16.1.0",
"react-dom": "^16.1.0",
"react-scripts": "1.0.17"
},
"workspaces": ["packages/*"],
"devDependencies": {
"gh-pages": "^1.0.0",
"husky": "^0.14.3",
Expand All @@ -23,16 +10,15 @@
"prop-types": "^15.6.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"start": "yarn --cwd packages/dolphino-app start",
"build": "yarn --cwd packages/dolphino-app build",
"test": "yarn --cwd packages/dolphino-app test",
"deploy": "gh-pages -d build",
"predeploy": "yarn run build",
"precommit": "lint-staged"
},
"lint-staged": {
"src/**/*.{js,jsx,json,css}": [
"packages/**/*.{js,jsx,json,css}": [
"prettier --single-quote --no-semi --trailing-comma es5 --write",
"git add"
]
Expand Down
28 changes: 28 additions & 0 deletions packages/dolphino-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "dolphino-app",
"version": "0.2.0",
"private": true,
"dependencies": {
"draft-js": "^0.10.4",
"draft-js-buttons": "^2.0.1",
"draft-js-color-picker-plugin": "^0.2.0",
"draft-js-markdown-plugin": "^1.1.0",
"draft-js-plugins-editor": "^2.0.1",
"draft-js-prism": "^1.0.5",
"draft-js-prism-decorator-plugin": "^0.2.0",
"draft-js-static-toolbar-plugin": "^2.0.1",
"prismjs": "^1.8.4",
"react": "^16.1.0",
"react-dom": "^16.1.0",
"react-scripts": "1.0.17"
},
"devDependencies": {
"prop-types": "^15.6.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions src/App.css → packages/dolphino-app/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
File renamed without changes.
8 changes: 8 additions & 0 deletions packages/dolphino-app/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'

it('renders without crashing', () => {
const div = document.createElement('div')
ReactDOM.render(<App />, div)
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
import createToolbarPlugin from 'draft-js-static-toolbar-plugin'
import createMarkdownPlugin from 'draft-js-markdown-plugin'
import toolbarTheme from 'draft-js-static-toolbar-plugin/lib/plugin.css'
import createColorPickerPlugin from './plugins/color-picker-plugin'
import createPrismPlugin from './plugins/prism-plugin'
import createColorPickerPlugin from 'draft-js-color-picker-plugin'
import createPrismPlugin from 'draft-js-prism-decorator-plugin'

const colorPickerPlugin = createColorPickerPlugin({ theme: toolbarTheme })
const toolbarPlugin = createToolbarPlugin({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { RichUtils } from 'draft-js'

const defaultStyle = {
background: 'blue',
padding: '0 .3em',
color: '#fff',
}

export default (style = {}) => {
return {
customStyleMap: {
HIGHLIGHT: {
...defaultStyle,
...style,
},
},
keyBindingFn: e => {
if (e.metaKey && e.key === 'k') {
return 'highlight'
}
},
handleKeyCommand: (command, editorState, { setEditorState }) => {
if (command === 'highlight') {
setEditorState(RichUtils.toggleInlineStyle(editorState, 'HIGHLIGHT'))
return 'handled'
}
},
}
}
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions packages/dolphino-app/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import registerServiceWorker from './registerServiceWorker'

ReactDOM.render(<App />, document.getElementById('root'))
registerServiceWorker()
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ const isLocalhost = Boolean(
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
)

export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
const publicUrl = new URL(process.env.PUBLIC_URL, window.location)
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
return;
return
}

window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`

if (isLocalhost) {
// This is running on localhost. Lets check if a service worker still exists or not.
checkValidServiceWorker(swUrl);
checkValidServiceWorker(swUrl)
} else {
// Is not local host. Just register service worker
registerValidSW(swUrl);
registerValidSW(swUrl)
}
});
})
}
}

Expand All @@ -48,28 +48,28 @@ function registerValidSW(swUrl) {
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
const installingWorker = registration.installing
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the old content will have been purged and
// the fresh content will have been added to the cache.
// It's the perfect time to display a "New content is
// available; please refresh." message in your web app.
console.log('New content is available; please refresh.');
console.log('New content is available; please refresh.')
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
console.log('Content is cached for offline use.')
}
}
};
};
}
}
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
console.error('Error during service worker registration:', error)
})
}

function checkValidServiceWorker(swUrl) {
Expand All @@ -84,25 +84,25 @@ function checkValidServiceWorker(swUrl) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
window.location.reload()
})
})
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl);
registerValidSW(swUrl)
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
)
})
}

export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
registration.unregister()
})
}
}
11 changes: 11 additions & 0 deletions packages/draft-js-color-picker-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "draft-js-color-picker-plugin",
"version": "0.2.0",
"main": "src/index.js",
"license": "MIT",
"peerDependencies": {
"draft-js": "^0.10.1",
"react": "^15.5.0 || ^16.0.0-rc",
"react-dom": "^15.5.0 || ^16.0.0-rc"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ export default (config = {}) => {
const selection = editorState.getSelection()

// remove previous color styles from selection in content
const nextContentState = Object.keys(
customStyleMap
).reduce((contentState, style) => {
return Modifier.removeInlineStyle(contentState, selection, style)
}, editorState.getCurrentContent())
const nextContentState = Object.keys(customStyleMap).reduce(
(contentState, style) => {
return Modifier.removeInlineStyle(contentState, selection, style)
},
editorState.getCurrentContent()
)

// FIXME Try not to add to the undo stack
let nextEditorState = EditorState.push(
Expand Down
11 changes: 11 additions & 0 deletions packages/draft-js-prism-decorator-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "draft-js-prism-decorator-plugin",
"version": "0.2.0",
"main": "index.js",
"license": "MIT",
"peerDependencies": {
"draft-js": "^0.10.1",
"react": "^15.5.0 || ^16.0.0-rc",
"react-dom": "^15.5.0 || ^16.0.0-rc"
}
}
8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/index.js

This file was deleted.

Loading

0 comments on commit ba879ac

Please sign in to comment.