Skip to content

Commit

Permalink
noarg updated and notes added
Browse files Browse the repository at this point in the history
  • Loading branch information
NazmusSayad committed Aug 23, 2024
1 parent c690b3b commit effeea5
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 33 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@babel/parser": "^7.20.7",
"ansi-colors": "^4.1.3",
"lskit": "^1.0.0",
"noarg": "^3.0.13",
"noarg": "^3.0.17",
"shelljs": "^0.8.5"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/__lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ console.clear()

import app from './main'

app.start(['dev', '-h'])
app.start(['dev', '-h', '--noEmit'])
// app.start(['init', '../npmize-test'])
// app.start(['dev', '../npmize-test', '--node'])
// app.start(['build', '../npmize-test'])
60 changes: 38 additions & 22 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import path from 'path'
import config from './config'
import dev from './program/dev'
import NoArg, { t } from 'noarg'
import NoArg from 'noarg'
import init from './program/init'
import build from './program/build'
import tsconfigJSON from './scripts/tsconfigJSON'
import { getVersion } from './utils'
import ansiColors from 'ansi-colors'

const app = NoArg.create(config.name, {
description: config.description,
flags: {
version: t.boolean().aliases('v').description('Show the version'),
version: NoArg.boolean().aliases('v').description('Show the version'),
},
}).on((_, flags) => {
if (flags.version) {
Expand All @@ -25,27 +26,33 @@ app
arguments: [
{
name: 'name',
type: t
.string()
type: NoArg.string()
.description('Name of the package')
.ask("What's the name of the package?")
.default('.'),
},
],

flags: {
pkg: t.boolean().default(true).description("Write 'package.json'"),
install: t.boolean().default(true).description('Install TypeScript'),
tsconfig: t.boolean().default(true).description('Write "tsconfig.json"'),
demo: t.boolean().default(true).description('Write a sample file'),
workflow: t.boolean().default(true).description('Write a workflow file'),
pkg: NoArg.boolean().default(true).description("Write 'package.json'"),
install: NoArg.boolean().default(true).description('Install TypeScript'),
tsconfig: NoArg.boolean()
.default(true)
.description('Write "tsconfig.json"'),
demo: NoArg.boolean().default(true).description('Write a sample file'),
workflow: NoArg.boolean()
.default(true)
.description('Write a workflow file'),

ignore: t
.boolean()
ignore: NoArg.boolean()
.default(true)
.description("Write '.gitignore' and '.npmignore'"),
npmignore: t.boolean().default(true).description("Write '.npmignore'"),
gitignore: t.boolean().default(true).description("Write '.gitignore'"),
npmignore: NoArg.boolean()
.default(true)
.description("Write '.npmignore'"),
gitignore: NoArg.boolean()
.default(true)
.description("Write '.gitignore'"),
},
})
.on(([nameArg = '.'], flags) => {
Expand All @@ -61,33 +68,42 @@ app
})
})

const devAndBuild = {
const devAndBuild = NoArg.createConfig({
optionalArguments: [
{
name: 'root',
type: t.string().description('Root directory'),
type: NoArg.string().description('Root directory'),
},
],

flags: {
module: t
.string('cjs', 'mjs')
module: NoArg.string('cjs', 'mjs')
.aliases('m')
.description("Output module's type"),

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

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

config: {
enableTrailingArgs: true,
trailingArgsSeparator: '--tsc',
},
}

notes: [
`Arguments after "${ansiColors.yellow(
'--tsc'
)}" will be passed to ${ansiColors.yellow('TypeScript')} compiler.`,

['--project', '--module', '--outDir', '--watch']
.map((flag) => ansiColors.yellow(flag))
.join(', ') + ' and their aliases are ignored.',
],
})

app
.create('dev', {
Expand All @@ -100,7 +116,7 @@ app
...options,
tsc: railingArgs as string[],
outDir: options.outDir
? path.join(rootPath, options.outDir)
? path.join(rootPath, options.outDir as string)
: path.join(
rootPath,
tsconfigJSON.read(rootPath)?.compilerOptions?.outDir ??
Expand Down
2 changes: 1 addition & 1 deletion src/program/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function runBuild(
cleanDir(tempDir)

tsc(basePath, [
...options.tsc.map((tsc) => `--${tsc}`),
...options.tsc,
`--outDir ${tempDir}`,
`--module ${moduleType === 'cjs' ? 'commonjs' : 'esnext'}`,
])
Expand Down
2 changes: 1 addition & 1 deletion src/program/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function (basePath: string, options: DevOptions) {
tsc(
basePath,
[
...options.tsc.map((tsc) => `--${tsc}`),
...options.tsc,
`--outDir ${tempDir}`,
`--module ${options.module === 'cjs' ? 'commonjs' : 'esnext'}`,
'--watch',
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"removeComments": true,
"removeComments": true
},
"compileOnSave": false,
"include": ["src"]
Expand Down

0 comments on commit effeea5

Please sign in to comment.