Skip to content

Commit

Permalink
Merge pull request #4 from biaov/hotfix/20231012-dev
Browse files Browse the repository at this point in the history
修复项目运行时的一些问题
  • Loading branch information
biaov authored Oct 12, 2023
2 parents c329902 + 46e05ae commit eac1abf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bin/mine-auto-cli.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
import '../index.js'
import '../dist/index.js'
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.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "mine-auto-cli",
"private": false,
"version": "2.0.2",
"exports": "./index.js",
"main": "./index.js",
"version": "2.0.3",
"exports": "./dist/index.js",
"main": "./dist/index.js",
"type": "module",
"bin": {
"auto": "bin/mine-auto-cli.js"
Expand All @@ -16,11 +16,10 @@
"description": "一个将多个命令简化成一个命令的项目 😆",
"scripts": {
"start": "npm run dev",
"dev": "vite build --watch && node scripts/build",
"build": "vite build && node scripts/build",
"dev": "npm run build -- --watch",
"build": "node scripts/build && vite build",
"prettier": "prettier --write '**/*.{js,ts,md,json}'",
"ncu": "ncu --configFileName .ncurc.json && npm i",
"pre-publish": "start cmd /k cd ./dist"
"ncu": "ncu --configFileName .ncurc.json && npm i"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
Expand Down
64 changes: 36 additions & 28 deletions scripts/hooks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFileSync, copyFileSync, existsSync, readdirSync, mkdirSync, readFileSync } from 'fs'
import { writeFileSync, copyFileSync, existsSync, readdirSync, mkdirSync, readFileSync, statSync, unlinkSync } from 'fs'
import { join } from 'path'
import { resetPath } from './path.js'

Expand All @@ -9,6 +9,12 @@ const packageJson = pkg
* 重写 package.json
*/
export const rewritePackage = () => {
/**
* 重置输出目录
*/
const output = resetPath('@/dist')
!existsSync(output) && mkdirSync(output)

packageJson.devDependencies = packageJson.scripts = {}
/**
* 写入最新的
Expand All @@ -17,39 +23,41 @@ export const rewritePackage = () => {
}

/**
* 复制资源
* 拷贝目录
*/
export const copyAssets = () => {
/**
* 根目录需要复制文件夹
*/
const needDirs = ['bin']
/**
* 根目录需要复制的文件
*/
const filePaths = ['README.md', 'LICENSE']
/**
* 根目录
*/
const inputDir = resetPath('@')
/**
* 输出目录
*/
const outputDir = resetPath('@/dist')

!existsSync(outputDir) && mkdirSync(outputDir)
needDirs.forEach(dir => {
const dirPath = resetPath(`@/${dir}`)
const copyDirectory = (source, destination) => {
const stat = statSync(source)
if (stat.isFile()) {
/**
* 复制文件
*/
existsSync(destination) && unlinkSync(destination)
copyFileSync(source, destination)
} else if (stat.isDirectory()) {
/**
* 创建目录
*/
mkdirSync(join(outputDir, dir))
readdirSync(dirPath).forEach(file => {
filePaths.push(`${dir}/${file}`)
!existsSync(destination) && mkdirSync(destination)

/**
* 原有目录
*/
const directory = readdirSync(source)
directory.forEach(file => {
copyDirectory(join(source, file), join(destination, file))
})
})
}
}

/**
* 复制资源
*/
export const copyAssets = () => {
/**
* 根目录需要复制的文件和目录
*/
const filePaths = ['bin', 'README.md', 'LICENSE']
filePaths.forEach(path => {
copyFileSync(join(inputDir, path), join(outputDir, path))
copyDirectory(resetPath(`@/${path}`), resetPath(`@/dist/${path}`))
})
}
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config: UserConfig = {
},
build: {
target: 'node16',
outDir: resolve(__dirname, './dist'),
outDir: resolve(__dirname, './dist/dist'),
lib: {
entry: resolve(__dirname, './src/index.ts'),
formats: ['es']
Expand Down

0 comments on commit eac1abf

Please sign in to comment.