-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathupdateVersion.js
52 lines (43 loc) · 1.65 KB
/
updateVersion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const path = require("path");
const fs = require("fs");
const failures = 0;
const LIB_DIR = path.resolve(process.cwd(), "lib");
const EXTENSIONS_DIR = path.resolve(process.cwd(), "extensions");
const libFolders = fs.readdirSync(LIB_DIR, { withFileTypes: true }).filter(function(file) {
return file.isDirectory() && fs.existsSync(path.resolve(LIB_DIR, file.name, "package.json"));
}).map(function(file) {
return file.name;
});
function updatePackageMetadata(libPath) {
const packageJsonPath = path.resolve(libPath, "package.json");
const outputFilepath = path.resolve(libPath, "src", "packageMetadata.ts");
const packageJson = require(packageJsonPath);
console.log(`Updating ${packageJson.name} to version ${packageJson.version}`);
const fileContents = [
"/* eslint-disable header/header */",
`export const name = "${packageJson.name}";`,
`export const version = "${packageJson.version}";`,
""
];
try {
fs.writeFileSync(outputFilepath, fileContents.join("\n"));
} catch {
failures += 1;
console.error(`Failed to update version for ${packageJson.name}`);
}
};
libFolders.forEach((lib) => {
const packagePath = path.resolve(LIB_DIR, lib);
updatePackageMetadata(packagePath);
});
const nodeExtensionsPath = path.resolve(EXTENSIONS_DIR, "msal-node-extensions");
updatePackageMetadata(nodeExtensionsPath);
if (failures > 0) {
console.error(`Failed to update versions on ${failures} packages`);
} else {
console.log("All package versions updated successfully!");
}