-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Support `--project` and `tsconfig.json` for specifying most configuration options. - Change generate API to integrate `sendMessage` into configuration object - Add support for `--verbose` logging and add additional logging - Rename `excludes` to `exclude` to align with `tsc` - Add more testing - Refactor CLI to behave better - Add support for `moduleResolution`
- Loading branch information
Showing
11 changed files
with
258 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.js | ||
*.js.map | ||
node_modules | ||
tmp | ||
!tasks/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
#!/usr/bin/env node | ||
require('./dts-generator.js'); | ||
var dtsGenerator = require('./dts-generator.js'); | ||
/* istanbul ignore if: we use the module interface in testing */ | ||
if (!module.parent) { | ||
dtsGenerator(process.argv.slice(2)).then(function (code) { | ||
return process.exit(code || 0); | ||
}, function (err) { | ||
throw err; | ||
}); | ||
} | ||
else { | ||
module.exports = dtsGenerator; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,76 @@ | ||
import dts = require('../index'); | ||
|
||
const kwArgs: { | ||
[key: string]: any; | ||
excludes?: string[]; | ||
externs?: string[]; | ||
files: string[]; | ||
} = { files: [] }; | ||
|
||
for (let i = 2, j = process.argv.length; i < j; ++i) { | ||
const arg = process.argv[i]; | ||
|
||
if (arg.charAt(0) === '-') { | ||
const key = process.argv[i].replace(/^-+/, ''); | ||
const value = process.argv[i + 1]; | ||
++i; | ||
|
||
if (key === 'exclude') { | ||
if (!kwArgs.excludes) { | ||
kwArgs.excludes = []; | ||
} | ||
import generate from '../index'; | ||
|
||
kwArgs.excludes.push(value); | ||
} | ||
else if (key === 'extern') { | ||
if (!kwArgs.externs) { | ||
kwArgs.externs = []; | ||
export = function main(argv: string[]): Promise<number | void> { | ||
const kwArgs: { | ||
[key: string]: any; | ||
baseDir?: string; | ||
exclude?: string[]; | ||
externs?: string[]; | ||
files: string[]; | ||
project?: string; | ||
sendMessage?: (message: any, ...optionalParams: any[]) => void; | ||
verbose?: boolean; | ||
} = { | ||
files: [], | ||
sendMessage: console.log.bind(console) | ||
}; | ||
|
||
for (let i = 0; i < argv.length; ++i) { | ||
const arg = argv[i]; | ||
|
||
if (arg.charAt(0) === '-') { | ||
const key = argv[i].replace(/^-+/, ''); | ||
const value = argv[i + 1]; | ||
++i; | ||
|
||
if (key === 'exclude') { | ||
if (!kwArgs.exclude) { | ||
kwArgs.exclude = []; | ||
} | ||
|
||
kwArgs.exclude.push(value); | ||
} | ||
else if (key === 'extern') { | ||
if (!kwArgs.externs) { | ||
kwArgs.externs = []; | ||
} | ||
|
||
kwArgs.externs.push(value); | ||
kwArgs.externs.push(value); | ||
} | ||
else if (key === 'verbose') { | ||
kwArgs.verbose = true; | ||
/* decrement counter, because vebose does not take a value */ | ||
--i; | ||
} | ||
else { | ||
kwArgs[key] = value; | ||
} | ||
} | ||
else { | ||
kwArgs[key] = value; | ||
kwArgs.files.push(argv[i]); | ||
} | ||
} | ||
else { | ||
kwArgs.files.push(process.argv[i]); | ||
|
||
[ 'name', 'out' ].forEach(function (key) { | ||
if (!kwArgs[key]) { | ||
console.error(`Missing required argument "${key}"`); | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
if (!kwArgs.baseDir && !kwArgs.project) { | ||
console.error(`Missing required argument of "baseDir" or "project"`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
[ 'baseDir', 'name', 'out' ].forEach(function (key) { | ||
if (!kwArgs[key]) { | ||
console.error('Missing required argument "' + key + '"'); | ||
if (!kwArgs.project && kwArgs.files.length === 0) { | ||
console.error('Missing files'); | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
if (kwArgs.files.length === 0) { | ||
console.error('Missing files'); | ||
process.exit(1); | ||
} | ||
console.log('Starting'); | ||
|
||
console.log('Starting'); | ||
dts.generate(<any> kwArgs, console.log.bind(console)).then(function () { | ||
console.log('Done!'); | ||
}, function (error: Error) { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
return generate(<any> kwArgs).then(function () { | ||
console.log('Done!'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
cd "$(dirname $0)/.." | ||
echo "Building modules..." | ||
node_modules/.bin/tsc --module umd --target es5 node_modules/intern/typings/intern/intern.d.ts typings/tsd.d.ts tests/typings/dts-generator/dts-generator.d.ts tests/intern.ts tests/unit/all.ts | ||
node_modules/.bin/tsc --module commonjs --target es5 typings/tsd.d.ts index.ts bin/dts-generator.ts | ||
node_modules/.bin/tsc --module commonjs --target es5 --sourcemap typings/tsd.d.ts index.ts bin/dts-generator.ts | ||
echo "Running intern..." | ||
node_modules/.bin/intern-client config=tests/intern reporters=Console | ||
echo "Cleanup..." | ||
rm -rf tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"version": "1.6.2", | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "umd", | ||
"declaration": false, | ||
"noImplicitAny": true | ||
}, | ||
"filesGlob": [ | ||
"./*.ts" | ||
], | ||
"files": [ | ||
"./index.ts", | ||
"./Bar.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
/// <reference path="../../../node_modules/intern/typings/intern/intern.d.ts" /> | ||
|
||
declare module 'intern/dojo/node!../../index' { | ||
let dtsGenerator: any; | ||
export default dtsGenerator; | ||
} | ||
|
||
declare module 'intern/dojo/node!../../../bin/dts-generator' { | ||
let dtsGenerator: any; | ||
export = dtsGenerator; | ||
} | ||
|
||
declare module 'intern/dojo/node!fs' { | ||
import * as fs from 'fs'; | ||
export = fs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './bin/dts-generator'; | ||
import './index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as registerSuite from 'intern!object'; | ||
import * as assert from 'intern/chai!assert'; | ||
import * as dtsGenerator from 'intern/dojo/node!../../../bin/dts-generator'; | ||
|
||
registerSuite({ | ||
name: 'bin/dts-generator', | ||
api: function () { | ||
assert.isFunction(dtsGenerator, 'dtsGenerator should be a function'); | ||
assert.strictEqual(Object.keys(dtsGenerator).length, 0, 'There should be no other keys'); | ||
}, | ||
basic: function () { | ||
return dtsGenerator([ | ||
'-name', | ||
'foo', | ||
'-project', | ||
'tests/support/foo', | ||
'-out', | ||
'tmp/foo.cli.d.ts' | ||
]); | ||
} | ||
}); |
Oops, something went wrong.