UNPKG

3.21 kBJavaScriptView Raw
1"use strict";
2/* -----------------------------------------------------------------------------
3| Copyright (c) Jupyter Development Team.
4| Distributed under the terms of the Modified BSD License.
5|----------------------------------------------------------------------------*/
6var __importStar = (this && this.__importStar) || function (mod) {
7 if (mod && mod.__esModule) return mod;
8 var result = {};
9 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
10 result["default"] = mod;
11 return result;
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14const fs = __importStar(require("fs-extra"));
15const inquirer = __importStar(require("inquirer"));
16const path = __importStar(require("path"));
17const utils = __importStar(require("./utils"));
18const questions = [
19 {
20 type: 'input',
21 name: 'name',
22 message: 'name: '
23 },
24 {
25 type: 'input',
26 name: 'title',
27 message: 'title: '
28 },
29 {
30 type: 'input',
31 name: 'description',
32 message: 'description: '
33 }
34];
35const template = `
36import {
37 JupyterFrontEnd, JupyterFrontEndPlugin
38} from '@jupyterlab/application';
39
40import {
41 IThemeManager
42} from '@jupyterlab/apputils';
43
44
45/**
46 * A plugin for the {{title}}
47 */
48const plugin: JupyterFrontEndPlugin<void> = {
49 id: '{{name}}:plugin',
50 requires: [IThemeManager],
51 activate: (app: JupyterFrontEnd, manager: IThemeManager) => {
52 manager.register({
53 name: '{{title}}',
54 isLight: true,
55 load: () => manager.loadCSS('{{name}}/index.css'),
56 unload: () => Promise.resolve(undefined)
57 });
58 },
59 autoStart: true
60};
61
62
63export default plugin;
64`;
65void inquirer.prompt(questions).then(answers => {
66 const { name, title, description } = answers;
67 const dest = path.resolve(path.join('.', name));
68 if (fs.existsSync(dest)) {
69 console.error('Package already exists: ', name);
70 process.exit(1);
71 }
72 fs.copySync(path.resolve('.', 'packages', 'theme-light-extension'), dest);
73 const jsonPath = path.join(dest, 'package.json');
74 const data = utils.readJSONFile(jsonPath);
75 data.name = name;
76 data.description = description;
77 utils.writePackageData(jsonPath, data);
78 // update the urls in urls.css
79 const filePath = path.resolve('.', name, 'style', 'urls.css');
80 let text = fs.readFileSync(filePath, 'utf8');
81 text = text.split('@jupyterlab/theme-light-extension').join(name);
82 fs.writeFileSync(filePath, text, 'utf8');
83 // remove lib, node_modules and static.
84 ['lib', 'node_modules', 'static'].forEach(folder => {
85 const folderPath = path.join('.', name, folder);
86 if (fs.existsSync(folderPath)) {
87 fs.removeSync(folderPath);
88 }
89 });
90 const readme = `${name}\n${description}\n`;
91 fs.writeFileSync(path.join('.', name, 'README.md'), readme, 'utf8');
92 let src = template.split('{{name}}').join(name);
93 src = src.split('{{title}}').join(title);
94 fs.writeFileSync(path.join('.', name, 'src', 'index.ts'), src, 'utf8');
95 // Signify successful complation.
96 console.debug(`Created new theme ${name}`);
97});
98//# sourceMappingURL=create-theme.js.map
\No newline at end of file