generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ 🎸 add out of container install
- Loading branch information
Showing
5 changed files
with
200 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/sh | ||
|
||
### Go to root | ||
cd $(git rev-parse --show-toplevel) >/dev/null | ||
|
||
### | ||
features=$(jq -r '.config.local[]' package.json) | ||
case $1 in | ||
--help) | ||
echo "Usage: $0 [--help] [<feature>]" | ||
exit | ||
;; | ||
*) | ||
echo "Selected features: $*" | npx --yes chalk-cli --stdin blue | ||
features=$* | ||
;; | ||
esac | ||
|
||
### 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 selected features | ||
for feature in $features; do | ||
if [ -f "./src/$feature/install.sh" ]; then | ||
### Run the install.sh script | ||
echo "Running src/$feature/install.sh..." | npx --yes chalk-cli --stdin blue | ||
bash ./src/$feature/install.sh /tmp | ||
else | ||
echo "$feature not found" | npx --yes chalk-cli --stdin red | ||
fi | ||
done | ||
|
||
### Call the configure.sh script in all selected features | ||
for feature in $features; do | ||
if [ -f "./src/$feature/configure.sh" ]; then | ||
### Run the install.sh script | ||
echo "Running src/$feature/configure.sh..." | npx --yes chalk-cli --stdin blue | ||
bash /tmp/$feature/configure.sh | ||
else | ||
echo "$feature not found" | npx --yes chalk-cli --stdin red | ||
fi | ||
done | ||
else | ||
echo "You are in a container: use devutils as devcontainer features:" | npx --yes chalk-cli --stdin yellow | ||
for feature in $features; do | ||
echo "ghcr.io/tomgrv/devcontainer-features/$feature" | ||
done | npx --yes chalk-cli --stdin yellow | ||
exit | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,123 @@ | ||
{ | ||
"name": "@tomgrv/devutils", | ||
"version": "1.0.0", | ||
"description": "Configure dev environment with devcontainer, gitflow, gitversion, git aliases & hooks. Can be used a devcontainer features", | ||
"keywords": [ | ||
"dev", | ||
"git", | ||
"hooks", | ||
"commitlint", | ||
"commitizen", | ||
"lint-staged", | ||
"prettier", | ||
"devmoji", | ||
"git-precommit-checks", | ||
"husky", | ||
"conventional-changelog", | ||
"gitversion", | ||
"gitflow", | ||
"changelog", | ||
"semver" | ||
], | ||
"homepage": "https://github.com/tomgrv/devcontainer-features#readme", | ||
"bugs": { | ||
"url": "https://github.com/tomgrv/devcontainer-features/issues", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/tomgrv/devcontainer-features.git" | ||
}, | ||
"funding": { | ||
"type": "individual", | ||
"url": "https://buymeacoffee.com/tomgrv" | ||
}, | ||
"author": "tomgrv", | ||
"type": "module", | ||
"bin": "./local-install.sh", | ||
"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" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "@commitlint/cz-commitlint" | ||
}, | ||
"local": [ | ||
"gitutils", | ||
"githooks" | ||
] | ||
}, | ||
"prettier": { | ||
"insertPragma": true, | ||
"semi": false, | ||
"singleQuote": true, | ||
"tabWidth": 4, | ||
"trailingComma": "es5" | ||
}, | ||
"peerDependencies": { | ||
"@commitlint/cli": "^19.2.2", | ||
"@commitlint/config-conventional": "^19.2.2", | ||
"@commitlint/core": "^19.2.2", | ||
"@commitlint/cz-commitlint": "^19.2.0", | ||
"commit-and-tag-version": "^12.4.1", | ||
"commitizen": "^4.3.0", | ||
"conventional-changelog-cli": "^2.1.1", | ||
"devmoji": "^2.3.0", | ||
"git-precommit-checks": "3.1.0", | ||
"husky": "^9.0.11", | ||
"lint-staged": "^15.2.2", | ||
"prettier": "^3.2.5" | ||
}, | ||
"commit-and-tag-version": { | ||
"bumpFiles": [ | ||
{ | ||
|
@@ -47,53 +166,9 @@ | |
"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" | ||
] | ||
], | ||
"scope-enum": [ | ||
2, | ||
"always", | ||
[ | ||
"deps", | ||
"release", | ||
"security", | ||
"i18n", | ||
"config", | ||
"add", | ||
"remove", | ||
"breaking", | ||
"modules", | ||
"packages", | ||
"ui-ux", | ||
"api", | ||
"model" | ||
] | ||
] | ||
} | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "@commitlint/cz-commitlint" | ||
"scripts": { | ||
"prebump": "gitversion -config .gitversion -showvariable MajorMinorPatch" | ||
} | ||
}, | ||
"git-precommit-checks": { | ||
|
@@ -109,20 +184,5 @@ | |
"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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters