Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Feature/language typescript (#254)
Browse files Browse the repository at this point in the history
* set inicial files for typescript template

Signed-off-by: Bruno N. Melo <[email protected]>

* fix on build and makefile

Signed-off-by: Bruno N. Melo <[email protected]>

* update and fix imports

Signed-off-by: Bruno N. Melo <[email protected]>

* adding new line on end of tsconfig

Signed-off-by: Bruno N. Melo <[email protected]>

* fix tsconfig Pretty format to pass on test

Signed-off-by: Bruno N. Melo <[email protected]>

* Fixing pretty

Signed-off-by: Bruno N. Melo <[email protected]>

* update on hello-world formula to the new template

Signed-off-by: Bruno N. Melo <[email protected]>

* fix some bugs

Signed-off-by: Bruno N. Melo <[email protected]>

* simplifying template removing interface

Signed-off-by: Bruno N. Melo <[email protected]>

* rename variables

Signed-off-by: Bruno N. Melo <[email protected]>
  • Loading branch information
brunonmelo authored Oct 2, 2020
1 parent 1929c42 commit f3ac1e7
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 0 deletions.
15 changes: 15 additions & 0 deletions templates/create_formula/languages/typescript/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM cimg/node:14.0

USER root

RUN curl -fsSL https://commons-repo.ritchiecli.io/install.sh | bash

RUN mkdir /rit
COPY . /rit
RUN sed -i 's/\r//g' /rit/set_umask.sh
RUN sed -i 's/\r//g' /rit/run.sh
RUN chmod +x /rit/set_umask.sh

WORKDIR /app
ENTRYPOINT ["/rit/set_umask.sh"]
CMD ["/rit/run.sh"]
19 changes: 19 additions & 0 deletions templates/create_formula/languages/typescript/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Make Run Node
BINARY_NAME_UNIX=run.sh
BINARY_NAME_WINDOWS=run.bat
BIN_FOLDER=bin

build: node-build docker

node-build:
mkdir -p $(BIN_FOLDER)
cp -r src/* $(BIN_FOLDER)
npm install --silent --no-progress --prefix $(BIN_FOLDER)
npm run build --silent --prefix $(BIN_FOLDER)
echo '#!/bin/sh' > $(BIN_FOLDER)/$(BINARY_NAME_UNIX)
echo 'node "$$(dirname "$$0")"/dist/index.js' >> $(BIN_FOLDER)/$(BINARY_NAME_UNIX)
echo 'node /dist/index.js' > $(BIN_FOLDER)/$(BINARY_NAME_WINDOWS)
chmod +x $(BIN_FOLDER)/$(BINARY_NAME_UNIX)

docker:
cp Dockerfile set_umask.sh $(BIN_FOLDER)
11 changes: 11 additions & 0 deletions templates/create_formula/languages/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ritchie Formula

## Command

```bash
#rit-replace{formulaCmd}
```

## Description

Formula description
33 changes: 33 additions & 0 deletions templates/create_formula/languages/typescript/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
:: Node parameters
echo off
SETLOCAL
SET BIN_FOLDER=bin
SET BAT_FILE=%BIN_FOLDER%\run.bat
SET SH_FILE=%BIN_FOLDER%\run.sh
:build
mkdir %BIN_FOLDER%
xcopy /E /I src %BIN_FOLDER%
cd %BIN_FOLDER%
call npm install --silent
call npm run build --silent
cd ..
call :BAT_WINDOWS
call :SH_LINUX
call :CP_DOCKER
GOTO DONE

:BAT_WINDOWS
echo @ECHO OFF > %BAT_FILE%
echo SET mypath=%%~dp0 >> %BAT_FILE%
echo start /B /WAIT node %%mypath:~0,-1%%/dist/index.js >> %BAT_FILE%

:SH_LINUX
echo node "$(dirname "$0")"/dist/index.js > %SH_FILE%
GOTO DONE

:CP_DOCKER
copy Dockerfile %BIN_FOLDER%
copy set_umask.sh %BIN_FOLDER%
GOTO DONE

:DONE
42 changes: 42 additions & 0 deletions templates/create_formula/languages/typescript/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"dockerImageBuilder": "cimg/node:14.0",
"inputs": [
{
"cache": {
"active": true,
"newLabel": "Type new value. ",
"qty": 3
},
"label": "Type your name: ",
"name": "input_text",
"type": "text"
},
{
"default": "false",
"items": [
"false",
"true"
],
"label": "Have you ever used Ritchie? ",
"name": "input_boolean",
"type": "bool"
},
{
"default": "everything",
"items": [
"daily tasks",
"workflows",
"toils",
"everything"
],
"label": "What do you want to automate? ",
"name": "input_list",
"type": "text"
},
{
"label": "Tell us a secret: ",
"name": "input_password",
"type": "password"
}
]
}
17 changes: 17 additions & 0 deletions templates/create_formula/languages/typescript/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"execution": [
"local",
"docker"
],
"os": {
"deps": [],
"support": [
"windows",
"mac",
"linux"
]
},
"tags": [
"#rit-replace{formulaTags}"
]
}
3 changes: 3 additions & 0 deletions templates/create_formula/languages/typescript/set_umask.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
umask 0011
$1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as chalk from 'chalk'

function run(inputText: string, inputBoolean: boolean, inputList: string, inputPassword: string) {
console.log('Hello World!')

console.log(chalk.green(`My name is ${inputText}.`))

if (inputBoolean) {
console.log(chalk.blue('I’ve already created formulas using Ritchie.'))
} else {
console.log(chalk.red('I’m excited in creating new formulas using Ritchie.'))
}

console.log(chalk.yellow(`Today, I want to automate ${inputList}.`))

console.log(chalk.cyan(`My secret is ${inputPassword}.`))
}

const Formula = run
export default Formula
8 changes: 8 additions & 0 deletions templates/create_formula/languages/typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import run from './formula/Formula'

const inputText: string = process.env.INPUT_TEXT
const inputBoolean: boolean = JSON.parse(process.env.INPUT_BOOLEAN.toLowerCase())
const inputList: string = process.env.INPUT_LIST
const inputPassword: string = process.env.INPUT_PASSWORD

run(inputText, inputBoolean, inputList, inputPassword)
15 changes: 15 additions & 0 deletions templates/create_formula/languages/typescript/src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"dependencies": {
"chalk": "^4.1.0",
"typescript": "^3.1.6"
},
"devDependencies": {
"@types/node": "^14.11.2"
},
"main": "index.js",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.0.0"
}
17 changes: 17 additions & 0 deletions templates/create_formula/languages/typescript/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"sourceMap": true,
"target": "es6",
"types": [
"node"
]
},
"exclude": [
"node_modules"
],
"include": [
"./**/*.ts"
]
}

0 comments on commit f3ac1e7

Please sign in to comment.