Skip to content

Commit

Permalink
更新代码
Browse files Browse the repository at this point in the history
  • Loading branch information
biaov committed May 28, 2024
1 parent f7ab882 commit 8e641d8
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 86 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
node-version: '20.12.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install -g npm
- run: npm ci
- run: npm i
- run: npm run build
- run: cd dist
- run: npm publish
- run: |
VERSION=$(node -p "require('./package.json').version")
cd dist
if [[ "$VERSION" == *"beta"* ]]; then
npm publish --tag=beta
else
npm publish
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
node_modules
.log
.log
.git
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-mine",
"private": false,
"version": "1.5.1",
"version": "1.5.2-beta.0",
"exports": "./dist/index.js",
"main": "./dist/index.js",
"type": "module",
Expand All @@ -18,17 +18,17 @@
"scripts": {
"start": "npm run dev",
"dev": "npm run build -- --watch",
"build": "node scripts/build && vite build",
"build": "vite build",
"prettier": "prettier --write '**/*.{js,ts,md,json}'",
"ncu": "ncu --configFileName .ncurc.json && npm i",
"pre-publish": "start cmd /k cd ./dist"
"tag": "node scripts/tag"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"provenance": true
},
"engines": {
"node": ">=20"
"node": ">=20.12"
},
"keywords": [
"cli",
Expand Down Expand Up @@ -68,4 +68,4 @@
"typescript": "^5.4.5",
"vite": "^5.2.11"
}
}
}
10 changes: 0 additions & 10 deletions scripts/build.js

This file was deleted.

6 changes: 6 additions & 0 deletions scripts/external.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pkg from '../package.json'

/**
* 扩展
*/
export const external = Object.keys(pkg.dependencies)
2 changes: 2 additions & 0 deletions scripts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { external } from './external'
export { default as rollupPluginCopy } from './rollup-plugin-copy'
15 changes: 0 additions & 15 deletions scripts/path.js

This file was deleted.

24 changes: 16 additions & 8 deletions scripts/hooks.js → scripts/rollup-plugin-copy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { writeFileSync, copyFileSync, existsSync, readdirSync, mkdirSync, statSync, unlinkSync } from 'fs'
import { join } from 'path'
import { resetPath } from './path.js'
import packageJson from '../package.json' assert { type: 'json' }
import pkg from '../package.json' assert { type: 'json' }

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

pkg.devDependencies = pkg.scripts = {} as any

packageJson.devDependencies = packageJson.scripts = {}
/**
* 写入最新的
*/
writeFileSync(resetPath('@/dist/package.json'), JSON.stringify(packageJson, null, 2))
writeFileSync(`${output}/package.json`, JSON.stringify(pkg, null, 2))
}

/**
* 拷贝目录
*/
const copyDirectory = (source, destination) => {
const copyDirectory = (source: string, destination: string) => {
const stat = statSync(source)
if (stat.isFile()) {
/**
Expand Down Expand Up @@ -56,6 +55,15 @@ export const copyAssets = () => {
*/
const filePaths = ['bin', 'README.md', 'LICENSE']
filePaths.forEach(path => {
copyDirectory(resetPath(`@/${path}`), resetPath(`@/dist/${path}`))
const destName = path.split('/').at(-1)
copyDirectory(path, `dist/${destName}`)
})
}

export default () => ({
name: 'rollup-plugin-copy',
closeBundle() {
rewritePackage()
copyAssets()
}
})
5 changes: 5 additions & 0 deletions scripts/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { execSync } from 'child_process'
import pkg from '../package.json' assert { type: 'json' }

execSync(`git tag v${pkg.version}`)
execSync(`git push origin v${pkg.version}`)
27 changes: 1 addition & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
/// <reference path="./module.d.ts" />

import updateNotifier from 'update-notifier'
import chalk from 'chalk'
import pkg from '../package.json'
import './commander'

const notifier = updateNotifier({ pkg })

if (notifier.update && notifier.update.latest !== pkg.version) {
let msg = ''
switch (notifier.update.type) {
case 'major':
msg = chalk.red('{latestVersion}')
break
case 'minor':
msg = chalk.yellow('{latestVersion}')
break
default:
msg = chalk.green('{latestVersion}')
break
}
const compareUrl = `https://github.com/biaov/${pkg.name}/compare/v${pkg.version}...v{latestVersion}`
notifier.notify({
defer: false,
isGlobal: true,
message: `有更新 ${chalk.dim('{currentVersion}')}${chalk.reset(' → ')}${msg}\n运行 ${chalk.cyan('{updateCommand}')} 命令更新\n${chalk.dim.underline(compareUrl)}`
})
}
import './update'
26 changes: 26 additions & 0 deletions src/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import updateNotifier from 'update-notifier'
import chalk from 'chalk'
import pkg from '../package.json'

const notifier = updateNotifier({ pkg })

if (notifier.update && notifier.update.latest !== pkg.version) {
let msg = ''
switch (notifier.update.type) {
case 'major':
msg = chalk.red('{latestVersion}')
break
case 'minor':
msg = chalk.yellow('{latestVersion}')
break
default:
msg = chalk.green('{latestVersion}')
break
}
const compareUrl = `https://github.com/biaov/${pkg.name}/compare/v${pkg.version}...v{latestVersion}`
notifier.notify({
defer: false,
isGlobal: true,
message: `有更新 ${chalk.dim('{currentVersion}')}${chalk.reset(' → ')}${msg}\n运行 ${chalk.cyan('{updateCommand}')} 命令更新\n${chalk.dim.underline(compareUrl)}`
})
}
10 changes: 5 additions & 5 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { writeFile, readFileSync } from 'fs'
import { resolve, dirname } from 'path'
import { resolve } from 'path'
import chalk from 'chalk'
import { fileURLToPath } from 'url'
import { PresetInfo } from './types'
import type { PresetInfo } from './types'

export const { dirname } = import.meta

export const __dirname = dirname(fileURLToPath(import.meta.url))
/**
* 预设数据路径
*/
const presetPath = resolve(__dirname, './presetData.json')
const presetPath = resolve(dirname, './presetData.json')

/**
* 保存本地预设信息
Expand Down
22 changes: 11 additions & 11 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { UserConfig } from 'vite'
import { resolve } from 'path'
import { external, rollupPluginCopy } from './scripts'

const { dirname } = import.meta

/**
* 配置文件
*/
const config: UserConfig = {
root: __dirname,
export default {
resolve: {
alias: {
'@': resolve(__dirname, './src')
'@': resolve(dirname, './src')
}
},
build: {
target: 'node16',
outDir: resolve(__dirname, './dist/dist'),
target: 'node20',
outDir: resolve(dirname, './dist/dist'),
lib: {
entry: resolve(__dirname, './src/index.ts'),
entry: resolve(dirname, './src/index.ts'),
formats: ['es']
},
rollupOptions: {
external: ['update-notifier', 'url', 'path', 'child_process', 'fs', 'chalk', 'commander', 'download-git-repo', 'inquirer', 'log-symbols', 'ora'],
external: [...external, 'path', 'child_process', 'fs'],
output: {
entryFileNames: '[name].js'
}
},
plugins: [rollupPluginCopy()]
},
ssr: false,
ssrManifest: false,
emptyOutDir: true
}
}

export default config

0 comments on commit 8e641d8

Please sign in to comment.