|
@@ -0,0 +1,104 @@
|
|
|
+/*-----------------------------------------------------------------------------
|
|
|
+| Copyright (c) Jupyter Development Team.
|
|
|
+| Distributed under the terms of the Modified BSD License.
|
|
|
+|----------------------------------------------------------------------------*/
|
|
|
+
|
|
|
+import * as fs from 'fs-extra';
|
|
|
+import * as inquirer from 'inquirer';
|
|
|
+import * as path from 'path';
|
|
|
+import * as utils from './utils';
|
|
|
+
|
|
|
+let questions = [
|
|
|
+ {
|
|
|
+ type: 'input',
|
|
|
+ name: 'name',
|
|
|
+ message: 'name: '
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'input',
|
|
|
+ name: 'title',
|
|
|
+ message: 'title: '
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'input',
|
|
|
+ name: 'description',
|
|
|
+ message: 'description: '
|
|
|
+ }
|
|
|
+];
|
|
|
+
|
|
|
+
|
|
|
+const template = `
|
|
|
+import {
|
|
|
+ JupyterLab, JupyterLabPlugin
|
|
|
+} from '@jupyterlab/application';
|
|
|
+
|
|
|
+import {
|
|
|
+ IThemeManager
|
|
|
+} from '@jupyterlab/apputils';
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * A plugin for the {{title}}
|
|
|
+ */
|
|
|
+const plugin: JupyterLabPlugin<void> = {
|
|
|
+ id: '{{name}}:plugin',
|
|
|
+ requires: [IThemeManager],
|
|
|
+ activate: function(app: JupyterLab, manager: IThemeManager) {
|
|
|
+ manager.register({
|
|
|
+ name: '{{title}}',
|
|
|
+ load: function() {
|
|
|
+ // Load the optional monospace font for the input/output prompt.
|
|
|
+ manager.loadCSS('https://fonts.googleapis.com/css?family=Roboto+Mono');
|
|
|
+ return manager.loadCSS('{{name}}/index.css');
|
|
|
+ },
|
|
|
+ unload: function() {
|
|
|
+ return Promise.resolve(void 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ autoStart: true
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+export default plugin;
|
|
|
+`;
|
|
|
+
|
|
|
+
|
|
|
+inquirer.prompt(questions).then(answers => {
|
|
|
+ let { name, title, description } = answers;
|
|
|
+ let dest = path.resolve(path.join('.', name));
|
|
|
+ if (fs.existsSync(dest)) {
|
|
|
+ console.error('Package already exists: ', name);
|
|
|
+ process.exit(1);
|
|
|
+ }
|
|
|
+ fs.copySync(path.resolve('.', 'packages', 'theme-light-extension'), dest);
|
|
|
+ let jsonPath = path.join(dest, 'package.json');
|
|
|
+ let data = utils.readJSONFile(jsonPath);
|
|
|
+ data.name = name;
|
|
|
+ data.description = description;
|
|
|
+ utils.writePackageData(jsonPath, data);
|
|
|
+
|
|
|
+ // update the urls in urls.css
|
|
|
+ let filePath = path.resolve('.', name, 'style', 'urls.css');
|
|
|
+ let text = fs.readFileSync(filePath, 'utf8');
|
|
|
+ text = text.split('@jupyterlab/theme-light-extension').join(name);
|
|
|
+ fs.writeFileSync(filePath, text, 'utf8');
|
|
|
+
|
|
|
+ // remove lib and node_modules.
|
|
|
+ ['lib', 'node_modules'].forEach(folder => {
|
|
|
+ let folderPath = path.join('.', name, folder);
|
|
|
+ if (fs.existsSync(folderPath)) {
|
|
|
+ fs.remove(folderPath);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ let readme = `${name}\n${description}\n`;
|
|
|
+ fs.writeFileSync(path.join('.', name, 'README.md'), readme, 'utf8');
|
|
|
+
|
|
|
+ let src = template.split('{{name}}').join(name);
|
|
|
+ src = src.split('{{title}}').join(title);
|
|
|
+ fs.writeFileSync(path.join('.', name, 'src', 'index.ts'), src, 'utf8');
|
|
|
+
|
|
|
+ // Signify successful complation.
|
|
|
+ console.log(`Created new theme ${name}`);
|
|
|
+});
|