【问题标题】:Show date time of the latest publish on Expo在 Expo 上显示最新发布的日期时间
【发布时间】:2021-05-14 04:38:28
【问题描述】:

我正在尝试获取将应用发布为应用版本的日期时间,因此我不必手动更新版本。我在“额外”对象中定义信息

app.config.js

export default ({ config }) => {
    config.extra = {
        buildDate: new Date(),
    };
    return config;
};

并通过 expo-constants

获取

App.js

import Constants from 'expo-constants';
...
<Text muted>Build date time: {moment.utc(Constants.manifest.extra.buildDate).format('DD/MM/YYYY HH:mm UTC')}</Text>
...

但是,当我打开应用程序时,值会发生变化 - 结果它每次都会再次运行,并且与发布应用程序无关。

如何正确配置?

【问题讨论】:

    标签: javascript node.js react-native expo


    【解决方案1】:

    我最终做的是以下

    1. 我在项目的根目录下添加了一个.scripts 文件夹
    2. 我在文件夹中添加了timestamp.js 脚本 时间戳.js
    
    const fs = require("fs");
    const t = new Date();
    const timestamp = 
        t.getFullYear() +
        ("0" + (t.getMonth() + 1)).slice(-2) +
        ("0" + t.getDate()).slice(-2);
    
    const statement = `export const timestamp = "${timestamp}"`;
    
    fs.writeFile("./src/util/VersionTimestamp.js", statement, (err) => {
      if (err) {
        console.error(err);
        return;
      }
      //file written successfully
    });
    
    
    1. 在某处添加了一个名为VersionTimestamp.js 的空文件
    2. 添加了一个 npm 脚本"publish": "node ./.scripts/timestamp.js &amp;&amp; expo publish"
    3. 发布时使用yarn run publish ... 而不是expo publish ...
    4. 然后我会导入版本时间戳并将其显示在应用程序中我想要的任何位置。

    P.S.:显然将脚本中的路径更新为您的路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多