Skip to content

Instantly share code, notes, and snippets.

@tkqubo
Last active January 4, 2016 15:50
Show Gist options
  • Save tkqubo/db63228005e4da272a34 to your computer and use it in GitHub Desktop.
Save tkqubo/db63228005e4da272a34 to your computer and use it in GitHub Desktop.
Create DefinitelyTyped Module.sh
#!/bin/bash
function error() {
echo $@ >&2
}
[[ ! -d $DEFINITELY_TYPED_DIRECTORY ]] && error 'DT directory not specified in DEFINITELY_TYPED_DIRECTORY' && exit 1
[[ -z $DEFINITELY_TYPED_NAME ]] && error 'GitHub name not specified in DEFINITELY_TYPED_USER' && exit 1
[[ -z $DEFINITELY_TYPED_USER ]] && error 'GitHub user not specified in DEFINITELY_TYPED_NAME' && exit 1
repoUrl=$1
[[ -z $repoUrl ]] && echo "Usage: $0 GITHUB_REPO" && exit 1
[[ ! $repoUrl =~ ^https://github.com/ ]] && error "Not a GitHub repo: $repoUrl" && exit 1
module=${${repoUrl##*/}%%.git}
[[ -z $module ]] && error "Invalid URL: ${repoUrl}" && exit 1
cd $DEFINITELY_TYPED_DIRECTORY
[[ $(ls $module 2>/dev/null) ]] && error "Module [$module] already exists" && exit 1
branch=$(git symbolic-ref --short HEAD)
[[ $branch != 'master' ]] && error 'To proceed, the current branch should be set to master' && exit 1
git branch --list | grep -E "^[* ] ${module}\$" > /dev/null
[[ $? == 0 ]] && error "Branch ${module} already exists" && exit 1
echo "Create branch $module"
git checkout -b $module
echo "Create module [$module]"
mkdir $module && cd $_
definition_file="${module}.d.ts"
class=${module##*-}
class=${class%%.*}
echo "Create [$definition_file]"
cat << _EOT_ > $definition_file
// Type definitions for ${module}
// Project: ${repoUrl}
// Definitions by: ${DEFINITELY_TYPED_NAME} <https://github.com/${DEFINITELY_TYPED_USER}>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "${module}" {
export interface ${class} {
//TODO
}
var ${class}: ${class};
export default ${class};
}
_EOT_
test_file="${module}-tests.ts"
echo "Create [$test_file]"
cat << _EOT_ > $test_file
/// <reference path="${definition_file}" />
//import $class = require('${module}');
import $class from '${module}';
//TODO
_EOT_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment