mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add script to generate new package
This commit is contained in:
parent
12b8c644f1
commit
23c73fff46
39
README.md
39
README.md
@ -109,43 +109,8 @@ Your package should have this structure:
|
||||
| foo-tests.ts | This contains sample code which tests the typings. This code does *not* run, but it is type-checked. |
|
||||
| tsconfig.json | This allows you to run `tsc` within the package. |
|
||||
|
||||
`index.d.ts` should start with a header looking like:
|
||||
|
||||
```ts
|
||||
// Type definitions for foo 1.2
|
||||
// Project: https://github.com/baz/foo
|
||||
// Definitions by: My Self <https://github.com/me>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
```
|
||||
|
||||
The `Project` link does not have to be to GitHub, but prefer linking to a source code repository rather than to a project website.
|
||||
|
||||
`tsconfig.json` should look like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"foo-tests.ts"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
These should be identical accross projects except that `foo-tests` will be replaced with the name of your test file,
|
||||
and you may also add the `"jsx"` compiler option if your library needs it.
|
||||
Generate these by running `tsc -p scripts`, then `node scripts/new-package.js new-package-name`.
|
||||
You may edit the `tsconfig.json` to add new files or to add the `"jsx"` compiler option.
|
||||
|
||||
DefinitelyTyped members routinely monitor for new PRs, though keep in mind that the number of other PRs may slow things down.
|
||||
|
||||
|
||||
45
scripts/new-package.ts
Normal file
45
scripts/new-package.ts
Normal file
@ -0,0 +1,45 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import { mkdirSync, writeFileSync } from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
const newPackageName = process.argv[2];
|
||||
if (!newPackageName) {
|
||||
throw new Error("Usage: node scripts/new-package.js new-package-name")
|
||||
}
|
||||
|
||||
mkdirSync(newPackageName);
|
||||
|
||||
write("index.d.ts", `// Type definitions for ${newPackageName} 1.2
|
||||
// Project: https://github.com/baz/foo (Does not have to be to GitHub, but prefer linking to a source code repository rather than to a project website.)
|
||||
// Definitions by: My Self <https://github.com/me>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
Fill the header in!
|
||||
`);
|
||||
const testsFile = `${newPackageName}-tests.ts`;
|
||||
write(testsFile, "");
|
||||
const tsconfig = {
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
`${newPackageName}-tests.ts`
|
||||
]
|
||||
};
|
||||
write("tsconfig.json", JSON.stringify(tsconfig, undefined, 4));
|
||||
|
||||
function write(name: string, content: string) {
|
||||
writeFileSync(path.join(newPackageName, name), content);
|
||||
}
|
||||
@ -25,7 +25,7 @@ function checkDir(home: string, count: number) {
|
||||
if (exists) {
|
||||
const old = JSON.parse(fs.readFileSync(target, 'utf-8'));
|
||||
|
||||
let entryPoint: string = undefined;
|
||||
let entryPoint: string;
|
||||
let definitionFiles = files.filter(f => (f.indexOf('.d.ts') > 0));
|
||||
if (definitionFiles.length === 1) {
|
||||
entryPoint = definitionFiles[0];
|
||||
@ -41,7 +41,7 @@ function checkDir(home: string, count: number) {
|
||||
return;
|
||||
}
|
||||
|
||||
let testFile = path.join(dir, path.basename(dir) + '-tests.ts');
|
||||
let testFile: string | undefined = path.join(dir, path.basename(dir) + '-tests.ts');
|
||||
if (!fs.existsSync(testFile)) {
|
||||
let onlyTest = files.filter(f => f.toLowerCase().indexOf('-tests.ts') > 0)[0];
|
||||
if (onlyTest) {
|
||||
|
||||
@ -3,16 +3,12 @@
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user