Skip to content

Commit

Permalink
noarg updated and temp out dir udpated
Browse files Browse the repository at this point in the history
  • Loading branch information
NazmusSayad committed Aug 21, 2024
1 parent 2b11f57 commit 9154dcf
Show file tree
Hide file tree
Showing 8 changed files with 494 additions and 31 deletions.
486 changes: 468 additions & 18 deletions package-lock.json

Large diffs are not rendered by default.

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.5",
"version": "1.0.6",
"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.4",
"noarg": "^3.0.6",
"shelljs": "^0.8.5"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/__lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ console.clear()
import app from './main'

// app.start(['init', '../npmize-test'])
// app.start(['dev', '../npmize-test', '--node'])
app.start(['build', '../npmize-test'])
app.start(['dev', '../npmize-test', '--node'])
// app.start(['build', '../npmize-test'])
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export default {
name: 'npmize' as Lowercase<string>,
description: 'A tool to help you publish your package to npm with ease',
defaultOutDir: './dist',
tempBuildDir: './.npmize',
tempOutDir: './.npmize',
ghWorkflowDir: './.github/workflows',
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ app
.create('init', {
description: 'Initialize a new npm package',

optionalArguments: [
arguments: [
{
name: 'name',
type: t.string().description('Name of the package'),
Expand Down
6 changes: 2 additions & 4 deletions src/program/build.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import fs from 'fs'
import path from 'path'
import * as lskit from 'lskit'
import config from '../config'
import tsc from '../scripts/tsc'
import { cleanDir, moveFiles } from '../utils'
import updateImports from '../updateImports'
import pushNodeCode from '../scripts/pushNodeCode'
import { cleanDir, getNodeModulesTempDir, moveFiles } from '../utils'

export default function (basePath: string, options: Options) {
console.log(`Build started at ${basePath}`)
Expand All @@ -28,7 +26,7 @@ function runBuild(
) {
console.log(`Building ${moduleType}...`)

const tempDir = path.join(basePath, config.tempBuildDir)
const tempDir = getNodeModulesTempDir(basePath)
cleanDir(tempDir)

tsc(basePath, [
Expand Down
5 changes: 2 additions & 3 deletions src/program/dev.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import fs from 'fs'
import path from 'path'
import config from '../config'
import tsc from '../scripts/tsc'
import updateImports from '../updateImports'
import { cleanDir, moveFiles } from '../utils'
import pushNodeCode from '../scripts/pushNodeCode'
import { cleanDir, getNodeModulesTempDir, moveFiles } from '../utils'

export default function (basePath: string, options: DevOptions) {
options.module ??= 'cjs'

const tempDir = path.join(basePath, config.tempBuildDir)
const tempDir = getNodeModulesTempDir(basePath)
cleanDir(tempDir)
cleanDir(options.outDir)

Expand Down
16 changes: 16 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs'
import path from 'path'
import shelljs from 'shelljs'
import config from './config'
import packageJSON from './scripts/packageJSON'

export function cleanDir(dir: string, createDir = true) {
Expand All @@ -17,6 +18,21 @@ export function getVersion() {
return packageJSON.read(path.join(__dirname, '../')).version
}

export function getNodeModulesTempDir(baseDir: string) {
const nodeModulesDir = path.join(baseDir, './node_modules/' + config.name)

if (fs.existsSync(nodeModulesDir)) {
return path.join(nodeModulesDir, config.tempOutDir)
} else {
const nodeModulesDir = path.join(baseDir, './node_modules')
if (fs.existsSync(nodeModulesDir)) {
return path.join(nodeModulesDir, config.tempOutDir)
}
}

return path.join(baseDir, config.tempOutDir)
}

export function moveFiles(
baseDir: string,
outDir: string,
Expand Down

0 comments on commit 9154dcf

Please sign in to comment.