|
#!/usr/bin/env sh |
|
# https://github.com/Microsoft/TypeScript-Node-Starter |
|
|
|
if [ ! -f ./package.json ]; then |
|
echo "Please run 'npm init' first." |
|
exit 1 |
|
fi |
|
|
|
DL= |
|
[ -z "$DL" ] && [ -x `which curl` ] && DL="`which curl` -sLO" |
|
[ -z "$DL" ] && [ -x `which wget` ] && DL="`which wget` -q" |
|
[ -z "$DL" ] && echo "Did not find curl or wget. Exiting." && exit 1 |
|
|
|
NODE= |
|
[ -z "$NODE" ] && [ -x `which node` ] && NODE="`which node`" |
|
[ -z "$NODE" ] && [ -x `which nodejs` ] && NODE="`which nodejs`" |
|
[ -z "$NODE" ] && echo "Did not find NodeJS. Exiting." && exit 1 |
|
|
|
NPM= |
|
[ -z "$NPM" ] && [ -x `which npm` ] && NPM="`which npm`" |
|
[ -z "$NPM" ] && echo "Did not find NPM. Exiting." && exit 1 |
|
|
|
$NPM i --save compression dotenv errorhandler express winston |
|
$NPM i --save-dev concurrently node-sass nodemon shelljs ts-node tslint typescript |
|
$NPM i --save-dev @types/compression @types/dotenv @types/errorhandler @types/express \ |
|
@types/node @types/shelljs |
|
|
|
echo " |
|
'use strict'; |
|
const fs = require('fs'); |
|
const pkg = JSON.parse(fs.readFileSync('./package.json')); |
|
|
|
pkg.main = 'dist/server.js'; |
|
pkg.scripts = pkg.scripts || {}; |
|
pkg.scripts['start'] = 'npm run serve'; |
|
pkg.scripts['build'] = 'npm run build-sass && npm run build-ts && npm run tslint && npm run copy-static-assets'; |
|
pkg.scripts['serve'] = 'node dist/server.js'; |
|
pkg.scripts['watch-node'] = 'nodemon dist/server.js'; |
|
pkg.scripts['watch'] = 'concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run watch-node\"'; |
|
pkg.scripts['build-ts'] = 'tsc'; |
|
pkg.scripts['watch-ts'] = 'tsc -w'; |
|
pkg.scripts['build-sass'] = 'node-sass src/public/css/main.scss dist/public/css/main.css'; |
|
pkg.scripts['watch-sass'] = 'node-sass -w src/public/css/main.scss dist/public/css/main.css'; |
|
pkg.scripts['tslint'] = 'tslint -c tslint.json -p tsconfig.json'; |
|
pkg.scripts['copy-static-assets'] = 'ts-node copyStaticAssets.ts'; |
|
pkg.scripts['debug'] = 'npm run build && npm run watch-debug'; |
|
pkg.scripts['serve-debug'] = 'nodemon --inspect dist/server.js'; |
|
pkg.scripts['watch-debug'] = 'concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve-debug\"'; |
|
|
|
fs.writeFileSync('./package.json', JSON.stringify(pkg, undefined, 2)); |
|
console.log('package.json updated'); |
|
" | $NODE |
|
|
|
REF="4779cb7e182cf41d5c62289bb80d2850e0265b71" |
|
FORK="Microsoft/TypeScript-Node-Starter" |
|
|
|
for f in \ |
|
"copyStaticAssets.ts" \ |
|
"tsconfig.json" \ |
|
"tslint.json" |
|
do |
|
$DL "https://raw.githubusercontent.com/$FORK/$REF/$f" |
|
done |
|
sed -e 's;^shell;// shell;' -i copyStaticAssets.ts |
|
|
|
DIR=src |
|
mkdir -p $DIR && pushd $DIR |
|
for f in \ |
|
"server.ts" |
|
do |
|
$DL "https://raw.githubusercontent.com/$FORK/$REF/$DIR/$f" |
|
done |
|
popd |
|
|
|
DIR=src/util |
|
mkdir -p $DIR && pushd $DIR |
|
for f in \ |
|
"logger.ts" \ |
|
"secrets.ts" |
|
do |
|
$DL "https://raw.githubusercontent.com/$FORK/$REF/$DIR/$f" |
|
done |
|
grep -v "import { Logger }" logger.ts | tee logger.ts~ && mv logger.ts~ logger.ts |
|
sed -e 's;new (Logger);winston.createLogger;' logger.ts | tee logger.ts~ && mv logger.ts~ logger.ts |
|
head -n `grep -n "const prod" secrets.ts | cut -d: -f1` secrets.ts | tee secrets.ts~ && mv secrets.ts~ secrets.ts |
|
popd |
|
|
|
DIR=src/public/css |
|
mkdir -p $DIR && pushd dir |
|
touch main.scss |
|
popd |
|
|