Skip to content

Commit

Permalink
feat: ✨ 🎸 add out of container install
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgrv committed Sep 16, 2024
1 parent 30a41c7 commit fbf6be5
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 136 deletions.
36 changes: 36 additions & 0 deletions local-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

### Go to root
cd $(git rev-parse --show-toplevel) >/dev/null

### Stash all changes including untracked files
stash=$(git stash -u && echo true)

### Ask to restart in container if this is not already the case
if [ "$CODESPACES" != "true" ] && [ "$REMOTE_CONTAINERS" != "true" ]; then
echo "You are not in a container" | npx --yes chalk-cli --stdin green

### Call the install.sh script in all subfloder of the dist folder
for module in $(jq -r '.config.local[]' package.json); do

### Run the install.sh script
echo "Running src/$module/install.sh..." | npx --yes chalk-cli --stdin blue
bash ./src/$module/install.sh /tmp
done

### Call the configure.sh script in all subfloder of the dist folder
for module in $(jq -r '.config.local[]' package.json); do

### Run the install.sh script
echo "Running src/$module/configure.sh..." | npx --yes chalk-cli --stdin blue
bash /tmp/$module/configure.sh
done
fi

### Stage non withespace changes
git ls-files --others --exclude-standard | xargs -I {} bash -c 'if [ -s "{}" ]; then git add "{}"; fi'
git diff -w --no-color | git apply --cached --ignore-whitespace
git checkout -- . && git reset && git add .

### Unstash changes
test -n "$stash" && git stash apply && git stash drop
256 changes: 133 additions & 123 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,128 +1,138 @@
{
"commit-and-tag-version": {
"bumpFiles": [
{
"filename": "composer.json",
"type": "json"
},
{
"filename": "package.json",
"type": "json"
},
{
"filename": "VERSION",
"type": "plain-text"
}
],
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"hidden": true
},
{
"type": "docs",
"hidden": true
},
{
"type": "style",
"hidden": true
},
{
"type": "refactor",
"hidden": true
},
{
"type": "perf",
"hidden": true
},
{
"type": "test",
"hidden": true
}
]
},
"scripts": {
"release": "npx commit-and-tag-version --no-verify --",
"lint": "npx lint-staged",
"update": "npx npm-check-updates -i -u",
"update-all": "npx npm run update -ws --root",
"test": "echo \"Warning: no test specified\""
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
],
"rules": {
"subject-case": [
2,
"never",
[
"start-case",
"pascal-case",
"upper-case"
"scripts": {
"lint": "npx --yes lint-staged",
"release": "npx --yes commit-and-tag-version --no-verify --",
"test": "echo \"Warning: no test specified\"",
"update": "npm-check-updates -i -u",
"update-all": "npm run update -ws --root"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
],
"rules": {
"subject-case": [
2,
"never",
[
"start-case",
"pascal-case",
"upper-case"
]
],
"scope-enum": [
2,
"always",
[
"deps",
"release",
"security",
"i18n",
"config",
"add",
"remove",
"breaking",
"modules",
"packages",
"ui-ux",
"api",
"model"
]
]
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,md,html,css,json,vue, yaml, yml}": [
"npx --yes prettier --write"
],
"*.php": [
"composer lint"
],
"package.json": [
"npx --yes sort-package-json"
]
],
"scope-enum": [
2,
"always",
[
"deps",
"release",
"security",
"i18n",
"config",
"add",
"remove",
"breaking",
"modules",
"packages",
"ui-ux",
"api",
"model"
},
"config": {
"commitizen": {
"path": "@commitlint/cz-commitlint"
},
"local": [
"gitutils",
"githooks"
]
},
"prettier": {
"insertPragma": true,
"semi": false,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "es5"
},
"commit-and-tag-version": {
"bumpFiles": [
{
"filename": "composer.json",
"type": "json"
},
{
"filename": "package.json",
"type": "json"
},
{
"filename": "VERSION",
"type": "plain-text"
}
],
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"hidden": true
},
{
"type": "docs",
"hidden": true
},
{
"type": "style",
"hidden": true
},
{
"type": "refactor",
"hidden": true
},
{
"type": "perf",
"hidden": true
},
{
"type": "test",
"hidden": true
}
],
"scripts": {
"prebump": "gitversion -config .gitversion -showvariable MajorMinorPatch"
}
},
"git-precommit-checks": {
"rules": [
{
"message": "You've got leftover conflict markers",
"regex": "/^[<>|=]{4,}/m"
},
{
"filter": "(^package\\.json|\\.git-precommit-checks.json)$",
"message": "You have unfinished devs",
"nonBlocking": "true",
"regex": "(?:FIXME|TODO)"
}
]
]
}
},
"config": {
"commitizen": {
"path": "@commitlint/cz-commitlint"
}
},
"git-precommit-checks": {
"rules": [
{
"message": "You've got leftover conflict markers",
"regex": "/^[<>|=]{4,}/m"
},
{
"filter": "(^package\\.json|\\.git-precommit-checks.json)$",
"message": "You have unfinished devs",
"nonBlocking": "true",
"regex": "(?:FIXME|TODO)"
}
]
},
"lint-staged": {
"*.{js,jsx,ts,tsx,md,html,css,json,vue, yaml, yml}": [
"npx prettier --write"
],
"*.php": [
"composer lint"
]
},
"prettier": {
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"insertPragma": true
}
}
2 changes: 1 addition & 1 deletion src/githooks/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
### Init directories
export source=$(dirname $(readlink -f $0))
export feature=$(basename $source | sed 's/_.*$//')
export target=/usr/local/share/$feature
export target=${1:-/usr/local/share}/$feature
echo "Activating feature <$feature>..."

### Makes sure the target directory exists
Expand Down
27 changes: 16 additions & 11 deletions src/gitutils/install-aliases.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
#!/bin/sh
set -e

### Install GitFlow with apt on Ubuntu or apk on Alpine
if [ -f /etc/alpine-release ]; then
apk update
apk add git-flow dos2unix jq
else
apt-get update
apt-get install -y git-flow dos2unix jq
fi
### Check if utils are installed
for bin in git-flow dos2unix jq; do
if [ -n "$(command -v $bin)" ]
then
echo "$bin is installed." | npx --yes chalk-cli --stdin green
elif [ -f /etc/alpine-release ]; then
apk update
apk add $bin
else
sudo apt-get update
sudo apt-get install -y $bin
fi
done

### For each entry in config.json file next to this file, create corresponding git config from key and value.
### if value is an object, parse it as json and create dotted keys
echo "Configuring git with <$source/config.json>..."
jq -r 'paths(scalars) as $p | [($p|join(".")), (getpath($p)|tostring)] | join(" ")' $source/config.json | while read key value; do
git config --system $key "$value"
git config --global $key "$value"
echo "Created config $key => $value"
done

### For each entry in alias.json file next to this file, create corresponding git alias from key and value
echo "Configuring aliases with <$source/alias.json>..."
jq -r 'keys[]' $source/alias.json | dos2unix | while read key; do
value=$(jq -r ".$key" $source/alias.json)
git config --system alias.$key "!sh -c '$value' - "
git config --global alias.$key "!sh -c '$value' - "
echo "Created alias $key => $value"
done

### For each script starting with _, create corresponding git alias without _ from script name
echo "Configuring scripts with <$target/_xx.sh>..."
for script in $target/_*.sh; do
alias=$(basename $script | sed -e 's/^_//g' -e 's/.sh$//g')
git config --system alias.$alias "!sh -c '$(readlink -f $script)' - "
git config --global alias.$alias "!sh -c '$(readlink -f $script)' - "
echo "Created alias $alias => $(readlink -f $script)"
done
2 changes: 1 addition & 1 deletion src/gitutils/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
### Init directories
export source=$(dirname $(readlink -f $0))
export feature=$(basename $source | sed 's/_.*$//')
export target=/usr/local/share/$feature
export target=${1:-/usr/local/share}/$feature
echo "Activating feature <$feature>..."

### Makes sure the target directory exists
Expand Down

0 comments on commit fbf6be5

Please sign in to comment.