├── .gitattributes ├── bin ├── cli.js └── cli2.js ├── test └── node_modules │ └── test │ ├── test-package-typings │ └── test-package │ │ ├── success.js │ │ └── index.d.ts │ └── package.json ├── src ├── tsconfig.json └── index.ts ├── LICENSE ├── package.json ├── .gitignore ├── README.md └── dist └── index.js /.gitattributes: -------------------------------------------------------------------------------- 1 | bin/*.js eol=lf -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require("../dist/index"); 3 | -------------------------------------------------------------------------------- /bin/cli2.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require("../dist/index"); 3 | -------------------------------------------------------------------------------- /test/node_modules/test/test-package-typings/test-package/success.js: -------------------------------------------------------------------------------- 1 | console.log('success'); -------------------------------------------------------------------------------- /test/node_modules/test/test-package-typings/test-package/index.d.ts: -------------------------------------------------------------------------------- 1 | declare const TestPackage: {}; 2 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": true, 4 | "outDir": "../dist" 5 | } 6 | } -------------------------------------------------------------------------------- /test/node_modules/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "indefinitely-typed-test-package", 3 | "private": true, 4 | "version": "1.0.0", 5 | "license": "MIT", 6 | "types": "index.d.ts" 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Dan Marshall 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "indefinitely-typed", 3 | "version": "1.1.0", 4 | "description": "🐣 Incubate your TypeScript declarations", 5 | "keywords": [ 6 | "TypeScript", 7 | "DefinitelyTyped" 8 | ], 9 | "bin": { 10 | "indefinitely-typed": "./bin/cli2.js" 11 | }, 12 | "main": "dist/index.js", 13 | "files": [ 14 | "bin", 15 | "dist" 16 | ], 17 | "scripts": { 18 | "build": "tsc -p ./src", 19 | "watch": "tsc -p ./src -w", 20 | "test": "cd test/node_modules/test && node ../../../bin/cli2.js --folder test-package-typings && node ../@types/test-package-typings/test-package/success.js" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/danmarshall/indefinitely-typed.git" 25 | }, 26 | "author": "Dan Marshall", 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/danmarshall/indefinitely-typed/issues" 30 | }, 31 | "homepage": "https://github.com/danmarshall/indefinitely-typed#readme", 32 | "dependencies": { 33 | "fs-extra": "^8.0.0", 34 | "minimist": "^1.2.5" 35 | }, 36 | "devDependencies": { 37 | "@types/fs-extra": "^5.0.4", 38 | "@types/minimist": "^1.2.0", 39 | "@types/node": "^10.11.7", 40 | "typescript": "^3.1.3" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # include test stuff 64 | !test/node_modules 65 | 66 | # but not test output 67 | test/node_modules/@types 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🐣 indefinitely-typed 2 | 3 | For TypeScript declarations that are still ...hatching. 4 | 5 | ## What this does 6 | 7 | Copies your folders into the dependee's `node_modules/@types/` folder. Because that's where the TypeScript compiler might look for it - see [TypeScript Module Resolution](https://www.typescriptlang.org/docs/handbook/module-resolution.html). 8 | 9 | ## Why you may need it 10 | 11 | [DefinitelyTyped](http://definitelytyped.org/) is the repository for __high quality__ TypeScript type definitions. Use this tool if: 12 | * your definitions are "pre-release", lacking tests or incomplete, but you still need to use them in a project. 13 | * you need to maintain versioning not possible with the [@types publisher](https://github.com/microsoft/DefinitelyTyped-tools). 14 | * you need to publish on demand, and not wait for the [@types publisher](https://github.com/microsoft/DefinitelyTyped-tools). 15 | 16 | ## Usage 17 | 18 | Let's say that you want to create TypeScript declarations for `cool-package`. 19 | 20 | 1. Create an NPM package for your typings, perhaps name it `cool-package-typings`. 21 | 1. `npm install indefinitely-typed`. 22 | 1. Create a folder named `cool-package`. 23 | 1. Add declaration files in this folder, like `index.d.ts`. 24 | 1. In the `package.json`'s `scripts`, add a `postinstall` script like this: 25 | ``` 26 | "postinstall": "indefinitely-typed --folder cool-package" 27 | ``` 28 | 29 | Now, when somebody installs `cool-package-typings`, they will have a `node_modules/@types/cool-package` folder, readily usable by their TypeScript project. 30 | 31 | 32 | ### Multiple packages 33 | If you have multiple packages, add more folder parameters like this: 34 | ``` 35 | indefinitely-typed --folder folder1 --folder folder2 --folder folder3 36 | ``` 37 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | var fs = require("fs-extra"); 4 | var path = require("path"); 5 | var minimist = require("minimist"); 6 | var log = console.log; 7 | log("======================="); 8 | log("indefinitely-typed installation ..."); 9 | var argv = minimist(process.argv.slice(2)); 10 | log('args:', argv); 11 | var cwd = process.cwd(); 12 | log("cwd: " + cwd); 13 | var pathToPackageJson = path.resolve(cwd, 'package.json'); 14 | log("looking for package.json at: " + pathToPackageJson); 15 | if (!fs.existsSync(pathToPackageJson)) { 16 | log("package.json not found, aborting."); 17 | } 18 | else { 19 | var packageJson = require(pathToPackageJson); 20 | log("package name is : " + packageJson.name); 21 | packageJson.isScoped = 22 | packageJson.name.substr(0, 1) === '@' && 23 | packageJson.name.indexOf('/') > 1; 24 | log("package is " + (packageJson.isScoped ? '' : 'not ') + "scoped."); 25 | var node_modules = path.resolve(cwd, packageJson.isScoped ? '../..' : '..'); 26 | log("using node_modules at " + node_modules); 27 | var segments = node_modules.split(path.sep); 28 | if (segments[segments.length - 1] !== 'node_modules') { 29 | log("error: this is not a node_modules folder."); 30 | } 31 | else { 32 | var types_1 = path.resolve(node_modules, '@types'); 33 | if (!fs.existsSync(types_1)) { 34 | log("creating folder " + types_1); 35 | fs.mkdirSync(types_1); 36 | } 37 | log("using @types folder at " + types_1); 38 | var folders = []; 39 | if (Array.isArray(argv.folder)) { 40 | folders = argv.folder; 41 | } 42 | else { 43 | folders = [argv.folder]; 44 | } 45 | folders.forEach(function (folder) { 46 | log("---"); 47 | log("folder: " + folder); 48 | var destDir = path.resolve(types_1, folder); 49 | if (fs.existsSync(destDir)) { 50 | log("deleting existing " + destDir + " , "); 51 | fs.removeSync(destDir); 52 | } 53 | var srcDir = path.resolve(cwd, folder); 54 | log("copying " + srcDir + " to " + destDir); 55 | fs.copySync(srcDir, destDir); 56 | log(folder + " complete!"); 57 | }); 58 | log("installation complete!"); 59 | } 60 | } 61 | log("======================="); 62 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import fs = require('fs-extra'); 2 | import path = require('path'); 3 | import minimist = require('minimist'); 4 | 5 | interface Args extends minimist.ParsedArgs { 6 | folder?: string | string[]; 7 | } 8 | 9 | interface PackageJson { 10 | name: string; 11 | isScoped?: boolean; 12 | } 13 | 14 | const log = console.log; 15 | 16 | log(`=======================`); 17 | log(`indefinitely-typed installation ...`); 18 | 19 | const argv = minimist(process.argv.slice(2)) as Args; 20 | log('args:', argv); 21 | 22 | const cwd = process.cwd(); 23 | log(`cwd: ${cwd}`); 24 | 25 | const pathToPackageJson = path.resolve(cwd, 'package.json'); 26 | log(`looking for package.json at: ${pathToPackageJson}`); 27 | 28 | if (!fs.existsSync(pathToPackageJson)) { 29 | log(`package.json not found, aborting.`); 30 | } else { 31 | 32 | const packageJson = require(pathToPackageJson) as PackageJson; 33 | log(`package name is : ${packageJson.name}`); 34 | 35 | packageJson.isScoped = 36 | packageJson.name.substr(0, 1) === '@' && 37 | packageJson.name.indexOf('/') > 1; 38 | log(`package is ${packageJson.isScoped ? '' : 'not '}scoped.`); 39 | 40 | const node_modules = path.resolve(cwd, packageJson.isScoped ? '../..' : '..'); 41 | log(`using node_modules at ${node_modules}`); 42 | 43 | const segments = node_modules.split(path.sep); 44 | if (segments[segments.length - 1] !== 'node_modules') { 45 | log(`error: this is not a node_modules folder.`); 46 | } else { 47 | 48 | const types = path.resolve(node_modules, '@types'); 49 | if (!fs.existsSync(types)) { 50 | log(`creating folder ${types}`); 51 | fs.mkdirSync(types); 52 | } 53 | log(`using @types folder at ${types}`); 54 | 55 | let folders: string[] = []; 56 | 57 | if (Array.isArray(argv.folder)) { 58 | folders = argv.folder; 59 | } else { 60 | folders = [argv.folder]; 61 | } 62 | 63 | folders.forEach(folder => { 64 | log(`---`); 65 | log(`folder: ${folder}`); 66 | 67 | const destDir = path.resolve(types, folder); 68 | if (fs.existsSync(destDir)) { 69 | log(`deleting existing ${destDir} , `); 70 | fs.removeSync(destDir); 71 | } 72 | const srcDir = path.resolve(cwd, folder); 73 | log(`copying ${srcDir} to ${destDir}`); 74 | 75 | fs.copySync(srcDir, destDir); 76 | 77 | log(`${folder} complete!`); 78 | }); 79 | 80 | log(`installation complete!`) 81 | } 82 | } 83 | 84 | log(`=======================`); 85 | --------------------------------------------------------------------------------