1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var __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 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | const fs = __importStar(require("fs-extra"));
|
15 | const inquirer = __importStar(require("inquirer"));
|
16 | const path = __importStar(require("path"));
|
17 | const utils = __importStar(require("./utils"));
|
18 | let 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 | ];
|
35 | const template = `
|
36 | import {
|
37 | JupyterFrontEnd, JupyterFrontEndPlugin
|
38 | } from '@jupyterlab/application';
|
39 |
|
40 | import {
|
41 | IThemeManager
|
42 | } from '@jupyterlab/apputils';
|
43 |
|
44 |
|
45 | /**
|
46 | * A plugin for the {{title}}
|
47 | */
|
48 | const 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 |
|
63 | export default plugin;
|
64 | `;
|
65 | void inquirer.prompt(questions).then(answers => {
|
66 | let { name, title, description } = answers;
|
67 | let 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 | let jsonPath = path.join(dest, 'package.json');
|
74 | let data = utils.readJSONFile(jsonPath);
|
75 | data.name = name;
|
76 | data.description = description;
|
77 | utils.writePackageData(jsonPath, data);
|
78 |
|
79 | let 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 |
|
84 | ['lib', 'node_modules', 'static'].forEach(folder => {
|
85 | let folderPath = path.join('.', name, folder);
|
86 | if (fs.existsSync(folderPath)) {
|
87 | fs.removeSync(folderPath);
|
88 | }
|
89 | });
|
90 | let 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 |
|
96 | console.log(`Created new theme ${name}`);
|
97 | });
|
98 |
|
\ | No newline at end of file |