Skip to content

Commit f82eeca

Browse files
Release v0.4.0 (#5)
1 parent fa488a0 commit f82eeca

File tree

7 files changed

+32
-6
lines changed

7 files changed

+32
-6
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

example/dts-bundle.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"proxyjs": {
77
"default": "Hello",
88
"outDir": "./dist",
9-
"requireFile": "./dist/build.js"
9+
"requireFile": "./dist/build.js",
10+
"exportAsDefault": true
1011
}
1112
}

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@
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",
@@ -24,4 +35,4 @@
2435
"bin": {
2536
"dts-bundle-proxyjs": "./dist/cli.js"
2637
}
27-
}
38+
}

src/arguments.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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.',

src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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.');

src/contracts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

src/generator.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)