diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..b3a29cb --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +git-tag-version=false + diff --git a/android/app/build.gradle b/android/app/build.gradle index 7984e2d..97bbf49 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.echo.app" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode 100 + versionName "0.1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/package-lock.json b/package-lock.json index 26b65a8..daa4c9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "echo-app", - "version": "0.0.0", + "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "echo-app", - "version": "0.0.0", + "version": "0.1.0", "dependencies": { "@capacitor-community/sqlite": "^5.7.2", "@capacitor/android": "^5.7.8", diff --git a/package.json b/package.json index d0ccabe..46803bd 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,17 @@ { "name": "echo-app", "private": true, - "version": "0.0.0", + "version": "0.1.0", "type": "module", "scripts": { "dev": "vite --host 0.0.0.0", "build": "vite build", "preview": "vite preview", "version:sync": "node scripts/sync-version.cjs", - "version": "npm run version:sync" + "release": "node scripts/release.cjs", + "release:patch": "node scripts/release.cjs patch", + "release:minor": "node scripts/release.cjs minor", + "release:major": "node scripts/release.cjs major" }, "dependencies": { "@capacitor-community/sqlite": "^5.7.2", diff --git a/scripts/release.cjs b/scripts/release.cjs new file mode 100644 index 0000000..e15d4fa --- /dev/null +++ b/scripts/release.cjs @@ -0,0 +1,45 @@ +/* 自定义发布脚本:接管 npm version + Android 版本同步 + git 提交与打 tag */ +const { execSync } = require('child_process') +const fs = require('fs') +const path = require('path') + +const rootDir = path.resolve(__dirname, '..') + +const run = (cmd) => { + console.log(`[release] ${cmd}`) + execSync(cmd, { stdio: 'inherit', cwd: rootDir }) +} + +const readJson = (file) => + JSON.parse(fs.readFileSync(path.join(rootDir, file), 'utf8')) + +const main = () => { + const type = process.argv[2] || 'patch' // patch / minor / major + + // 1)仅更新 version 字段,不让 npm 自动 commit / tag(.npmrc 已全局禁止,但这里再显式加一层保险) + run(`npm version ${type} --no-git-tag-version`) + + // 2)同步 Android 版本(versionCode / versionName) + run('npm run version:sync') + + // 3)读取新版本号 + const pkg = readJson('package.json') + const version = pkg.version + + // 4)只提交与版本相关的文件,避免误提交其它开发中的改动 + const filesToAdd = [ + 'package.json', + 'package-lock.json', + 'android/app/build.gradle', + ] + run(`git add ${filesToAdd.join(' ')}`) + + // 5)提交并打 tag + run(`git commit -m "chore: release v${version}"`) + run(`git tag v${version}`) + + console.log(`[release] 完成: v${version}`) +} + +main() +