配置 EAS 元数据

了解配置 EAS 元数据的不同方法。


重要 EAS 元数据 目前处于测试阶段,可能会发生重大变更。

EAS 元数据通过位于 项目根目录store.config.json 文件进行配置。

🌐 EAS Metadata is configured by a store.config.json file at the root of your project.

你可以通过 eas.json metadataPath 属性配置存储配置文件的路径或名称。除了默认的 JSON 格式,EAS 元数据还支持使用 JavaScript 文件进行更动态的配置。

🌐 You can configure the path or name of the store config file with the eas.json metadataPath property. Besides the default JSON format, EAS Metadata also supports more dynamic config using JavaScript files.

静态存储配置

🌐 Static store config

EAS 元数据的默认存储配置类型是一个简单的 JSON 文件。下面的代码片段显示了一个示例存储配置,其中包含用英语(美国)编写的基本 App Store 信息。

🌐 The default store config type for EAS Metadata is a simple JSON file. The code snippet below shows an example store config with basic App Store information written in English (U.S.).

你可以在存储配置架构中找到所有配置选项。

🌐 You can find all configuration options in the store config schema.

如果你安装了 VS Code Expo 工具扩展,你将在 store.config.json 文件中获得自动补齐、建议和警告。

store.config.json
{ "configVersion": 0, "apple": { "info": { "en-US": { "title": "Awesome App", "subtitle": "Your self-made awesome app", "description": "The most awesome app you have ever seen", "keywords": ["awesome", "app"], "marketingUrl": "https://example.com/en/promo", "supportUrl": "https://example.com/en/support", "privacyPolicyUrl": "https://example.com/en/privacy" } } } }

动态存储配置

🌐 Dynamic store config

有时,元数据属性可以从动态值中受益。例如,元数据中的版权声明应包含当前年份。这可以通过 EAS 元数据自动化实现。

🌐 At times, Metadata properties can benefit from dynamic values. For example, the Metadata copyright notice should contain the current year. This can be automated with EAS Metadata.

要动态生成内容,首先创建一个 JavaScript 配置文件 store.config.js。然后,在 eas.json 文件中使用 metadataPath 属性来选择 JS 配置文件。

🌐 To generate content dynamically, start by creating a JavaScript config file store.config.js. Then, use the metadataPath property in the eas.json file to pick the JS config file.

eas metadata:pull 无法更新动态存储配置文件。取而代之的是,它会创建一个与配置文件同名的 JSON 文件。你可以导入该 JSON 文件以重用 eas metadata:pull 的数据。

store.config.js
// Use the data from `eas metadata:pull` const config = require('./store.config.json'); const year = new Date().getFullYear(); config.apple.copyright = `${year} Acme, Inc.`; module.exports = config;
eas.json
{ "submit": { "production": { "ios": { "metadataPath": "./store.config.js" } } } }

使用外部内容存储配置

🌐 Store config with external content

在使用外部服务进行本地化时,你需要获取外部内容。EAS 元数据支持从动态存储配置文件导出的同步和异步函数。在进行验证和与商店同步之前,会等待函数结果。

🌐 When using external services for localizations, you have to fetch external content. EAS Metadata supports synchronous and asynchronous functions exported from dynamic store config files. The function results are awaited before validating and syncing with the stores.

store.config.js 函数在 Node.js 中执行。如果你需要特殊值,例如密钥,请使用环境变量。

store.config.js
// Use the data from `eas metadata:pull` const config = require('./store.config.json'); module.exports = async () => { const year = new Date().getFullYear(); const info = await fetchLocalizations('...').then(response => response.json()); config.apple.copyright = `${year} Acme, Inc.`; config.apple.info = info; return config; };
eas.json
{ "submit": { "production": { "ios": { "metadataPath": "./store.config.js" } } } }