Skip to content

Commit e7d2135

Browse files
committed
Add project files
0 parents  commit e7d2135

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM node:12
2+
COPY entrypoint.sh /entrypoint.sh
3+
RUN chmod +x /entrypoint.sh
4+
ENTRYPOINT ["/entrypoint.sh"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Jossy Devers
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Minify-JS Action
2+
3+
## Package Managers
4+
5+
## License
6+
[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/JossyDevers/minify-js/blob/master/LICENSE)
7+
8+
## Version
9+
[![GitHub Release](https://img.shields.io/github/v/release/jossydevers/minify-js)]()
10+
11+
Github action to minify html, javascript and css files, using [minify](https://www.npmjs.com/package/minify).
12+
13+
### Usage
14+
First you need to check out your repository, then configure the Minify-JS job, at the end you can commit to your repository.
15+
Below is an example of how to do all of this.
16+
17+
```yaml
18+
name: Minify Workflow
19+
on:
20+
push:
21+
branches: [ master ]
22+
23+
jobs:
24+
build:
25+
runs-on: ubuntu-latest
26+
steps:
27+
# Checks-out your repository
28+
- uses: actions/checkout@v2
29+
with:
30+
ref: ${{ github.ref }}
31+
32+
# Job for Minify-JS
33+
- name: Minify-JS Action
34+
uses: jossydevers/minify-js@v1.0.0
35+
with:
36+
directory: 'src/component.js' # (OPTIONAL)
37+
output: 'minify/src/' # (OPTIONAL)
38+
39+
# Auto-commit to repository
40+
- uses: stefanzweifel/git-auto-commit-action@v4
41+
with:
42+
commit_message: 'Minify-JS : Commit Pipeline'
43+
branch: ${{ github.ref }}
44+
```

action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Minify-JS Action'
2+
description: 'Github action to minify html, javascript and css files, using @minify package'
3+
4+
inputs:
5+
directory:
6+
description: "File to minify, (By default it minifies in all routes)"
7+
required: false
8+
output:
9+
description: "Path where the minified files will be saved (By default the minified files will be saved in the original file path)"
10+
required: false
11+
12+
runs:
13+
using: 'docker'
14+
image: 'Dockerfile'
15+
16+
branding:
17+
icon: "box"
18+
color: "green"

entrypoint.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
npm install -g minify
3+
apt-get update
4+
apt-get -y install moreutils
5+
6+
minify_file(){
7+
directory=$1
8+
basename=$(basename $directory);
9+
extension="${basename##*.}"
10+
output="";
11+
if [ -z "$INPUT_OUTPUT" ]
12+
then
13+
output="${directory%/*}/"
14+
else
15+
mkdir -p $INPUT_OUTPUT
16+
output="$INPUT_OUTPUT";
17+
fi
18+
filename="${basename%.*}"
19+
output_path="${output}${filename}.min.${extension}"
20+
rm ${output_path}
21+
minify ${directory} | sponge ${output_path}
22+
echo "Minified ${directory} > ${output_path}"
23+
}
24+
25+
if [ -z "$INPUT_DIRECTORY" ]
26+
then
27+
find . -type f \( -iname \*.html -o -iname \*.js -o -iname \*.css \) | while read fname
28+
do
29+
if [[ "$fname" != *"min."* ]]; then
30+
minify_file $fname
31+
fi
32+
done
33+
else
34+
minify_file $INPUT_DIRECTORY
35+
fi

0 commit comments

Comments
 (0)