Skip to content

Commit

Permalink
noarg updated and readme updated
Browse files Browse the repository at this point in the history
  • Loading branch information
NazmusSayad committed Aug 22, 2024
1 parent 84ebbe3 commit 69d2a15
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 109 deletions.
70 changes: 13 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ This package tries to help you to make npm package without thinking about cjs an
- Very very simple.
- Very very lightweight.
- This supports `typescript`.
- **Compile** to `cjs` and `mjs` without any distraction.
- Enables `__dirname` and `__filename` for `mjs`(EsModule).
- Can work with **browser**, **node** everything related to JavaScript.

<a href="https://npmjs.com/package/npmize">
<img src="https://img.shields.io/npm/v/npmize" alt="npm package">
Expand Down Expand Up @@ -58,69 +60,23 @@ The interface for command-line usage is fairly simplistic at this stage, as seen
npmize <command> [options]
```

### Example:
## How to use?

Add the help flag to see what **functionality** are available.

```shell
npmize dev
npmize --help
```

_This starts typescript watch mode._

<br/>

---

<br/>

## Commands

| Command | Description |
| ------- | ----------------------------- |
| init | Initilize `package.json` |
| dev | Start `typescript` watch mode |
| build | Build for prod |

<br/>

## Command Options

| Option | Description |
| ------------ | --------------------------------------------------------------- |
| --no-install | Not to install required dependencies automatically |
| --no-ignore | Not to add recommended ignore files to .gitignore \| .npmignore |
| --no-src | Not to create src/index.ts folder when not exists |

### Command: `init`

| Option | Description |
| -------- | --------------------- |
| --bin | Also add `bin` field |
| --legacy | Uses `.js` for fields |

### Command: `dev` & `build`

You can use almost any typescript cli command here by using `--tsc`.
eg: `--tsc--jsx=react` --> `--jsx react`

Not allowed list: `--project` `--outDir` `--module` `--watch` and their aliases

| Option | Description |
| ------------ | --------------------------------------- |
| --module=cjs | This starts dev mode of commonjs module |
| --module=mjs | This starts dev mode of esmodule module |

<br/>

### Command: `build`

| Option | Description |
| -------- | ----------------------------------------------------- |
| --node | This enables `__dirname` and `__filename` in esmodule |
| --legacy | Uses `.js` files and creates package.json with type |
### Example:

<br/>
```shell
npmize init project-name
npmize --help
npmize --help-usage
```

---
- _*This makes your project ready*_

<br/>

Expand Down
54 changes: 14 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "npmize",
"description": "Let's create an npm package without worrying about anything.",
"version": "1.0.8",
"version": "1.0.9",
"bin": "./dist/index.js",
"scripts": {
"lab": "nodemon ./src/__lab.ts",
Expand All @@ -13,7 +13,7 @@
"@babel/parser": "^7.20.7",
"ansi-colors": "^4.1.3",
"lskit": "^1.0.0",
"noarg": "^3.0.6",
"noarg": "^3.0.13",
"shelljs": "^0.8.5"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/__lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ console.clear()

import app from './main'

app.start(['init', '../npmize-test'])
app.start(['dev', '-h'])
// app.start(['init', '../npmize-test'])
// app.start(['dev', '../npmize-test', '--node'])
// app.start(['build', '../npmize-test'])
17 changes: 8 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { getVersion } from './utils'

const app = NoArg.create(config.name, {
description: config.description,

flags: {
version: t.boolean().aliases('v').description('Show the version'),
},
Expand Down Expand Up @@ -78,29 +77,28 @@ const devAndBuild = {

outDir: t.string().aliases('o').description('Output directory'),

tsc: t
.array(t.string())
.aliases('t')
.default([])
.description("TypeScript's options"),

node: t
.boolean()
.aliases('n')
.default(false)
.description('Enable __dirname and __filename in ES modules'),
},

config: {
enableTrailingArgs: true,
},
}

app
.create('dev', {
description: 'Start a development',
...devAndBuild,
})
.on(([rootArg = '.'], options) => {
.on(([rootArg = '.', railingArgs], options) => {
const rootPath = path.resolve(rootArg as string)
dev(rootPath, {
...options,
tsc: railingArgs as string[],
outDir: options.outDir
? path.join(rootPath, options.outDir)
: path.join(
Expand All @@ -116,10 +114,11 @@ app
description: 'Build the package for production',
...devAndBuild,
})
.on(([rootArg = '.'], options) => {
.on(([rootArg = '.', railingArgs], options) => {
const rootPath = path.resolve(rootArg as string)
build(rootPath, {
...options,
tsc: railingArgs as string[],
outDir: options.outDir
? path.join(rootPath, options.outDir)
: path.join(
Expand Down

0 comments on commit 69d2a15

Please sign in to comment.