Last active
January 11, 2023 19:23
-
-
Save neverkas/7253ee1ecd66c1c64cfad368443e15bb to your computer and use it in GitHub Desktop.
Ejecutar Servidor HTTP + Evitar instalar paquetes npm de forma global
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Renombrar el archivo por Makefile | |
| # | |
| # Objetivos: | |
| # 1. Ejecutar paquetes npm del proyecto inicializado | |
| # 2. Evitar instalar paquetes npm de forma global con -g | |
| # | |
| package-http-server = light-server | |
| package-params=-s . -p 8000 | |
| npm_bin=$$(npm bin) | |
| ##@ Utilidades | |
| init: install-npm-packages ## Inicializar proyecto | |
| $(info Proyecto npm inicializado) | |
| # Nota: el doble $ es para que NO lo evalué como una macro de GNU Make | |
| r run: ## Ejecutar Servidor HTTP | |
| $(npm_bin)/$(package-http-server) $(package-params) | |
| # Nota: alternativa, si el otro target run no funcione | |
| xrun: ## Ejecutar Servidor HTTP (alternativa) | |
| export PATH="./node_modules/.bin:$$PATH" && \ | |
| $(package-http-server) $(package-params) | |
| # Nota: con --yes en el npm init, nos evita completar los datos de package.json | |
| i install-npm-packages: ## Instalar paquetes npm | |
| npm init --yes && npm install $(package-http-server) --save-dev | |
| ##@ Otros | |
| c clean: ## Limpiar recursos | |
| rm package.json | |
| rm -rvf node_modules | |
| h help: ## Mostrar menú de ayuda | |
| @awk 'BEGIN {FS = ":.*##"; printf "\nOpciones para usar:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | |
| .PHONY: h help init r run xrun c clean i install-npm-packages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Objetivos: | |
| # 1. Ejecutar paquetes npm del proyecto inicializado | |
| # 2. Evitar instalar paquetes npm de forma global con -g | |
| # | |
| # Nota: el doble $ es para que NO lo evalué como una macro de GNU Make, | |
| # escapamos el $ para que lo tome como un caracter común | |
| npm_bin=$$(npm bin) | |
| dir_js=./js | |
| typescript_params=--outdir $(dir_js) | |
| typescript_bin=$(npm_bin)/tsc $(typescript_params) | |
| ##@ Utilidades | |
| init: install-npm-packages ## Inicializar proyecto | |
| $(info Proyecto npm inicializado) | |
| # Nota: con --yes en el npm init, nos evita completar los datos de package.json | |
| i install-npm-packages: | |
| npm init --yes && \ | |
| npm install typescript @types/node --save-dev && \ | |
| npm install rxjs --save-dev | |
| ##@ Ejemplos RxJs agrupados por tipo de operador | |
| operadores-de-creacion: ## | |
| $(typescript_bin) $@.ts && node $(dir_js)/$@.js | |
| operadores-de-filtrado: ## | |
| $(typescript_bin) $@.ts && node $(dir_js)/$@.js | |
| operadores-de-transformacion: ## | |
| $(typescript_bin) $@.ts && node $(dir_js)/$@.js | |
| ##@ Otros | |
| c clean: clean-js-files ## Limpiar recursos | |
| rm package*.json | |
| rm -rvf node_modules | |
| clean-js-files: ## Eliminar archivos transpilados | |
| rm -vf $(dir_js)/*.js | |
| h help: ## Mostrar menú de ayuda | |
| @awk 'BEGIN {FS = ":.*##"; printf "\nOpciones para usar:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | |
| .PHONY: h help init r c clean i install-npm-packages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| HTTP_PORT=8000 | |
| run: | |
| python -m SimpleHTTPServer $(HTTP_PORT) | |
| .PHONY: run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment