@supersdk/supercli 0.2.1-staging.21 → 0.3.0-staging.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +4 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/add.js +519 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/init.js +234 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/publishSite.js +354 -71
- package/dist/commands/publishSite.js.map +1 -1
- package/dist/config/appConfig.js +160 -45
- package/dist/config/appConfig.js.map +1 -1
- package/dist/publish/siteConfig.js +278 -63
- package/dist/publish/siteConfig.js.map +1 -1
- package/dist/template/README.md +144 -85
- package/dist/template/android/app/build.gradle.kts +0 -3
- package/dist/template/android/app/src/main/java/com/supersdk/simple/EnvironmentStore.java +41 -0
- package/dist/template/android/app/src/main/java/com/supersdk/simple/MainActivity.java +57 -4
- package/dist/template/android/app/src/main/java/com/supersdk/simple/SimpleApplication.java +3 -1
- package/dist/template/android/gradle/supersdk-config-reader.gradle +5 -3
- package/dist/template/android/supersdk-default.config.json +4 -3
- package/dist/template/ios/Sources/App/EnvironmentStore.swift +35 -0
- package/dist/template/ios/Sources/App/SimpleSDKBootstrap.swift +2 -1
- package/dist/template/ios/Sources/App/SimpleSDKProbe.swift +15 -0
- package/dist/template/ios/Sources/App/SimpleViewController.swift +52 -8
- package/dist/template/ios/Tests/SimpleAppTests/SimpleSDKInitializationTests.swift +12 -1
- package/dist/template/scripts/android_snapshot_canary.py +17 -8
- package/dist/template/scripts/build_android.sh +36 -9
- package/dist/template/scripts/build_ios.sh +63 -24
- package/dist/template/scripts/build_site.sh +43 -0
- package/dist/template/scripts/lib/workspace.sh +43 -0
- package/dist/template/scripts/serve_web.py +26 -9
- package/dist/template/scripts/super_build_orchestrator.py +49 -28
- package/dist/template/scripts/supersdk_template.py +759 -240
- package/dist/template/scripts/web_package.py +44 -20
- package/dist/template/super_build.sh +40 -12
- package/dist/template/supersdk.json +25 -13
- package/dist/template/template_manifest.json +25 -0
- package/dist/template/web/src/css/style.css +28 -0
- package/dist/template/web/src/index.html +8 -0
- package/dist/template/web/src/js/app.js +92 -19
- package/dist/workspace/config.js +440 -0
- package/dist/workspace/config.js.map +1 -0
- package/dist/workspace/identity.js +106 -0
- package/dist/workspace/identity.js.map +1 -0
- package/dist/workspace/interactive.js +96 -0
- package/dist/workspace/interactive.js.map +1 -0
- package/dist/workspace/template.js +357 -0
- package/dist/workspace/template.js.map +1 -0
- package/package.json +1 -1
- package/dist/commands/createApp.js +0 -448
- package/dist/commands/createApp.js.map +0 -1
- package/dist/createApp/copyTemplate.js +0 -561
- package/dist/createApp/copyTemplate.js.map +0 -1
- package/dist/template/scripts/build_web.sh +0 -12
|
@@ -1,20 +1,64 @@
|
|
|
1
1
|
import UIKit
|
|
2
2
|
|
|
3
|
+
/// 最小 demo:显示 App 名 + 当前运行时环境,并允许在运行时切换环境。
|
|
4
|
+
///
|
|
5
|
+
/// 切换只写偏好,不重复调用 `initialize` —— SDK 初始化是进程级的,就地重入没有保证。
|
|
6
|
+
/// 真正生效点在下次启动的 `AppDelegate`,这句话必须**显示给用户**,
|
|
7
|
+
/// 而不是让人以为点一下就换好了。
|
|
3
8
|
final class SimpleViewController: UIViewController {
|
|
9
|
+
private let environmentLabel = UILabel()
|
|
10
|
+
|
|
4
11
|
override func viewDidLoad() {
|
|
5
12
|
super.viewDidLoad()
|
|
6
13
|
view.backgroundColor = .systemBackground
|
|
7
14
|
|
|
8
|
-
let
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
let title = UILabel()
|
|
16
|
+
title.text = "SuperSDK Simple"
|
|
17
|
+
title.textColor = .label
|
|
18
|
+
title.font = .preferredFont(forTextStyle: .title2)
|
|
19
|
+
|
|
20
|
+
let spidLabel = UILabel()
|
|
21
|
+
spidLabel.text = "spid: \(SimpleConfig.spid)"
|
|
22
|
+
spidLabel.textColor = .secondaryLabel
|
|
23
|
+
spidLabel.font = .preferredFont(forTextStyle: .footnote)
|
|
24
|
+
|
|
25
|
+
environmentLabel.textColor = .secondaryLabel
|
|
26
|
+
environmentLabel.font = .preferredFont(forTextStyle: .footnote)
|
|
27
|
+
environmentLabel.numberOfLines = 0
|
|
28
|
+
environmentLabel.textAlignment = .center
|
|
29
|
+
|
|
30
|
+
let picker = UISegmentedControl(items: EnvironmentStore.choices)
|
|
31
|
+
picker.selectedSegmentIndex = EnvironmentStore.choices.firstIndex(of: EnvironmentStore.current) ?? 0
|
|
32
|
+
picker.addTarget(self, action: #selector(environmentChanged(_:)), for: .valueChanged)
|
|
33
|
+
|
|
34
|
+
let stack = UIStackView(arrangedSubviews: [title, spidLabel, environmentLabel, picker])
|
|
35
|
+
stack.axis = .vertical
|
|
36
|
+
stack.alignment = .center
|
|
37
|
+
stack.spacing = 12
|
|
38
|
+
stack.translatesAutoresizingMaskIntoConstraints = false
|
|
39
|
+
view.addSubview(stack)
|
|
14
40
|
|
|
15
41
|
NSLayoutConstraint.activate([
|
|
16
|
-
|
|
17
|
-
|
|
42
|
+
stack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
|
43
|
+
stack.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
|
44
|
+
stack.leadingAnchor.constraint(greaterThanOrEqualTo: view.leadingAnchor, constant: 24),
|
|
45
|
+
stack.trailingAnchor.constraint(lessThanOrEqualTo: view.trailingAnchor, constant: -24),
|
|
18
46
|
])
|
|
47
|
+
|
|
48
|
+
renderEnvironment()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@objc
|
|
52
|
+
private func environmentChanged(_ sender: UISegmentedControl) {
|
|
53
|
+
let index = sender.selectedSegmentIndex
|
|
54
|
+
guard index >= 0, index < EnvironmentStore.choices.count else {
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
EnvironmentStore.set(EnvironmentStore.choices[index])
|
|
58
|
+
renderEnvironment()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private func renderEnvironment() {
|
|
62
|
+
environmentLabel.text = "environment: \(EnvironmentStore.current)\n(applies on next launch)"
|
|
19
63
|
}
|
|
20
64
|
}
|
|
@@ -8,11 +8,22 @@ final class SimpleSDKInitializationTests: XCTestCase {
|
|
|
8
8
|
let result = SimpleSDKProbe.resetAndInitializeForTesting()
|
|
9
9
|
XCTAssertTrue(result.resetClearedState)
|
|
10
10
|
XCTAssertEqual(result.initializedSpid, SimpleConfig.spid)
|
|
11
|
-
|
|
11
|
+
// environment 不再是构建期投影,所以断言钉的是「init 收到的就是运行时选择的那个值」。
|
|
12
|
+
XCTAssertEqual(result.initializedEnvironment, result.expectedEnvironment)
|
|
13
|
+
XCTAssertTrue(EnvironmentStore.isValid(result.expectedEnvironment))
|
|
12
14
|
XCTAssertTrue(result.providerWasSet)
|
|
13
15
|
XCTAssertEqual(result.providerTypeName, "SimpleSDKProvider")
|
|
14
16
|
#else
|
|
15
17
|
XCTFail("SimpleSDKProbe is DEBUG-only; run the SimpleApp test scheme with Debug configuration")
|
|
16
18
|
#endif
|
|
17
19
|
}
|
|
20
|
+
|
|
21
|
+
func testEnvironmentIsSwitchableAtRuntime() {
|
|
22
|
+
#if DEBUG
|
|
23
|
+
XCTAssertEqual(SimpleSDKProbe.environmentRoundTripForTesting(), EnvironmentStore.choices)
|
|
24
|
+
XCTAssertFalse(EnvironmentStore.set("NOT VALID"))
|
|
25
|
+
#else
|
|
26
|
+
XCTFail("SimpleSDKProbe is DEBUG-only; run the SimpleApp test scheme with Debug configuration")
|
|
27
|
+
#endif
|
|
28
|
+
}
|
|
18
29
|
}
|
|
@@ -72,8 +72,8 @@ def classify_metadata_url(url, timeout):
|
|
|
72
72
|
return ("fail", f"snapshot metadata unavailable: {status_label(first)}")
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def managed_android_version(root):
|
|
76
|
-
android_root = Path(root) /
|
|
75
|
+
def managed_android_version(root, project):
|
|
76
|
+
android_root = Path(root) / project
|
|
77
77
|
for candidate in (
|
|
78
78
|
android_root / ".supersdk" / "managed" / "config.json",
|
|
79
79
|
android_root / "supersdk-default.config.json",
|
|
@@ -91,25 +91,34 @@ def managed_android_version(root):
|
|
|
91
91
|
return None
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
def
|
|
95
|
-
|
|
94
|
+
def resolve_project(config_path, project):
|
|
95
|
+
if project:
|
|
96
|
+
return project
|
|
97
|
+
return supersdk_template.resolve_single(config_path, "android", None)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def effective_android_version(root, project, config_path):
|
|
101
|
+
version = managed_android_version(root, project)
|
|
96
102
|
if version is not None:
|
|
97
103
|
return version
|
|
98
|
-
|
|
99
|
-
supersdk_template.
|
|
100
|
-
|
|
104
|
+
# 🔴 只校验被选中的那个 android 项目:一个坏的 iosPackageUrl 不该拦住 Android 的 canary。
|
|
105
|
+
normalized = supersdk_template.load_and_validate(config_path, "android", project)
|
|
106
|
+
projects = supersdk_template.require_selection(normalized, "android", project)
|
|
107
|
+
return projects[0]["sdk"]["androidVersion"]
|
|
101
108
|
|
|
102
109
|
|
|
103
110
|
def main(argv):
|
|
104
111
|
parser = argparse.ArgumentParser(description="Check SuperSDK Android SNAPSHOT metadata before Gradle")
|
|
105
112
|
parser.add_argument("--root", required=True)
|
|
113
|
+
parser.add_argument("--project", default=None)
|
|
106
114
|
parser.add_argument("--config", required=True)
|
|
107
115
|
parser.add_argument("--metadata-base-url", default=os.environ.get("SUPERSDK_ANDROID_SNAPSHOT_METADATA_BASE_URL", DEFAULT_METADATA_BASE_URL))
|
|
108
116
|
parser.add_argument("--timeout", type=float, default=5.0)
|
|
109
117
|
args = parser.parse_args(argv)
|
|
110
118
|
|
|
111
119
|
try:
|
|
112
|
-
|
|
120
|
+
project = resolve_project(Path(args.config), args.project)
|
|
121
|
+
version = effective_android_version(Path(args.root), project, Path(args.config))
|
|
113
122
|
except supersdk_template.ConfigError as exc:
|
|
114
123
|
print(str(exc), file=sys.stderr)
|
|
115
124
|
return 1
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
set -euo pipefail
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
5
|
+
# shellcheck source=lib/workspace.sh
|
|
6
|
+
. "$SCRIPT_DIR/lib/workspace.sh"
|
|
7
|
+
WORKSPACE_ROOT="$(supersdk_require_workspace_root "$SCRIPT_DIR")"
|
|
6
8
|
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
|
7
|
-
|
|
9
|
+
HELPER="$WORKSPACE_ROOT/scripts/supersdk_template.py"
|
|
10
|
+
CONFIG="$WORKSPACE_ROOT/supersdk.json"
|
|
11
|
+
PROJECT_DIR=""
|
|
8
12
|
|
|
9
13
|
usage() {
|
|
10
|
-
echo "Usage: scripts/build_android.sh --build [--config path]" >&2
|
|
14
|
+
echo "Usage: scripts/build_android.sh --build [--project DIR] [--config path]" >&2
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
skip_toolchain() {
|
|
@@ -20,7 +24,7 @@ requires_non_skip_snapshot_canary() {
|
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
run_snapshot_canary() {
|
|
23
|
-
canary_output="$("$PYTHON_BIN" "$
|
|
27
|
+
canary_output="$("$PYTHON_BIN" "$WORKSPACE_ROOT/scripts/android_snapshot_canary.py" --root "$WORKSPACE_ROOT" --project "$PROJECT_DIR" --config "$CONFIG" 2>&1)" || {
|
|
24
28
|
printf '%s\n' "$canary_output" >&2
|
|
25
29
|
exit 1
|
|
26
30
|
}
|
|
@@ -77,6 +81,14 @@ while [ "$#" -gt 0 ]; do
|
|
|
77
81
|
build_seen=true
|
|
78
82
|
shift
|
|
79
83
|
;;
|
|
84
|
+
--project)
|
|
85
|
+
if [ "$#" -lt 2 ]; then
|
|
86
|
+
usage
|
|
87
|
+
exit 2
|
|
88
|
+
fi
|
|
89
|
+
PROJECT_DIR="$2"
|
|
90
|
+
shift 2
|
|
91
|
+
;;
|
|
80
92
|
--config)
|
|
81
93
|
if [ "$#" -lt 2 ]; then
|
|
82
94
|
usage
|
|
@@ -95,7 +107,14 @@ if [ "$build_seen" = false ]; then
|
|
|
95
107
|
build_seen=true
|
|
96
108
|
fi
|
|
97
109
|
|
|
98
|
-
|
|
110
|
+
# 项目目录来自配置,不是固定层级。省略 --project 时由引擎解析:唯一 android 项目才放行,
|
|
111
|
+
# 多个就要求显式指定,绝不「挑第一个」。
|
|
112
|
+
if [ -z "$PROJECT_DIR" ]; then
|
|
113
|
+
PROJECT_DIR="$("$PYTHON_BIN" "$HELPER" resolve --config "$CONFIG" --platform android)"
|
|
114
|
+
fi
|
|
115
|
+
ANDROID_ROOT="$WORKSPACE_ROOT/$PROJECT_DIR"
|
|
116
|
+
|
|
117
|
+
"$PYTHON_BIN" "$HELPER" inject --root "$WORKSPACE_ROOT" --config "$CONFIG" --platform android --project "$PROJECT_DIR"
|
|
99
118
|
|
|
100
119
|
if [ "${SUPERSDK_ANDROID_BUILD_TEST_MODE:-0}" = "1" ]; then
|
|
101
120
|
run_snapshot_canary
|
|
@@ -104,7 +123,7 @@ if [ "${SUPERSDK_ANDROID_BUILD_TEST_MODE:-0}" = "1" ]; then
|
|
|
104
123
|
fi
|
|
105
124
|
|
|
106
125
|
if [ ! -x "$ANDROID_ROOT/gradlew" ] || [ ! -f "$ANDROID_ROOT/gradle/wrapper/gradle-wrapper.jar" ]; then
|
|
107
|
-
skip_toolchain "missing Gradle wrapper; expected
|
|
126
|
+
skip_toolchain "missing Gradle wrapper; expected $PROJECT_DIR/gradlew and $PROJECT_DIR/gradle/wrapper/gradle-wrapper.jar"
|
|
108
127
|
fi
|
|
109
128
|
|
|
110
129
|
if ! command -v java >/dev/null 2>&1; then
|
|
@@ -158,9 +177,16 @@ if [ -z "$sdk_dir" ]; then
|
|
|
158
177
|
IFS="$old_ifs"
|
|
159
178
|
fi
|
|
160
179
|
if [ -z "$sdk_dir" ] || [ ! -d "$sdk_dir" ]; then
|
|
161
|
-
skip_toolchain "missing Android SDK; checked
|
|
180
|
+
skip_toolchain "missing Android SDK; checked $PROJECT_DIR/local.properties sdk.dir, ANDROID_HOME, ANDROID_SDK_ROOT, ~/Library/Android/sdk, ~/Android/Sdk, and /opt/android-sdk"
|
|
162
181
|
fi
|
|
163
182
|
|
|
183
|
+
# 🔴 检测到的 sdk_dir 必须真的传给 Gradle,否则这段搜索白做:环境里恰好有 ANDROID_HOME 时
|
|
184
|
+
# 一切正常,没有时 Gradle 直接报 "SDK location not found" —— 而上面那句 skip 又不会触发
|
|
185
|
+
# (SDK 明明找到了),于是名字里写着 `_or_toolchain_skip` 的用例变成硬失败。
|
|
186
|
+
# 不写 local.properties:那是用户自己的文件、且被 .gitignore 排除,构建脚本不该改它。
|
|
187
|
+
export ANDROID_HOME="${ANDROID_HOME:-$sdk_dir}"
|
|
188
|
+
export ANDROID_SDK_ROOT="${ANDROID_SDK_ROOT:-$sdk_dir}"
|
|
189
|
+
|
|
164
190
|
run_snapshot_canary
|
|
165
191
|
|
|
166
192
|
evidence_dir="$ANDROID_ROOT/.supersdk/evidence"
|
|
@@ -185,7 +211,7 @@ fi
|
|
|
185
211
|
|
|
186
212
|
apk_path="$(find "$ANDROID_ROOT/app/build/outputs/apk/debug" -name '*.apk' | head -n 1)"
|
|
187
213
|
if [ -z "$apk_path" ]; then
|
|
188
|
-
echo "Android build did not produce a debug APK under app/build/outputs/apk/debug" >&2
|
|
214
|
+
echo "Android build did not produce a debug APK under $PROJECT_DIR/app/build/outputs/apk/debug" >&2
|
|
189
215
|
exit 1
|
|
190
216
|
fi
|
|
191
217
|
final_application_id="$(extract_final_application_id "$apk_path")"
|
|
@@ -219,6 +245,7 @@ version = config["sdk"]["androidVersion"]
|
|
|
219
245
|
payload = {
|
|
220
246
|
"skip": False,
|
|
221
247
|
"apkPath": apk_path,
|
|
248
|
+
"projectDir": config["dir"],
|
|
222
249
|
"declaredApplicationId": config["platform_config"]["package"],
|
|
223
250
|
"finalApplicationId": final_application_id,
|
|
224
251
|
"mergedManifestPath": merged_manifest,
|
|
@@ -1,18 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
set -euo pipefail
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
5
|
+
# shellcheck source=lib/workspace.sh
|
|
6
|
+
. "$SCRIPT_DIR/lib/workspace.sh"
|
|
7
|
+
WORKSPACE_ROOT="$(supersdk_require_workspace_root "$SCRIPT_DIR")"
|
|
8
|
+
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
|
9
|
+
HELPER="$WORKSPACE_ROOT/scripts/supersdk_template.py"
|
|
10
|
+
CONFIG="$WORKSPACE_ROOT/supersdk.json"
|
|
11
|
+
PROJECT_DIR=""
|
|
12
|
+
|
|
13
|
+
usage() {
|
|
14
|
+
echo "Usage: scripts/build_ios.sh --build [--project DIR]" >&2
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
build_seen=false
|
|
18
|
+
while [ "$#" -gt 0 ]; do
|
|
19
|
+
case "$1" in
|
|
20
|
+
--build)
|
|
21
|
+
if [ "$build_seen" = true ]; then
|
|
22
|
+
usage
|
|
23
|
+
exit 2
|
|
24
|
+
fi
|
|
25
|
+
build_seen=true
|
|
26
|
+
shift
|
|
27
|
+
;;
|
|
28
|
+
--project)
|
|
29
|
+
if [ "$#" -lt 2 ]; then
|
|
30
|
+
usage
|
|
31
|
+
exit 2
|
|
32
|
+
fi
|
|
33
|
+
PROJECT_DIR="$2"
|
|
34
|
+
shift 2
|
|
35
|
+
;;
|
|
36
|
+
*)
|
|
37
|
+
echo "error: expected --build" >&2
|
|
38
|
+
exit 2
|
|
39
|
+
;;
|
|
40
|
+
esac
|
|
41
|
+
done
|
|
42
|
+
|
|
43
|
+
if [ -z "$PROJECT_DIR" ]; then
|
|
44
|
+
PROJECT_DIR="$("$PYTHON_BIN" "$HELPER" resolve --config "$CONFIG" --platform ios)"
|
|
7
45
|
fi
|
|
8
46
|
|
|
9
|
-
|
|
10
|
-
IOS_DIR="$APP_ROOT/ios"
|
|
47
|
+
IOS_DIR="$WORKSPACE_ROOT/$PROJECT_DIR"
|
|
11
48
|
GENERATED_DIR="$IOS_DIR/.supersdk/generated"
|
|
12
49
|
GENERATED_SPEC="$GENERATED_DIR/project.generated.yml"
|
|
13
|
-
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
|
14
50
|
|
|
15
|
-
"$PYTHON_BIN" - "$
|
|
51
|
+
"$PYTHON_BIN" - "$WORKSPACE_ROOT" "$PROJECT_DIR" <<'PY'
|
|
16
52
|
import json
|
|
17
53
|
import importlib.util
|
|
18
54
|
import re
|
|
@@ -30,12 +66,12 @@ def quote(value):
|
|
|
30
66
|
|
|
31
67
|
|
|
32
68
|
def swift_string(value):
|
|
33
|
-
# json.dumps
|
|
69
|
+
# spid 被下面的 ASCII 约束限死,所以 json.dumps 就是一个合法的 Swift 字符串字面量。
|
|
34
70
|
return json.dumps(str(value))
|
|
35
71
|
|
|
36
72
|
|
|
37
|
-
def load_template_contract(
|
|
38
|
-
helper_path =
|
|
73
|
+
def load_template_contract(workspace_root):
|
|
74
|
+
helper_path = workspace_root / "scripts" / "supersdk_template.py"
|
|
39
75
|
spec = importlib.util.spec_from_file_location("supersdk_template_contract", helper_path)
|
|
40
76
|
if spec is None or spec.loader is None:
|
|
41
77
|
fail_invalid("supersdk_template.py contract cannot be loaded")
|
|
@@ -44,9 +80,10 @@ def load_template_contract(app_root):
|
|
|
44
80
|
return module
|
|
45
81
|
|
|
46
82
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
83
|
+
workspace_root = Path(sys.argv[1]).resolve()
|
|
84
|
+
project_dir = sys.argv[2]
|
|
85
|
+
template_contract = load_template_contract(workspace_root)
|
|
86
|
+
ios_dir = workspace_root / project_dir
|
|
50
87
|
managed_path = ios_dir / ".supersdk" / "managed" / "config.json"
|
|
51
88
|
generated_dir = ios_dir / ".supersdk" / "generated"
|
|
52
89
|
generated_spec = generated_dir / "project.generated.yml"
|
|
@@ -54,7 +91,8 @@ simple_config = generated_dir / "SimpleConfig.swift"
|
|
|
54
91
|
|
|
55
92
|
if not managed_path.is_file():
|
|
56
93
|
print(
|
|
57
|
-
"ios managed config missing; run scripts/supersdk_template.py inject --platform ios
|
|
94
|
+
f"ios managed config missing; run scripts/supersdk_template.py inject --platform ios --project {project_dir} "
|
|
95
|
+
"or ./super_build.sh --platform ios --build",
|
|
58
96
|
file=sys.stderr,
|
|
59
97
|
)
|
|
60
98
|
sys.exit(1)
|
|
@@ -77,6 +115,7 @@ if managed.get("managed_by") != template_contract.MANAGED_BY:
|
|
|
77
115
|
fail_invalid(f"managed_by must be {template_contract.MANAGED_BY}")
|
|
78
116
|
if managed.get("schema_version") != template_contract.MANAGED_CONFIG_SCHEMA_VERSION:
|
|
79
117
|
fail_invalid(f"schema_version must be {template_contract.MANAGED_CONFIG_SCHEMA_VERSION}")
|
|
118
|
+
# 类型名就是 managed config 里的 platform 值;这个字面量必须跟着 PROJECT_TYPES 走。
|
|
80
119
|
if managed.get("platform") != "ios":
|
|
81
120
|
fail_invalid("platform must be ios")
|
|
82
121
|
|
|
@@ -86,7 +125,7 @@ if not isinstance(platform_config, dict):
|
|
|
86
125
|
spm_mode = platform_config.get("spmMode", "mock")
|
|
87
126
|
|
|
88
127
|
if spm_mode == "real":
|
|
89
|
-
print("
|
|
128
|
+
print("spmMode=real is not supported until SDK-F040 remote SPM is ready", file=sys.stderr)
|
|
90
129
|
sys.exit(1)
|
|
91
130
|
if spm_mode != "mock":
|
|
92
131
|
fail_invalid("platform_config.spmMode must be mock")
|
|
@@ -94,9 +133,8 @@ if spm_mode != "mock":
|
|
|
94
133
|
spid = managed.get("spid")
|
|
95
134
|
if not isinstance(spid, str) or not re.fullmatch(template_contract.SPID_PATTERN, spid):
|
|
96
135
|
fail_invalid(f"spid must match ^{template_contract.SPID_PATTERN}$")
|
|
97
|
-
environment
|
|
98
|
-
|
|
99
|
-
fail_invalid(f"environment must match ^{template_contract.ENVIRONMENT_PATTERN}$")
|
|
136
|
+
# 🔴 这里**没有** environment:它是运行时 init 参数,不进构建产物。
|
|
137
|
+
# demo 在运行时切换环境(见 Sources/App/EnvironmentStore.swift)。
|
|
100
138
|
name = managed.get("name")
|
|
101
139
|
if not isinstance(name, str) or not name:
|
|
102
140
|
fail_invalid("name must be a non-empty string")
|
|
@@ -110,10 +148,12 @@ version_code = version.get("code")
|
|
|
110
148
|
if not template_contract.is_positive_int(version_code):
|
|
111
149
|
fail_invalid("version.code must be a positive integer")
|
|
112
150
|
|
|
113
|
-
#
|
|
151
|
+
# 没有推导兜底:App 身份来自 projects[].bundleId,否则构建失败。
|
|
114
152
|
bundle_id = platform_config.get("bundleId")
|
|
115
153
|
if bundle_id is None:
|
|
116
|
-
fail_invalid(
|
|
154
|
+
fail_invalid(
|
|
155
|
+
f"platform_config.bundleId is required; set bundleId on the ios project in {template_contract.CONFIG_FILENAME}"
|
|
156
|
+
)
|
|
117
157
|
if not isinstance(bundle_id, str) or not re.fullmatch(template_contract.BUNDLE_ID_PATTERN, bundle_id):
|
|
118
158
|
fail_invalid("platform_config.bundleId must be a bundle identifier")
|
|
119
159
|
mock_package = (ios_dir / "MockSuperSDKPackage").resolve()
|
|
@@ -129,9 +169,8 @@ simple_config.write_text(
|
|
|
129
169
|
|
|
130
170
|
enum SimpleConfig {
|
|
131
171
|
static let spid = %s
|
|
132
|
-
static let environment = %s
|
|
133
172
|
}
|
|
134
|
-
""" %
|
|
173
|
+
""" % swift_string(spid),
|
|
135
174
|
encoding="utf-8",
|
|
136
175
|
)
|
|
137
176
|
|
|
@@ -159,8 +198,8 @@ generated_spec.write_text(rendered, encoding="utf-8")
|
|
|
159
198
|
print(f"rendered {generated_spec}")
|
|
160
199
|
PY
|
|
161
200
|
|
|
162
|
-
# SDK
|
|
163
|
-
#
|
|
201
|
+
# SDK 内部的 Teamwork 评审闸门。第三方模板用户不应设置 SUPERSDK_CI_GATE;
|
|
202
|
+
# 本地正常构建走下面的模拟器自动选择。
|
|
164
203
|
if [ "${SUPERSDK_CI_GATE:-}" = "ws03-ios-xcodegen-generate" ] && [ "$(uname -s)" != "Darwin" ]; then
|
|
165
204
|
echo "IOS_MACOS_EXECUTOR_MISSING: ws03-ios-xcodegen-generate requires a macOS/Xcode runner" >&2
|
|
166
205
|
exit 1
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
5
|
+
# shellcheck source=lib/workspace.sh
|
|
6
|
+
. "$SCRIPT_DIR/lib/workspace.sh"
|
|
7
|
+
WORKSPACE_ROOT="$(supersdk_require_workspace_root "$SCRIPT_DIR")"
|
|
8
|
+
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
|
9
|
+
HELPER="$WORKSPACE_ROOT/scripts/supersdk_template.py"
|
|
10
|
+
CONFIG="$WORKSPACE_ROOT/supersdk.json"
|
|
11
|
+
PROJECT_DIR=""
|
|
12
|
+
|
|
13
|
+
build_seen=false
|
|
14
|
+
while [ "$#" -gt 0 ]; do
|
|
15
|
+
case "$1" in
|
|
16
|
+
--build)
|
|
17
|
+
if [ "$build_seen" = true ]; then
|
|
18
|
+
echo "error: expected --build" >&2
|
|
19
|
+
exit 2
|
|
20
|
+
fi
|
|
21
|
+
build_seen=true
|
|
22
|
+
shift
|
|
23
|
+
;;
|
|
24
|
+
--project)
|
|
25
|
+
if [ "$#" -lt 2 ]; then
|
|
26
|
+
echo "error: --project requires a value" >&2
|
|
27
|
+
exit 2
|
|
28
|
+
fi
|
|
29
|
+
PROJECT_DIR="$2"
|
|
30
|
+
shift 2
|
|
31
|
+
;;
|
|
32
|
+
*)
|
|
33
|
+
echo "error: expected --build" >&2
|
|
34
|
+
exit 2
|
|
35
|
+
;;
|
|
36
|
+
esac
|
|
37
|
+
done
|
|
38
|
+
|
|
39
|
+
if [ -z "$PROJECT_DIR" ]; then
|
|
40
|
+
PROJECT_DIR="$("$PYTHON_BIN" "$HELPER" resolve --config "$CONFIG" --platform site)"
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
exec "$PYTHON_BIN" "$WORKSPACE_ROOT/scripts/web_package.py" package-managed --root "$WORKSPACE_ROOT" --project "$PROJECT_DIR"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# 工作空间定位的单一实现,被 super_build.sh 与所有 build_<type>.sh 复用。
|
|
3
|
+
#
|
|
4
|
+
# 🔴 为什么不能再用 `APP_ROOT="$(dirname "$0")/.."`:项目目录由用户在 supersdk.json 的
|
|
5
|
+
# `projects[].dir` 里指定,深度不定(`android`、`apps/android`、`clients/mobile/android`…)。
|
|
6
|
+
# 任何「固定层级」的反推都会在第一个非默认布局上算错根目录,而且是**静默**算错 ——
|
|
7
|
+
# 注入会写到一个不存在的地方,构建照样退出 0。
|
|
8
|
+
#
|
|
9
|
+
# 定位语义与 CLI 侧一致:向上查找 `supersdk.json`,它所在的目录就是工作空间根。
|
|
10
|
+
# `scripts/` 与 `super_build.sh` 是工作空间级共享物,所以脚本自身位置永远在根之下。
|
|
11
|
+
|
|
12
|
+
supersdk_find_workspace_root() {
|
|
13
|
+
dir="$1"
|
|
14
|
+
while :; do
|
|
15
|
+
if [ -f "$dir/supersdk.json" ]; then
|
|
16
|
+
printf '%s\n' "$dir"
|
|
17
|
+
return 0
|
|
18
|
+
fi
|
|
19
|
+
parent="$(dirname "$dir")"
|
|
20
|
+
if [ "$parent" = "$dir" ]; then
|
|
21
|
+
return 1
|
|
22
|
+
fi
|
|
23
|
+
dir="$parent"
|
|
24
|
+
done
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# 允许调用方(编排器/CI)显式钉住根目录;否则从给定起点向上查找。
|
|
28
|
+
supersdk_workspace_root() {
|
|
29
|
+
if [ -n "${SUPERSDK_WORKSPACE_ROOT:-}" ]; then
|
|
30
|
+
printf '%s\n' "$SUPERSDK_WORKSPACE_ROOT"
|
|
31
|
+
return 0
|
|
32
|
+
fi
|
|
33
|
+
supersdk_find_workspace_root "$1"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
supersdk_require_workspace_root() {
|
|
37
|
+
root="$(supersdk_workspace_root "$1" || true)"
|
|
38
|
+
if [ -z "$root" ]; then
|
|
39
|
+
echo "error: no supersdk.json found at or above $1; run this script from inside a SuperSDK workspace" >&2
|
|
40
|
+
exit 1
|
|
41
|
+
fi
|
|
42
|
+
printf '%s\n' "$root"
|
|
43
|
+
}
|
|
@@ -5,14 +5,25 @@ import http.server
|
|
|
5
5
|
import sys
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
|
|
8
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
9
|
+
import supersdk_template
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def resolve_site_dir(root, project):
|
|
13
|
+
"""站点目录来自配置,不是写死的 `web/`。"""
|
|
14
|
+
if project:
|
|
15
|
+
return project
|
|
16
|
+
return supersdk_template.resolve_single(Path(root) / supersdk_template.CONFIG_FILENAME, "site", None)
|
|
17
|
+
|
|
8
18
|
|
|
9
19
|
def main(argv=None):
|
|
10
|
-
parser = argparse.ArgumentParser(description="Serve
|
|
20
|
+
parser = argparse.ArgumentParser(description="Serve a SuperSDK site project for local HTTP debugging")
|
|
11
21
|
parser.add_argument("--root", default=Path(__file__).resolve().parents[1], type=Path)
|
|
22
|
+
parser.add_argument("--project", default=None, help="Site project directory; resolved from supersdk.json when omitted.")
|
|
12
23
|
parser.add_argument(
|
|
13
24
|
"--host",
|
|
14
25
|
default="127.0.0.1",
|
|
15
|
-
help="Bind host. The default is loopback-only; non-loopback binds expose the
|
|
26
|
+
help="Bind host. The default is loopback-only; non-loopback binds expose the workspace root.",
|
|
16
27
|
)
|
|
17
28
|
parser.add_argument("--port", default=8000, type=int)
|
|
18
29
|
parser.add_argument(
|
|
@@ -23,28 +34,34 @@ def main(argv=None):
|
|
|
23
34
|
args = parser.parse_args(argv)
|
|
24
35
|
|
|
25
36
|
root = args.root.resolve()
|
|
26
|
-
|
|
37
|
+
try:
|
|
38
|
+
site_dir = resolve_site_dir(root, args.project)
|
|
39
|
+
except supersdk_template.ConfigError as exc:
|
|
40
|
+
print(str(exc), file=sys.stderr)
|
|
41
|
+
return 1
|
|
42
|
+
|
|
43
|
+
# Prefer the built package root: only <project>/dist carries the generated
|
|
27
44
|
# supersdk-config.json that the browser fallback path reads.
|
|
28
45
|
entry = None
|
|
29
|
-
for relative in ("
|
|
46
|
+
for relative in (f"{site_dir}/dist/index.html", f"{site_dir}/src/index.html"):
|
|
30
47
|
if (root / relative).is_file():
|
|
31
48
|
entry = relative
|
|
32
49
|
break
|
|
33
50
|
if entry is None:
|
|
34
|
-
print(f"
|
|
51
|
+
print(f"{site_dir}/dist/index.html or {site_dir}/src/index.html not found under {root}", file=sys.stderr)
|
|
35
52
|
return 1
|
|
36
|
-
if entry.
|
|
53
|
+
if entry.endswith("/src/index.html"):
|
|
37
54
|
print(
|
|
38
|
-
"warning: serving unbuilt
|
|
55
|
+
f"warning: serving unbuilt {site_dir}/src; run scripts/build_site.sh --build for the browser config fallback",
|
|
39
56
|
file=sys.stderr,
|
|
40
57
|
)
|
|
41
58
|
|
|
42
59
|
remote_bind = args.host not in {"127.0.0.1", "localhost", "::1"}
|
|
43
60
|
if remote_bind and not args.allow_remote:
|
|
44
|
-
print("refusing non-loopback bind; pass --allow-remote to expose the full
|
|
61
|
+
print("refusing non-loopback bind; pass --allow-remote to expose the full workspace root", file=sys.stderr)
|
|
45
62
|
return 1
|
|
46
63
|
if remote_bind:
|
|
47
|
-
print("warning: serving the full
|
|
64
|
+
print("warning: serving the full workspace root on a non-loopback host", file=sys.stderr)
|
|
48
65
|
|
|
49
66
|
handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=str(root))
|
|
50
67
|
server = http.server.ThreadingHTTPServer((args.host, args.port), handler)
|