Skip to content

Commit a490f1a

Browse files
authored
bundle flow-type definitions in the package (#5)
- implement a build step which will auto-generate the flow-type definitions based on TypeScript .d.ts files
1 parent 586f6a8 commit a490f1a

File tree

3 files changed

+87
-14
lines changed

3 files changed

+87
-14
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"coverage": "cross-env CI=1 react-scripts test --coverage --coverageReporters=text-lcov | coveralls",
2727
"prebuild": "rimraf dist",
2828
"build": "rollup -c",
29+
"postbuild": "node ./scripts/flowgen.js",
2930
"start": "rollup -c -w",
3031
"prepare": "yarn run build",
3132
"predeploy": "cd example && yarn install && yarn run build"
@@ -47,6 +48,8 @@
4748
"@types/react-test-renderer": "^16.8.1",
4849
"coveralls": "^3.0.3",
4950
"cross-env": "^5.2.0",
51+
"flowgen": "^1.9.0",
52+
"glob": "^7.1.4",
5053
"prettier": "^1.16.4",
5154
"prop-types": "^15.7.2",
5255
"react": "^16.8.4",

scripts/flowgen.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const fs = require('fs');
2+
const glob = require('glob');
3+
const { compiler, beautify } = require('flowgen');
4+
5+
console.group('Generating flow type definitions...');
6+
7+
const typeScriptDefinitions = glob.sync('dist/**/*.d.ts', {
8+
absolute: true,
9+
});
10+
11+
typeScriptDefinitions.forEach(path => {
12+
console.log('Transpiling flow type definitions from:', path);
13+
fs.writeFileSync(
14+
path.replace('.d.ts', '.js.flow'),
15+
beautify(
16+
`// @flow
17+
18+
${compiler.compileDefinitionFile(path)}
19+
`,
20+
),
21+
);
22+
});
23+
24+
console.log('Finished!');
25+
console.groupEnd();

yarn.lock

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,6 +4070,21 @@ flatten@^1.0.2:
40704070
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
40714071
integrity sha1-2uRqnXj74lKSJYzB54CkHZXAN4I=
40724072

4073+
flowgen@^1.9.0:
4074+
version "1.9.0"
4075+
resolved "https://registry.yarnpkg.com/flowgen/-/flowgen-1.9.0.tgz#a67dcd300574036cca9b0c42de142ae9885f8ff6"
4076+
integrity sha512-dDH1Degcdg+c/qKMgRAnXEg4Tdek/p4Ymn/JzJMG+A/olZ6o9V/F74Ygr4lX8ZS/x/QE/N8wwfRNWrh05jdX0A==
4077+
dependencies:
4078+
"@babel/code-frame" "^7.0.0"
4079+
"@babel/highlight" "^7.0.0"
4080+
commander "^2.11.0"
4081+
lodash "^4.17.4"
4082+
paralleljs "^0.2.1"
4083+
prettier "^1.16.4"
4084+
shelljs "^0.8.3"
4085+
typescript "^3.3.3333"
4086+
typescript-compiler "^1.4.1-2"
4087+
40734088
flush-write-stream@^1.0.0:
40744089
version "1.1.1"
40754090
resolved "https://registry.yarnpkg.com/flush-write-stream/-/flush-write-stream-1.1.1.tgz#8dd7d873a1babc207d94ead0c2e0e44276ebf2e8"
@@ -4303,10 +4318,10 @@ glob-to-regexp@^0.3.0:
43034318
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"
43044319
integrity sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs=
43054320

4306-
glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3:
4307-
version "7.1.3"
4308-
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1"
4309-
integrity sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==
4321+
glob@^7.0.0, glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4:
4322+
version "7.1.4"
4323+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
4324+
integrity sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==
43104325
dependencies:
43114326
fs.realpath "^1.0.0"
43124327
inflight "^1.0.4"
@@ -4899,6 +4914,11 @@ internal-ip@^3.0.1:
48994914
default-gateway "^2.6.0"
49004915
ipaddr.js "^1.5.2"
49014916

4917+
interpret@^1.0.0:
4918+
version "1.2.0"
4919+
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.2.0.tgz#d5061a6224be58e8083985f5014d844359576296"
4920+
integrity sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==
4921+
49024922
invariant@^2.2.2, invariant@^2.2.4:
49034923
version "2.2.4"
49044924
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
@@ -6962,6 +6982,11 @@ parallel-transform@^1.1.0:
69626982
inherits "^2.0.3"
69636983
readable-stream "^2.1.5"
69646984

6985+
paralleljs@^0.2.1:
6986+
version "0.2.1"
6987+
resolved "https://registry.yarnpkg.com/paralleljs/-/paralleljs-0.2.1.tgz#ebca745d3e09c01e2bebcc14858891ff4510e926"
6988+
integrity sha1-68p0XT4JwB4r68wUhYiR/0UQ6SY=
6989+
69656990
69666991
version "2.1.1"
69676992
resolved "https://registry.yarnpkg.com/param-case/-/param-case-2.1.1.tgz#df94fd8cf6531ecf75e6bef9a0858fbc72be2247"
@@ -8310,6 +8335,13 @@ realpath-native@^1.0.0:
83108335
dependencies:
83118336
util.promisify "^1.0.0"
83128337

8338+
rechoir@^0.6.2:
8339+
version "0.6.2"
8340+
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
8341+
integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=
8342+
dependencies:
8343+
resolve "^1.1.6"
8344+
83138345
83148346
version "2.2.2"
83158347
resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.2.tgz#9946fb3274e1628de6e36b2f6714953b4845094f"
@@ -8561,13 +8593,20 @@ [email protected]:
85618593
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
85628594
integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=
85638595

8564-
[email protected], resolve@^1.10.0, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.6.0, resolve@^1.8.1, resolve@^1.9.0:
8596+
85658597
version "1.10.0"
85668598
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.10.0.tgz#3bdaaeaf45cc07f375656dfd2e54ed0810b101ba"
85678599
integrity sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==
85688600
dependencies:
85698601
path-parse "^1.0.6"
85708602

8603+
resolve@^1.1.6, resolve@^1.10.0, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.6.0, resolve@^1.8.1, resolve@^1.9.0:
8604+
version "1.11.1"
8605+
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.11.1.tgz#ea10d8110376982fef578df8fc30b9ac30a07a3e"
8606+
integrity sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==
8607+
dependencies:
8608+
path-parse "^1.0.6"
8609+
85718610
restore-cursor@^2.0.0:
85728611
version "2.0.0"
85738612
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
@@ -8640,22 +8679,14 @@ rollup-plugin-typescript2@^0.20.1:
86408679
rollup-pluginutils "2.4.1"
86418680
tslib "1.9.3"
86428681

8643-
8682+
[email protected], rollup-pluginutils@^2.3.3:
86448683
version "2.4.1"
86458684
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.4.1.tgz#de43ab54965bbf47843599a7f3adceb723de38db"
86468685
integrity sha512-wesMQ9/172IJDIW/lYWm0vW0LiKe5Ekjws481R7z9WTRtmO59cqyM/2uUlxvf6yzm/fElFmHUobeQOYz46dZJw==
86478686
dependencies:
86488687
estree-walker "^0.6.0"
86498688
micromatch "^3.1.10"
86508689

8651-
rollup-pluginutils@^2.3.3:
8652-
version "2.3.3"
8653-
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.3.3.tgz#3aad9b1eb3e7fe8262820818840bf091e5ae6794"
8654-
integrity sha512-2XZwja7b6P5q4RZ5FhyX1+f46xi1Z3qBKigLRZ6VTZjwbN0K1IFGMlwm06Uu0Emcre2Z63l77nq/pzn+KxIEoA==
8655-
dependencies:
8656-
estree-walker "^0.5.2"
8657-
micromatch "^2.3.11"
8658-
86598690
rollup@^1.6.0:
86608691
version "1.6.0"
86618692
resolved "https://registry.yarnpkg.com/rollup/-/rollup-1.6.0.tgz#4329f4634718197c678d18491724d50d8b7ee76c"
@@ -8914,6 +8945,15 @@ [email protected]:
89148945
array-reduce "~0.0.0"
89158946
jsonify "~0.0.0"
89168947

8948+
shelljs@^0.8.3:
8949+
version "0.8.3"
8950+
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.3.tgz#a7f3319520ebf09ee81275b2368adb286659b097"
8951+
integrity sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==
8952+
dependencies:
8953+
glob "^7.0.0"
8954+
interpret "^1.0.0"
8955+
rechoir "^0.6.2"
8956+
89178957
shellwords@^0.1.1:
89188958
version "0.1.1"
89198959
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
@@ -9704,6 +9744,11 @@ typedarray@^0.0.6:
97049744
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
97059745
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
97069746

9747+
typescript-compiler@^1.4.1-2:
9748+
version "1.4.1-2"
9749+
resolved "https://registry.yarnpkg.com/typescript-compiler/-/typescript-compiler-1.4.1-2.tgz#ba4f7db22d91534a1929d90009dce161eb72fd3f"
9750+
integrity sha1-uk99si2RU0oZKdkACdzhYety/T8=
9751+
97079752
typescript@^3.3.3333:
97089753
version "3.3.3333"
97099754
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.3333.tgz#171b2c5af66c59e9431199117a3bcadc66fdcfd6"

0 commit comments

Comments
 (0)