|
1 | 1 | import fs from "fs"; |
2 | 2 | import path from "path"; |
3 | 3 |
|
4 | | -// package.jsonとソースファイルのパスを設定 |
5 | 4 | const packageFile = path.join(process.cwd(), "./package.json"); |
6 | 5 | const layoutFile = path.join(process.cwd(), "./src/routes/+layout.svelte"); |
| 6 | +const manifestFile = path.join(process.cwd(), "./static/manifest.json"); |
7 | 7 |
|
8 | | -// package.jsonを読み込んでバージョンを取得 |
9 | 8 | const packageJson = JSON.parse(fs.readFileSync(packageFile, 'utf-8')); |
10 | 9 | const version = packageJson.version; |
11 | 10 |
|
12 | | -// UTCタイムスタンプを生成 |
| 11 | +// Create UTC Timestamp |
13 | 12 | const now = new Date(); |
14 | 13 | const timestamp = `${now.getUTCFullYear()}${String(now.getUTCMonth() + 1).padStart( |
15 | 14 | 2, |
16 | | - "0")}${String(now.getUTCDate()).padStart(2, "0")}${String(now.getUTCHours()).padStart( |
| 15 | + "0" |
| 16 | +)}${String(now.getUTCDate()).padStart(2, "0")}${String(now.getUTCHours()).padStart( |
17 | 17 | 2, |
18 | | - "0")}${String(now.getUTCMinutes()).padStart(2, "0")}${String( |
| 18 | + "0" |
| 19 | +)}${String(now.getUTCMinutes()).padStart(2, "0")}${String( |
19 | 20 | now.getUTCSeconds() |
20 | 21 | ).padStart(2, "0")}`; |
21 | 22 |
|
22 | | -// レイアウトファイルを読み込んで更新 |
23 | | -fs.readFile(layoutFile, "utf-8", (err, content) => { |
| 23 | +// Update manifest.json |
| 24 | +fs.readFile(manifestFile, "utf-8", (err, content) => { |
24 | 25 | if (err) throw err; |
| 26 | + |
| 27 | + const manifestJson = JSON.parse(content); |
| 28 | + manifestJson.version = version; |
| 29 | + |
| 30 | + fs.writeFile(manifestFile, JSON.stringify(manifestJson, null, 2), "utf-8", (err) => { |
| 31 | + if (err) throw err; |
| 32 | + console.log(`Version ${version} updated in ${manifestFile}`); |
| 33 | + }); |
| 34 | +}); |
25 | 35 |
|
26 | | - const regex = /<div id="buildTimestamp">(.*?)<\/div>/; |
| 36 | +// Update layout.svelte(Header) |
| 37 | +fs.readFile(layoutFile, "utf-8", (err, content) => { |
| 38 | + if (err) throw err; |
| 39 | + |
| 40 | + const regex = /\<div class="version"\>(.*?)\<\/div\>/; |
27 | 41 | const updatedContent = content.replace( |
28 | 42 | regex, |
29 | | - `<div id="buildTimestamp" class="text-xs">v${version} (Build: ${timestamp} UTC)</div>` |
| 43 | + `<div class="version">v${version} (Build: ${timestamp} UTC)</div>` |
30 | 44 | ); |
31 | | - |
| 45 | + |
32 | 46 | fs.writeFile(layoutFile, updatedContent, "utf-8", (err) => { |
33 | 47 | if (err) throw err; |
34 | 48 | console.log(`Version ${version} and UTC build timestamp added to ${layoutFile}`); |
|
0 commit comments