From 18459f1e4b665664ccd89e7cc5c1ff9f39c0772e Mon Sep 17 00:00:00 2001 From: cneicy Date: Wed, 26 Aug 2026 02:49:40 +0800 Subject: [PATCH] chore: initialize standalone UPM package --- .gitea/workflows/publish.yml | 49 +++++++++++++++++++ .gitea/workflows/unity-verify.yml | 39 +++++++++++++++ .gitignore | 10 ++++ .npmignore | 8 +++ CHANGELOG.md | 11 +++++ CHANGELOG.md.meta | 7 +++ Development~/UnityProject/.gitignore | 6 +++ Development~/UnityProject/Assets/.gitkeep | 0 .../UnityProject/Packages/manifest.json | 15 ++++++ .../ProjectSettings/ProjectVersion.txt | 2 + README.md | 23 +++++++++ README.md.meta | 7 +++ Runtime.meta | 8 +++ Runtime/ShrinkCommand.Integration.App.asmdef | 18 +++++++ .../ShrinkCommand.Integration.App.asmdef.meta | 7 +++ Runtime/ShrinkCommandAppComponent.cs | 49 +++++++++++++++++++ Runtime/ShrinkCommandAppComponent.cs.meta | 11 +++++ Runtime/ShrinkCommandAppInstaller.cs | 48 ++++++++++++++++++ Runtime/ShrinkCommandAppInstaller.cs.meta | 11 +++++ package.json | 25 ++++++++++ package.json.meta | 7 +++ 21 files changed, 361 insertions(+) create mode 100644 .gitea/workflows/publish.yml create mode 100644 .gitea/workflows/unity-verify.yml create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 CHANGELOG.md create mode 100644 CHANGELOG.md.meta create mode 100644 Development~/UnityProject/.gitignore create mode 100644 Development~/UnityProject/Assets/.gitkeep create mode 100644 Development~/UnityProject/Packages/manifest.json create mode 100644 Development~/UnityProject/ProjectSettings/ProjectVersion.txt create mode 100644 README.md create mode 100644 README.md.meta create mode 100644 Runtime.meta create mode 100644 Runtime/ShrinkCommand.Integration.App.asmdef create mode 100644 Runtime/ShrinkCommand.Integration.App.asmdef.meta create mode 100644 Runtime/ShrinkCommandAppComponent.cs create mode 100644 Runtime/ShrinkCommandAppComponent.cs.meta create mode 100644 Runtime/ShrinkCommandAppInstaller.cs create mode 100644 Runtime/ShrinkCommandAppInstaller.cs.meta create mode 100644 package.json create mode 100644 package.json.meta diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml new file mode 100644 index 0000000..066256c --- /dev/null +++ b/.gitea/workflows/publish.yml @@ -0,0 +1,49 @@ +name: Publish UPM package + +on: + push: + tags: + - 'v*' + workflow_dispatch: + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + env: + NODE_AUTH_TOKEN: ${{ secrets.SHRINKSDK_PACKAGE_TOKEN }} + steps: + - name: Fetch tagged revision + shell: bash + run: | + set -eu + ref="${{ gitea.sha }}" + test -n "$ref" + git init . + git remote add origin "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.App.git" + git fetch --depth=1 origin "$ref" + git checkout --detach FETCH_HEAD + + - name: Validate immutable release version + shell: bash + run: | + set -eu + tag="$(git describe --exact-match --tags HEAD)" + version="$(node -p "require('./package.json').version")" + test "$tag" = "v$version" + npm pack --dry-run + + - name: Publish to ShrinkSDK registry + shell: bash + run: | + set -eu + : "${NODE_AUTH_TOKEN:?SHRINKSDK_PACKAGE_TOKEN is required}" + npmrc="$HOME/.npmrc" + cleanup() { rm -f "$npmrc"; } + trap cleanup EXIT + printf '%s\n' \ + 'registry=https://git.crash.work/api/packages/ShrinkSDK/npm/' \ + '//git.crash.work/api/packages/ShrinkSDK/npm/:_authToken=${NODE_AUTH_TOKEN}' > "$npmrc" + npm publish --registry=https://git.crash.work/api/packages/ShrinkSDK/npm/ \ No newline at end of file diff --git a/.gitea/workflows/unity-verify.yml b/.gitea/workflows/unity-verify.yml new file mode 100644 index 0000000..cb867e0 --- /dev/null +++ b/.gitea/workflows/unity-verify.yml @@ -0,0 +1,39 @@ +name: Verify standalone Unity package + +on: + workflow_dispatch: + +jobs: + editmode: + runs-on: unity-2022.3.62f3 + container: + image: docker.1panel.live/unityci/editor:ubuntu-2022.3.62f3-windows-mono-3 + volumes: + - /www/dk_project/bt-recovery/gitea/runner/seedskey-unity-license:/root/.local/share/unity3d/Unity + - /www/dk_project/bt-recovery/gitea/runner/seedskey-unity-entitlements:/root/.config/unity3d/Unity/licenses + steps: + - name: Fetch selected revision + shell: bash + run: | + set -eu + ref="${{ gitea.sha }}" + git init . + git remote add origin "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.App.git" + git fetch --depth=1 origin "$ref" + git checkout --detach FETCH_HEAD + + - name: Run package EditMode tests + shell: bash + run: | + set -eu + unity_bin="$(command -v unity-editor || command -v unity || command -v Unity || true)" + test -n "$unity_bin" + "$unity_bin" \ + -batchmode \ + -nographics \ + -quit \ + -projectPath "$PWD/Development~/UnityProject" \ + -runTests \ + -testPlatform EditMode \ + -testResults "$PWD/TestResults/editmode.xml" \ + -logFile "$PWD/TestResults/unity.log" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..246935d --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/Development~/UnityProject/[Ll]ibrary/ +/Development~/UnityProject/[Tt]emp/ +/Development~/UnityProject/[Oo]bj/ +/Development~/UnityProject/[Ll]ogs/ +/Development~/UnityProject/[Uu]ser[Ss]ettings/ +/Development~/UnityProject/TestResults/ +/Tools~/**/[Bb]in/ +/Tools~/**/[Oo]bj/ +*.user +*.DotSettings.user diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..700f03d --- /dev/null +++ b/.npmignore @@ -0,0 +1,8 @@ +.git/ +.gitea/ +Development~/ +Tools~/ +*.csproj +*.sln +*.user +*.DotSettings.user diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d7c0103 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +本文件记录 `ShrinkCommand.Integration.App` 的包内变更。 + +## [0.1.0] - 2026-05-18 + +### Added + +- 新增 `ShrinkCommand` 与 `ShrinkApp.Core` 的桥接包。 +- 新增 `ShrinkCommandAppInstaller`,把默认命令服务挂入宿主服务容器。 +- 新增 `ShrinkCommandAppService` 作为宿主侧命令门面。 diff --git a/CHANGELOG.md.meta b/CHANGELOG.md.meta new file mode 100644 index 0000000..dede82c --- /dev/null +++ b/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1754b3bc0377768409187131b594bda6 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Development~/UnityProject/.gitignore b/Development~/UnityProject/.gitignore new file mode 100644 index 0000000..aa2eb00 --- /dev/null +++ b/Development~/UnityProject/.gitignore @@ -0,0 +1,6 @@ +[Ll]ibrary/ +[Tt]emp/ +[Oo]bj/ +[Ll]ogs/ +[Uu]ser[Ss]ettings/ +TestResults/ \ No newline at end of file diff --git a/Development~/UnityProject/Assets/.gitkeep b/Development~/UnityProject/Assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Development~/UnityProject/Packages/manifest.json b/Development~/UnityProject/Packages/manifest.json new file mode 100644 index 0000000..ad8355f --- /dev/null +++ b/Development~/UnityProject/Packages/manifest.json @@ -0,0 +1,15 @@ +{ + "scopedRegistries": [ + { + "name": "ShrinkSDK", + "url": "https://git.crash.work/api/packages/ShrinkSDK/npm/", + "scopes": [ + "com.cneicy" + ] + } + ], + "dependencies": { + "com.unity.test-framework": "1.1.33", + "com.cneicy.shrink-command-integration-app": "file:../../.." + } +} diff --git a/Development~/UnityProject/ProjectSettings/ProjectVersion.txt b/Development~/UnityProject/ProjectSettings/ProjectVersion.txt new file mode 100644 index 0000000..587f809 --- /dev/null +++ b/Development~/UnityProject/ProjectSettings/ProjectVersion.txt @@ -0,0 +1,2 @@ +m_EditorVersion: 2022.3.62f3 +m_EditorVersionWithRevision: 2022.3.62f3 (96770f904ca7) diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f32796 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# ShrinkCommand.Integration.App + +`ShrinkCommand.Integration.App` 是 `ShrinkCommand` 与 `ShrinkApp.Core` 的桥接层。它的职责很简单:把默认命令服务挂进 `ShrinkApp` 的服务容器里,让项目在进入统一宿主模式后,仍能用熟悉的命令系统,而不需要到处手动拿 `ShrinkCommandRuntime.Default`。 + +## 当前能力 + +- 提供原生 `ShrinkCommandAppComponent`,发布 `shrink.service.command` +- 把 `ShrinkCommandRuntime.Default` 包装为 `ShrinkCommandAppService` +- ContextLoader 下由 Starter 组合根装配,服务门面随组件停用可逆注销 +- `ShrinkCommandAppInstaller` 仅保留给 ClassicHost 兼容路径,已标记过时 + +## 使用示例 + +```csharp +var command = ShrinkApp.ShrinkApp.Services.GetRequired(); +var result = await command.ExecuteAsync(source, "help"); +``` + +## 说明 + +- 本包不改变 `ShrinkCommand` 的原有 API。 +- 静态命令的默认注册仍由 `ShrinkCommandRuntime.Default` 完成。 +- 运行时实例命令仍然走 `RegisterCommands(object target)`。 diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..b6d83a5 --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: da6f74ed70ed86e48bc9309983a690b9 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime.meta b/Runtime.meta new file mode 100644 index 0000000..27fbc44 --- /dev/null +++ b/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 79640806d61572d44b10ae9bbb0ace79 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ShrinkCommand.Integration.App.asmdef b/Runtime/ShrinkCommand.Integration.App.asmdef new file mode 100644 index 0000000..7ddce94 --- /dev/null +++ b/Runtime/ShrinkCommand.Integration.App.asmdef @@ -0,0 +1,18 @@ +{ + "name": "ShrinkCommand.Integration.App", + "rootNamespace": "ShrinkCommand.Integration.App", + "references": [ + "ShrinkCommand.Runtime", + "ShrinkApp.Core.Runtime", + "ShrinkContext.Core.Runtime", + "UniTask" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} diff --git a/Runtime/ShrinkCommand.Integration.App.asmdef.meta b/Runtime/ShrinkCommand.Integration.App.asmdef.meta new file mode 100644 index 0000000..a5c227c --- /dev/null +++ b/Runtime/ShrinkCommand.Integration.App.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e5805c0a2f81e6f47818b1dac7d15e6c +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ShrinkCommandAppComponent.cs b/Runtime/ShrinkCommandAppComponent.cs new file mode 100644 index 0000000..1f8c414 --- /dev/null +++ b/Runtime/ShrinkCommandAppComponent.cs @@ -0,0 +1,49 @@ +#nullable enable +using System; +using System.Collections.Generic; +using Cysharp.Threading.Tasks; +using ShrinkApp; +using ShrinkContext; +using ShrinkCommand; + +namespace ShrinkCommand.Integration.App +{ + /// + /// ShrinkCommand 的原生 Cordis 组件(阶段 3): + /// 提供 shrink.service.command 余效应键(默认命令服务),依赖者按键注入; + /// 与经典 ShrinkCommandAppInstaller(ModuleId "shrink.command")二选一使用(同键供给冲突保护)。 + /// + public sealed class ShrinkCommandAppComponent : IShrinkComponent + { + public const string ServiceKey = "shrink.service.command"; + public const string ModuleKey = "app.module.shrink.command"; + + private static readonly string[] ProvideKeys = { ModuleKey, ServiceKey }; + + public string Name => "shrink.command"; + + public IReadOnlyList Inject => Array.Empty(); + + public IReadOnlyList Provide => ProvideKeys; + + public UniTask ApplyAsync(ShrinkCtx ctx, object? config) + { + var service = ShrinkCommandRuntime.Default; + ctx.Set(ServiceKey, service); + ctx.Set(ModuleKey, Name); + + if (config is ShrinkAppServices appServices) + { + var facade = new ShrinkCommandAppService(service); + appServices.Register(facade); + ctx.EffectInverse(() => + { + appServices.TryUnregister(facade); + return UniTask.CompletedTask; + }); + } + + return UniTask.CompletedTask; + } + } +} diff --git a/Runtime/ShrinkCommandAppComponent.cs.meta b/Runtime/ShrinkCommandAppComponent.cs.meta new file mode 100644 index 0000000..4b584f9 --- /dev/null +++ b/Runtime/ShrinkCommandAppComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 507e23e02986281488456a63dc8ffdbe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ShrinkCommandAppInstaller.cs b/Runtime/ShrinkCommandAppInstaller.cs new file mode 100644 index 0000000..5a6a066 --- /dev/null +++ b/Runtime/ShrinkCommandAppInstaller.cs @@ -0,0 +1,48 @@ +#nullable enable + +using System; +using Cysharp.Threading.Tasks; +using ShrinkApp; + +namespace ShrinkCommand.Integration.App +{ + [ShrinkAppModuleInstaller] + [Obsolete("ClassicHost compatibility only. ContextLoader projects should use ShrinkCommandAppComponent from a composition root.")] + public sealed class ShrinkCommandAppInstaller : IShrinkAppModuleInstaller + { + public string ModuleId => "shrink.command"; + public int Order => -1500; + public System.Collections.Generic.IReadOnlyList DependsOn => Array.Empty(); + + public void RegisterServices(ShrinkAppContext context) + { + context.Services.Register(new ShrinkCommandAppService(ShrinkCommandRuntime.Default)); + } + + public UniTask InitializeAsync(ShrinkAppContext context) + { + return UniTask.CompletedTask; + } + } + + public sealed class ShrinkCommandAppService + { + public ShrinkCommandAppService(ShrinkCommandService service) + { + Service = service ?? throw new ArgumentNullException(nameof(service)); + } + + public ShrinkCommandService Service { get; } + + public UniTask ExecuteAsync( + IShrinkCommandSource source, + string rawInput, + System.Threading.CancellationToken cancellationToken = default) + => Service.ExecuteAsync(source, rawInput, cancellationToken); + + public string BuildHelp(IShrinkCommandSource? source, string? prefix = null) + => Service.BuildHelp(source, prefix); + + public System.Collections.Generic.IReadOnlyList Commands => Service.Commands; + } +} diff --git a/Runtime/ShrinkCommandAppInstaller.cs.meta b/Runtime/ShrinkCommandAppInstaller.cs.meta new file mode 100644 index 0000000..d696176 --- /dev/null +++ b/Runtime/ShrinkCommandAppInstaller.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a71473a2ecd04c3459903841fee6da7d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..67d6794 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "com.cneicy.shrink-command-integration-app", + "version": "0.1.0", + "displayName": "ShrinkCommand - App Integration", + "description": "ShrinkCommand 与 ShrinkApp 的桥接层,把默认命令服务纳入统一宿主服务容器。", + "unity": "2022.3", + "dependencies": { + "com.cneicy.shrink-command": "0.2.0", + "com.cneicy.shrink-app-core": "0.1.1", + "com.cysharp.unitask": "2.5.10", + "com.cneicy.shrink-context-core": "0.1.0" + }, + "keywords": [ + "command", + "integration", + "app", + "console" + ], + "author": { + "name": "cneicy", + "url": "https://git.crash.work/ShrinkSDK" + }, + "documentationUrl": "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.App", + "changelogUrl": "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.App/src/branch/main/CHANGELOG.md" +} diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..15a121b --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 126abcc047b44714593c2f94aa587c75 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: