@@ -15,18 +15,57 @@ const shelljs = require('shelljs');
1515
1616const { fetchTargets, fetchTopologicalSorting } = require ( './utils' ) ;
1717
18+ function buildES6 ( target ) {
19+ const { code } = shelljs . exec (
20+ `yarn tsc --project ${ path . join (
21+ target . location ,
22+ 'tsconfig.json'
23+ ) } --outDir ${ path . resolve ( './dist' , target . folderName , 'lib' ) } `
24+ ) ;
25+
26+ if ( code !== 0 ) {
27+ throw new Error ( `fail to compile the ${ target . name } ` ) ;
28+ }
29+ }
30+
31+ function buildCommonjs ( target ) {
32+ const { code } = shelljs . exec (
33+ `yarn tsc --project ${ path . join (
34+ target . location ,
35+ 'tsconfig.json'
36+ ) } --outDir ${ path . resolve (
37+ './dist' ,
38+ target . folderName ,
39+ 'src'
40+ ) } --module commonjs`
41+ ) ;
42+
43+ if ( code !== 0 ) {
44+ throw new Error ( `fail to compile the ${ target . name } ` ) ;
45+ }
46+ }
47+
48+ async function updatePackageJson ( target ) {
49+ const packageJsonPath = `${ path . resolve (
50+ './dist' ,
51+ target . folderName ,
52+ 'package.json'
53+ ) } `;
54+ const json = await fsEx . readJson ( packageJsonPath ) ;
55+ json . main = './src/index.js' ;
56+ json . types = './src/index.d.ts' ;
57+ json . module = './lib/index.js' ;
58+ json . exports = {
59+ require : './src/index.js' ,
60+ import : './lib/index.js'
61+ } ;
62+ await fsEx . writeJson ( packageJsonPath , json , { spaces : 2 } ) ;
63+ }
64+
1865async function buildTarget ( target ) {
1966 if ( target . private !== true ) {
20- const { code } = shelljs . exec (
21- `yarn tsc --project ${ path . join (
22- target . location ,
23- 'tsconfig.json'
24- ) } --outDir ${ path . resolve ( './dist' , target . folderName ) } `
25- ) ;
26-
27- if ( code !== 0 ) {
28- throw new Error ( `fail to compile the ${ target . name } ` ) ;
29- }
67+ buildES6 ( target ) ;
68+ buildCommonjs ( target ) ;
3069 const files = [ 'package.json' , 'README.md' , 'LICENSE' ] ;
3170 const copyTasks = files
3271 . map ( file => {
@@ -38,7 +77,7 @@ async function buildTarget(target) {
3877 . map ( f => fs . copyFile ( f . src , f . dest ) ) ;
3978 await Promise . all ( copyTasks ) ;
4079 console . log ( `${ colors . blue ( target . name ) } ${ colors . green ( 'success' ) } 🚀` ) ;
41-
80+ updatePackageJson ( target ) ;
4281 await fs . rm ( `${ path . resolve ( './node_modules/' + target . name ) } ` , {
4382 force : true ,
4483 recursive : true
0 commit comments