Are you tired of complex placeholders that breaks your code?
π€² If you (like me) is tired to losing your time with magical scaffolding tools with weird syntaxes and tons of useless functions, install Snip and scaffold now a new application.
because at the of the day we just want a new app based on some template to start our programming
π‘ Why use ${placeholder}
, {{placeholder}}
or [placeholder]
if we can just use __placeholder_
?
π¦ In any modern language, underscore _
is a valid name identifier,
because of that we just employ it in the placeholder syntax.
π§ But Snip is not limited only to programming languages. We are able to process any file that is not binary.
can you imagine the possibilities?
π With Snip we...:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/kattlo/snip/main/install.sh)"
From remote templation hosted in Github:
snip c -t snipme/java11-quarkus-maven code-with-snip
If you have a templation at localhost file system:
snip c -t file:/path/to/my/templation code-with-snip
π Build your brand new app
βοΈ Open it in your favorite IDE . . .
Every placeholder must follow this pattern:
__[a-zA-Z]+[\\w]*[0-9a-zA-Z]+_"
Simplifying...:
__myplaceholder_
__SomePlaceHolder_
__cde_place0_
__AB_Place90_
__place-holder_
_d_placeholder_
__e_place holder_
__20aplaceholder_
And you may use placeholders in directory names, file names and file content.
__namespace_
__placeholder_
Controller__namespace_
/__domain_
/__classname_
__entity_
.avsc__namespace_
/controller/__domain_
Get.java
package __namespace_;
public class __domain_Get{
}
### Built-in Placeholders
- `__namespace_`: project's namespace (aka package)
- `__name_`: project's name
- `__version_`: project's version
#### Processing of `__namespace_`
When `__namespace_` is used in directories names, there is a special
processing.
__Example__:
When the templation has a directory structure like this:
. βββ src βββ _namespace
And `__namespace_=com.example`. After Snip scaffolding, the
new directory structure will be:
. βββ src βββ com βββ example
### Custom Placeholders
As long as you follow the [placeholder pattern](#placeholders) and do not use
any [built-in placeholders](#built-in-placeholders), you may define your own
placeholders.
You must make clear in the templation docs what are the placeholders names
and the expected values.
To pass your custom placeholder to Snip scaffold is so simple, just use the
`-p` option as many as you want.
```bash
snip c <options> \
-p '__comment_=Some comments to use' \
-p "__author_=$USER" \
-p '__domain__=payments' \
-t <templation> \
'my-new-project-name'
To create your templation is so simple, you must refactor an existing project to use some of built-in placeholders and your own.
Done! π€ You have a templation to use.
Examples:
TODO
.snipignore
Always there are files and folders that you want to ignore during the scaffolding
process, for this you may create a .snipignore
file.
Example:
## Folders ##
.git/
.gradle/
build/
## Files ##
.project
.classpath
my-file.txt
## Wildcards ##
*.png
*.iml
*.iws
.snip.yml
To declare your custom placeholders and post scaffold scripts to execute,
you may create the .snip.yml
within your templation repository.
Example:
description: |
Java 11 with Gradle
placeholders:
strict: yes # Every placeholder in the spec must be present
spec:
- name: __c_author_
pattern: ".+" # [optional] Java Regex to validate the value: https://cutt.ly/OxOZBZY
label: Author Name
- name: __c_domain_
pattern: '[A-Z][\w]+' # [optional] Java Regex to validate the value: https://cutt.ly/OxOZBZY
label: Class name for Domain
post:
script: # The base directory for scripts is --directory
linux: # To run on Linux & MacOS
- ls -alh .
- ./gradlew clean test --info
windows: # to run on Windows
- .\gradlew.bat clean test --info
The following instructions per O.S. may be used to brand new installations or updates.
Method | Command |
---|---|
curl | sh -c "$(curl -fsSL https://raw.githubusercontent.com/kattlo/snip/main/install.sh)" |
wget | sh -c "$(wget -O- https://raw.githubusercontent.com/kattlo/snip/main/install.sh)" |
fetch | sh -c "$(fetch -o - https://raw.githubusercontent.com/kattlo/snip/main/install.sh)" |
Manual inspection
It's a good idea to inspect the install script from projects you don't yet know. You can do that by downloading the install script first, looking through it so everything looks normal, then running it:
wget https://raw.githubusercontent.com/kattlo/snip/main/install.sh
sh install.sh
snip
sudo chmod +x snip
sudo mv snip /usr/local/bin/snip
snip -h
VCRUNTIME140.dll
to C:\Windows\System32\
PATH
environment variablesnip -h
# Replace '<version>' with the downloaded version
java -jar snip-v<version>-all.jar -h
If you want to build an ΓΌber-jar, execute the following command:
./gradlew build -Dquarkus.package.type=uber-jar -PossrhUsername=inv4lid -PossrhPassword=inv4lid
The application is now runnable using java -jar cli/build/snip.jar
.
You can create a native executable using:
./gradlew clean build \
-Dquarkus.package.type=native \
-Dquarkus.native.additional-build-args=-H:EnableURLProtocols=https,-H:IncludeResources='.*json$' \
-PossrhUsername=inv4lid -PossrhPassword=inv4lid
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
./gradlew clean build \
-Dquarkus.package.type=native \
-Dquarkus.native.container-build=true \
-Dquarkus.native.additional-build-args=-H:EnableURLProtocols=https,-H:IncludeResources='.*json$' \
-PossrhUsername=inv4lid -PossrhPassword=inv4lid
You can then execute your native executable with: .cli/build/snip
If you want to learn more about building native executables, please consult https://quarkus.io/guides/gradle-tooling.