UNPKG

2.98 kBPlain TextView Raw
1#!/bin/bash
2
3# Declare configuration files
4tsconfigConfigPath="$(pwd)/tsconfig.json"
5tslintConfigPath="$(pwd)/tslint.json"
6prettierConfigPath="$(pwd)/prettier.json"
7jestConfigPath="$(pwd)/jest.json"
8stylelintConfigPath="$(pwd)/stylelint.json"
9typedocConfigPath="$(pwd)/typedoc.json"
10
11CMD=$1
12shift
13
14error() {
15 echo -e "\e[31m$@"; exit 1;
16}
17
18exe() {
19 echo "$@" ; $@ ;
20}
21
22case $CMD in
23 "clean")
24 exe "rimraf **/node_modules"
25 ;;
26 "compile:clean")
27 exe "rimraf dist"
28 ;;
29 "compile:ts")
30 if [ -f $tsconfigConfigPath ]; then
31 exe "tsc --pretty --project $tsconfigConfigPath $@"
32 else
33 error "File not found $tsconfigConfigPath"
34 fi
35 ;;
36 "document:clean")
37 exe "rimraf docs"
38 ;;
39 "document:ts")
40 if [ -f $typedocConfigPath ]; then
41 if [ -f $tsconfigConfigPath ]; then
42 exe "typedoc --options $typedocConfigPath --tsconfig $tsconfigConfigPath $@"
43 else
44 error "File not found $tsconfigConfigPath"
45 fi
46 else
47 error "File not found $typedocConfigPath"
48 fi
49 ;;
50 "lint:ts")
51 if [ -f $tslintConfigPath ]; then
52 exe "tslint -t codeFrame --config $tslintConfigPath $@"
53 else
54 error "File not found $tslintConfigPath"
55 fi
56 ;;
57 "lint:scss")
58 if [ -f $stylelintConfigPath ]; then
59 exe "stylelint --syntax scss --config $stylelintConfigPath $@" # src/**/*.scss
60 else
61 error "File not found $stylelintConfigPath"
62 fi
63 ;;
64 "pretty")
65 if [ -f $prettierConfigPath ]; then
66 exe "prettier --write --config $prettierConfigPath $@" # src/**/*.{scss,ts,tsx}
67 else
68 error "File not found $prettierConfigPath"
69 fi
70 ;;
71 "pretty:ts")
72 if [ -f $tslintConfigPath ]; then
73 exe "tslint -t codeFrame --config $tslintConfigPath --fix $@" # src/**/*.{ts,tsx}
74 else
75 error "File not found $tslintConfigPath"
76 fi
77 ;;
78 "pretty:scss")
79 if [ -f $stylelintConfigPath ]; then
80 exe "stylelint --syntax scss --config $stylelintConfigPath --fix $@" # src/**/*.scss
81 else
82 error "File not found $stylelintConfigPath"
83 fi
84 ;;
85 "test")
86 if [ -f $jestConfigPath ]; then
87 exe "jest --maxWorkers 2 --config $jestConfigPath --env=jsdom $@"
88 else
89 error "File not found $jestConfigPath"
90 fi
91 ;;
92 "test:clean")
93 exe "rimraf coverage"
94 ;;
95 "test:watch")
96 if [ -f $jestConfigPath ]; then
97 exe "jest --watch --config $jestConfigPath --env=jsdom $@"
98 else
99 error "File not found $jestConfigPath"
100 fi
101 ;;
102*)
103# Fallback if not defined above
104if [[ -z "$CMD" ]]; then
105 echo "USAGE: ./task (clean|compile|document|lint|pretty|test)"
106 exit 0
107fi
108 error "Command not found $CMD"
109;;
110esac