This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18146 from atom/migrate-dev-live-reload-package
➡️ Migrate core package 'dev-live-reload' into ./packages
- Loading branch information
Showing
54 changed files
with
1,134 additions
and
6 deletions.
There are no files selected for viewing
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
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 @@ | ||
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2014 GitHub Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,13 @@ | ||
# Dev Live Reload package | ||
|
||
This live reloads the Atom `.less` files. You edit styles and they are magically reflected in any running Atom windows. Magic! :tophat: :sparkles: :rabbit2: | ||
|
||
Installed by default on Atom windows running in dev mode. Use the "Application: Open Dev" command to open a new dev mode window. | ||
|
||
Use <kbd>meta-shift-ctrl-r</kbd> to reload all core and package stylesheets. | ||
|
||
This package is __experimental__, it does not handle the following: | ||
|
||
* File additions to a theme. New files will not be watched. | ||
|
||
![gif](https://f.cloud.github.com/assets/69169/1387004/d2dc45f2-3b84-11e3-877e-cac8c51e9702.gif) |
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 @@ | ||
'.platform-darwin': | ||
'cmd-ctrl-R': 'dev-live-reload:reload-all' | ||
|
||
'.platform-win32': | ||
'alt-ctrl-R': 'dev-live-reload:reload-all' |
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 @@ | ||
const fs = require('fs-plus') | ||
const path = require('path') | ||
const Watcher = require('./watcher') | ||
|
||
module.exports = | ||
class BaseThemeWatcher extends Watcher { | ||
constructor () { | ||
super() | ||
this.stylesheetsPath = path.dirname(atom.themes.resolveStylesheet('../static/atom.less')) | ||
this.watch() | ||
} | ||
|
||
watch () { | ||
const filePaths = fs.readdirSync(this.stylesheetsPath).filter(filePath => path.extname(filePath).includes('less')) | ||
|
||
for (const filePath of filePaths) { | ||
this.watchFile(path.join(this.stylesheetsPath, filePath)) | ||
} | ||
} | ||
|
||
loadStylesheet () { | ||
this.loadAllStylesheets() | ||
} | ||
|
||
loadAllStylesheets () { | ||
atom.themes.reloadBaseStylesheets() | ||
} | ||
} |
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,24 @@ | ||
module.exports = { | ||
activate (state) { | ||
if (!atom.inDevMode() || atom.inSpecMode()) return | ||
|
||
if (atom.packages.hasActivatedInitialPackages()) { | ||
this.startWatching() | ||
} else { | ||
this.activatedDisposable = atom.packages.onDidActivateInitialPackages(() => this.startWatching()) | ||
} | ||
}, | ||
|
||
deactivate () { | ||
if (this.activatedDisposable) this.activatedDisposable.dispose() | ||
if (this.commandDisposable) this.commandDisposable.dispose() | ||
if (this.uiWatcher) this.uiWatcher.destroy() | ||
}, | ||
|
||
startWatching () { | ||
const UIWatcher = require('./ui-watcher') | ||
this.uiWatcher = new UIWatcher({themeManager: atom.themes}) | ||
this.commandDisposable = atom.commands.add('atom-workspace', 'dev-live-reload:reload-all', () => this.uiWatcher.reloadAll()) | ||
if (this.activatedDisposable) this.activatedDisposable.dispose() | ||
} | ||
} |
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,48 @@ | ||
const fs = require('fs-plus') | ||
|
||
const Watcher = require('./watcher') | ||
|
||
module.exports = | ||
class PackageWatcher extends Watcher { | ||
static supportsPackage (pack, type) { | ||
if (pack.getType() === type && pack.getStylesheetPaths().length) return true | ||
return false | ||
} | ||
|
||
constructor (pack) { | ||
super() | ||
this.pack = pack | ||
this.watch() | ||
} | ||
|
||
watch () { | ||
const watchedPaths = [] | ||
const watchPath = stylesheet => { | ||
if (!watchedPaths.includes(stylesheet)) this.watchFile(stylesheet) | ||
watchedPaths.push(stylesheet) | ||
} | ||
|
||
const stylesheetsPath = this.pack.getStylesheetsPath() | ||
|
||
if (fs.isDirectorySync(stylesheetsPath)) this.watchDirectory(stylesheetsPath) | ||
|
||
const stylesheetPaths = new Set(this.pack.getStylesheetPaths()) | ||
const onFile = stylesheetPath => stylesheetPaths.add(stylesheetPath) | ||
const onFolder = () => true | ||
fs.traverseTreeSync(stylesheetsPath, onFile, onFolder) | ||
|
||
for (let stylesheet of stylesheetPaths) { | ||
watchPath(stylesheet) | ||
} | ||
} | ||
|
||
loadStylesheet (pathName) { | ||
if (pathName.includes('variables')) this.emitGlobalsChanged() | ||
this.loadAllStylesheets() | ||
} | ||
|
||
loadAllStylesheets () { | ||
console.log('Reloading package', this.pack.name) | ||
this.pack.reloadStylesheets() | ||
} | ||
} |
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,81 @@ | ||
const {CompositeDisposable} = require('atom') | ||
|
||
const BaseThemeWatcher = require('./base-theme-watcher') | ||
const PackageWatcher = require('./package-watcher') | ||
|
||
module.exports = | ||
class UIWatcher { | ||
constructor () { | ||
this.subscriptions = new CompositeDisposable() | ||
this.reloadAll = this.reloadAll.bind(this) | ||
this.watchers = [] | ||
this.baseTheme = this.createWatcher(new BaseThemeWatcher()) | ||
this.watchPackages() | ||
} | ||
|
||
watchPackages () { | ||
this.watchedThemes = new Map() | ||
this.watchedPackages = new Map() | ||
for (const theme of atom.themes.getActiveThemes()) { this.watchTheme(theme) } | ||
for (const pack of atom.packages.getActivePackages()) { this.watchPackage(pack) } | ||
this.watchForPackageChanges() | ||
} | ||
|
||
watchForPackageChanges () { | ||
this.subscriptions.add(atom.themes.onDidChangeActiveThemes(() => { | ||
// We need to destroy all theme watchers as all theme packages are destroyed | ||
// when a theme changes. | ||
for (const theme of this.watchedThemes.values()) { theme.destroy() } | ||
|
||
this.watchedThemes.clear() | ||
|
||
// Rewatch everything! | ||
for (const theme of atom.themes.getActiveThemes()) { this.watchTheme(theme) } | ||
})) | ||
|
||
this.subscriptions.add(atom.packages.onDidActivatePackage(pack => this.watchPackage(pack))) | ||
|
||
this.subscriptions.add(atom.packages.onDidDeactivatePackage(pack => { | ||
// This only handles packages - onDidChangeActiveThemes handles themes | ||
const watcher = this.watchedPackages.get(pack.name) | ||
if (watcher) watcher.destroy() | ||
this.watchedPackages.delete(pack.name) | ||
})) | ||
} | ||
|
||
watchTheme (theme) { | ||
if (PackageWatcher.supportsPackage(theme, 'theme')) this.watchedThemes.set(theme.name, this.createWatcher(new PackageWatcher(theme))) | ||
} | ||
|
||
watchPackage (pack) { | ||
if (PackageWatcher.supportsPackage(pack, 'atom')) this.watchedPackages.set(pack.name, this.createWatcher(new PackageWatcher(pack))) | ||
} | ||
|
||
createWatcher (watcher) { | ||
watcher.onDidChangeGlobals(() => { | ||
console.log('Global changed, reloading all styles') | ||
this.reloadAll() | ||
}) | ||
watcher.onDidDestroy(() => this.watchers.splice(this.watchers.indexOf(watcher), 1)) | ||
this.watchers.push(watcher) | ||
return watcher | ||
} | ||
|
||
reloadAll () { | ||
this.baseTheme.loadAllStylesheets() | ||
for (const pack of atom.packages.getActivePackages()) { | ||
if (PackageWatcher.supportsPackage(pack, 'atom')) pack.reloadStylesheets() | ||
} | ||
|
||
for (const theme of atom.themes.getActiveThemes()) { | ||
if (PackageWatcher.supportsPackage(theme, 'theme')) theme.reloadStylesheets() | ||
} | ||
} | ||
|
||
destroy () { | ||
this.subscriptions.dispose() | ||
this.baseTheme.destroy() | ||
for (const pack of this.watchedPackages.values()) { pack.destroy() } | ||
for (const theme of this.watchedThemes.values()) { theme.destroy() } | ||
} | ||
} |
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,72 @@ | ||
const {CompositeDisposable, File, Directory, Emitter} = require('atom') | ||
const path = require('path') | ||
|
||
module.exports = | ||
class Watcher { | ||
constructor () { | ||
this.destroy = this.destroy.bind(this) | ||
this.emitter = new Emitter() | ||
this.disposables = new CompositeDisposable() | ||
this.entities = [] // Used for specs | ||
} | ||
|
||
onDidDestroy (callback) { | ||
this.emitter.on('did-destroy', callback) | ||
} | ||
|
||
onDidChangeGlobals (callback) { | ||
this.emitter.on('did-change-globals', callback) | ||
} | ||
|
||
destroy () { | ||
this.disposables.dispose() | ||
this.entities = null | ||
this.emitter.emit('did-destroy') | ||
this.emitter.dispose() | ||
} | ||
|
||
watch () { | ||
// override me | ||
} | ||
|
||
loadStylesheet (stylesheetPath) { | ||
// override me | ||
} | ||
|
||
loadAllStylesheets () { | ||
// override me | ||
} | ||
|
||
emitGlobalsChanged () { | ||
this.emitter.emit('did-change-globals') | ||
} | ||
|
||
watchDirectory (directoryPath) { | ||
if (this.isInAsarArchive(directoryPath)) return | ||
const entity = new Directory(directoryPath) | ||
this.disposables.add(entity.onDidChange(() => this.loadAllStylesheets())) | ||
this.entities.push(entity) | ||
} | ||
|
||
watchGlobalFile (filePath) { | ||
const entity = new File(filePath) | ||
this.disposables.add(entity.onDidChange(() => this.emitGlobalsChanged())) | ||
this.entities.push(entity) | ||
} | ||
|
||
watchFile (filePath) { | ||
if (this.isInAsarArchive(filePath)) return | ||
const reloadFn = () => this.loadStylesheet(entity.getPath()) | ||
|
||
const entity = new File(filePath) | ||
this.disposables.add(entity.onDidChange(reloadFn)) | ||
this.disposables.add(entity.onDidDelete(reloadFn)) | ||
this.disposables.add(entity.onDidRename(reloadFn)) | ||
this.entities.push(entity) | ||
} | ||
|
||
isInAsarArchive (pathToCheck) { | ||
const {resourcePath} = atom.getLoadSettings() | ||
return pathToCheck.startsWith(`${resourcePath}${path.sep}`) && path.extname(resourcePath) === '.asar' | ||
} | ||
} |
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,9 @@ | ||
'menu': [ | ||
'label': 'Packages' | ||
'submenu': [ | ||
'label': 'Dev Live Reload' | ||
'submenu': [ | ||
{ 'label': 'Reload All Styles', 'command': 'dev-live-reload:reload-all' } | ||
] | ||
] | ||
] |
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 @@ | ||
{ | ||
"name": "dev-live-reload", | ||
"main": "./lib/main", | ||
"version": "0.48.1", | ||
"description": "Live reload atom themes and packages.", | ||
"repository": "https://github.com/atom/atom", | ||
"license": "MIT", | ||
"dependencies": { | ||
"fs-plus": "^3.0.0" | ||
}, | ||
"engines": { | ||
"atom": "*" | ||
}, | ||
"devDependencies": { | ||
"standard": "^10.0.3" | ||
}, | ||
"standard": { | ||
"env": { | ||
"atomtest": true, | ||
"browser": true, | ||
"jasmine": true, | ||
"node": true | ||
}, | ||
"globals": [ | ||
"atom" | ||
] | ||
} | ||
} |
Oops, something went wrong.