@@ -5,6 +5,9 @@ const glob = require('glob');
55const path = require ( 'path' ) ;
66
77const packageRoot = path . join ( __dirname , '../packages' ) ;
8+ const toolsRoot = path . join ( __dirname , '../tools' ) ;
9+ const distRoot = path . join ( __dirname , '../dist' ) ;
10+
811
912// All the supported packages. Go through the packages directory and create a map of
1013// name => fullPath.
@@ -20,7 +23,7 @@ const packages =
2023 let name = pkgJson [ 'name' ] ;
2124
2225 packages [ name ] = {
23- dist : path . join ( __dirname , '../dist' , pkg . name ) ,
26+ dist : path . join ( distRoot , pkg . name ) ,
2427 packageJson : path . join ( pkg . root , 'package.json' ) ,
2528 root : pkg . root ,
2629 relative : path . relative ( path . dirname ( __dirname ) , pkg . root ) ,
@@ -29,12 +32,38 @@ const packages =
2932 return packages ;
3033 } , { } ) ;
3134
35+ const tools = glob . sync ( path . join ( toolsRoot , '**/package.json' ) )
36+ . map ( toolPath => path . relative ( toolsRoot , path . dirname ( toolPath ) ) )
37+ . map ( toolName => {
38+ const root = path . join ( toolsRoot , toolName ) ;
39+ const pkgJson = JSON . parse ( fs . readFileSync ( path . join ( root , 'package.json' ) , 'utf8' ) ) ;
40+ const name = pkgJson [ 'name' ] ;
41+ const dist = path . join ( distRoot , toolName ) ;
42+
43+ return {
44+ name,
45+ main : path . join ( dist , pkgJson [ 'main' ] ) ,
46+ mainTs : path . join ( toolsRoot , toolName , pkgJson [ 'main' ] . replace ( / \. j s $ / , '.ts' ) ) ,
47+ root,
48+ packageJson : path . join ( toolsRoot , toolName , 'package.json' ) ,
49+ dist
50+ } ;
51+ } )
52+ . reduce ( ( tools , tool ) => {
53+ tools [ tool . name ] = tool ;
54+ return tools ;
55+ } , { } ) ;
56+
3257
33- module . exports = packages ;
58+ module . exports = { packages, tools } ;
3459
3560
3661// If we run this from the command line, just output the list of modules neatly formatted.
3762if ( require . main === module ) {
38- // eslint-disable-next-line no-console
63+ /* eslint-disable no-console */
64+ console . log ( 'Packages:' ) ;
3965 console . log ( JSON . stringify ( packages , null , 2 ) ) ;
66+ console . log ( '' ) ;
67+ console . log ( 'Tools:' ) ;
68+ console . log ( JSON . stringify ( tools , null , 2 ) ) ;
4069}
0 commit comments