Skip to content

Commit 4f390a0

Browse files
authored
Merge pull request #314 from ianhi/ts
Convert frontend to typescript
2 parents 4faf35f + ae0ec2d commit 4f390a0

39 files changed

+7993
-3499
lines changed

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
dist
3+
coverage
4+
**/*.d.ts
5+
tests
6+
ipympl/nbextension/extension.js

.eslintrc.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: './tsconfig.json',
5+
sourceType: 'module',
6+
},
7+
extends: [
8+
'eslint:recommended',
9+
'plugin:@typescript-eslint/eslint-recommended',
10+
'plugin:@typescript-eslint/recommended',
11+
'plugin:prettier/recommended'
12+
],
13+
plugins: ['@typescript-eslint'],
14+
rules: {
15+
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
16+
'@typescript-eslint/no-explicit-any': 'off',
17+
'@typescript-eslint/no-namespace': 'off',
18+
'@typescript-eslint/no-use-before-define': 'off',
19+
'@typescript-eslint/explicit-module-boundary-types': 'off',
20+
'@typescript-eslint/quotes': [
21+
'error',
22+
'single',
23+
{ avoidEscape: true, allowTemplateLiterals: false }
24+
],
25+
curly: ['error', 'all'],
26+
eqeqeq: 'error',
27+
'prefer-arrow-callback': 'error'
28+
},
29+
ignorePatterns: ['.eslintrc.js']
30+
};

.github/workflows/main.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ jobs:
3737
channels: conda-forge
3838

3939
- name: Install ipympl
40-
run: pip install -e .
40+
run: |
41+
python -m build
42+
pip install dist/*.whl
4143
4244
- name: Check installation files
4345
run: |
@@ -58,8 +60,7 @@ jobs:
5860
- name: Test flake8
5961
run: flake8 ipympl --ignore=E501,W504,W503
6062

61-
- name: Test JS linters
62-
working-directory: js
63+
- name: Test TS linters
6364
run: |
6465
npm run eslint:check
6566
npm run prettier:check
@@ -138,7 +139,7 @@ jobs:
138139
139140
- name: Manually install labextension for lab2
140141
if: ${{ matrix.jlab_version }} == 2
141-
run: jupyter labextension install js
142+
run: jupyter labextension install .
142143

143144
- name: Test installation files
144145
run: |

.github/workflows/mpl-latest.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ jobs:
3030
- name: Install dependencies
3131
shell: bash -l {0}
3232
run: |
33-
mamba install python=${{ matrix.python-version }} pip nodejs ipywidgets=7.6 jupyter jupyterlab=3 pillow numpy flake8 pytest nbval
33+
mamba install python=${{ matrix.python-version }} pip nodejs ipywidgets=7.6 jupyter jupyterlab=3 pillow numpy flake8 pytest nbval yarn build
3434
pip install git+https://github.com/matplotlib/matplotlib.git
3535
3636
- name: Install ipympl
3737
shell: bash -l {0}
38-
run: pip install -e .
38+
run: |
39+
python -m build
40+
pip install dist/*.whl
3941
4042
- name: Check installation files
4143
shell: bash -l {0}

.gitignore

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,33 @@ build/
55
*.py[cod]
66
node_modules/
77

8-
# Generated Javascript
9-
ipympl/nbextension/
10-
ipympl/labextension/
11-
ipympl/*.tgz
12-
js/*.tgz
13-
148
# OS X
159
.DS_Store
1610

1711
# vscode
1812
.vscode/
13+
14+
lib/
15+
16+
# NPM
17+
# ----
18+
19+
**/node_modules/
20+
ipympl/nbextension/index.*
21+
ipympl/nbextension/package.json
22+
ipympl/labextension/*.tgz
23+
24+
# Coverage data
25+
# -------------
26+
**/coverage/
27+
28+
# Packed lab extensions
29+
ipympl/labextension
30+
31+
# OS specific items
32+
.DS_Store
33+
34+
# Sphinx documentation
35+
docs/_build/
36+
docs/source/_static/embed-bundle.js
37+
docs/source/_static/embed-bundle.js.map

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
**/node_modules
3+
**/lib
4+
**/package.json

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 4
4+
}

MANIFEST.in

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
recursive-include ipympl/nbextension *.*
22
recursive-include ipympl/labextension *.*
33

4-
graft js/src
5-
include js/package.json
6-
include js/webpack.config.js
7-
include LICENSE
8-
include jupyter-matplotlib.json
9-
104
include setup.py
115
include pyproject.toml
6+
7+
include tsconfig.json
8+
include package.json
9+
include webpack.config.js
10+
include ipympl/labextension/*.tgz
11+
12+
# Documentation
13+
graft docs
14+
exclude docs/\#*
15+
prune docs/build
16+
prune docs/gh-pages
17+
prune docs/dist
18+
19+
# Examples
20+
graft examples
21+
22+
# Javascript files
23+
graft ipympl/nbextension
24+
graft src
25+
graft css
26+
prune **/node_modules
27+
prune coverage
28+
prune lib
29+
30+
# Patterns to exclude from any directory
31+
global-exclude *~
32+
global-exclude *.pyc
33+
global-exclude *.pyo
34+
global-exclude .git
35+
global-exclude .ipynb_checkpoints

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,26 @@ notebook / lab frontend. For lab, this is done by the command:
9999

100100
```bash
101101
jupyter labextension develop --overwrite .
102-
npm run build
102+
yarn run build
103103
```
104104

105105
For classic notebook, you need to run:
106106
```bash
107-
jupyter nbextension install --py --symlink --sys-prefix ipympl
107+
jupyter nbextension install --py --symlink --sys-prefix --overwrite ipympl
108108
jupyter nbextension enable --py --sys-prefix ipympl
109109
```
110110

111111
#### How to see your changes
112112

113-
**Javascript**:
113+
**Typescript**:
114114

115-
You need to rebuild the JS when you make a code change:
115+
If you use JupyterLab to develop then you can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the widget.
116116

117117
```bash
118-
cd js
118+
# Watch the source directory in one terminal, automatically rebuilding when needed
119119
yarn run watch
120+
# Run JupyterLab in another terminal
121+
jupyter lab
120122
```
121123

122124
After a change wait for the build to finish and then refresh your browser and the changes should take effect.

babel.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
sourceMap: 'inline',
3+
presets: [
4+
[
5+
'@babel/preset-env',
6+
{
7+
targets: {
8+
node: 'current',
9+
},
10+
},
11+
],
12+
],
13+
};
14+

0 commit comments

Comments
 (0)