diff --git a/templates/create_formula/languages/typescript/Dockerfile b/templates/create_formula/languages/typescript/Dockerfile new file mode 100644 index 00000000..98982798 --- /dev/null +++ b/templates/create_formula/languages/typescript/Dockerfile @@ -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"] diff --git a/templates/create_formula/languages/typescript/Makefile b/templates/create_formula/languages/typescript/Makefile new file mode 100644 index 00000000..b67070b1 --- /dev/null +++ b/templates/create_formula/languages/typescript/Makefile @@ -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) diff --git a/templates/create_formula/languages/typescript/README.md b/templates/create_formula/languages/typescript/README.md new file mode 100644 index 00000000..24d35136 --- /dev/null +++ b/templates/create_formula/languages/typescript/README.md @@ -0,0 +1,11 @@ +# Ritchie Formula + +## Command + +```bash +#rit-replace{formulaCmd} +``` + +## Description + +Formula description diff --git a/templates/create_formula/languages/typescript/build.bat b/templates/create_formula/languages/typescript/build.bat new file mode 100644 index 00000000..f9f3d462 --- /dev/null +++ b/templates/create_formula/languages/typescript/build.bat @@ -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 diff --git a/templates/create_formula/languages/typescript/config.json b/templates/create_formula/languages/typescript/config.json new file mode 100644 index 00000000..f37a72ed --- /dev/null +++ b/templates/create_formula/languages/typescript/config.json @@ -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" + } + ] +} diff --git a/templates/create_formula/languages/typescript/metadata.json b/templates/create_formula/languages/typescript/metadata.json new file mode 100644 index 00000000..c7e6c4b9 --- /dev/null +++ b/templates/create_formula/languages/typescript/metadata.json @@ -0,0 +1,17 @@ +{ + "execution": [ + "local", + "docker" + ], + "os": { + "deps": [], + "support": [ + "windows", + "mac", + "linux" + ] + }, + "tags": [ + "#rit-replace{formulaTags}" + ] +} diff --git a/templates/create_formula/languages/typescript/set_umask.sh b/templates/create_formula/languages/typescript/set_umask.sh new file mode 100644 index 00000000..091c13d6 --- /dev/null +++ b/templates/create_formula/languages/typescript/set_umask.sh @@ -0,0 +1,3 @@ +#!/bin/sh +umask 0011 +$1 diff --git a/templates/create_formula/languages/typescript/src/formula/Formula.ts b/templates/create_formula/languages/typescript/src/formula/Formula.ts new file mode 100644 index 00000000..90f7a426 --- /dev/null +++ b/templates/create_formula/languages/typescript/src/formula/Formula.ts @@ -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 diff --git a/templates/create_formula/languages/typescript/src/index.ts b/templates/create_formula/languages/typescript/src/index.ts new file mode 100644 index 00000000..63e41b37 --- /dev/null +++ b/templates/create_formula/languages/typescript/src/index.ts @@ -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) diff --git a/templates/create_formula/languages/typescript/src/package.json b/templates/create_formula/languages/typescript/src/package.json new file mode 100644 index 00000000..511903c9 --- /dev/null +++ b/templates/create_formula/languages/typescript/src/package.json @@ -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" +} diff --git a/templates/create_formula/languages/typescript/src/tsconfig.json b/templates/create_formula/languages/typescript/src/tsconfig.json new file mode 100644 index 00000000..f110088c --- /dev/null +++ b/templates/create_formula/languages/typescript/src/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "outDir": "dist", + "sourceMap": true, + "target": "es6", + "types": [ + "node" + ] + }, + "exclude": [ + "node_modules" + ], + "include": [ + "./**/*.ts" + ] +}