Skip to content

Commit cb23b1e

Browse files
committed
Add project files
1 parent 35eb2c4 commit cb23b1e

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
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"]

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
1-
# es2015-transpiler
2-
Trasnpilar javascript code to the ES2015 specification with the help of babel used by most browsers
1+
# Traspiler-JS Action
2+
3+
Github action to transpile javascript code to make it cross-browser compatible, using [@babel/cli](https://babeljs.io/docs/en/babel-cli), [@babel/core](https://www.npmjs.com/package/@babel/core) and [@babel/preset-env](https://babeljs.io/docs/en/babel-preset-env) packages.
4+
5+
### Usage
6+
Here the target branch is `foo`. You need to checkout your repository so the ES2015 Trasnpiler job can access it. Then, you can auto-commit the files to the repository if desired.
7+
8+
```yaml
9+
name: Transpiler-JS Workflow
10+
on:
11+
push:
12+
branches: [ master ]
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
# Checks-out your repository
19+
- uses: actions/checkout@v2
20+
with:
21+
ref: ${{ github.ref }}
22+
23+
# Job for transpiler the code
24+
- name: ESM2015 COMPILATION
25+
uses: jossydevers/transpiler-js@v1.0.0
26+
with:
27+
# If the typename is specified, the transpilation result file will be as follows path/filename.{tipename}.js
28+
# By default the value is 'release'
29+
typename: 'release' (OPTIONAL)
30+
# Directory in which to start searching for files to transpile
31+
# By default the entire repository is transpiled
32+
directory: 'src/' (OPTIONAL)
33+
# Directory where the transpilation result will be stored
34+
# By default each transpiled file is saved in the folder next to the original file
35+
output: 'transpile/' (OPTIONAL)
36+
37+
# Auto-commit to repository
38+
- uses: stefanzweifel/git-auto-commit-action@v4
39+
with:
40+
commit_message: Github Action : Code Transpiled
41+
branch: ${{ github.ref }}
42+
```

action.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Traspiler-JS Action'
2+
description: 'Transpile javascript code with Babel 7 to make it cross-browser compatible'
3+
4+
inputs:
5+
typename:
6+
description: "The typename sets the transpilation result file as follows: path/filename.{typename}.js (By default the value is 'release')"
7+
required: false
8+
directory:
9+
description: "Directory in which to start searching for files to transpile (By default the entire repository is transpiled)"
10+
required: false
11+
output:
12+
description: "Directory where the transpilation result will be stored (By default each transpiled file is saved in the folder next to the original file)"
13+
required: false
14+
15+
runs:
16+
using: 'docker'
17+
image: 'Dockerfile'
18+
19+
branding:
20+
icon: "box"
21+
color: "blue"

entrypoint.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
npm install --save-dev @babel/cli @babel/core @babel/preset-env
4+
5+
if [ -z "$INPUT_TYPENAME" ]
6+
then
7+
INPUT_TYPENAME="release"
8+
fi
9+
10+
transpile_file(){
11+
if [[ "$directory" != *"${INPUT_TYPENAME}."* ]];
12+
then
13+
directory=$1
14+
basename=$(basename $directory);
15+
extension="${basename##*.}"
16+
filename="${basename%.*}"
17+
if [ -z "$INPUT_OUTPUT" ];
18+
then
19+
output="${directory%/*}/"
20+
else
21+
mkdir -p $INPUT_OUTPUT
22+
output="$INPUT_OUTPUT";
23+
fi
24+
output_path="${output}${filename}.${INPUT_TYPENAME}.${extension}"
25+
$(npx babel ${directory} --out-file ${output_path} --presets /github/workspace/node_modules/@babel/preset-env)
26+
echo "COMPILE ${directory} | OUTPUT ${output_path}"
27+
fi
28+
}
29+
30+
for fname in "${INPUT_DIRECTORY}*.js"
31+
do
32+
transpile_file $fname;
33+
done

0 commit comments

Comments
 (0)