Skip to content

Commit 1278aa7

Browse files
committed
feat: migration from js to ts
1 parent 558ba9b commit 1278aa7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+501
-228
lines changed

.babelrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

.babelrc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const presets = [
2+
[
3+
'@babel/preset-env',
4+
{
5+
modules: process.env.NODE_ENV === 'es' ? false : 'commonjs'
6+
}
7+
],
8+
'@babel/preset-react',
9+
'@babel/preset-typescript'
10+
]
11+
12+
const plugins = [
13+
'@babel/plugin-proposal-class-properties',
14+
'@babel/plugin-proposal-object-rest-spread'
15+
]
16+
17+
if (process.env.NODE_ENV === 'test') {
18+
plugins.push('@babel/plugin-transform-modules-commonjs')
19+
}
20+
21+
module.exports = { presets, plugins }

.circleci/config.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Javascript Node CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
docker:
9+
# specify the version you desire here
10+
- image: circleci/node:10.11
11+
12+
# Specify service dependencies here if necessary
13+
# CircleCI maintains a library of pre-built images
14+
# documented at https://circleci.com/docs/2.0/circleci-images/
15+
# - image: circleci/mongo:3.4.4
16+
17+
working_directory: ~/repo
18+
19+
steps:
20+
- checkout
21+
22+
# Download and cache dependencies
23+
- restore_cache:
24+
keys:
25+
- v1-dependencies-{{ checksum "package.json" }}
26+
# fallback to using the latest cache if no exact match is found
27+
- v1-dependencies-
28+
29+
- run: yarn install
30+
31+
- save_cache:
32+
paths:
33+
- node_modules
34+
key: v1-dependencies-{{ checksum "package.json" }}
35+
36+
# run tests!
37+
- run: yarn test
38+

.eslintrc.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ typings/
5757
# dotenv environment variables file
5858
.env
5959

60-
# dist dir
60+
# bundle dir
6161
lib
62+
es
6263

6364
package-lock.json

.npmignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
node_modules/
55
npm-debug.log
66

7+
src/
78
tests/
89
examples/
910
coverage/
11+
.circleci
12+
.vscode
1013

14+
.babelrc.js
1115
.travis.yml
1216
*.config.js
13-
.eslintrc.json
17+
tslint.json
18+
tsconfig.json
19+
.prettierrc
20+
commitlint.config.js

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierrc

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

.travis.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
sudo: false
12
language: node_js
23
cache:
34
directories:
@@ -6,13 +7,31 @@ cache:
67
notifications:
78
email: false
89
node_js:
10+
- '10'
11+
- '9'
912
- '8'
1013
before_script:
11-
- npm prune
14+
- PATH=${PATH//:\.\/node_modules\/\.bin/}
1215
after_success:
1316
- npm run build
14-
- npm run coveralls
15-
- npm run semantic-release
17+
- npm run coverage
18+
- npm install -g travis-deploy-once
19+
- travis-deploy-once "npm run semantic-release"
1620
branches:
1721
only:
1822
- master
23+
- dev
24+
- /^greenkeeper/.*$/
25+
before_deploy:
26+
- cd examples
27+
- npm install
28+
- npm run build
29+
deploy:
30+
provider: pages
31+
skip-cleanup: true
32+
github-token: $GH_TOKEN
33+
keep-history: false
34+
local-dir: examples/site
35+
on:
36+
branch: master
37+
node: '10'

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Yuki Zhang
3+
Copyright (c) 2017-present Yuki Zhang
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

examples/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/.storybook/.babelrc

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/.storybook/addons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
import '@storybook/addon-options/register'
2+
import '@storybook/addon-actions/register'

examples/.storybook/config.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { configure } from '@storybook/react'
22
import { setOptions } from '@storybook/addon-options'
33

4-
function loadStories() {
5-
require('../stories')
6-
// You can require as many stories as you need.
7-
}
8-
94
setOptions({
105
name: 'One React',
11-
url: '#'
6+
url: '#',
7+
goFullScreen: false,
8+
showAddonPanel: true,
9+
addonPanelInRight: true,
1210
})
1311

12+
// automatically import all files ending with *.story.tsx
13+
const req = require.context('../stories', true, /.story.tsx$/)
14+
function loadStories() {
15+
req.keys().forEach(filename => req(filename))
16+
}
17+
1418
configure(loadStories, module)

examples/.storybook/manager-head.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<script>
22
document.title = "One React"
33
</script>
4-
<link rel="icon" type="image/ico" href="favicon.ico" />
4+
<link rel="icon" type="image/png" href="https://cdn.rawgit.com/one-react/assets/2a4f10b4/logo.png">

examples/.storybook/webpack.config.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
const path = require('path')
22

3-
module.exports = {
4-
module: {
5-
rules: [
3+
module.exports = (baseConfig, env, defaultConfig) => {
4+
defaultConfig.module.rules.push({
5+
test: /\.(ts|tsx)$/,
6+
exclude: /node_modules/,
7+
use: [
68
{
7-
test: /\.scss$/,
8-
use: ['style-loader', 'css-loader', 'sass-loader'],
9+
loader: require.resolve('babel-loader'),
10+
options: {
11+
cacheDirectory: true,
12+
...require('../../.babelrc')
13+
}
914
},
10-
{
11-
test: /\.jsx?$/,
12-
use: {
13-
loader: 'babel-loader',
14-
options: {
15-
cacheDirectory: true,
16-
}
17-
},
18-
exclude: /node_modules/,
19-
}
15+
require.resolve('react-docgen-typescript-loader')
2016
]
21-
},
22-
resolve: {
23-
extensions: ['.js', '.jsx'],
24-
modules: ['node_modules', '../node_modules']
25-
},
17+
}, {
18+
test: /\.scss$/,
19+
use: ['style-loader', 'css-loader', 'sass-loader']
20+
})
21+
22+
defaultConfig.resolve.extensions.push('.ts', '.tsx')
23+
24+
defaultConfig.resolve.modules.push(
25+
path.resolve(__dirname, '../node_modules'),
26+
path.resolve(__dirname, '../../node_modules')
27+
)
28+
29+
defaultConfig.devServer = {
30+
inline: true,
31+
hot: true
32+
}
33+
34+
return defaultConfig
2635
}

examples/package.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
8-
"dev": "start-storybook -p 9001 -c .storybook",
9-
"build-storybook": "build-storybook -s public",
10-
"deploy": "storybook-to-ghpages"
7+
"dev": "start-storybook -s public -p 9001 -c .storybook",
8+
"build": "build-storybook -s public -o site"
119
},
12-
"storybook-deployer": {
13-
"gitUsername": "Yuki Bot",
14-
"gitEmail": "zhangjihong1993@gmail.com",
15-
"commitMessage": "Deploy Storybook"
16-
},
17-
"author": "",
10+
"author": "foryuki <foryuki@outlook.com>",
1811
"license": "MIT",
1912
"devDependencies": {
20-
"@storybook/addon-options": "^3.2.17",
21-
"@storybook/react": "^3.2.15",
22-
"css-loader": "^0.28.7",
13+
"@babel/core": "^7.0.1",
14+
"@storybook/addon-info": "^3.4.10",
15+
"@storybook/addon-options": "^3.4.10",
16+
"@storybook/react": "^3.4.10",
17+
"@types/storybook__addon-actions": "^3.4.1",
18+
"@types/storybook__addon-info": "^3.4.2",
19+
"@types/storybook__react": "^3.0.9",
20+
"babel-loader": "^8.0.2",
21+
"css-loader": "^1.0.0",
2322
"node-sass": "^4.7.2",
24-
"sass-loader": "^6.0.6",
25-
"style-loader": "^0.19.0"
23+
"react-docgen-typescript-loader": "^3.0.0",
24+
"sass-loader": "^7.1.0",
25+
"style-loader": "^0.23.0",
26+
"typescript": "^3.0.3"
2627
},
2728
"dependencies": {
2829
"react": "^16.1.1",

examples/public/.gitkeep

Whitespace-only changes.

examples/public/favicon.ico

-561 Bytes
Binary file not shown.

examples/stories/controlled.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

examples/stories/example.story.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { PureComponent } from 'react'
2+
3+
import { Switch } from '../../src'
4+
5+
class Example extends PureComponent {
6+
state = {
7+
value1: false,
8+
value2: true
9+
}
10+
11+
render() {
12+
return (
13+
<div>
14+
<div className="title">
15+
是否开启: {this.state.value1 ? 'YES' : 'NO'}
16+
</div>
17+
<Switch isChecked={this.state.value1} onChange={this.handleChange1} />
18+
<div className="title">
19+
是否开启: {this.state.value2 ? 'YES' : 'NO'}
20+
</div>
21+
<Switch isChecked={this.state.value2} onChange={this.handleChange2} />
22+
</div>
23+
)
24+
}
25+
26+
handleChange1 = isChecked => {
27+
this.setState({
28+
value1: isChecked
29+
})
30+
}
31+
32+
handleChange2 = isChecked => {
33+
this.setState({
34+
value2: isChecked
35+
})
36+
}
37+
}
38+
39+
export default Example

0 commit comments

Comments
 (0)