-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.sh
99 lines (77 loc) · 2.23 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
echo "NPM Package Generator."
CONFIRM="N"
while true; do
case "$CONFIRM" in
N)
echo
printf "Enter Package Name: "
read PackageName
printf "Enter Version Number: "
read Version
printf "Enter your Name: "
read AuthorName
printf "Enter your Email Address: "
read Email
;;
X)
exit
;;
Y)
break
;;
esac
echo
echo "Package Name: $PackageName"
echo "Package Version: $Version"
echo "Name: $AuthorName"
echo "Email: $Email"
echo
printf "Generate npm package? [Y|N|X] "
read CONFIRM
done
function replace_consts {
while IFS= read -r data; do
echo "$data" |
sed 's/{{PackageNameUpperUnderscored}}/'"$PackageNameUpperUnderscored"/ |
sed 's/{{PackageName}}/'"$PackageName"/ |
sed 's/{{AuthorName}}/'"$AuthorName"/ |
sed 's/{{Version}}/'"$Version"/ |
sed 's/{{Email}}/'"$Email"/ |
sed 's/{{Year}}/'"$Year"/
done
}
OUTPUT_FOLDER="`pwd`/$PackageName"
if [ -r "$OUTPUT_FOLDER" ]; then
echo "Directory already exists: $OUTPUT_FOLDER"
exit 1
fi
PackageNameUpperUnderscored=`echo "$PackageName" | tr "[:lower:]-" "[:upper:]_"`
Year=`date +%Y`
TMP_INPUT_FOLDER="/tmp/`date +%s`-npm-package"
git clone "https://github.com/enb-make/npm-package.git" "$TMP_INPUT_FOLDER"
rm -Rf "$TMP_INPUT_FOLDER"/*.sh
mv "$TMP_INPUT_FOLDER"/README.md.in "$TMP_INPUT_FOLDER"/README.md
echo
echo "Generating npm package..."
cd "$TMP_INPUT_FOLDER"
find . | grep -v './.git/' | while read FILENAME; do
if [ -f "$FILENAME" ]; then
FILENAME=`echo "$FILENAME" | sed 's/.\///'`
RESULT_FILENAME=`echo "$FILENAME" | replace_consts`
OUTPUT_FILENAME="$OUTPUT_FOLDER/$RESULT_FILENAME"
mkdir -p `dirname $OUTPUT_FILENAME`
cat "$FILENAME" | replace_consts > "$OUTPUT_FILENAME"
echo "Generated $FILENAME -> $RESULT_FILENAME"
fi
done
cd "$OUTPUT_FOLDER"
git init
echo
echo "Git repository initialized"
npm install
echo
echo "NPM packages installed"
echo
echo "NPM package stub created: $OUTPUT_FOLDER"
rm -Rf "$TMP_INPUT_FOLDER"