Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian.panek committed Jan 23, 2018
1 parent 82e8d47 commit e7fd89f
Show file tree
Hide file tree
Showing 2 changed files with 238 additions and 14 deletions.
63 changes: 49 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@

## Description

Project generator based on live archetypes (example projects).
**Project generator based on live archetypes** (example projects).

Newcomers of Gradle Build System very often complain about that in Gradle there is no Maven's archetype like mechanism OOTB. This plugin tries to fill that gap.

Assumptions:

* instead of creating a virtual project aka Maven Archetype with placeholders, plugin allows to treat any existing project like a base for a new project.
* maintenance of real / working example projects is easier than maintaining archetypes (there is no need to regenerate project every time to prove that archetype is working properly).
* it is easier to copy rich example project and remove redundant things than creating and assembling project from the scratch.
* from business perspective, plugin allows to perform rebranding at code level (perform massive renaming, repackaging).
* Instead of creating a virtual project aka Maven Archetype with placeholders, plugin allows to treat any existing project like a base for a new project.
* It is easier to copy rich example project and remove redundant things than creating project from archetype and looking for missing things.
* From business perspective, plugin allows to automate rebranding at code level (perform massive renaming, repackaging).
* Maintenance of real / working example projects is probably easier than maintaining archetypes (there is no need to regenerate project every time to prove that archetype is working properly).

## Table of Contents

* [Usage](#usage)
* [Defining and executing configurations](#defining-and-executing-configurations)
* [Providing properties](#providing-properties)
* [Output](#output)
* [License](#license)

## Usage

Expand All @@ -29,7 +39,7 @@ buildscript {
apply plugin: 'com.neva.fork'
fork {
config {
config { // 'default'
cloneFiles()
moveFiles([
"/example": "/{{projectName}}"
Expand All @@ -41,20 +51,38 @@ fork {
])
copyTemplateFile("gradle.properties")
}
config 'setup', {
copyTemplateFile("gradle.properties")
}
}
```

Fork configuration above will:
### Defining and executing configurations

* copy all project files respecting filtering defined in *.gitignore* files,
* rename directories using rules with properties injecting,
* replace contents using rules with properties injecting.
Default fork configuration will:

To execute fork configuration, run command:
* Copy all project files respecting filtering defined in *.gitignore* files.
* Rename directories using rules with properties injecting.
* Replace contents using rules with properties injecting.
* Generate from template a file containing user specific properties (like repository credentials etc).

```bash
sh gradlew fork
```
Setup fork configuration will:

* Do only last step from default configuration.

1. To execute default configuration, run command:

```bash
sh gradlew fork
```

2. To execute configuration named `setup`, run command:

```bash
sh gradlew fork -Pfork.config=setup
```

### Providing properties

Properties can be provided by (order makes precedence):

Expand Down Expand Up @@ -93,6 +121,8 @@ Properties can be provided by (order makes precedence):

4. Mixed approach.

### Output

As a fork result, there will be a cloned project with correctly changed directory names, with replaced project name and label in text files (all stuff being previously performed manually).

<pre>
Expand All @@ -108,3 +138,8 @@ Replacing 'example' with 'sample' in file C:\Users\krystian.panek\Projects\sampl
Copying file from C:\Users\krystian.panek\Projects\example\gradle\fork\gradle.properties to ..\sample\gradle.properties
Expanding properties in file ..\sample\gradle.properties
</pre>

## License

**Gradle AEM Plugin** is licensed under the [Apache License, Version 2.0 (the "License")](https://www.apache.org/licenses/LICENSE-2.0.txt)

189 changes: 189 additions & 0 deletions gh-md-toc
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#!/usr/bin/env bash

#
# Steps:
#
# 1. Download corresponding html file for some README.md:
# curl -s $1
#
# 2. Discard rows where no substring 'user-content-' (github's markup):
# awk '/user-content-/ { ...
#
# 3.1 Get last number in each row like ' ... </span></a>sitemap.js</h1'.
# It's a level of the current header:
# substr($0, length($0), 1)
#
# 3.2 Get level from 3.1 and insert corresponding number of spaces before '*':
# sprintf("%*s", substr($0, length($0), 1)*3, " ")
#
# 4. Find head's text and insert it inside "* [ ... ]":
# substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
#
# 5. Find anchor and insert it inside "(...)":
# substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8)
#

gh_toc_version="0.4.9"

gh_user_agent="gh-md-toc v$gh_toc_version"

#
# Download rendered into html README.md by its url.
#
#
gh_toc_load() {
local gh_url=$1

if type curl &>/dev/null; then
curl --user-agent "$gh_user_agent" -s "$gh_url"
elif type wget &>/dev/null; then
wget --user-agent="$gh_user_agent" -qO- "$gh_url"
else
echo "Please, install 'curl' or 'wget' and try again."
exit 1
fi
}

#
# Converts local md file into html by GitHub
#
# ➥ curl -X POST --data '{"text": "Hello world github/linguist#1 **cool**, and #1!"}' https://api.github.com/markdown
# <p>Hello world github/linguist#1 <strong>cool</strong>, and #1!</p>'"
gh_toc_md2html() {
local gh_file_md=$1
URL=https://api.github.com/markdown/raw
TOKEN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt"
if [ -f "$TOKEN" ]; then
URL="$URL?access_token=$(cat $TOKEN)"
fi
curl -s --user-agent "$gh_user_agent" \
--data-binary @"$gh_file_md" -H "Content-Type:text/plain" \
$URL
}

#
# Is passed string url
#
gh_is_url() {
case $1 in
https* | http*)
echo "yes";;
*)
echo "no";;
esac
}

#
# TOC generator
#
gh_toc(){
local gh_src=$1
local gh_src_copy=$1
local gh_ttl_docs=$2

if [ "$gh_src" = "" ]; then
echo "Please, enter URL or local path for a README.md"
exit 1
fi


# Show "TOC" string only if working with one document
if [ "$gh_ttl_docs" = "1" ]; then

echo "Table of Contents"
echo "================="
echo ""
gh_src_copy=""

fi

if [ "$(gh_is_url "$gh_src")" == "yes" ]; then
gh_toc_load "$gh_src" | gh_toc_grab "$gh_src_copy"
else
gh_toc_md2html "$gh_src" | gh_toc_grab "$gh_src_copy"
fi
}

#
# Grabber of the TOC from rendered html
#
# $1 — a source url of document.
# It's need if TOC is generated for multiple documents.
#
gh_toc_grab() {
# if closed <h[1-6]> is on the new line, then move it on the prev line
# for example:
# was: The command <code>foo1</code>
# </h1>
# became: The command <code>foo1</code></h1>
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
# find strings that corresponds to template
grep -E -o '<a.*id="user-content-[^"]*".*</h[1-6]' |
# remove code tags
sed 's/<code>//' | sed 's/<\/code>//' |
# now all rows are like:
# <a id="user-content-..." href="..."><span ...></span></a> ... </h1
# format result line
# * $0 — whole string
echo -e "$(awk -v "gh_url=$1" '{
print sprintf("%*s", substr($0, length($0), 1)*3, " ") "* [" substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)"](" gh_url substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8) ")"}' | sed 'y/+/ /; s/%/\\x/g')"
}

#
# Returns filename only from full path or url
#
gh_toc_get_filename() {
echo "${1##*/}"
}

#
# Options hendlers
#
gh_toc_app() {
local app_name="gh-md-toc"

if [ "$1" = '--help' ] || [ $# -eq 0 ] ; then
echo "GitHub TOC generator ($app_name): $gh_toc_version"
echo ""
echo "Usage:"
echo " $app_name src [src] Create TOC for a README file (url or local path)"
echo " $app_name - Create TOC for markdown from STDIN"
echo " $app_name --help Show help"
echo " $app_name --version Show version"
return
fi

if [ "$1" = '--version' ]; then
echo "$gh_toc_version"
return
fi

if [ "$1" = "-" ]; then
if [ -z "$TMPDIR" ]; then
TMPDIR="/tmp"
elif [ -n "$TMPDIR" -a ! -d "$TMPDIR" ]; then
mkdir -p "$TMPDIR"
fi
local gh_tmp_md
gh_tmp_md=$(mktemp $TMPDIR/tmp.XXXXXX)
while read input; do
echo "$input" >> "$gh_tmp_md"
done
gh_toc_md2html "$gh_tmp_md" | gh_toc_grab ""
return
fi

for md in "$@"
do
echo ""
gh_toc "$md" "$#"
done

echo ""
echo "Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)"
}

#
# Entry point
#
gh_toc_app "$@"

0 comments on commit e7fd89f

Please sign in to comment.