Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample code doesn't work (with ts-node) #41

Open
jrhite opened this issue Jan 23, 2018 · 6 comments · May be fixed by #47
Open

sample code doesn't work (with ts-node) #41

jrhite opened this issue Jan 23, 2018 · 6 comments · May be fixed by #47

Comments

@jrhite
Copy link

jrhite commented Jan 23, 2018

I'm using the barebones example code in the documentation for the 'greet' command. Does clime work with ts-node? Either it clime doesn' work with ts-node or I'm missing something super silly.

I have:

src/cli.ts
src/commands/default.ts

cli.ts:

import * as Path from 'path';
import { CLI, Shim } from 'clime';

// The second parameter is the path to folder that contains command modules.
let cli = new CLI('greet', Path.join(__dirname, 'commands'));

// Clime in its core provides an object-based command-line infrastructure.
// To have it work as a common CLI, a shim needs to be applied:
let shim = new Shim(cli);
shim.execute(process.argv);

default.ts:

import {
  Command,
  command,
  param,
} from 'clime';

@command({
  description: 'This is a command for printing a greeting message',
})
export default class extends Command {
  execute(
    @param({
      description: 'Your loud name',
      required: true,
    })
    name: string,
  ) {
    return `Hello, ${name}!`;
  }
}

Here is my tsconfig.json file:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "lib": ["es6", "es2016", "ES2016.Array.Include", "dom", "ES2017.object"],
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "strictNullChecks": false,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "outDir": "build",
    "sourceMap": true,
    "allowJs": true
  },
  "exclude": [
    "node_modules"
  ]
}

But when I run it with ts-node -P . src/cli.ts, the only output I ever see is (note: tsconfig.json lives in .):

  USAGE

    greet <subcommand>

It doesn't complain about the required name parameter missing. I get no description, etc...

What am I missing here?

@vilicvane
Copy link
Owner

Hi, clime currently does not work with ts-node, as it searches compiled .js files for commands and their metadata.

Could you elaborate a little bit on the motivation using ts-node instead of standard pre-compiled files in your case?

@jrhite
Copy link
Author

jrhite commented Jan 23, 2018

Hi,

Thanks for the response.

I have a project I've built that is all typescript. I've been running ts-node exclusively to run it. I recently introduced (or wanted to introduce) the clime dependency as I now need cli parsing and this project looks like a great option.

I was a bit curious as to why clime might not work with ts-node. I'm using a fair amount of 3rd party dependencies (both TS and JS) and they all seem to work fine with ts-node.

I'm brand new to the node world...and I prefer avoiding an extra compile step (I've worked a lot with python and other scripted languages that don't need compiling as this happens on the fly).

This may be out-of-scope or maybe a feature request, but clime itself is written in TS. Wouldn't it be natural to be able to use it with ts-node? Couldn't it scan the .ts files just the way it scans the .js files?

Thoughts?

Thanks!

@vilicvane
Copy link
Owner

Thanks for the detailed feedback. I think it's reasonable to be able to specify module extensions in this case. Will try to add ts-node support if I get some time, while PR is welcome.

marshall007 added a commit to marshall007/clime that referenced this issue Apr 30, 2018
@marshall007 marshall007 linked a pull request Apr 30, 2018 that will close this issue
marshall007 added a commit to marshall007/clime that referenced this issue May 24, 2018
@asafh
Copy link

asafh commented Nov 28, 2018

Hi @vilic, did you get the chance to take a look at the PR and possibly merge it?

Thanks for the package!

@peleteiro
Copy link

👍

@AEPKILL
Copy link

AEPKILL commented Mar 1, 2019

you can add the following code to make it work properly.

import { CLI } from 'clime';

CLI.commandModuleExtension = '.ts';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants