123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /*-----------------------------------------------------------------------------
- | 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() {
- 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}`);
- });
|