forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-theme.ts
102 lines (86 loc) · 2.55 KB
/
create-theme.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*-----------------------------------------------------------------------------
| 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}`);
});