功能:同步小程序流程
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Purpose: safeRequire supports config.js by holding or executing the safe require page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function safeRequire(modulePath) {
|
||||
try {
|
||||
return require(modulePath)
|
||||
@@ -6,6 +10,10 @@ function safeRequire(modulePath) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getEnvVersion supports config.js by holding or executing the get env version page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getEnvVersion() {
|
||||
if (typeof wx === 'undefined') {
|
||||
return 'develop'
|
||||
@@ -30,6 +38,10 @@ function getEnvVersion() {
|
||||
return 'develop'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getRuntimePlatform supports config.js by holding or executing the get runtime platform page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getRuntimePlatform() {
|
||||
if (typeof wx === 'undefined') {
|
||||
return 'devtools'
|
||||
@@ -56,6 +68,10 @@ function getRuntimePlatform() {
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: normalizeDomain supports config.js by holding or executing the normalize domain page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function normalizeDomain(value, fallbackValue) {
|
||||
const target = String(value || fallbackValue || '').trim()
|
||||
if (!target) {
|
||||
@@ -64,6 +80,10 @@ function normalizeDomain(value, fallbackValue) {
|
||||
return target.replace(/\/+$/, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: ensureHttps supports config.js by holding or executing the ensure https page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function ensureHttps(value, envVersion) {
|
||||
if (!value) {
|
||||
throw new Error(`Missing API domain for ${envVersion}`)
|
||||
@@ -74,11 +94,31 @@ function ensureHttps(value, envVersion) {
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: localOverride supports config.js by holding or executing the local override page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const localOverride = safeRequire('./config.local')
|
||||
/**
|
||||
* Purpose: ENV_VERSION supports config.js by holding or executing the env version page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const ENV_VERSION = getEnvVersion()
|
||||
/**
|
||||
* Purpose: RUNTIME_PLATFORM supports config.js by holding or executing the runtime platform page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const RUNTIME_PLATFORM = getRuntimePlatform()
|
||||
/**
|
||||
* Purpose: IS_DEVTOOLS supports config.js by holding or executing the is devtools page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const IS_DEVTOOLS = RUNTIME_PLATFORM === 'devtools'
|
||||
|
||||
/**
|
||||
* Purpose: DEFAULT_DOMAINS supports config.js by holding or executing the default domains page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const DEFAULT_DOMAINS = {
|
||||
local: 'http://127.0.0.1:80',
|
||||
tunnel: 'https://yunail.art',
|
||||
@@ -87,13 +127,29 @@ const DEFAULT_DOMAINS = {
|
||||
release: 'https://yunail.art'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: DOMAIN_MAP supports config.js by holding or executing the domain map page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const DOMAIN_MAP = {
|
||||
...DEFAULT_DOMAINS,
|
||||
...(localOverride.domains || {})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: DEFAULT_DEVELOP_TARGET supports config.js by holding or executing the default develop target page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const DEFAULT_DEVELOP_TARGET = IS_DEVTOOLS ? 'local' : 'dev-remote'
|
||||
/**
|
||||
* Purpose: DEVELOP_TARGET supports config.js by holding or executing the develop target page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const DEVELOP_TARGET = String(localOverride.developTarget || DEFAULT_DEVELOP_TARGET)
|
||||
/**
|
||||
* Purpose: API_DOMAIN supports config.js by holding or executing the api domain page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const API_DOMAIN = ensureHttps(
|
||||
ENV_VERSION === 'develop'
|
||||
? normalizeDomain(DOMAIN_MAP[DEVELOP_TARGET], DOMAIN_MAP['dev-remote'])
|
||||
|
||||
Reference in New Issue
Block a user