Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
Cómo crear mi propio cli usando mecanografiado y nodo

Quiero crear mi propio cli usando TypeScript y Node.

Después de construir el código usando tsc , lo instalé como un cli global usando npm install -g . Cuando se ejecuta test-cli en cmd, se espera que imprima "test" en la consola, pero en su lugar abre un archivo javascript build/index.js en el editor. Parece que abre un archivo en lugar de ejecutar el archivo.

Mientras revisaba el archivo test-cli.cmd en C:\Users\MyUser\AppData\Roaming\npm , descubrí que es un poco diferente de otros archivos cli exitosos.

contenido test-cli.cmd (no funciona):

 ... "%dp0%\node_modules\test-cli\build\index.js" %* ...

Contenido truffle.cmd (funciona correctamente):

 ... IF EXIST "%dp0%\node.exe" ( SET "_prog=%dp0%\node.exe" ) ELSE ( SET "_prog=node" SET PATHEXT=%PATHEXT:;.JS;=;% ) "%_prog%" "%dp0%\node_modules\truffle\build\cli.bundled.js" %* ...

Definitivamente tener una diferencia para especificar node.exe para ejecutar ese archivo javascript. ¿Como puedo solucionar este problema?

Aquí está mi descripción general del código :

Árbol de fuentes:

 |__build | |__index.js | |__index.map.js |__src | |__index.ts |__package.json |__tsconfig.json

index.ts solo tiene un código simple.

 // index.ts console.log("my test cli");

También tenga datos simples en package.json

 // package.json { "name": "test-cli", "version": "1.0.0", "main": "src/index.ts", "bin": { "test-cli": "build/index.js" }, "license": "MIT", "scripts": { "build": "tsc", "test": "echo \"Error: no test specified\" && exit 1" }, "devDependencies": { "@types/node": "^17.0.22", "ts-node": "^10.7.0", "typescript": "^4.6.2" } }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!