-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"currentVersion": "1.19.5", | ||
"integrity": "sha256-JwUksNJ6/R07ZiLRoXbGeNrtlFZMFDKX4hemPiHOmCA=" | ||
} |
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,60 @@ | ||
|
||
// Iterate over all the .razor files in Pages and replace | ||
// https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/<<current-version>>/jquery.validate.min.js | ||
// with the new version. | ||
// Also replace the integrity attribute with the new integrity attribute. | ||
// The current integrity attribute and the current version can be read from a json file on this script folder | ||
// called jquery-validate-versions.json that has the following structure: | ||
// { | ||
// "currentVersion": "1.19.5", | ||
// "integrity": "sha256-JwUksNJ6/R07ZiLRoXbGeNrtlFZMFDKX4hemPiHOmCA=", | ||
// "newVersion": "1.20.1", | ||
// "newIntegrity": "sha256-7Z6+1q1Z2+7e5Z2e5Z2+7e5Z2+7e5Z2+7e5Z2+7e5Z2=" | ||
// } | ||
// After we've updated the files, we'll update the json file with the new version and integrity. | ||
|
||
// Read the JSON file | ||
import fs from 'fs'; | ||
|
||
const jqueryValidateVersions = JSON.parse(fs.readFileSync('./jquery-validate-versions.json', 'utf8')); | ||
|
||
// Get the current version and integrity | ||
const currentVersion = jqueryValidateVersions.currentVersion; | ||
const integrity = jqueryValidateVersions.integrity; | ||
|
||
// Get the new version and integrity | ||
const newVersion = jqueryValidateVersions.newVersion; | ||
const newIntegrity = jqueryValidateVersions.newIntegrity; | ||
|
||
// Iterate recursively over all the .razor files in the Pages folder | ||
const replaceIntegrity = (dir) => { | ||
const files = fs.readdirSync(dir); | ||
files.forEach((file) => { | ||
const filePath = `${dir}/${file}`; | ||
const stat = fs.statSync(filePath); | ||
if (stat.isDirectory()) { | ||
replaceIntegrity(filePath); | ||
} else { | ||
if (filePath.endsWith('.cshtml')) { | ||
// Read the file | ||
let content = fs.readFileSync(filePath, 'utf8'); | ||
// Replace the old version with the new version | ||
content = content.replace(`https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/${currentVersion}/jquery.validate.min.js`, `https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/${newVersion}/jquery.validate.min.js`); | ||
// Replace the old integrity with the new integrity | ||
content = content.replace(`integrity="${integrity}"`, `integrity="${newIntegrity}"`); | ||
// Write the file | ||
fs.writeFileSync(filePath, content); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
replaceIntegrity('./src/Areas/Identity'); | ||
|
||
// Update the JSON file with the new version and integrity | ||
jqueryValidateVersions.currentVersion = newVersion; | ||
jqueryValidateVersions.integrity = newIntegrity; | ||
delete jqueryValidateVersions.newVersion; | ||
delete jqueryValidateVersions.newIntegrity; | ||
|
||
fs.writeFileSync('./jquery-validate-versions.json', JSON.stringify(jqueryValidateVersions, null, 2)); |
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,32 @@ | ||
// Get jquery.validate.min.js from node_modules/jquery-validation/dist/ and compute its sha256 integrity attribute | ||
// Get the version from node_modules/jquery-validation/package.json | ||
// Update <<RepoRoot>>/src/Identity/UI/jquery-validate-versions.json with the version and integrity attribute | ||
// by adding the newVersion and newIntegrity properties to the top level object. | ||
|
||
import crypto from 'crypto'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
const repoRoot = process.env.RepoRoot; | ||
if (!repoRoot) { | ||
throw new Error('RepoRoot environment variable is not set') | ||
} | ||
|
||
// Get the version from node_modules/jquery-validation/package.json | ||
const packageJson = JSON.parse(fs.readFileSync(path.join(import.meta.dirname, 'node_modules', 'jquery-validation', 'package.json'))); | ||
const newVersion = packageJson.version; | ||
|
||
// Get jquery.validate.min.js from node_modules/jquery-validation/dist/ and compute its sha256 integrity attribute | ||
const nodeModulesDir = path.join(import.meta.dirname, 'node_modules', 'jquery-validation', 'dist'); | ||
const source = path.join(nodeModulesDir, 'jquery.validate.min.js'); | ||
// Compute Base64(SHA256(jquery.validate.min.js bytes)) | ||
const sha256Hash = crypto.createHash('sha256').update(fs.readFileSync(source)).digest('base64'); | ||
console.log(`Computed integrity hash for jquery.validate.min.js: sha256-${sha256Hash}`); | ||
|
||
// Update <<RepoRoot>>/src/Identity/UI/jquery-validate-versions.json with the version and integrity attribute | ||
const jqueryValidateVersionsFile = path.join(repoRoot, 'src', 'Identity', 'UI', 'jquery-validate-versions.json'); | ||
const jqueryValidateVersions = JSON.parse(fs.readFileSync(jqueryValidateVersionsFile)); | ||
jqueryValidateVersions.newVersion = newVersion; | ||
jqueryValidateVersions.newIntegrity = `sha256-${sha256Hash}`; | ||
fs.writeFileSync(jqueryValidateVersionsFile, JSON.stringify(jqueryValidateVersions, null, 2)); | ||
console.log(`Updated ${jqueryValidateVersionsFile} with new version and integrity hash`); |