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

feat: introduced CLI mode to the parser #36

Merged
merged 10 commits into from
Jul 30, 2024

Conversation

canerakdas
Copy link
Member

Description

With this PR, we have added parsing features via CLI.

The following commands you can use:
-i, --input <patterns...> Specify input file patterns using glob syntax
-e, --exclude <patterns...> Specify patterns to exclude files from being processed
-o, --output <path> Specify the output directory path
-t, --target <mode> Set the processing mode (default: "mdx")
-h, --help display help for command

Just an idea; In the future, we may add verbose to debug logs or silent mode to hide logs 🤔

  • I left a todo in cli.mjs because I wasn't sure where and how to connect to Parser. I think after #33 is closed, we can determine how we will use it here and organize it
  • I used Commander.js while preparing this CLI. If there is an alternative that you think might be better, I can try it. It provides many features by default for us to add and test \o/

Validation

First of all make sure the script is executable, after that, you can start to use ./bin/cli.mjs -h

Related Issues

Fixes #3

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I've covered new added functionality with unit tests if necessary.

@canerakdas canerakdas requested a review from a team as a code owner July 8, 2024 16:04
@ovflowd
Copy link
Member

ovflowd commented Jul 8, 2024

First of all make sure the script is executable, after that, you can start to use ./bin/cli.mjs -h

I assume with the entry on package.json, if I install this package, how do I run this binary without explicitly doing node bin/cli.mjs -h? How do we define the alias of the binary?

bin/cli.mjs Outdated Show resolved Hide resolved
@canerakdas
Copy link
Member Author

First of all make sure the script is executable, after that, you can start to use ./bin/cli.mjs -h

I assume with the entry on package.json, if I install this package, how do I run this binary without explicitly doing node bin/cli.mjs -h? How do we define the alias of the binary?

AFAIK after packing and installing it globally, we can use it with the package name

For example; In package.json, add an example name and version to the package (for example; api-docs-tooling, 0.0.1);
You can package the package with npm pack and install and use it globally with npm i -g api-docs-tooling-0.0.1.tgz

@ovflowd
Copy link
Member

ovflowd commented Jul 8, 2024

First of all make sure the script is executable, after that, you can start to use ./bin/cli.mjs -h

I assume with the entry on package.json, if I install this package, how do I run this binary without explicitly doing node bin/cli.mjs -h? How do we define the alias of the binary?

AFAIK after packing and installing it globally, we can use it with the package name

For example; In package.json, add an example name and version to the package (for example; api-docs-tooling, 0.0.1); You can package the package with npm pack and install and use it globally with npm i -g api-docs-tooling-0.0.1.tgz

I'm more concerned on how the binary name is resolved. For example, the package https://www.npmjs.com/package/npm-check-updates is resolved as a binary ncu but the package is actually npm-check-updates (needs to be called as npx npm-check-updates)

@canerakdas
Copy link
Member Author

canerakdas commented Jul 8, 2024

First of all make sure the script is executable, after that, you can start to use ./bin/cli.mjs -h

I assume with the entry on package.json, if I install this package, how do I run this binary without explicitly doing node bin/cli.mjs -h? How do we define the alias of the binary?

AFAIK after packing and installing it globally, we can use it with the package name
For example; In package.json, add an example name and version to the package (for example; api-docs-tooling, 0.0.1); You can package the package with npm pack and install and use it globally with npm i -g api-docs-tooling-0.0.1.tgz

I'm more concerned on how the binary name is resolved. For example, the package https://www.npmjs.com/package/npm-check-updates is resolved as a binary ncu but the package is actually npm-check-updates (needs to be called as npx npm-check-updates)

https://github.com/raineorshine/npm-check-updates/blob/main/package.json#L43-L44

First of all make sure the script is executable, after that, you can start to use ./bin/cli.mjs -h

I assume with the entry on package.json, if I install this package, how do I run this binary without explicitly doing node bin/cli.mjs -h? How do we define the alias of the binary?

AFAIK after packing and installing it globally, we can use it with the package name
For example; In package.json, add an example name and version to the package (for example; api-docs-tooling, 0.0.1); You can package the package with npm pack and install and use it globally with npm i -g api-docs-tooling-0.0.1.tgz

I'm more concerned on how the binary name is resolved. For example, the package https://www.npmjs.com/package/npm-check-updates is resolved as a binary ncu but the package is actually npm-check-updates (needs to be called as npx npm-check-updates)

Now I checked, when we want to make a special naming other than the package name, we can show more than one source/target with a different name we want under the bin 🤔

https://github.com/raineorshine/npm-check-updates/blob/main/package.json#L43-L44

In this scenario, we can add the name of the package to @nodejs/api-docs-tooling to follow the same pattern as the website. Also, we can target the binary with different name like this;

  "bin": {
    "api-docs-tooling": "./bin/cli.mjs",
    "adt": "./bin/cli.mjs",
    ... more options
  },

So we can use it in the CLI as api-docs-tooling, adt, or what we want

@ovflowd
Copy link
Member

ovflowd commented Jul 8, 2024

First of all make sure the script is executable, after that, you can start to use ./bin/cli.mjs -h

I assume with the entry on package.json, if I install this package, how do I run this binary without explicitly doing node bin/cli.mjs -h? How do we define the alias of the binary?

AFAIK after packing and installing it globally, we can use it with the package name
For example; In package.json, add an example name and version to the package (for example; api-docs-tooling, 0.0.1); You can package the package with npm pack and install and use it globally with npm i -g api-docs-tooling-0.0.1.tgz

I'm more concerned on how the binary name is resolved. For example, the package npmjs.com/package/npm-check-updates is resolved as a binary ncu but the package is actually npm-check-updates (needs to be called as npx npm-check-updates)

raineorshine/npm-check-updates@main/package.json#L43-L44

First of all make sure the script is executable, after that, you can start to use ./bin/cli.mjs -h

I assume with the entry on package.json, if I install this package, how do I run this binary without explicitly doing node bin/cli.mjs -h? How do we define the alias of the binary?

AFAIK after packing and installing it globally, we can use it with the package name
For example; In package.json, add an example name and version to the package (for example; api-docs-tooling, 0.0.1); You can package the package with npm pack and install and use it globally with npm i -g api-docs-tooling-0.0.1.tgz

I'm more concerned on how the binary name is resolved. For example, the package npmjs.com/package/npm-check-updates is resolved as a binary ncu but the package is actually npm-check-updates (needs to be called as npx npm-check-updates)

Now I checked, when we want to make a special naming other than the package name, we can show more than one source/target with a different name we want under the bin 🤔

raineorshine/npm-check-updates@main/package.json#L43-L44

In this scenario, we can change the name of the package to @nodejs/api-docs-tooling to follow the same pattern as the website, and on the bin field;

  "bin": {
    "api-docs-tooling": "./bin/cli.mjs",
    "adt": "./bin/cli.mjs",
    ... more options
  },

So we can use it in the CLI as api-docs-tooling, adt, or what we want

cc @nodejs/releasers or @nodejs/build or @nodejs/package-maintenance has there been any other package we published (either internally) with a binary? (I assume yes) and if so, what has been the naming format used?

I'm keen on doing something like node-api-doc or something like that...

@wesleytodd
Copy link
Member

has there been any other package we published (either internally) with a binary? (I assume yes) and if so, what has been the naming format used?

I think the main thing I try to consider these days is that npx works as intended, which should mean that using the name of the package is the easiest way. I think you covered this above, but I admit that I mainly just skimmed the above convo.

@ovflowd
Copy link
Member

ovflowd commented Jul 12, 2024

has there been any other package we published (either internally) with a binary? (I assume yes) and if so, what has been the naming format used?

I think the main thing I try to consider these days is that npx works as intended, which should mean that using the name of the package is the easiest way. I think you covered this above, but I admit that I mainly just skimmed the above convo.

Yeah, I also believe the name of the binary should be the name of the package for simplicity and consistency sake. But I wonder what sort of naming conventions are used. Do you have any example, Wes?

bin/cli.mjs Outdated Show resolved Hide resolved
@ovflowd
Copy link
Member

ovflowd commented Jul 20, 2024

@canerakdas I believe you can rebase this ;D

bin/cli.mjs Outdated Show resolved Hide resolved
bin/cli.mjs Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/constants.mjs Outdated Show resolved Hide resolved
bin/cli.mjs Outdated Show resolved Hide resolved
bin/cli.mjs Outdated Show resolved Hide resolved
bin/cli.mjs Outdated Show resolved Hide resolved
bin/cli.mjs Show resolved Hide resolved
package.json Show resolved Hide resolved
Copy link
Member

@ovflowd ovflowd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ovflowd ovflowd merged commit 9f19e82 into nodejs:main Jul 30, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a CLI mode to the parser (cli.mjs)
5 participants