generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOOTSTRAP.sh
47 lines (33 loc) · 2.1 KB
/
BOOTSTRAP.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
#!/usr/bin/env zsh
set -e # abort when any command errors, prevents this script from self-removing at the end if anything went wrong
echo -n "Plugin Name: "
read -r name
repo=$(git remote -v | head -n1 | sed 's/\.git.*//' | sed 's/.*://')
# plugin id is the same as the git repo name and can therefore be inferred
# INFO "The id can't contain `obsidian`." https://docs.obsidian.md/Plugins/Releasing/Submit+your+plugin#Step+3+Submit+your+plugin+for+review
id=$(echo "$repo" | cut -d/ -f2 | sed -E 's/-?obsidian-?//')
# desc can be inferred from github description (not using jq for portability)
desc=$(curl -sL "https://api.github.com/repos/$repo" | grep "description" | head -n1 | cut -d'"' -f4)
# plugin class can be id in camelcase and therefore also inferred
class=$(echo "$id" | perl -pe 's/^(\w)/\U$1/' | perl -pe 's/-(\w)/\U$1/g') # kebab-case to PascalCase
# current year for license
year=$(date +"%Y")
#───────────────────────────────────────────────────────────────────────────────
LC_ALL=C # prevent byte sequence error
# replace them all
# $1: placeholder name as {{mustache-template}}
# $2: the replacement
function replacePlaceholders() {
# INFO macOS' sed requires `sed -i ''`, remove the `''` when on Linux or using GNU sed
find . -type f -not -path '*/\.git/*' -not -name ".DS_Store" -not -path '*/node_modules/*' -exec sed -i '' "s|$1|$2|g" {} \;
}
replacePlaceholders "{{plugin-name}}" "$name"
replacePlaceholders "{{plugin-id}}" "$id"
replacePlaceholders "{{plugin-repo}}" "$repo"
replacePlaceholders "{{plugin-desc}}" "$desc"
replacePlaceholders "{{plugin-class}}" "$class"
replacePlaceholders "{{year}}" "$year"
#───────────────────────────────────────────────────────────────────────────────
print "\033[1;32mSuccess. Script will delete itself.\033[0m"
# make this script delete itself
rm -- "$0"