Skip to content

Commit

Permalink
dev mode will use single module
Browse files Browse the repository at this point in the history
  • Loading branch information
NazmusSayad committed Aug 20, 2024
1 parent 64e81b5 commit 7051dc0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 27 deletions.
2 changes: 1 addition & 1 deletion 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.0",
"version": "1.0.1",
"bin": "./dist/index.js",
"scripts": {
"lab": "nodemon ./src/__lab.ts",
Expand Down
6 changes: 0 additions & 6 deletions src/program/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ import tsc from '../scripts/tsc'
import { cleanDir, moveFiles } from '../utils'
import updateImports from '../updateImports'
import pushNodeCode from '../scripts/pushNodeCode'
import packageJSON from '../scripts/packageJSON'

export default function (basePath: string, options: Options) {
const data = packageJSON.read(basePath)
if (data.type) {
options.module ??= data.type === 'module' ? 'mjs' : 'cjs'
}

console.log(`Build started at ${basePath}`)
console.log('')

Expand Down
14 changes: 2 additions & 12 deletions src/program/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import config from '../config'
import tsc from '../scripts/tsc'
import updateImports from '../updateImports'
import { cleanDir, moveFiles } from '../utils'
import packageJSON from '../scripts/packageJSON'
import pushNodeCode from '../scripts/pushNodeCode'

export default function (basePath: string, options: DevOptions) {
const data = packageJSON.read(basePath)
if (data.type) {
options.module ??= data.type === 'module' ? 'mjs' : 'cjs'
}
options.module ??= 'cjs'

const tempDir = path.join(basePath, config.tempBuildDir)
cleanDir(tempDir)
Expand All @@ -29,13 +25,7 @@ export default function (basePath: string, options: DevOptions) {
fs.watch(tempDir, { recursive: true }, (event, filename) => {
if (event !== 'change' || !filename) return
if (!(filename.endsWith('.js') || filename.endsWith('.ts'))) return

if (options.module) {
makeOutFiles(filename, options.module)
} else {
makeOutFiles(filename, 'cjs')
makeOutFiles(filename, 'mjs')
}
makeOutFiles(filename, options.module!)
})

tsc(
Expand Down
13 changes: 5 additions & 8 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 packageJSON from './scripts/packageJSON'

export function cleanDir(dir: string, createDir = true) {
if (fs.existsSync(dir)) {
Expand All @@ -13,14 +14,10 @@ export function cleanDir(dir: string, createDir = true) {
}

export function getVersion() {
try {
const packageJSON = JSON.parse(
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8')
)
return 'v' + packageJSON.version
} catch {
return 'Something went wrong!'
}
const { version } = packageJSON.read(path.join(__dirname, '../'))

if (version) console.log(`v${version}`)
else console.log('No version found in package.json')
}

export function moveFiles(
Expand Down

0 comments on commit 7051dc0

Please sign in to comment.