mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-02 04:10:10 +08:00
- @cindy/maker-shared/ui-mock:两端共用的演示项目与任务(桌面数据库行格式) - Desktop:restart --mock 使用独立 ui-mock 沙箱,首次免账号进入并补齐模拟任务 - Mobile:sim:start/whoami/rebuild 支持 --mock,visual mock 改用共享数据 - 文档:docs/dev-rules/ui-mock-data.md,并在启动说明与 AGENTS 索引中链接 Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
38 lines
1.7 KiB
JavaScript
38 lines
1.7 KiB
JavaScript
import { readFileSync, existsSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { parseProjectEnv } from '@expo/env';
|
|
import { metroEnvironmentFingerprint } from '../sim-metro.mjs';
|
|
|
|
export const UI_MOCK_ENV = 'EXPO_PUBLIC_CINDY_MOBILE_VISUAL_MOCK';
|
|
|
|
/**
|
|
* `--mock` selects the login-free UI mock data (docs/dev-rules/ui-mock-data.md).
|
|
* It only sets the bundle env, so start, whoami and rebuild must all pass it.
|
|
*/
|
|
export function applySimMockArg(args, env = process.env) {
|
|
const passthrough = args.filter((arg) => arg !== '--mock');
|
|
if (passthrough.length !== args.length) env[UI_MOCK_ENV] = '1';
|
|
return passthrough;
|
|
}
|
|
|
|
/** Read the same inputs for start, diagnostics and rebuild, without repairing files. */
|
|
export function readSimEnvironment(mobileDir, buildEnv, systemEnv = process.env) {
|
|
const projectEnv = parseProjectEnv(mobileDir, {
|
|
mode: systemEnv.NODE_ENV ?? 'development', silent: true, systemEnv: { ...systemEnv },
|
|
});
|
|
const loginScenario = systemEnv.EXPO_PUBLIC_LOGIN_SCENARIO?.trim()
|
|
?? projectEnv.env.EXPO_PUBLIC_LOGIN_SCENARIO?.trim() ?? '';
|
|
const uiMock = ['1', 'true', 'yes'].includes(
|
|
(systemEnv[UI_MOCK_ENV] ?? projectEnv.env[UI_MOCK_ENV] ?? '').trim().toLowerCase());
|
|
const files = {};
|
|
for (const name of ['.env', 'scripts/self-host-regions.json']) {
|
|
const file = join(mobileDir, name);
|
|
files[name] = existsSync(file) ? readFileSync(file, 'utf8') : null;
|
|
}
|
|
return { loginScenario, uiMock, envFingerprint: metroEnvironmentFingerprint({
|
|
// Only a mock Metro adds the key, so existing real-data fingerprints stay valid.
|
|
env: { ...buildEnv, EXPO_PUBLIC_LOGIN_SCENARIO: loginScenario, ...(uiMock ? { [UI_MOCK_ENV]: '1' } : {}) },
|
|
files,
|
|
}) };
|
|
}
|