Skip to content

Commit fa488a0

Browse files
author
Martynas Žilinskas
authored
Feature/v0.3.0 (#4)
* Added missing index.js. * Fixed relative path. * 0.2.0 * Another generating require relative path fix. * Fixed generator path appender. * Renemade to outDir #1. * Fixed default generator appender. * Renamed g to o argument. * Added config checks for required arguments. * Fixed examples. * 0.3.0 * 0.3.0
1 parent 2caadf5 commit fa488a0

File tree

8 files changed

+22
-16
lines changed

8 files changed

+22
-16
lines changed

example/dist/hello.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* Generated by main-file-generator */
2-
module.exports.default = require('./build.js').Default;
2+
module.exports.default = require('./build.js').default;

example/dts-bundle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"removeSource": true,
66
"proxyjs": {
77
"default": "Hello",
8-
"generateDir": "./dist",
8+
"outDir": "./dist",
99
"requireFile": "./dist/build.js"
1010
}
1111
}

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "example-lib",
3-
"version": "1.0.0",
3+
"version": "0.3.0",
44
"main": "./dist/index.js",
55
"devDependencies": {
66
"rollup": "^0.34.7",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dts-bundle-proxyjs",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "Generates JS proxies from bundled dts.",
55
"main": "index.js",
66
"scripts": {

src/arguments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export default yargs
1313
})
1414
.option('default', {
1515
alias: 'd',
16-
describe: 'Bundled default export.',
16+
describe: 'Bundled require default export.',
1717
type: 'string'
1818
})
19-
.option('generatedir', {
20-
alias: 'g',
19+
.option('outDir', {
20+
alias: 'o',
2121
describe: 'Where generate JS files.',
2222
type: 'string'
2323
})
24-
.option('requirefile', {
24+
.option('requireFile', {
2525
alias: 'r',
2626
describe: 'Bundled JS main file.',
2727
type: 'string'

src/cli.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ class Cli {
3939

4040
private getConfig(config: Contracts.Config, args: Contracts.Arguments) {
4141
if (args.default != null) config.proxyjs.default = args.default;
42-
if (args.generatedir != null) config.proxyjs.generateDir = args.generatedir;
43-
if (args.requirefile != null) config.proxyjs.requireFile = args.requirefile;
42+
if (args.outDir != null) config.proxyjs.outDir = args.outDir;
43+
if (args.requireFile != null) config.proxyjs.requireFile = args.requireFile;
4444
if (config.baseDir == null) config.baseDir = '';
45+
if (config.proxyjs.outDir == null) {
46+
this.throwError('[Error] In proxyjs config `outDir` is undefined.');
47+
}
48+
if (config.proxyjs.requireFile == null) {
49+
this.throwError('[Error] In proxyjs config `requireFile` is undefined.');
50+
}
4551
return config;
4652
}
4753

src/contracts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface Config {
44
out: string;
55
proxyjs: {
66
default: string;
7-
generateDir: string;
7+
outDir: string;
88
requireFile: string;
99
}
1010
}
@@ -15,6 +15,6 @@ export interface Arguments {
1515
help: boolean;
1616
version: boolean;
1717
default: string;
18-
generatedir: string;
19-
requirefile: string;
18+
outDir: string;
19+
requireFile: string;
2020
}

src/generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class Generator {
3737
console.info(clc.yellow('Generating files:'));
3838
matches.forEach((match: string) => {
3939
let cleanedMatch = this.cleanModule(match);
40-
let fullFilePath = path.join(process.cwd(), this.config.proxyjs.generateDir, `${match}.js`);
40+
let fullFilePath = path.join(process.cwd(), this.config.proxyjs.outDir, `${match}.js`);
4141
// Make sure that all folders are created.
4242
mkdirp.sync(path.dirname(fullFilePath));
4343

@@ -61,7 +61,7 @@ export default class Generator {
6161

6262
private generateLine(requirePath: string, moduleName: string) {
6363
if (this.config.proxyjs.default === moduleName) {
64-
moduleName = 'Default';
64+
moduleName = 'default';
6565
}
6666
return `module.exports.default = require('${requirePath}').${moduleName};`;
6767
}
@@ -77,7 +77,7 @@ export default class Generator {
7777
filePath = filePath.split(path.sep).join('/');
7878
}
7979

80-
if (filePath.indexOf('/') === -1) {
80+
if (filePath.indexOf('../') !== 0) {
8181
filePath = './' + filePath;
8282
}
8383

0 commit comments

Comments
 (0)