From 06f119792378aa1e91a1d9c3140dc31dcec7ed34 Mon Sep 17 00:00:00 2001 From: wtto00 Date: Tue, 12 Nov 2024 15:27:29 +0800 Subject: [PATCH 01/10] new version: 0.0.2-alpha --- CHANGELOG.md | 13 ++++++++++++- docs/package.json | 2 +- package.json | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d5498..f626dd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,20 @@ ## [Unreleased] +## [0.0.2-alpha] - 2024-11-12 + +### Fixed + +- 修复无法使用 `vite` 的模式 `--mode` 参数 + +### Changed + +- `transform` 添加 `--force` 参数 + ## [0.0.1-alpha] - 2024-11-11 First version. -[unreleased]: https://github.com/wtto00/biome-config/compare/v0.0.1-alpha...HEAD +[unreleased]: https://github.com/wtto00/biome-config/compare/v0.0.2-alpha...HEAD +[0.0.1-alpha]: https://github.com/wtto00/biome-config/releases/tag/v0.0.2-alpha [0.0.1-alpha]: https://github.com/wtto00/biome-config/releases/tag/v0.0.1-alpha diff --git a/docs/package.json b/docs/package.json index 2105572..64a87df 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,6 +1,6 @@ { "name": "uniapp-cli-doc", - "version": "0.0.1-alpha", + "version": "0.0.2-alpha", "description": "Document of CLI for uniapp.", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/package.json b/package.json index 2e18664..0b27ea9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@wtto00/uniapp-cli", - "version": "0.0.1-alpha", + "version": "0.0.2-alpha", "description": "CLI for uniapp.", "type": "module", "bin": { From 86ef988b69cec3118a275f26bb620084a2812484 Mon Sep 17 00:00:00 2001 From: wtto00 Date: Tue, 12 Nov 2024 15:45:42 +0800 Subject: [PATCH 02/10] fix: version script --- package.json | 1 + src/utils/const.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b27ea9..a879375 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ }, "packageManager": "pnpm@9.12.2", "lint-staged": { + "package.json": ["pnpm prebuild", "git add src/utils/const.ts"], "*": ["biome check --no-errors-on-unmatched --write"] } } diff --git a/src/utils/const.ts b/src/utils/const.ts index 3e8b489..4c41f5c 100644 --- a/src/utils/const.ts +++ b/src/utils/const.ts @@ -1 +1 @@ -export const CLI_VERSION = '0.0.1-alpha' +export const CLI_VERSION = '0.0.2-alpha' From abe7e203e65861775b11db11f2a7efe4ba71d430 Mon Sep 17 00:00:00 2001 From: wtto00 Date: Tue, 12 Nov 2024 20:50:08 +0800 Subject: [PATCH 03/10] chore: docs --- docs/adapter/unicloud.md | 6 ++++-- docs/guide/create.md | 2 +- src/android/modules/push.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/adapter/unicloud.md b/docs/adapter/unicloud.md index 68799c0..ac7b305 100644 --- a/docs/adapter/unicloud.md +++ b/docs/adapter/unicloud.md @@ -1,5 +1,7 @@ # uniCloud +如果项目中使用了 `uniCloud`,需要按照以下方式配置,才可以正常连接 `云端云函数`。不支持连接 `本地云函数`。 + 在 `uniapp-cli.config.json` 中配置 `UNI_CLOUD_PROVIDER`: ```jsonc @@ -29,9 +31,9 @@ export UNI_CLOUD_PROVIDER='[{"accessTokenKey":"access_token_mp-****","clientSecret":"****","endpoint":"https://api.next.bspapp.com","envType":"public","provider":"aliyun","requestUrl":"https://api.next.bspapp.com/client","spaceId":"mp-****","spaceName":"****","id":"****"}]' ``` -![unicloud后台信息](/unicloud.png) +打开 [uniCloud 后台](https://unicloud.dcloud.net.cn/),选择用到的服务空间,点击进入详情,如下图所示: -如上图所示: +![unicloud后台信息](/unicloud.png) - **accessTokenKey**: 等于 `access_token_` + 图中的 `SpaceId` - **clientSecret**: 等于图中的 `ClientSecret` diff --git a/docs/guide/create.md b/docs/guide/create.md index 04edef9..f98c4f9 100644 --- a/docs/guide/create.md +++ b/docs/guide/create.md @@ -30,7 +30,7 @@ Options: ## 项目名称 -`project-name`应用名称有一些规范: +`project-name`应用名称有一些规范: - 应用名称不能为空 - 应用名称所有字母都应该使用小写,即不能使用大写或大小写混合 diff --git a/src/android/modules/push.ts b/src/android/modules/push.ts index 97e52a0..d9b00dd 100644 --- a/src/android/modules/push.ts +++ b/src/android/modules/push.ts @@ -22,7 +22,7 @@ export function appendPush(results: Results) { const { appid, appkey, appsecret, icons, offline, fcm, mi, meizu, hms, honor, oppo, vivo } = push.unipush - // HBuilderX 3.99及以上版本所需的libs仅为: + // HBuilderX 3.99及以上版本所需的libs仅为: appendSet(results.libs, ['aps-release.aar', 'aps-unipush-release.aar']) appendMerge(results.appBuildGradle, 'manifestPlaceholders', { From c2594c2156e8ac63f4d2e54c692441b9c0c6b8e0 Mon Sep 17 00:00:00 2001 From: wtto00 Date: Wed, 13 Nov 2024 02:18:15 +0800 Subject: [PATCH 04/10] fix: error in test --- .github/workflows/test.yml | 3 ++ src/platforms/mp-weixin.ts | 2 +- tests/android.test.ts | 89 ++++++++++++++++++++++++++++++++++++++ tests/harmony.test.ts | 9 ++++ tests/help.test.ts | 2 +- tests/ios.test.ts | 9 ++++ tests/platform.test.ts | 63 +-------------------------- tests/requirement.test.ts | 41 +++++++++++++++--- 8 files changed, 147 insertions(+), 71 deletions(-) create mode 100644 tests/android.test.ts create mode 100644 tests/harmony.test.ts create mode 100644 tests/ios.test.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77f3842..b5241ce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,5 +44,8 @@ jobs: - name: Install Dependencies run: pnpm i + - name: Prepare + run: echo "${{secrets.SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa + - name: Test run: pnpm test diff --git a/src/platforms/mp-weixin.ts b/src/platforms/mp-weixin.ts index 2d502b7..2d49f60 100644 --- a/src/platforms/mp-weixin.ts +++ b/src/platforms/mp-weixin.ts @@ -44,7 +44,7 @@ const mpWeixin: ModuleClass = { async requirement() { if (process.platform !== 'win32' && process.platform !== 'darwin') { - Log.error(`微信开发者平台不支持平台: ${process.platform}`) + Log.error(`${Log.failSignal} 微信开发者平台不支持平台: ${process.platform}`) return } diff --git a/tests/android.test.ts b/tests/android.test.ts new file mode 100644 index 0000000..2599174 --- /dev/null +++ b/tests/android.test.ts @@ -0,0 +1,89 @@ +import assert from 'node:assert' +import { rmSync, writeFileSync } from 'node:fs' +import { after, before, describe, it } from 'node:test' +import { execaSync } from 'execa' +import { readJsonFile } from '../src/utils/file.js' +import Log from '../src/utils/log.js' +import { AndroidAbiFilters, type ManifestConfig } from '../src/utils/manifest.config.js' +import { execaUniapp, execaUniappSync } from './helper.js' + +describe('android', () => { + before( + async () => { + execaUniappSync('create test-project-android --template dcloudio/uni-preset-vue#vite-ts') + process.chdir('test-project-android') + execaSync({ shell: true })`pnpm --ignore-workspace install` + }, + { timeout: 60000 }, + ) + + after( + () => { + process.chdir('..') + rmSync('test-project-android', { force: true, recursive: true }) + }, + { timeout: 60000 }, + ) + + it('requirement', { timeout: 10000 }, async () => {}) + + it('add', { timeout: 60000 }, async () => { + const { stdout } = await execaUniapp('platform add android') + + assert.equal( + stdout, + Log.errorColor(`${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用名称: name`), + ) + const manifest = readJsonFile('src/manifest.json', true) + + manifest.name = 'Test Project Platform' + writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') + const { stdout: stdout1 } = await execaUniapp('platform add android') + assert.equal( + stdout1, + Log.errorColor(`${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用appid: appid`), + ) + + manifest.appid = '__UNI__1FC8DF9' + writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') + const { stdout: stdout2 } = await execaUniapp('platform add android') + assert.equal( + stdout2, + Log.errorColor( + `${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用Appkey: app-plus.distribute.android.dcloud_appkey`, + ), + ) + + if (manifest['app-plus']?.distribute?.android) + manifest['app-plus'].distribute.android.dcloud_appkey = 'c1b4ac7b9a38a1036528ac460ac70f18' + writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') + const { stdout: stdout3 } = await execaUniapp('platform add android') + assert.equal( + stdout3, + Log.errorColor( + `${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用包名: app-plus.distribute.android.packagename`, + ), + ) + + if (manifest['app-plus']?.distribute?.android) + manifest['app-plus'].distribute.android.packagename = 'com.example.uniapp' + writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') + const { stdout: stdout4 } = await execaUniapp('platform add android') + assert.equal( + stdout4, + Log.errorColor( + `${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用所支持的CPU类型: app-plus.distribute.android.abiFilters`, + ), + ) + + if (manifest['app-plus']?.distribute?.android) + manifest['app-plus'].distribute.android.abiFilters = [AndroidAbiFilters.x64, AndroidAbiFilters.ARM64] + writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') + const { stdout: stdout5 } = await execaUniapp('platform add android') + assert.equal(stdout5, Log.successColor(`${Log.successSignal} 平台 android 已成功添加。`)) + }) + + it('remove', { timeout: 60000, todo: true }) + it('run', { timeout: 60000, todo: true }) + it('build', { timeout: 60000, todo: true }) +}) diff --git a/tests/harmony.test.ts b/tests/harmony.test.ts new file mode 100644 index 0000000..e201899 --- /dev/null +++ b/tests/harmony.test.ts @@ -0,0 +1,9 @@ +import { describe, it } from 'node:test' + +describe('harmony', () => { + it('requirement', { timeout: 10000, todo: true }) + it('add', { timeout: 60000, todo: true }) + it('remove', { timeout: 60000, todo: true }) + it('run', { timeout: 60000, todo: true }) + it('build', { timeout: 60000, todo: true }) +}) diff --git a/tests/help.test.ts b/tests/help.test.ts index 57ea09e..afcfc21 100644 --- a/tests/help.test.ts +++ b/tests/help.test.ts @@ -12,10 +12,10 @@ Options: Commands: create [options] 创建新项目 requirements|requirement 检查给定平台的环境要求 + transform [options] [target] 转换HBuilderX项目到CLI项目 platform 管理应用的平台 run [options] 开始运行给定的平台 build [options] 打包给定的平台 - transform [target] 转换HBuilderX项目到CLI项目 help [command] display help for command` describe('help', async () => { diff --git a/tests/ios.test.ts b/tests/ios.test.ts new file mode 100644 index 0000000..f7867cd --- /dev/null +++ b/tests/ios.test.ts @@ -0,0 +1,9 @@ +import { describe, it } from 'node:test' + +describe('ios', () => { + it('requirement', { timeout: 10000, todo: true }) + it('add', { timeout: 60000, todo: true, skip: process.platform !== 'darwin' }) + it('remove', { timeout: 60000, todo: true, skip: process.platform !== 'darwin' }) + it('run', { timeout: 60000, todo: true, skip: process.platform !== 'darwin' }) + it('build', { timeout: 60000, todo: true, skip: process.platform !== 'darwin' }) +}) diff --git a/tests/platform.test.ts b/tests/platform.test.ts index bde5196..37ad643 100644 --- a/tests/platform.test.ts +++ b/tests/platform.test.ts @@ -1,10 +1,8 @@ import assert from 'node:assert' -import { rmSync, writeFileSync } from 'node:fs' +import { rmSync } from 'node:fs' import { after, before, describe, it } from 'node:test' import { execaSync } from 'execa' -import { readJsonFile } from '../src/utils/file.js' import Log from '../src/utils/log.js' -import { AndroidAbiFilters, type ManifestConfig } from '../src/utils/manifest.config.js' import { execaUniapp, execaUniappSync } from './helper.js' const HELP_TEXT = `Usage: uniapp platform [options] @@ -124,63 +122,4 @@ quickapp-huawei: ${Log.successColor(`${Log.successSignal} 已安装`)}`, const { stdout } = await execaUniapp('platform add mp-xhs') assert.equal(stdout, Log.successColor(`${Log.successSignal} 平台 mp-xhs 已成功添加。`)) }) - - it('add android', { timeout: 60000 }, async () => { - const { stdout } = await execaUniapp('platform add android') - assert.equal( - stdout, - Log.errorColor(`${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用名称: name`), - ) - const manifest = readJsonFile('src/manifest.json', true) - - manifest.name = 'Test Project Platform' - writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') - const { stdout: stdout1 } = await execaUniapp('platform add android') - assert.equal( - stdout1, - Log.errorColor(`${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用appid: appid`), - ) - - manifest.appid = '__UNI__1FC8DF9' - writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') - const { stdout: stdout2 } = await execaUniapp('platform add android') - assert.equal( - stdout2, - Log.errorColor( - `${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用Appkey: app-plus.distribute.android.dcloud_appkey`, - ), - ) - - if (manifest['app-plus']?.distribute?.android) - manifest['app-plus'].distribute.android.dcloud_appkey = 'c1b4ac7b9a38a1036528ac460ac70f18' - writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') - const { stdout: stdout3 } = await execaUniapp('platform add android') - assert.equal( - stdout3, - Log.errorColor( - `${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用包名: app-plus.distribute.android.packagename`, - ), - ) - - if (manifest['app-plus']?.distribute?.android) - manifest['app-plus'].distribute.android.packagename = 'com.example.uniapp' - writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') - const { stdout: stdout4 } = await execaUniapp('platform add android') - assert.equal( - stdout4, - Log.errorColor( - `${Log.failSignal} 平台 android 添加失败: 请在文件manifest.json中配置应用所支持的CPU类型: app-plus.distribute.android.abiFilters`, - ), - ) - - if (manifest['app-plus']?.distribute?.android) - manifest['app-plus'].distribute.android.abiFilters = [AndroidAbiFilters.x64, AndroidAbiFilters.ARM64] - writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2), 'utf8') - const { stdout: stdout5 } = await execaUniapp('platform add android') - assert.equal(stdout5, Log.successColor(`${Log.successSignal} 平台 android 已成功添加。`)) - }) - - it('add ios', { todo: true }) - - it('add harmony', { todo: true }) }) diff --git a/tests/requirement.test.ts b/tests/requirement.test.ts index 3b69603..d448647 100644 --- a/tests/requirement.test.ts +++ b/tests/requirement.test.ts @@ -59,11 +59,21 @@ describe('requirement', () => { }) it('mp-weixin', { timeout: 10000 }, async () => { + const { stdout } = await execaUniapp('requirement mp-weixin') + if (process.platform !== 'win32' && process.platform !== 'darwin') { + assert.equal( + stdout, + `mp-weixin: +${Log.successColor(`${Log.successSignal} 平台 \`mp-weixin\` 已安装`)} +${Log.errorColor(`${Log.failSignal} 微信开发者平台不支持平台: ${process.platform}`)} +`, + ) + return + } const defaultPath = isWindows() ? 'C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat' : '/Applications/wechatwebdevtools.app/Contents/MacOS/cli' const isInstall = existsSync(defaultPath) - const { stdout } = await execaUniapp('requirement mp-weixin') if (isInstall) { assert.equal( stdout, @@ -90,6 +100,16 @@ ${Log.warnColor(`${Log.failSignal} 微信开发者工具没有安装`)} process.env.WEIXIN_DEV_TOOL = cliPath writeFileSync(cliPath, '', 'utf8') const { stdout } = await execaUniapp('requirement mp-weixin') + if (process.platform !== 'win32' && process.platform !== 'darwin') { + assert.equal( + stdout, + `mp-weixin: +${Log.successColor(`${Log.successSignal} 平台 \`mp-weixin\` 已安装`)} +${Log.errorColor(`${Log.failSignal} 微信开发者平台不支持平台: ${process.platform}`)} +`, + ) + return + } assert.equal( stdout, `mp-weixin: @@ -107,6 +127,19 @@ ${Log.successColor(`${Log.successSignal} 微信开发者工具已安装 (${cliPa : '/Applications/wechatwebdevtools.app/Contents/MacOS/cli' const isInstall = existsSync(defaultPath) const { stdout } = await execaUniapp('requirement h5 mp-weixin') + if (process.platform !== 'win32' && process.platform !== 'darwin') { + assert.equal( + stdout, + `h5: +${Log.successColor(`${Log.successSignal} 平台 \`h5\` 已安装`)} + +mp-weixin: +${Log.successColor(`${Log.successSignal} 平台 \`mp-weixin\` 已安装`)} +${Log.errorColor(`${Log.failSignal} 微信开发者平台不支持平台: ${process.platform}`)} +`, + ) + return + } assert.equal( stdout, `h5: @@ -124,12 +157,6 @@ ${ ) }) - it('android', { timeout: 10000, todo: true }) - - it('ios', { timeout: 10000, todo: true }) - - it('harmony', { timeout: 10000, todo: true }) - it('mp-alipay', { todo: true }) it('mp-baidu', { todo: true }) it('mp-toutiao', { todo: true }) From 59dbbe8adb2ebac8b98a1e35f655c0aa2492e2d3 Mon Sep 17 00:00:00 2001 From: wtto00 Date: Wed, 13 Nov 2024 02:21:12 +0800 Subject: [PATCH 05/10] fix: test ci --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b5241ce..89e636d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,7 +45,7 @@ jobs: run: pnpm i - name: Prepare - run: echo "${{secrets.SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa + run: mkdir ~/.ssh && echo "${{secrets.SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa - name: Test run: pnpm test From 7446eb208fd315b8af84c4016c90337c2f1348d5 Mon Sep 17 00:00:00 2001 From: wtto00 Date: Wed, 13 Nov 2024 02:37:09 +0800 Subject: [PATCH 06/10] fix: test ci --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 89e636d..26657b7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,7 +45,10 @@ jobs: run: pnpm i - name: Prepare - run: mkdir ~/.ssh && echo "${{secrets.SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa + run: | + mkdir ~/.ssh + echo "${{secrets.SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa - name: Test run: pnpm test From 7aa223ff913e0ba3f1307a75bbb0215c0acf04df Mon Sep 17 00:00:00 2001 From: wtto00 Date: Wed, 13 Nov 2024 03:05:24 +0800 Subject: [PATCH 07/10] fix: test ci --- .github/workflows/test.yml | 1 + tests/android.test.ts | 17 +++++++++++------ tests/harmony.test.ts | 1 - tests/ios.test.ts | 1 - tests/requirement.test.ts | 3 +++ 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26657b7..a8a9d24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,6 +49,7 @@ jobs: mkdir ~/.ssh echo "${{secrets.SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa + ssh -T git@gitee.com - name: Test run: pnpm test diff --git a/tests/android.test.ts b/tests/android.test.ts index 2599174..e8b0616 100644 --- a/tests/android.test.ts +++ b/tests/android.test.ts @@ -1,5 +1,5 @@ import assert from 'node:assert' -import { rmSync, writeFileSync } from 'node:fs' +import { rm, writeFileSync } from 'node:fs' import { after, before, describe, it } from 'node:test' import { execaSync } from 'execa' import { readJsonFile } from '../src/utils/file.js' @@ -12,21 +12,26 @@ describe('android', () => { async () => { execaUniappSync('create test-project-android --template dcloudio/uni-preset-vue#vite-ts') process.chdir('test-project-android') - execaSync({ shell: true })`pnpm --ignore-workspace install` + execaSync({ shell: true })`pnpm --ignore-workspace --no-lockfile install` }, { timeout: 60000 }, ) after( - () => { + async () => { process.chdir('..') - rmSync('test-project-android', { force: true, recursive: true }) + await new Promise((resolve, reject) => + setTimeout(() => { + rm('test-project-android', { force: true, recursive: true }, (err) => { + if (err) reject(err) + else resolve(undefined) + }) + }, 1000), + ) }, { timeout: 60000 }, ) - it('requirement', { timeout: 10000 }, async () => {}) - it('add', { timeout: 60000 }, async () => { const { stdout } = await execaUniapp('platform add android') diff --git a/tests/harmony.test.ts b/tests/harmony.test.ts index e201899..b23a328 100644 --- a/tests/harmony.test.ts +++ b/tests/harmony.test.ts @@ -1,7 +1,6 @@ import { describe, it } from 'node:test' describe('harmony', () => { - it('requirement', { timeout: 10000, todo: true }) it('add', { timeout: 60000, todo: true }) it('remove', { timeout: 60000, todo: true }) it('run', { timeout: 60000, todo: true }) diff --git a/tests/ios.test.ts b/tests/ios.test.ts index f7867cd..2c50930 100644 --- a/tests/ios.test.ts +++ b/tests/ios.test.ts @@ -1,7 +1,6 @@ import { describe, it } from 'node:test' describe('ios', () => { - it('requirement', { timeout: 10000, todo: true }) it('add', { timeout: 60000, todo: true, skip: process.platform !== 'darwin' }) it('remove', { timeout: 60000, todo: true, skip: process.platform !== 'darwin' }) it('run', { timeout: 60000, todo: true, skip: process.platform !== 'darwin' }) diff --git a/tests/requirement.test.ts b/tests/requirement.test.ts index d448647..29e81c9 100644 --- a/tests/requirement.test.ts +++ b/tests/requirement.test.ts @@ -157,6 +157,9 @@ ${ ) }) + it('android', { timeout: 10000, todo: true }) + it('ios', { timeout: 10000, todo: true }) + it('harmony', { timeout: 10000, todo: true }) it('mp-alipay', { todo: true }) it('mp-baidu', { todo: true }) it('mp-toutiao', { todo: true }) From ea1368b81d88b0e49c992855a6eb144aa5ea6059 Mon Sep 17 00:00:00 2001 From: wtto00 Date: Wed, 13 Nov 2024 03:30:48 +0800 Subject: [PATCH 08/10] fix: test ci --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a8a9d24..44ec0c9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,7 +49,8 @@ jobs: mkdir ~/.ssh echo "${{secrets.SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - ssh -T git@gitee.com + echo "Host *" > ~/.ssh/config + echo " StrictHostKeyChecking accept-new" >> ~/.ssh/config - name: Test run: pnpm test From bf14ffda90107caa641f0d31ade94bdf296edb61 Mon Sep 17 00:00:00 2001 From: wtto00 Date: Wed, 13 Nov 2024 03:34:38 +0800 Subject: [PATCH 09/10] fix: .gitignore not exist --- src/utils/git.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/git.ts b/src/utils/git.ts index cf37d4d..a7c5512 100644 --- a/src/utils/git.ts +++ b/src/utils/git.ts @@ -1,10 +1,10 @@ -import { readFileSync, writeFileSync } from 'node:fs' +import { existsSync, readFileSync, writeFileSync } from 'node:fs' import { resolve } from 'node:path' import { App } from './app.js' export function gitIgnorePath(ignorePath: string) { const ignoreFilePath = resolve(App.projectRoot, '.gitignore') - const content = readFileSync(ignoreFilePath, 'utf8') + const content = existsSync(ignoreFilePath) ? readFileSync(ignoreFilePath, 'utf8') : 'node_modules\ndist' const lines = content.split('\n') if (lines.includes(ignorePath)) return lines.push(ignorePath, '') From 00d29eaa69c63c9272f6a18d2988a3f7bee6d51b Mon Sep 17 00:00:00 2001 From: wtto00 Date: Wed, 13 Nov 2024 05:01:16 +0800 Subject: [PATCH 10/10] chore: docs --- docs/.vitepress/config.mts | 8 +- docs/adapter/android.md | 106 +++++++++++++++++++++ docs/adapter/index.md | 3 +- docs/adapter/unicloud.md | 2 +- docs/guide/build.md | 178 +++++++++++++++++++++++++++++++++++ docs/guide/platform.md | 75 +++++++++++++++ docs/guide/run.md | 184 +++++++++++++++++++++++++++++++++++++ 7 files changed, 553 insertions(+), 3 deletions(-) create mode 100644 docs/adapter/android.md create mode 100644 docs/guide/build.md create mode 100644 docs/guide/platform.md create mode 100644 docs/guide/run.md diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 10ea19f..abe5c89 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -44,6 +44,9 @@ export default defineConfig({ { text: '创建项目', link: 'create' }, { text: '检查环境', link: 'requirement' }, { text: '转换项目', link: 'transform' }, + { text: '平台管理', link: 'platform' }, + { text: '启动运行', link: 'run' }, + { text: '构建打包', link: 'build' }, ], base: '/guide/', }, @@ -58,7 +61,10 @@ export default defineConfig({ '/adapter/': [ { text: '适配', - items: [{ text: 'uniCloud', link: 'unicloud' }], + items: [ + { text: 'uniCloud', link: 'unicloud' }, + { text: 'Android', link: 'android' }, + ], base: '/adapter/', }, ], diff --git a/docs/adapter/android.md b/docs/adapter/android.md new file mode 100644 index 0000000..acef791 --- /dev/null +++ b/docs/adapter/android.md @@ -0,0 +1,106 @@ +# Android 适配指南 + +## 开发环境要求 + +参见 [Requiement Android App](../guide/requirement.html#android-app)。 + +## 运行打包要求 + +- 需要在 `manifest.json` 中配置 `app-plus.distribute.android.dcloud_appkey`。[appkey 申请](https://nativesupport.dcloud.net.cn/AppDocs/usesdk/appkey.html)。 +- 需要配置 [签名](../config/#keystore-path)。 + +## uni 一键登录 + +使用 `uni一键登录` 模块的,需要在 `manifest.json` 中配置 `app-plus.distribute.sdkConfigs.oauth.univerify.appid`。 + +## Facebook 登录 + +使用 `Facebook登录` 模块的,如果要上架 Google Play,需要在 `manifest.json` 中配置 `app-plus.distribute.sdkConfigs.oauth.facebook.permission_ad_remove` 为 `true`。 + +## 友盟统计 + +使用 `友盟统计` 模块的,如果要上架 Google Play,需要在 `manifest.json` 中配置 `app-plus.distribute.sdkConfigs.statics.umeng.google_play` 为 `true`。 + +## 消息推送 + +使用 `消息推送` 模块的,有原来的在 `开发者后台->unipush->配置管理->应用管理` 中配置,需要在 `manifest.json` 中添加如下配置: + +```jsonc +{ + "app-plus": { + "distribute": { + "sdkConfigs": { + "push": { + "unipush": { + "appid": "", + "appkey": "", + "appsecret": "", + "hms": { + "appid": "", + "config": "" + }, + "oppo": { + "appkey": "", + "appsecret": "" + }, + "vivo": { + "appid": "", + "appkey": "" + }, + "mi": { + "appid": "", + "appkey": "" + }, + "meizu": { + "appid": "", + "appkey": "" + }, + "honor": { + "appid": "" + }, + "fcm": { + "serverkey": "", + "channelid": "", + "config_ios": "", + "config_android": "" + } + } + } + } + } + } +} +``` + +## 高德地图 + +如果是在 `nvue` 页面中使用的高德地图,需要在 `manifest.json` 中配置 `app-plus.distribute.sdkConfigs.maps.amap.nvue` 为 `true`。 + +## 语音输入 + +使用 `语音输入` 模块的,需要在 `manifest.json` 中配置中,添加如下配置: + +```json +{ + "app-plus": { + "distribute": { + "sdkConfigs": { + "speech": { + "baidu": { + "__platform__": ["android", "ios"], + "appid_android": "", + "apikey_android": "", + "secretkey_android": "", + "appid_ios": "", + "apikey_ios": "", + "secretkey_ios": "" + }, + "xunfei": { + "appid": "" + } + } + } + } + } +} +``` diff --git a/docs/adapter/index.md b/docs/adapter/index.md index 624c20d..700987d 100644 --- a/docs/adapter/index.md +++ b/docs/adapter/index.md @@ -2,4 +2,5 @@ 相对于 `HBuilderX` 项目,使用 `uniapp-cli` 开发,需要做一些额外配置。 -- [uniCloud](./unicloud) +- [uniCloud 适配指南](./unicloud) +- [Android 适配指南](./android) diff --git a/docs/adapter/unicloud.md b/docs/adapter/unicloud.md index ac7b305..c9905de 100644 --- a/docs/adapter/unicloud.md +++ b/docs/adapter/unicloud.md @@ -1,4 +1,4 @@ -# uniCloud +# uniCloud 适配指南 如果项目中使用了 `uniCloud`,需要按照以下方式配置,才可以正常连接 `云端云函数`。不支持连接 `本地云函数`。 diff --git a/docs/guide/build.md b/docs/guide/build.md new file mode 100644 index 0000000..18832bd --- /dev/null +++ b/docs/guide/build.md @@ -0,0 +1,178 @@ +# 构建打包 + +使用 `uniapp build` 构建打包特定的平台。 + +## 帮助信息 + +```bash +uniapp help build +``` + +``` +Usage: uniapp build + +打包给定的平台 + +Arguments: + platform 要打包的平台: android,ios,h5,mp-weixin... + +Options: + --no-open 不自动打开 + --mode vite 环境模式 + --bundle 打包产物: aab,apk(默认) + --device 运行到给定的设备上 + -h, --help 帮助信息 + +示例: + uniapp build android --bundle aab + uniapp build ios + uniapp build mp-weixin +``` + +## --no-open + +同 [运行参数--no-open](./run#no-open)。 + +- `H5` 平台此参数无效。 + +## --mode + +同 [运行参数--mode](./run#mode)。 + +## --device + +同 [运行参数--device](./run#device)。 + +## H5 + +```bash +uniapp build h5 +``` + +构建打包 `H5` 平台。 + +打包后的产物在目录 `dist/build/h5`。 + +## Android App + +```bash +uniapp build android +``` + +构建打包 `Android` 平台。 + +## iOS App + +```bash +uniapp build ios +``` + +🚧 WIP 正在开发中... + +## 鸿蒙 App + +```bash +uniapp build harmony +``` + +🚧 WIP 正在开发中... + +## 微信小程序 + +```bash +uniapp build mp-weixin +``` + +构建打包 `微信小程序` 平台。 + +打包后的产物在目录 `dist/build/mp-weixin`。 + +如果配置了 [WEIXIN_DEV_TOOL](../config/#weixin-dev-tool),则会自动打开开发者工具。 + +## 支付宝小程序 + +```bash +uniapp build mp-alipay +``` + +🚧 WIP 正在开发中... + +## 百度小程序 + +```bash +uniapp build mp-baidu +``` + +🚧 WIP 正在开发中... + +## 头条小程序 + +```bash +uniapp build mp-toutiao +``` + +🚧 WIP 正在开发中... + +## 飞书小程序 + +```bash +uniapp build mp-lark +``` + +🚧 WIP 正在开发中... + +## QQ 小程序 + +```bash +uniapp build mp-qq +``` + +🚧 WIP 正在开发中... + +## 快手小程序 + +```bash +uniapp build mp-kuaishou +``` + +🚧 WIP 正在开发中... + +## 京东小程序 + +```bash +uniapp build mp-jd +``` + +🚧 WIP 正在开发中... + +## 360 小程序 + +```bash +uniapp build mp-360 +``` + +🚧 WIP 正在开发中... + +## 小红书小程序 + +```bash +uniapp build mp-xhs +``` + +🚧 WIP 正在开发中... + +## 快应用 + +```bash +uniapp build quickapp-union +``` + +🚧 WIP 正在开发中... + +## 华为快应用 + +```bash +uniapp build quickapp-huawei +``` + +🚧 WIP 正在开发中... diff --git a/docs/guide/platform.md b/docs/guide/platform.md new file mode 100644 index 0000000..4b945ce --- /dev/null +++ b/docs/guide/platform.md @@ -0,0 +1,75 @@ +# 平台管理 + +使用 `uniapp platform` 管理项目中的各平台。 + +## 帮助信息 + +```bash +uniapp help platform +``` + +``` +Usage: uniapp platform [options] + +管理应用的平台 + +Options: + -h, --help 帮助信息 + +Commands: + add 添加并安装给定的平台 + rm|remove 移除并卸载给定的平台 + ls|list 列出所有已安装和可用的平台 + help [command] display help for command +``` + +## 列举各平台 + +使用 `ls` 或者 `list` 子命令,来列举出当前项目中,已安装和未安装的平台。 + +例如 `uniapp platform ls`,输出如下: + +``` +android: ✖ 未安装 +ios: ✖ 未安装 +harmony: ✖ 未安装 +h5: ✔ 已安装 +mp-weixin: ✔ 已安装 +mp-alipay: ✔ 已安装 +mp-baidu: ✔ 已安装 +mp-toutiao: ✔ 已安装 +mp-lark: ✔ 已安装 +mp-qq: ✔ 已安装 +mp-kuaishou: ✔ 已安装 +mp-jd: ✔ 已安装 +mp-360: ✖ 未安装 +mp-xhs: ✔ 已安装 +quickapp-union: ✔ 已安装 +quickapp-huawei: ✔ 已安装 +``` + +## 添加平台 + +使用 `add` 子命令,来添加所需要的平台。 + +会自动使用检测到的包管理器,从 `npm` 上安装 uniapp 所对应的平台包。比如微信小程序对应的依赖包为: `@dcloudio/uni-mp-weixin`。 + +::: code-group +对于 `Android` 平台,安装的时候,会自动下载离线打包 SDK 中的 `libs` 文件到本地目录中。具体可参见 [UNIAPP_ANDROID_SDK_URL](../config/#uniapp-android-sdk-url) 中的说明。 + +安装完成后,生成的 `Android` 原生工程项目在目录 `platform/android` 中。此时该原生项目并不完整,需要运行(`run`)或者打包(`build`)之后,才会补充完缺失的文件。 +::: + +**TODO**: `ios` 以及 `harmony` 平台离线 SDK 的说明。 + +## 移除平台 + +使用 `rm` 或者 `remove` 子命令,来移除不需要的平台。 + +会自动使用检测到的包管理器,卸载本地已安装的平台包。 + +对于 `Android` 平台,还会自动删除原生项目的目录 `platform/android`。 + +对于 `iOS` 平台,还会自动删除原生项目的目录 `platform/ios`。 + +对于 `Harmony` 平台,还会自动删除原生项目的目录 `platform/harmony`。 diff --git a/docs/guide/run.md b/docs/guide/run.md new file mode 100644 index 0000000..76c663d --- /dev/null +++ b/docs/guide/run.md @@ -0,0 +1,184 @@ +# 启动运行 + +使用 `uniapp run` 启动运行特定的平台。 + +## 帮助信息 + +```bash +uniapp help run +``` + +``` +Usage: uniapp run + +开始运行给定的平台 + +Arguments: + platform 要运行的平台: android,ios,h5,mp-weixin... + +Options: + --no-open 不自动打开 + --mode vite 环境模式 + --device 运行到给定的设备上 + -h, --help 帮助信息 + +示例: + uniapp run android --device myEmulator + uniapp run ios + uniapp run mp-weixin +``` + +## --no-open + +运行完毕后,是否自动打开平台所对应的工具。 + +各平台要打开的工具对应列表如下: + +- h5: 浏览器 +- android: 已连接的 `Android` 设备或者模拟器 +- mp-weixin: [微信开发者工具](https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html) +- 其他: 待开发 + +## --mode + +`vite` 框架的 [模式](https://vitejs.cn/vite3-cn/guide/env-and-mode.html#modes) 配置。 + +## --device + +运行到 `Android` 平台时,要打开的已连接设备的名称。设备名称可通过 `adb devices` 来获取。 + +如果存在多个已连接的 `Android` 设备或者模拟器,此参数会用到。 + +## H5 + +```bash +uniapp run h5 +``` + +启动运行 `H5` 平台。 + +## Android App + +```bash +uniapp run android +``` + +启动运行 `Android` 平台。 + +::: warning 注意事项 +暂时不太清楚,DCloud 官方 App 的热更新是怎么做到的。所以暂时使用的方案是,每次更新都会卸载原来的 App 后,重新安装新打包的 App。如果有热更新的解决方案,非常期待您的 PR 或者讨论。 +::: + +## iOS App + +```bash +uniapp run ios +``` + +🚧 WIP 正在开发中... + +## 鸿蒙 App + +```bash +uniapp run harmony +``` + +🚧 WIP 正在开发中... + +## 微信小程序 + +```bash +uniapp run mp-weixin +``` + +启动运行 `微信小程序` 平台。 + +如果配置了 [WEIXIN_DEV_TOOL](../config/#weixin-dev-tool),则会自动打开开发者工具。 + +## 支付宝小程序 + +```bash +uniapp run mp-alipay +``` + +🚧 WIP 正在开发中... + +## 百度小程序 + +```bash +uniapp run mp-baidu +``` + +🚧 WIP 正在开发中... + +## 头条小程序 + +```bash +uniapp run mp-toutiao +``` + +🚧 WIP 正在开发中... + +## 飞书小程序 + +```bash +uniapp run mp-lark +``` + +🚧 WIP 正在开发中... + +## QQ 小程序 + +```bash +uniapp run mp-qq +``` + +🚧 WIP 正在开发中... + +## 快手小程序 + +```bash +uniapp run mp-kuaishou +``` + +🚧 WIP 正在开发中... + +## 京东小程序 + +```bash +uniapp run mp-jd +``` + +🚧 WIP 正在开发中... + +## 360 小程序 + +```bash +uniapp run mp-360 +``` + +🚧 WIP 正在开发中... + +## 小红书小程序 + +```bash +uniapp run mp-xhs +``` + +🚧 WIP 正在开发中... + +## 快应用 + +```bash +uniapp run quickapp-union +``` + +🚧 WIP 正在开发中... + +## 华为快应用 + +```bash +uniapp run quickapp-huawei +``` + +🚧 WIP 正在开发中...