Last active
October 30, 2016 17:38
-
-
Save yajamon/c2e4760edf495a7efafe81473c92acde to your computer and use it in GitHub Desktop.
generate project for typescript
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
#!/bin/bash | |
main(){ | |
if ! isRequireCommandsInstalled; then | |
return 1 | |
fi | |
subtasksBuild=() | |
makePackageJsonIfNeeded | |
setupGitignore | |
setupGulp | |
setupTypescript | |
setupEslint | |
setupTasks | |
echo "Script end." | |
return 0 | |
} | |
isRequireCommandsInstalled(){ | |
commands=$1 | |
local command | |
for command in "npm gulp" | |
do | |
if ! isExistsCommand command; then | |
return 1 | |
fi | |
done | |
return 0 | |
} | |
isExistsCommand(){ | |
if ! type "$1" > /dev/null 2>&1; then | |
echo "Command not found: $1" | |
return 1 | |
fi | |
return 0 | |
} | |
makePackageJsonIfNeeded(){ | |
if [ ! -f ./package.json ]; then | |
echo "package.json not found." | |
makePackageJson | |
fi | |
return 0 | |
} | |
makePackageJson(){ | |
echo "Make private package.json OK?(Y/n)" | |
local isPrivatePackage | |
read isPrivatePackage | |
if [ "$isPrivatePackage" = "Y" -o "$isPrivatePackage" = "" ]; then | |
echo "Make json" | |
echo "{\"private\":true}" >> ./package.json | |
else | |
echo "Start npm init." | |
npm init | |
fi | |
return 0 | |
} | |
setupGitignore(){ | |
curl -L -s https://www.gitignore.io/node >> .gitignore | |
} | |
setupGulp(){ | |
npm install --save-dev gulp | |
if [ ! -f ./gulpfile.js ];then | |
{ | |
echo "let gulp = require('gulp');" | |
} > gulpfile.js | |
fi | |
} | |
setupTypescript(){ | |
npm install --save-dev typescript gulp-typescript | |
local taskname="build:ts" | |
subtasksBuild+=($taskname) | |
mkdir -p ./src/ts | |
{ | |
echo "{" | |
echo " \"compilerOptions\": {" | |
echo " \"module\": \"commonjs\"," | |
echo " \"noImplicitAny\": true," | |
echo " \"removeComments\": true," | |
echo " \"target\": \"es6\"" | |
echo " }" | |
echo "}" | |
} > ./src/ts/tsconfig.json | |
{ | |
echo "let ts = require('gulp-typescript')" | |
echo "let tsProject = ts.createProject('src/ts/tsconfig.json', {" | |
echo " out: 'app.js', sortOutput: true," | |
echo "});" | |
echo "gulp.task('$taskname', function() {" | |
echo " let tsResult = gulp.src('src/ts/**/*.ts')" | |
echo " .pipe(ts(tsProject));" | |
echo " tsResult.js.pipe(gulp.dest('dist/js/'));" | |
echo "});" | |
} >> gulpfile.js | |
} | |
setupEslint(){ | |
npm install --save-dev eslint babel-eslint eslint-config-google | |
{ | |
echo "{" | |
echo " \"parser\": \"babel-eslint\"," | |
echo " \"extends\": \"google\"," | |
echo " \"rules\": {" | |
echo " \"spaced-comment\": \"off\"" | |
echo " }" | |
echo "}" | |
} >> .eslistrc.json | |
} | |
setupDtsm(){ | |
npm install --save-dev dtsm | |
$(npm bin)/dtsm init | |
{ | |
echo "typings" | |
} >> .gitignore | |
} | |
setupTasks(){ | |
local tasks=() | |
for task in $subtasksBuild | |
do | |
tasks+=("'$task',") | |
done | |
{ | |
echo "gulp.task('build',[${tasks[@]}]);" | |
} >> gulpfile.js | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment