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
Showing
16 changed files
with
274 additions
and
184 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 +1,3 @@ | ||
.DS_Store | ||
npm-debug.log | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
## 0.1.0 - First Release | ||
* Enable to turn on/off LiveReload server | ||
|
||
## 0.3.0 | ||
* Works with Atom 1.0 | ||
* Supports some preferences |
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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"atom-workspace": { | ||
"ctrl-shift-r": "livereload:toggle" | ||
} | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
"use babel"; | ||
|
||
import {CompositeDisposable} from 'atom'; | ||
import livereload from 'livereload'; | ||
import _ from 'lodash'; | ||
|
||
const DEFAULT_EXTS = 'html css js png gif jpg php php5 py rb erb coffee'.split(' '); | ||
const DEFAULT_EXCLUSIONS = '.git/ .svn/ .hg/'.split(' '); | ||
|
||
class LivereloadView extends HTMLDivElement { | ||
server = null; | ||
subscriptions = null; | ||
tooltipText = 'hello'; | ||
|
||
initialize(state) { | ||
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable | ||
this.subscriptions = new CompositeDisposable(); | ||
|
||
// add content | ||
this.innerHTML = '<a href="#" data-url></a>'; | ||
this.firstChild.addEventListener('click', (event) => this.handleClick(event), false); | ||
|
||
this.classList.add('livereload-status', 'inline-block'); | ||
} | ||
|
||
loadConfig() { | ||
let ret = {}; | ||
|
||
// port number | ||
ret.port = atom.config.get('livereload.port'); | ||
|
||
// use HTTPS | ||
ret.https = atom.config.get('livereload.useHTTPS') ? {} : null; | ||
|
||
// applyJSLive and applyCSSLive | ||
ret.applyJSLive = atom.config.get('livereload.applyJSLive'); | ||
ret.applyCSSLive = atom.config.get('livereload.applyCSSLive'); | ||
|
||
// exts | ||
let exts = atom.config.get('livereload.exts').split(',').map( ext => ext.trim() ); | ||
exts = _.difference(exts, DEFAULT_EXTS); | ||
exts = _.uniq(exts); | ||
ret.exts = exts; | ||
|
||
let exclusions = atom.config.get('livereload.exclusions').split(',').map( ex => ex.trim() ); | ||
exclusions = exclusions.concat(['.DS_Store', '.gitignore']); | ||
exclusions = _.difference(exclusions, DEFAULT_EXCLUSIONS); | ||
exclusions = _.uniq(exclusions); | ||
ret.exclusions = exclusions; | ||
|
||
return ret; | ||
} | ||
|
||
attach() { | ||
// Register command that toggles this view | ||
this.subscriptions.add( | ||
atom.commands.add( 'atom-workspace', { 'livereload:toggle': this.toggle.bind(this) } ) | ||
); | ||
|
||
// tooltip | ||
this.subscriptions.add( | ||
atom.tooltips.add( this, {title: () => this.tooltipText} ) | ||
); | ||
} | ||
|
||
detach() { | ||
this.subscriptions.dispose(); | ||
} | ||
|
||
serialize() { | ||
|
||
} | ||
|
||
destroy() { | ||
try { this.detach() } catch(e){}; | ||
|
||
this.subscriptions = null; | ||
this.remove(); | ||
} | ||
|
||
toggle() { | ||
if (this.server) { | ||
this.closeServer(); | ||
} else { | ||
this.startServer(); | ||
} | ||
} | ||
|
||
handleClick(event) { | ||
event.preventDefault(); | ||
if (this.firstChild.dataset.url) { | ||
atom.clipboard.write(this.firstChild.dataset.url, 'url'); | ||
} | ||
} | ||
|
||
startServer() { | ||
this.firstChild.dataset.url = ''; | ||
this.firstChild.textContent = 'LiveReload: ...'; | ||
|
||
// load configurations | ||
let config = this.loadConfig(); | ||
|
||
// create a server | ||
this.server = livereload.createServer(config); | ||
|
||
this.server.config.server | ||
.on('error', (err) => { | ||
if (err.code === 'EADDRINUSE') { | ||
this.tooltipText = `Trying port ${config.port+1}...`; | ||
console.log(`LiveReload: port ${config.port} already in use. Trying port ${config.port+1}...`); | ||
config.port++; | ||
|
||
try { this.server.close(); } catch(e) {}; | ||
this.server = null; | ||
|
||
setTimeout( this.startServer.bind(this), 1000 ); | ||
} | ||
}) | ||
.on('listening', () => { | ||
console.log(`LiveReload: listening on port ${config.port}.`); | ||
|
||
this.firstChild.textContent = `LiveReload: ${config.port}`; | ||
this.tooltipText = 'Click to copy the URL to clipboard'; | ||
this.firstChild.dataset.url = (config.useHTTPS ? 'https':'http') + `://localhost:${config.port}/livereload.js`; | ||
|
||
let paths = atom.project.getPaths(); | ||
this.server.watch(paths); | ||
}); | ||
} | ||
|
||
closeServer() { | ||
this.firstChild.textContent = 'LiveReload: Off'; | ||
this.server.config.server.close(); | ||
this.server = null; | ||
} | ||
} | ||
|
||
var LivereloadViewTag = document.registerElement('livereload-status-bar', {prototype:LivereloadView.prototype}); | ||
|
||
export default LivereloadViewTag; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"use babel"; | ||
|
||
import LivereloadView from './livereload-view'; | ||
import {CompositeDisposable} from 'atom'; | ||
|
||
export default { | ||
livereloadView: null, | ||
|
||
config: { | ||
port: { | ||
title: 'Port Number', | ||
type: 'integer', | ||
default: 35729 | ||
}, | ||
exts : { | ||
title: 'Additional Extensions', | ||
description: 'The server will watch these comma-separated extensions as well as the defaults.', | ||
type: 'string', | ||
default: 'html, css, js, png, gif, jpg, php, php5, py, rb, erb, coffee' | ||
}, | ||
exclusions: { | ||
title: 'Additional Exclusions', | ||
description: 'The server will ignore these path in addition to the defaults.', | ||
type: 'string', | ||
default: '.DS_Store, .gitignore, .git/, .svn/, .hg/' | ||
}, | ||
applyJSLive: { | ||
title: 'Apply JavaScript Live', | ||
type: 'boolean', | ||
description: 'If checked, LiveReload will reload JS files in the background instead of reloading the page.', | ||
default: false | ||
}, | ||
applyCSSLive: { | ||
title: 'Apply CSS Live', | ||
type: 'boolean', | ||
description: 'If checked, LiveReload will reload CSS files in the background instead of refreshing the page.', | ||
default: true | ||
}, | ||
useHTTPS: { | ||
title: 'Use HTTPS Protocol', | ||
type: 'boolean', | ||
default: false | ||
} | ||
}, | ||
|
||
activate(state) { | ||
this.livereloadView = new LivereloadView(); | ||
this.livereloadView.initialize(state); | ||
this.livereloadView.attach(); | ||
}, | ||
|
||
deactivate() { | ||
if (this.statusBarTile) { | ||
this.statusBarTile.destory(); | ||
} | ||
this.statusBarTile = null; | ||
this.livereloadView.detach(); | ||
this.livereloadView.destroy(); | ||
}, | ||
|
||
serialize() { | ||
return { livereloadViewState: this.livereloadView.serialize() }; | ||
}, | ||
|
||
consumeStatusBar(statusBar) { | ||
this.statusBarTile = statusBar.addRightTile({item:this.livereloadView, priority:100}); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.