Forráskód Böngészése

Make version and gitDescription part of the application

Steven Silvester 8 éve
szülő
commit
f14801a495
5 módosított fájl, 76 hozzáadás és 30 törlés
  1. 4 24
      jupyterlab/index.js
  2. 1 1
      jupyterlab/lab.html
  3. 21 2
      jupyterlab/loader.js
  4. 48 0
      src/application/index.ts
  5. 2 3
      src/statedb/plugin.ts

+ 4 - 24
jupyterlab/index.js

@@ -2,8 +2,6 @@
 // Distributed under the terms of the Modified BSD License.
 
 var JupyterLab = require('../lib/application').JupyterLab;
-var extractPlugins = require('@jupyterlab/extension-builder/lib/extract').extractPlugins;
-
 
 // ES6 Promise polyfill
 require('es6-promise').polyfill();
@@ -11,25 +9,7 @@ require('es6-promise').polyfill();
 require('font-awesome/css/font-awesome.min.css');
 require('../lib/default-theme/index.css');
 
-
-/**
- * Get an entry point given by the user after validating.
- */
-function getEntryPoint(entryPoint) {
-  var plugins = jupyter.require(entryPoint);
-  try {
-    plugins = extractPlugins(plugins);
-  } catch (err) {
-    console.error(err);
-    plugins = [];
-  }
-  return plugins;
-}
-
-
-jupyter.lab = new JupyterLab();
-jupyter.getEntryPoint = getEntryPoint;
-jupyter.version = require('../package.json').version;
-jupyter.gitDescription = process.env.GIT_DESCRIPTION;
-
-module.exports = jupyter.lab;
+module.exports = new JupyterLab({
+  version: require('../package.json').version,
+  gitDescription: process.env.GIT_DESCRIPTION
+});

+ 1 - 1
jupyterlab/lab.html

@@ -44,7 +44,7 @@ Distributed under the terms of the Modified BSD License.
 
 {% block script %}
 <script>
-  var lab = jupyter.require("{{ jupyterlab_main }}");
+  var lab = jupyter.lab = jupyter.require("{{ jupyterlab_main }}");
   var plugins = [];
 
   {% for plugin_entry in plugin_entries %}

+ 21 - 2
jupyterlab/loader.js

@@ -2,11 +2,30 @@
 // Distributed under the terms of the Modified BSD License.
 
 var ModuleLoader = require('@jupyterlab/extension-builder/lib/loader').ModuleLoader;
+var extractPlugins = require('@jupyterlab/extension-builder/lib/extract').extractPlugins;
 
 var loader = new ModuleLoader();
+var requireFunc = loader.require.bind(loader);
+
+
+/**
+ * Get an entry point given by the user after validating.
+ */
+function getEntryPoint(entryPoint) {
+  var plugins = requireFunc(entryPoint);
+  try {
+    plugins = extractPlugins(plugins);
+  } catch (err) {
+    console.error(err);
+    plugins = [];
+  }
+  return plugins;
+}
+
 
 module.exports = {
   define: loader.define.bind(loader),
-  require: loader.require.bind(loader),
-  requireBundle: loader.ensureBundle.bind(loader)
+  require: requireFunc,
+  requireBundle: loader.ensureBundle.bind(loader),
+  getEntryPoint: getEntryPoint
 }

+ 48 - 0
src/application/index.ts

@@ -26,6 +26,15 @@ type JupyterLabPlugin<T> = Application.IPlugin<JupyterLab, T>;
  */
 export
 class JupyterLab extends Application<ApplicationShell> {
+  /**
+   * Construct a new JupyterLab object.
+   */
+  constructor(options: JupyterLab.IOptions = {}) {
+    super();
+    this._version = options.version || 'unknown';
+    this._gitDescription = options.gitDescription || 'unknown';
+  }
+
   /**
    * A promise that resolves when the JupyterLab application is started.
    */
@@ -33,6 +42,20 @@ class JupyterLab extends Application<ApplicationShell> {
     return this._startedDelegate.promise;
   }
 
+  /**
+   * The version of the application.
+   */
+  get version() {
+    return this._version;
+  }
+
+  /**
+   * The git description of the application.
+   */
+  get gitDescription(): string {
+    return this._gitDescription;
+  }
+
   /**
    * Start the JupyterLab application.
    */
@@ -55,4 +78,29 @@ class JupyterLab extends Application<ApplicationShell> {
 
   private _startedDelegate = new utils.PromiseDelegate<void>();
   private _startedFlag = false;
+  private _version: string;
+  private _gitDescription: string;
+}
+
+
+/**
+ * The namespace for `JupyterLab` class statics.
+ */
+export
+namespace JupyterLab {
+  /**
+   * The options used to initialize a JupyterLab object.
+   */
+  export
+  interface IOptions {
+    /**
+     * The version of the JupyterLab application.
+     */
+    version?: string;
+
+    /**
+     * The git description of the JupyterLab application.
+     */
+    gitDescription?: string;
+  }
 }

+ 2 - 3
src/statedb/plugin.ts

@@ -40,8 +40,7 @@ const plugin: JupyterLabPlugin<IStateDB> = {
  */
 function activateState(app: JupyterLab, palette: ICommandPalette): Promise<IStateDB> {
   let state = new StateDB();
-  let jupyter = (window as any).jupyter;
-  let version = jupyter ? jupyter.version : 'unknown';
+  let version = app.version;
   let command = 'statedb:clear';
   let category = 'Help';
   let key = 'statedb:version';
@@ -49,7 +48,7 @@ function activateState(app: JupyterLab, palette: ICommandPalette): Promise<IStat
   let save = () => state.save(key, { version });
   let reset = () => state.clear().then(save);
   let check = (value: JSONObject) => {
-    let old = value && (value as any).version;
+    let old = value && value[version];
     if (!old || old !== version) {
       console.log(`Upgraded: ${old || 'unknown'} to ${version}; Resetting DB.`);
       return reset();