@oondemand/oon-core-front 0.3.52 → 0.3.54

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/bin/cli.js CHANGED
@@ -72,6 +72,59 @@ function readEnv(name) {
72
72
  return line ? line.split("=").slice(1).join("=").trim().replace(/^["']|["']$/g, "") : undefined;
73
73
  }
74
74
 
75
+ function readPackageVersion(directory) {
76
+ try {
77
+ const packagePath = path.join(directory, "package.json");
78
+ const payload = JSON.parse(fs.readFileSync(packagePath, "utf8"));
79
+ return typeof payload.version === "string" && payload.version.trim()
80
+ ? payload.version.trim()
81
+ : undefined;
82
+ } catch (_error) {
83
+ return undefined;
84
+ }
85
+ }
86
+
87
+ function resolveCentralRoot() {
88
+ const candidates = [cwd, path.dirname(cwd)];
89
+ return candidates.find((directory) => fs.existsSync(path.join(directory, "central.app.json"))) ?? cwd;
90
+ }
91
+
92
+ function resolveSourceCommit(root) {
93
+ const configured = [
94
+ process.env.OON_BUILD_COMMIT,
95
+ process.env.CENTRAL_COMMIT_SHA,
96
+ process.env.SOURCE_COMMIT_SHA,
97
+ process.env.GITHUB_SHA,
98
+ ].find((candidate) => candidate?.trim());
99
+ if (configured) return configured.trim();
100
+
101
+ const result = spawnSync("git", ["rev-parse", "HEAD"], {
102
+ cwd: root,
103
+ encoding: "utf8",
104
+ stdio: ["ignore", "pipe", "ignore"],
105
+ });
106
+ return result.status === 0 && result.stdout?.trim()
107
+ ? result.stdout.trim()
108
+ : undefined;
109
+ }
110
+
111
+ function prepareBuildMetadata(mode) {
112
+ const root = resolveCentralRoot();
113
+ const centralVersion = readPackageVersion(root) ?? readPackageVersion(cwd);
114
+ const commit = resolveSourceCommit(root);
115
+ const releaseId = process.env.OON_RELEASE_ID || process.env.RELEASE_ID;
116
+ const environment = process.env.OON_ENVIRONMENT
117
+ || process.env.DEPLOY_ENVIRONMENT
118
+ || process.env.NODE_ENV
119
+ || (mode === "dev" ? "development" : "production");
120
+
121
+ process.env.VITE_OON_BUILD_TIME ||= new Date().toISOString();
122
+ if (centralVersion) process.env.VITE_OON_CENTRAL_VERSION ||= centralVersion;
123
+ if (commit) process.env.VITE_OON_BUILD_COMMIT ||= commit;
124
+ if (releaseId) process.env.VITE_OON_RELEASE_ID ||= releaseId;
125
+ process.env.VITE_OON_ENVIRONMENT ||= environment;
126
+ }
127
+
75
128
  async function syncMetadata() {
76
129
  const apiUrl = readEnv("OON_API_URL") || readEnv("VITE_API_URL");
77
130
  if (!apiUrl) {
@@ -101,8 +154,10 @@ async function syncMetadata() {
101
154
  async function main() {
102
155
  switch (cmd) {
103
156
  case "dev":
157
+ prepareBuildMetadata("dev");
104
158
  return runVite(["dev"]);
105
159
  case "build":
160
+ prepareBuildMetadata("build");
106
161
  return runVite(["build"]);
107
162
  case "preview":
108
163
  return runVite(["preview"]);