Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup #44

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.log
node_modules
dist
20 changes: 20 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let presets = [
["@babel/preset-env", {
targets: {
"electron": 5
}
}]
];

let plugins = [];

if (process.env.BABEL_ENV === "development") {
plugins.push("@babel/plugin-transform-modules-commonjs")
}

module.exports = {
presets: presets,
plugins: plugins,
exclude: "node_modules/**",
sourceMaps: "inline"
}
10 changes: 7 additions & 3 deletions lib/html-preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use babel'

import { ScrollView } from 'atom-space-pen-views'
import ScrollView from 'atom-space-pen-views-plus/src/scroll-view'
import fs from 'fs-plus'
import path from 'path'

Expand Down Expand Up @@ -81,3 +79,9 @@ export default class HTMLPreview extends ScrollView {
return this.detach()
}
}

export function deserialize({filePath, uri}) {
if (fs.isFileSync(filePath)) {
return new HTMLPreview(uri)
}
}
17 changes: 13 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
'use babel'
import { CompositeDisposable } from 'atom'
import path from 'path'

let subs = null
let toolbar = null
let juliaClient = null
let HTMLPreviewView = require('./html-preview.js')

// ./html-preview.js exports
let HTMLPreviewView = null
let deserializeHTML = null

export function activate () {
subs = new CompositeDisposable()

subs.add(atom.workspace.addOpener((uri) => {
if (path.extname(uri) === '.html' && uri.startsWith('preview://')) {

// load HTMLPreviewView if null
if (HTMLPreviewView == null) {
import('./html-preview').then(({default: HTMLPreview}) => HTMLPreviewView = HTMLPreview)
}
return new HTMLPreviewView(uri)
}
}))
Expand Down Expand Up @@ -145,7 +152,9 @@ export function deactivate () {
}

export function deserialize({filePath, uri}) {
if (require('fs-plus').isFileSync(filePath)) {
return new HTMLPreviewView(uri)
// load deserializeHTML if null
if (deserializeHTML == null) {
import('./html-preview').then(({deserialize}) => deserializeHTML = deserialize)
}
return deserializeHTML({filePath, uri})
}
Loading