File tree Expand file tree Collapse file tree 7 files changed +32
-6
lines changed
Expand file tree Collapse file tree 7 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,8 @@ $ dts-bundle-proxy -c dts-bundle.json
4343 "proxyjs" : {
4444 "default" : " Hello" ,
4545 "generateDir" : " ./dist" ,
46- "requireFile" : " ./dist/build.js"
46+ "requireFile" : " ./dist/build.js" ,
47+ "exportAsDefault" : true
4748 }
4849}
4950```
@@ -56,6 +57,7 @@ $ dts-bundle-proxy -c dts-bundle.json
5657| default | string | none | Parts that must be included. |
5758| generateDir ` * ` | string | none | Parts that will be generated js files. |
5859| requireFile ` * ` | string | none | Bundled js file from where proxy will be made. |
60+ | exportAsDefault | bool | true | Generated js files exported as default. |
5961
6062` * ` - Required.
6163
Original file line number Diff line number Diff line change 66 "proxyjs" : {
77 "default" : " Hello" ,
88 "outDir" : " ./dist" ,
9- "requireFile" : " ./dist/build.js"
9+ "requireFile" : " ./dist/build.js" ,
10+ "exportAsDefault" : true
1011 }
1112}
Original file line number Diff line number Diff line change 77 "build" : " tsc -p ." ,
88 "prepublish" : " npm run build"
99 },
10- "author" :
" Giedrius Grabauskas <[email protected] >, Martynas Zilinskas <[email protected] >" ,
10+ "repository" : {
11+ "type" : " git" ,
12+ "url" : " git+https://github.com/QuatroCode/dts-bundle-proxyjs.git"
13+ },
14+ "authors" : [
15+ " Giedrius Grabauskas <[email protected] >" ,
16+ " Martynas Zilinskas <[email protected] >" 17+ ],
1118 "license" : " GPL-3.0" ,
19+ "bugs" : {
20+ "url" : " https://github.com/QuatroCode/dts-bundle-proxyjs/issues"
21+ },
22+ "homepage" : " https://github.com/QuatroCode/dts-bundle-proxyjs#readme" ,
1223 "devDependencies" : {
1324 "@types/cli-color" : " ^0.3.28" ,
1425 "@types/mkdirp" : " ^0.3.28" ,
2435 "bin" : {
2536 "dts-bundle-proxyjs" : " ./dist/cli.js"
2637 }
27- }
38+ }
Original file line number Diff line number Diff line change @@ -16,6 +16,11 @@ export default yargs
1616 describe : 'Bundled require default export.' ,
1717 type : 'string'
1818 } )
19+ . option ( 'exportAsDefault' , {
20+ describe : 'Generated js files exported as default.' ,
21+ type : 'boolean' ,
22+ default : undefined
23+ } )
1924 . option ( 'outDir' , {
2025 alias : 'o' ,
2126 describe : 'Where generate JS files.' ,
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ class Cli {
4141 if ( args . default != null ) config . proxyjs . default = args . default ;
4242 if ( args . outDir != null ) config . proxyjs . outDir = args . outDir ;
4343 if ( args . requireFile != null ) config . proxyjs . requireFile = args . requireFile ;
44+ if ( args . exportAsDefault != null ) config . proxyjs . exportAsDefault = args . exportAsDefault ;
4445 if ( config . baseDir == null ) config . baseDir = '' ;
4546 if ( config . proxyjs . outDir == null ) {
4647 this . throwError ( '[Error] In proxyjs config `outDir` is undefined.' ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export interface Config {
66 default : string ;
77 outDir : string ;
88 requireFile : string ;
9+ exportAsDefault : boolean ;
910 }
1011}
1112
@@ -17,4 +18,5 @@ export interface Arguments {
1718 default : string ;
1819 outDir : string ;
1920 requireFile : string ;
21+ exportAsDefault : boolean ;
2022}
Original file line number Diff line number Diff line change @@ -63,7 +63,11 @@ export default class Generator {
6363 if ( this . config . proxyjs . default === moduleName ) {
6464 moduleName = 'default' ;
6565 }
66- return `module.exports.default = require('${ requirePath } ').${ moduleName } ;` ;
66+ let exporterPrefix = "module.exports" ;
67+ if ( this . config . proxyjs . exportAsDefault === undefined || this . config . proxyjs . exportAsDefault != null && this . config . proxyjs . exportAsDefault ) {
68+ exporterPrefix += ".default" ;
69+ }
70+ return `${ exporterPrefix } = require('${ requirePath } ').${ moduleName } ;` ;
6771 }
6872
6973 private cleanModule ( string : string ) {
@@ -76,7 +80,7 @@ export default class Generator {
7680 if ( path . sep !== "/" ) {
7781 filePath = filePath . split ( path . sep ) . join ( '/' ) ;
7882 }
79-
83+
8084 if ( filePath . indexOf ( '../' ) !== 0 ) {
8185 filePath = './' + filePath ;
8286 }
You can’t perform that action at this time.
0 commit comments