Skip to content

Commit

Permalink
code optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
NazmusSayad committed Sep 25, 2024
1 parent f93bb83 commit c3f4098
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# npmize
dist
.npmize
node_modules
4 changes: 2 additions & 2 deletions package-lock.json

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

17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "npmize",
"version": "1.1.1",
"description": "Let's create an npm package without worrying about anything.",
"version": "1.1.0",
"bin": "./dist/index.js",
"scripts": {
"dev": "tsc -w",
"build": "node ./build.cjs",
"tsc": "tsc --noEmit --watch",
"lab": "run ./src/__lab__/index.ts"
},
"type": "commonjs",
"dependencies": {
"@babel/parser": "^7.25.6",
"ansi-colors": "^4.1.3",
Expand All @@ -23,19 +22,27 @@
},
"keywords": [
"npm",
"npmize",
"npm-tool",
"npm-build",
"build-tool",
"npm-build-tool"
"npm-build-tool",
"npm-package",
"npm-package-tool",
"npm-package-maker",
"npm-package-builder",
"npm-package-creator",
"npm-package-generator"
],
"license": "ISC",
"type": "commonjs",
"author": "https://github.com/NazmusSayad",
"homepage": "https://github.com/NazmusSayad/npmize#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/NazmusSayad/npmize.git"
},
"bugs": {
"url": "https://github.com/NazmusSayad/npmize/issues"
},
"homepage": "https://github.com/NazmusSayad/npmize#readme"
}
}
3 changes: 0 additions & 3 deletions src/__lab__/another.ts
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
import rype from '../../../rype/dist/index.mjs'

console.log(rype)
5 changes: 3 additions & 2 deletions src/__lab__/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
console.clear()
const TEST_TARGET = '../rype'
const TEST_TARGET = '../npmize-test'
import { app } from '../app'
import '../main'

// app.start(['init', TEST_TARGET])
// app.start(['dev', TEST_TARGET])
app.start(['build', TEST_TARGET])
// app.start(['build', TEST_TARGET])
app.start(['-v'])
35 changes: 21 additions & 14 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,56 @@ export const init = app.create('init', {
arguments: [
{
name: 'name',
type: NoArg.string()
.description('Name of the package')
.ask("What's the name of the package?")
.default('.'),
description: 'Name of the package',
type: NoArg.string().default('.').ask("What's the name of the package?"),
},
],

flags: {
pkg: NoArg.boolean().default(true).description("Write 'package.json'"),
install: NoArg.boolean().default(true).description('Install TypeScript'),
pkg: NoArg.boolean()
.default(true)
.description('Make package.json with needed fields'),
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'),

install: NoArg.boolean()
.default(true)
.description('Install needed npm packages'),
sample: NoArg.boolean()
.default(true)
.description('Write a sample file ./src/index.ts'),
ignore: NoArg.boolean()
.default(true)
.description("Write '.gitignore' and '.npmignore'"),
npmignore: NoArg.boolean().default(true).description("Write '.npmignore'"),
gitignore: NoArg.boolean().default(true).description("Write '.gitignore'"),

npmignore: NoArg.boolean().default(true).description('Write .npmignore'),
gitignore: NoArg.boolean().default(true).description('Write .gitignore'),
},
})

const devAndBuild = NoArg.defineConfig({
optionalArguments: [
{
name: 'root',
description: 'Root directory of the package',
type: NoArg.string().description('Root directory'),
},
],

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

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

trailingArguments: '--tsc',

notes: [
`Arguments after "${ansiColors.yellow(
'--tsc'
Expand All @@ -76,14 +79,18 @@ const devAndBuild = NoArg.defineConfig({
.map((flag) => ansiColors.yellow(flag))
.join(', ') + ' and their aliases are ignored.',
],

trailingArguments: '--tsc',
customRenderHelp: { helpUsageTrailingArgsLabel: '[TypeScript Args]' },
})

export const dev = app.create('dev', {
...devAndBuild,
description: 'Start a development',
description: 'Start the development compiler',
flags: {
...devAndBuild.flags,
focus: NoArg.string('cjs', 'mjs')
.aliases('f')
.default('mjs')
.description(
'Focus the typescript compilation process of a specific module'
Expand Down
14 changes: 7 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ app.app.on((_, flags) => {
} else app.app.renderHelp()
})

app.init.on(([nameArg = '.'], flags) => {
const root = path.resolve(nameArg)
app.init.on(([name = '.'], flags) => {
const root = path.resolve(name)

init(root, {
writeSample: flags.demo,
writeSample: flags.sample,
writePackageJSON: flags.pkg,
installPackages: flags.install,
writeGitIgnore: flags.ignore && flags.gitignore,
Expand All @@ -27,8 +27,8 @@ app.init.on(([nameArg = '.'], flags) => {
})
})

app.dev.on(([rootArg = '.', railingArgs], options) => {
const rootPath = path.resolve(rootArg)
app.dev.on(([root = '.', railingArgs], options) => {
const rootPath = path.resolve(root)
const tsConfig = readTSConfig(rootPath)

if (!tsConfig) {
Expand All @@ -52,8 +52,8 @@ app.dev.on(([rootArg = '.', railingArgs], options) => {
})
})

app.build.on(([rootArg = '.', railingArgs], options) => {
const rootPath = path.resolve(rootArg)
app.build.on(([root = '.', railingArgs], options) => {
const rootPath = path.resolve(root)
const tsConfig = readTSConfig(rootPath)

if (!tsConfig) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import packageJSON from '../scripts/packageJSON'
import config from '../config'

export function getVersion() {
return packageJSON.read(path.join(__dirname, '../')).version
return 'v' + packageJSON.read(path.join(__dirname, '../../')).version
}

export function getNodeModulesTempDir(baseDir: string, suffix: string) {
Expand Down

0 comments on commit c3f4098

Please sign in to comment.