-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: using commit hash to hash file name
- Loading branch information
Showing
6 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const {resolve} = require('node:path'); | ||
const {execSync} = require('node:child_process'); | ||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
|
||
const commitHash = execSync('git rev-parse --short HEAD').toString().trim(); | ||
|
||
const indexHTMLPath = resolve(__dirname, '../dist/index.html'); | ||
|
||
function fileName(name) { | ||
const parsed = path.parse(name); | ||
parsed.name = `${parsed.name}.${commitHash}`; | ||
parsed.base = `${parsed.name}${parsed.ext}`; | ||
return path.format(parsed); | ||
} | ||
|
||
fs.readFile(indexHTMLPath, 'utf8', function(err, data) { | ||
if (err) { | ||
return console.log(err); | ||
} | ||
|
||
const indexName = fileName('index.js'); | ||
const clientName = fileName('client.js'); | ||
const devtoolsName = fileName('devtools.js'); | ||
|
||
let result = data.replace(new RegExp(indexName, 'g'), | ||
`react-render/${indexName}`); | ||
|
||
result = result.replace(new RegExp(clientName, 'g'), | ||
`react-render/${clientName}`); | ||
|
||
result = result.replace(new RegExp(devtoolsName, 'g'), | ||
`react-render/${devtoolsName}`); | ||
|
||
// Write the updated content back to the file | ||
fs.writeFile(indexHTMLPath, result, 'utf8', function(err) { | ||
if (err) return console.log(err); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
/// <reference types="vite/client" /> | ||
|
||
interface ImportMetaEnv { | ||
readonly VITE_COMMIT_HASH: string; | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters