Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Babelify nearly everything #455

Merged
merged 13 commits into from
May 12, 2017
41 changes: 0 additions & 41 deletions lib/apm.coffee

This file was deleted.

37 changes: 37 additions & 0 deletions lib/apm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use babel'

import {BufferedProcess} from 'atom';

function run(args) {
return new Promise(function(resolve) {
var command = atom.packages.getApmPath();

var log = '';
var stdout = data => log += `${data}`;
var stderr = data => log += `${data}`;

var exit = code => resolve({log, code});

new BufferedProcess({command, args, stdout, stderr, exit});
});
}

function fullname(name, version) {
return (version != null) ? `${name}@${version}` : name
};

function parseDependencies(dependencies) {
return Object.keys(dependencies).map((name) => {
return fullname(name, dependencies[name])
})
};

export default {
install(name, version) {
var nameIsObject = typeof name === 'object';

var args = nameIsObject ? parseDependencies(name) : [fullname(name, version)];

return run(['install', '--compatible', '--no-confirm', '--no-color'].concat(args));
}
}
43 changes: 0 additions & 43 deletions lib/atom-helper.coffee

This file was deleted.

55 changes: 55 additions & 0 deletions lib/atom-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use babel'

import localStorage from './local-storage';
import { name } from '../package.json';

export default {
isLastFocusedWindow() {
return parseInt(localStorage.get('lastFocusedWindow')) === process.pid;
},

setLastFocusedWindow() {
localStorage.set('lastFocusedWindow', process.pid);
},

trackFocusedWindow() {
this.setLastFocusedWindow();
window.onfocus = this.setLastFocusedWindow;
},

cleanup() {
if (this.isLastFocusedWindow()) {
localStorage.delete('lastFocusedWindow');
}
},

emit(key, detail) {
atom.emitter.emit(key, detail);
},

on(key, callback) {
return atom.emitter.on(key, callback);
},

closePaneItems() {
atom.workspace.getPanes().forEach(pane => pane.close());
},

resetPackage() {
atom.packages.deactivatePackage(name);

atom.packages.activatePackage(name).then(() =>
atom.menu.sortPackagesMenu()
);
},

reloadStylesheets() {
var pkg = atom.packages.getActivePackage(name);
pkg.reloadStylesheets();
},

addStylesheet(css) {
atom.styles.addStyleSheet(css);
}
};

95 changes: 0 additions & 95 deletions lib/auth.coffee

This file was deleted.

117 changes: 117 additions & 0 deletions lib/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
'use babel'

import _token from './token';
import _url from 'url';
import fetch from './fetch';
import localStorage from './local-storage';
import shell from 'shell';
import {BrowserWindow} from 'remote';
import {learnCo} from './config';
import {version} from '../package.json';

var authUrl = `${learnCo}/api/v1/users/me?ile_version=${version}`;

function confirmOauthToken(token) {
var headers = new Headers({'Authorization': `Bearer ${token}`});

return fetch(authUrl, {headers}).then(function(data) {
return (data.email != null) ? data : false
});
}

function githubLogin() {
return new Promise((resolve, reject) => {
var win = new BrowserWindow({autoHideMenuBar: true, show: false, width: 440, height: 660, resizable: false});
var { webContents } = win;

win.setSkipTaskbar(true);
win.setMenuBarVisibility(false);
win.setTitle('Sign in to Github to get started with the Learn IDE');

// show window only if login is required
webContents.on('did-finish-load', () => win.show());

// hide window immediately after login
webContents.on('will-navigate', (e, url) => {
if (url.match(`${learnCo}/users/auth/github/callback`)) { return win.hide(); }
});

webContents.on('did-get-redirect-request', (e, oldURL, newURL) => {
if (!newURL.match(/ide_token/)) { return; }

var token = _url.parse(newURL, true).query.ide_token;

confirmOauthToken(token).then((res) => {
if (res == null) { return; }

localStorage.set('didCompleteGithubLogin');
_token.set(token);
win.destroy();
resolve();
});
});

if (!win.loadURL(`${learnCo}/ide/token?ide_config=true`)) {
atom.notifications.warning('Learn IDE: connectivity issue', {
detail: `The editor is unable to connect to ${learnCo}. Are you connected to the internet?`,
buttons: [
{text: 'Try again', onDidClick() { learnSignIn(); }}
]
});
}})
};

function learnSignIn() {
return new Promise((resolve, reject) => {
var win = new BrowserWindow({autoHideMenuBar: true, show: false, width: 400, height: 600, resizable: false});
var {webContents} = win;

win.setSkipTaskbar(true);
win.setMenuBarVisibility(false);
win.setTitle('Welcome to the Learn IDE');

webContents.on('did-finish-load', () => win.show());

webContents.on('new-window', (e, url) => {
e.preventDefault();
win.destroy();
shell.openExternal(url);
});

webContents.on('will-navigate', (e, url) => {
if (url.match(/github_sign_in/)) {
win.destroy();
githubLogin().then(resolve);
}
});

webContents.on('did-get-redirect-request', (e, oldURL, newURL) => {
if (newURL.match(/ide_token/)) {
var token = _url.parse(newURL, true).query.ide_token;

if (token != null && token.length) {
confirmOauthToken(token).then((res) => {
if (!res) { return; }
_token.set(token);
resolve();
});
}
}

if (newURL.match(/github_sign_in/)) {
win.destroy();
githubLogin().then(resolve);
}
});

if (!win.loadURL(`${learnCo}/ide/sign_in?ide_onboard=true`)) {
win.destroy();
githubLogin.then(resolve);
}
})
}

export default function() {
var existingToken = _token.get();
return (!existingToken) ? learnSignIn() : confirmOauthToken(existingToken)
}
Loading