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

Use NPM, node ES5, and browserify. #268

Merged
merged 54 commits into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ff9406f
require.js ES5 -> commonjs ES5
jdfreder Aug 11, 2015
b88fa01
Use npm for js and less builds
jdfreder Aug 11, 2015
8f0ea42
Allow for graceful failure by finishing string. ;)
rgbkrk Aug 11, 2015
22fd1bc
Ignore some gunk.
rgbkrk Aug 11, 2015
6a29601
Install jquery from npm (needed as dependency).
rgbkrk Aug 11, 2015
ad80ae9
Fix bugs :bug:
jdfreder Aug 12, 2015
6469065
Re-add require.js for backwards compat.
jdfreder Aug 12, 2015
c180719
Post install bower install
jdfreder Aug 12, 2015
81a2998
Dynamically load contents, also browserify contents.
jdfreder Aug 12, 2015
3498a51
Get all of the apps working except notebookapp
jdfreder Aug 12, 2015
f7d546c
Add clean script
jdfreder Aug 12, 2015
37d92cb
Fix jquery dependency
jdfreder Aug 12, 2015
2332b71
Get the notebook working!
jdfreder Aug 12, 2015
72bdf87
Fix package check
jdfreder Aug 12, 2015
e0f3141
Magic r.js stuff
jdfreder Aug 14, 2015
c8ff593
Move source out
jdfreder Aug 14, 2015
4c07a8b
Add new cjs conversion method
jdfreder Aug 14, 2015
a719e19
Add script to amd-ify the commonjs code,
jdfreder Aug 14, 2015
6258f54
Almost working 100%
jdfreder Aug 14, 2015
b2ae17d
Fix some problems reported by Matthias
jdfreder Aug 17, 2015
aa097ba
Add typeahead npm ref
jdfreder Aug 17, 2015
c0a30d4
Commandpalette
jdfreder Aug 17, 2015
2bb0957
Don't try loading cluster stuff in namespace.
jdfreder Aug 18, 2015
b2bf69f
fix jsversion command
jdfreder Aug 18, 2015
72d052e
Debowerify and google caja support
jdfreder Aug 19, 2015
b8f25ee
Remove debowerify
jdfreder Aug 19, 2015
81e0fb3
Change global namespace logic to placehold with `null`
jdfreder Aug 19, 2015
89f8dfa
Use npm to include legacy namespace components.
jdfreder Aug 19, 2015
f299381
Make sure destination exists
jdfreder Aug 19, 2015
9fe3f63
Fix global flag of jprop function in namespace
jdfreder Aug 19, 2015
0650a19
Fix Toolbar reference
jdfreder Aug 19, 2015
0a1854a
Fix remaining problems in namespace
jdfreder Aug 19, 2015
541aed3
Add defferred loading of jquery in terminal
jdfreder Aug 19, 2015
7df0a11
Make caja point to the same file
jdfreder Aug 19, 2015
55dd626
Fix tests
jdfreder Aug 19, 2015
e44d912
Let kyle work on things
jdfreder Aug 19, 2015
84c9cb7
Move version line into contruction block
jdfreder Aug 19, 2015
b0ec31d
Fix Caja
jdfreder Aug 19, 2015
b0cd502
Add detail to nbextension test.
jdfreder Aug 19, 2015
0bc24c5
Remove logs
jdfreder Aug 19, 2015
a9610dc
Assume idle if late loaded.
jdfreder Aug 19, 2015
69bb4b1
Truely load jquery, jqueryui, and bootstrap as globals.
jdfreder Aug 20, 2015
c802038
Remove jquery, jqueryui, and bootstrap from npm packages
jdfreder Aug 20, 2015
84ce0ce
Address @rgbkrk 's comments
jdfreder Aug 21, 2015
8c8c95c
Load CodeMirror once globally
jdfreder Aug 21, 2015
467ae32
Make sure requirejs can't be set more than once.
jdfreder Aug 21, 2015
7f41017
Don't use bind
jdfreder Aug 21, 2015
3bc3fda
Travis you old fart, get modern with a phantomjs from this century :p…
jdfreder Aug 21, 2015
b689700
Only build once, via npm postinstall
jdfreder Aug 21, 2015
03a5b47
Assume undefined is idle.
jdfreder Aug 22, 2015
7717a98
Load underscore globally
jdfreder Aug 22, 2015
307d9ee
Include components in setup base
blink1073 Aug 26, 2015
511bb68
Move search and replace into the right directory
jdfreder Aug 26, 2015
8ca1e85
commonjs-ify searchandreplace
jdfreder Aug 26, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ src

*.swp
*.map

.eggs/

# Bundled/generated JavaScript
notebook/static/auth/js
notebook/static/base/js
notebook/static/edit/js
notebook/static/notebook/js
notebook/static/services
notebook/static/terminal/js
notebook/static/tree/js

# npm logs
npm-debug.log
6 changes: 6 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"browserify": true,
"node": true,
"jquery": true,
"predef": [ "requirejs", "define", "Promise", "CodeMirror"]
}
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,36 @@ pip install --pre -e .
jupyter notebook
```

## Working on the frontend
The Notebook frontend depends on a wide set of libraries and package managers.
NPM is used to macro manage the frontend build process. You can build the
frontend Javascript and LESS by running

```
npm run build
```

If you need to build the Javascript alone

```
npm run build:js
```

Or LESS

```
npm run build:css
```

To build specific sub components, separate using a colon. i.e. to build only
the terminal's Javascript

```
npm run build:js:terminal
```

To clean all built output

```
npm run clean
```
15 changes: 8 additions & 7 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
"name": "jupyter-notebook-deps",
"version": "0.0.1",
"dependencies": {
"backbone": "components/backbone#~1.2",
"bootstrap": "components/bootstrap#~3.3",
"bootstrap-tour": "0.9.0",
"codemirror": "~5.5",
"es6-promise": "~1.0",
"font-awesome": "components/font-awesome#~4.2.0",
"requirejs": "~2.1",
"google-caja": "5669",
"MathJax": "components/MathJax#~2.5",
"bootstrap": "components/bootstrap#~3.3",
"bootstrap-tour": "0.9.0",
"jquery": "components/jquery#~2.0",
"jquery-ui": "components/jqueryui#~1.10",
"codemirror": "~5.5",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON doesn't support comments, so I'm leaving one here in GitHub. The following packages can be removed from bower and the setupbase check now, but I left them here for backwards compatibility... In case any users are loading them in via requirejs.

"term.js": "chjj/term.js#~0.0.4",
"backbone": "components/backbone#~1.2",
"marked": "~0.3",
"MathJax": "components/MathJax#~2.5",
"moment": "~2.8.4",
"requirejs": "~2.1",
"term.js": "chjj/term.js#~0.0.4",
"text-encoding": "~0.1",
"underscore": "components/underscore#~1.5",
"jquery-typeahead": "~2.0.0"
Expand Down
35 changes: 35 additions & 0 deletions notebook/amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var amdWrap = require("amd-wrap-legacy");
var glob = require("glob");
var path = require('path');
var fs = require('fs');
var mkdirp = require("mkdirp");

var source = "./notebook/static-src";
var destination = "./notebook/static";

glob(path.join(source, "**/*.js"), function(err, files) {
if (err) {
console.error('Could not glob files.', err);
} else {
files.forEach(function(file, index) {
var toFile = path.join(destination, path.relative(source, file));
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
console.error('Could not read file ' + file, err);
} else {
mkdirp(path.dirname(toFile), function(err) {
if (err) {
console.error('Could not mkdirp ', err);
} else {
fs.writeFile(toFile, amdWrap(data), function(err) {
if(err) {
return console.error('Could not write file ' + toFile, err);
}
});
}
});
}
});
});
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 changes: 2 additions & 2 deletions notebook/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def ws_url(self):
@property
def contents_js_source(self):
self.log.debug("Using contents: %s", self.settings.get('contents_js_source',
'services/contents'))
return self.settings.get('contents_js_source', 'services/contents')
'services/contents.bundle'))
return self.settings.get('contents_js_source', 'services/contents.bundle')

#---------------------------------------------------------------
# Manager objects
Expand Down
35 changes: 35 additions & 0 deletions notebook/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var fs = require('fs');
var aliasify = require('aliasify');
var browserify = require('browserify');
var mkdirp = require("mkdirp");
var path = require('path');

var aliasifyConfig = {
aliases: {
jqueryui: 'jquery-ui',
termjs: 'term.js',
caja: 'google-caja/html-css-sanitizer-minified'
},
verbose: false
}

var b = browserify({
paths: [
__dirname + '/static-src',
__dirname + '/static/components',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the issue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using debowerify to handle bower components for me, but something about the .. in the relative paths caused the whole thing to barf. This is an alternative that allows me to reference bower components, which are not available in npm.

],
debug: true,
fullPaths: true
});

b.transform(aliasify, aliasifyConfig);
var mkdirp = require("mkdirp");
b.add(__dirname + '/static-src/' + process.argv[2]);
var toFile = __dirname + '/static/' + process.argv[3];
mkdirp(path.dirname(toFile), function(err) {
if (err) {
console.error('Could not mkdirp ', err);
} else {
b.bundle().pipe(fs.createWriteStream(toFile));
}
});
14 changes: 14 additions & 0 deletions notebook/static-src/auth/js/loginmain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

var IPython = require('base/js/namespace');
var page = require('base/js/page');

module.exports = function loginMain() {
var page_instance = new page.Page();
$('button#login_submit').addClass("btn btn-default");
page_instance.show();
$('input#password_input').focus();

IPython.page = page_instance;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

define([
'base/js/utils',
'jquery',
], function(utils, $){
"use strict";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is cleaner.

I wonder if we should be declaring jquery global in the files in addition to the jshintrc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already did :)


var utils = require('base/js/utils');

var LoginWidget = function (selector, options) {
options = options || {};
this.base_url = options.base_url || utils.get_body_data("baseUrl");
Expand Down Expand Up @@ -34,5 +32,4 @@ define([
});
};

return {'LoginWidget': LoginWidget};
});
exports.LoginWidget = LoginWidget;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

define(['base/js/namespace', 'base/js/page'], function(IPython, page) {
function logout_main() {
var IPython = require('base/js/namespace');
var page = require('base/js/page');

module.exports = function logoutMain() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that since we were returning a function it's cool that the name changed here to the JavaScriptism of CamelCase.

var page_instance = new page.Page();
page_instance.show();

IPython.page = page_instance;
}
return logout_main;
});
};
5 changes: 5 additions & 0 deletions notebook/static-src/auth/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

exports.login_main = require('./loginmain');
exports.logout_main = require('./logoutmain');
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

define(function(require) {
"use strict";

var CodeMirror = require('codemirror/lib/codemirror');
var $ = require('jquery');

/**
* A wrapper around bootstrap modal for easier use
Expand Down Expand Up @@ -37,7 +33,6 @@ define(function(require) {
*
**/
var modal = function (options) {

var modal = $("<div/>")
.addClass("modal")
.addClass("fade")
Expand Down Expand Up @@ -198,13 +193,11 @@ define(function(require) {
});

modal_obj.on('shown.bs.modal', function(){ editor.refresh(); });

};
var dialog = {

module.exports = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

modal : modal,
kernel_modal : kernel_modal,
edit_metadata : edit_metadata,
};

return dialog;
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@
// require(['base/js/events'], function (events) {
// events.on("event.Namespace", function () { do_stuff(); });
// });
"use strict";

define(['base/js/namespace', 'jquery'], function(IPython, $) {
"use strict";

if (!window.jupyterEvents) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so here begins the re-write of the events. Glad you figured this one out.

var Events = function () {};

var events = new Events();

// Backwards compatability.
IPython.Events = Events;
IPython.events = events;

return $([events]);
});
window.jupyterEvents = $([new Events()]);
}

module.exports = window.jupyterEvents;
94 changes: 94 additions & 0 deletions notebook/static-src/base/js/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

"use strict";

/**
* jquery, jquery-ui, and bootstrap all really on weird window level logic.
* This module handles the global loading of those tools.
*/
module.exports = new Promise(function(resolve, reject) {
if (window.hasOwnProperty('jquery')) {
resolve();
}

requirejs(['jquery'], function($) {
var jQueryProperty = {
get: function() {
return $;
},
configurable: false
};
Object.defineProperty(window, '$', jQueryProperty);
Object.defineProperty(window, 'jQuery', jQueryProperty);
console.log('jQuery loaded and available in global namespace');

requirejs(['jqueryui', 'bootstrap'], function() {
if ($.prototype.modal) {
console.log('bootstrap loaded and injected into jQuery\'s namespace');
} else {
reject(new Error('bootstrap not injected into jQuery prototype'));
}

if ($.prototype.draggable && $.prototype.resizable) {
console.log('jQueryUI loaded and injected into jQuery\'s namespace');
} else {
reject(new Error('jQueryUI not injected into jQuery prototype'));
}

requirejs([
'codemirror/lib/codemirror',
'codemirror/mode/meta',
'codemirror/addon/comment/comment',
'codemirror/addon/dialog/dialog',
'codemirror/addon/edit/closebrackets',
'codemirror/addon/edit/matchbrackets',
'codemirror/addon/search/searchcursor',
'codemirror/addon/search/search',
'codemirror/keymap/emacs',
'codemirror/keymap/sublime',
'codemirror/keymap/vim',
'codemirror/mode/python/python',
'codemirror/addon/runmode/runmode',
'codemirror/mode/gfm/gfm',
'notebook/js/codemirror-ipython',
'notebook/js/codemirror-ipythongfm'
], function(CodeMirror) {
var codeMirrorProperty = {
get: function() {
return CodeMirror;
},
configurable: false
};
Object.defineProperty(window, 'CodeMirror', codeMirrorProperty);
console.log('CodeMirror loaded and available in global namespace');


requirejs(['underscore'], function(_) {
var underscoreProperty = {
get: function() {
return _;
},
configurable: false
};
Object.defineProperty(window, '_', underscoreProperty);
console.log('underscore loaded and available in global namespace');

resolve();
}, function(err) {
console.error('could not load underscore');
reject(err);
});
}, function(err) {
console.error('could not load CodeMirror and/or it\'s plugins');
reject(err);
});
}, function(err) {
console.error('could not load jqueryui and/or bootstrap');
reject(err);
});
}, function(err) {
console.error('could not load jquery');
reject(err);
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I look forward to this one being cleaned up in a different PR later. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go for it : )

Loading