forked from haraka/Haraka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin2npm.sh
executable file
·111 lines (91 loc) · 2.72 KB
/
plugin2npm.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
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
usage()
{
echo "$0 \$plugin_name"
exit
}
if [ -z "$1" ]; then
usage
fi
export GITHUB_ORG="haraka"
export PLUGIN_NAME="haraka-plugin-$1"
export PLUGIN_REPO="../$PLUGIN_NAME"
export GIT_CMD="git -C $PLUGIN_REPO"
if [ -d "$PLUGIN_REPO" ]; then
echo "repo exists at $PLUGIN_REPO"
else
git clone [email protected]:haraka/haraka-plugin-template.git "$PLUGIN_REPO" || exit
$GIT_CMD remote rm origin || exit
$GIT_CMD remote add origin "[email protected]:$GITHUB_ORG/$PLUGIN_NAME.git" || exit
fi
if grep template "$PLUGIN_REPO/README.md"; then
echo "redressing as $PLUGIN_NAME"
sed -i '' -e "s/template/${1}/g" "$PLUGIN_REPO/README.md"
sed -i '' \
-e "s/template/${1}/g" \
-e "s/template\.ini/$1.ini/" \
"$PLUGIN_REPO/test/index.js"
sed -i '' -e "s/template/${1}/g" package.json
sed -i '' \
-e "s/_template/_${1}/g" \
-e "s/template\.ini/$1.ini/" \
"$PLUGIN_REPO/index.js"
$GIT_CMD mv config/template.ini "config/$1.ini"
$GIT_CMD add package.json README.md index.js test config
$GIT_CMD commit -m "publish $1 as NPM module"
$GIT_CMD rm redress.sh
fi
if [ -f "docs/plugins/$1.md" ]; then
echo "copying docs/plugin/$1.md to $PLUGIN_REPO/README.md"
head -n8 "$PLUGIN_REPO/README.md" > foo.md
cat "docs/plugins/$1.md" >> foo.md
tail -n14 "$PLUGIN_REPO/README.md" >> foo.md
mv foo.md "$PLUGIN_REPO/README.md"
git rm "docs/plugins/$1.md" || exit
fi
if [ -f "config/$1.ini" ]; then
echo "copying $1.ini"
cp "config/$1.ini" "$PLUGIN_REPO/config/$1.ini"
git rm "config/$1.ini"
$GIT_CMD add "config/$1.ini"
fi
if [ -f "plugins/$1.js" ]; then
echo "copying plugins/$1.js"
cp "plugins/$1.js" "$PLUGIN_REPO/index.js"
tee "plugins/$1.js" <<DEPRECATED
exports.register = function () {
this.logerror('This plugin has moved. See https://github.com/haraka/haraka-plugin-$1');
}
DEPRECATED
$GIT_CMD add index.js
fi
if [ -f "tests/plugins/$1.js" ]; then
echo "copying tests/plugins/$1.js"
cp "tests/plugins/$1.js" "$PLUGIN_REPO/test/index.js"
git rm "tests/plugins/$1.js"
if [ ! -f "$PLUGIN_REPO/run_tests" ]; then
tee "$PLUGIN_REPO/run_tests" <<'EO_TEST_RUN'
#!/usr/bin/env node
'use strict'
try {
var reporter = require('nodeunit').reporters.default;
}
catch (e) {
console.log(`
Error: ${e.message}
Cannot find nodeunit. Did you run 'npm install'?
`)
process.exit()
}
process.chdir(__dirname);
reporter.run([ 'test' ], undefined, (err) => {
process.exit(((err) ? 1 : 0));
});
EO_TEST_RUN
sed -i '' \
-e 's/"_mocha"/"nodeunit"/' \
-e 's/"mocha"/"nodeunit"/' \
"$PLUGIN_REPO/package.json"
$GIT_CMD add package.json
fi
fi