diff --git a/applicationinsights-react-native/package.json b/applicationinsights-react-native/package.json index dd6083bb..743a6b40 100644 --- a/applicationinsights-react-native/package.json +++ b/applicationinsights-react-native/package.json @@ -94,4 +94,4 @@ "optional": true } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 7fde0ad5..01325dc8 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "rupdate": "node common/scripts/install-run-rush.js update --recheck --purge --full", "serve": "grunt serve", "setVersion": "node ./tools/release-tools/setVersion.js", + "setAiVersion": "node ./tools/release-tools/setAiVersion.js", "purge": "node common/scripts/install-run-rush.js purge", "fullClean": "git clean -xdf && npm install && rush update --recheck --full", "fullCleanBuild": "npm run fullClean && npm run rebuild", diff --git a/sample/package.json b/sample/package.json index 947c78b0..43f52d99 100644 --- a/sample/package.json +++ b/sample/package.json @@ -1,26 +1,26 @@ { - "name": "applicationinsights-reactnative-sample", - "version": "1.1.1", - "main": "node_modules/expo/AppEntry.js", - "scripts": { - "start": "expo start", - "android": "expo start --android", - "ios": "expo start --ios", - "web": "expo start --web" - }, - "dependencies": { - "@expo/webpack-config": "^18.0.1", - "@microsoft/applicationinsights-react-native": "^4.3.4", - "@microsoft/applicationinsights-web": "^3.3.4", - "expo": "~48.0.18", - "expo-status-bar": "~1.4.4", - "react": "18.2.0", - "react-dom": "18.2.0", - "react-native": "0.71.8", - "react-native-web": "~0.18.10" - }, - "devDependencies": { - "@babel/core": "^7.20.0" - }, - "private": true + "name": "applicationinsights-reactnative-sample", + "version": "1.1.1", + "main": "node_modules/expo/AppEntry.js", + "scripts": { + "start": "expo start", + "android": "expo start --android", + "ios": "expo start --ios", + "web": "expo start --web" + }, + "dependencies": { + "@expo/webpack-config": "^18.0.1", + "@microsoft/applicationinsights-react-native": "^4.3.4", + "@microsoft/applicationinsights-web": "^3.3.4", + "expo": "~48.0.18", + "expo-status-bar": "~1.4.4", + "react": "18.2.0", + "react-dom": "18.2.0", + "react-native": "0.71.8", + "react-native-web": "~0.18.10" + }, + "devDependencies": { + "@babel/core": "^7.20.0" + }, + "private": true } diff --git a/tools/release-tools/package.json b/tools/release-tools/package.json index 9c4ac730..3ef4fc79 100644 --- a/tools/release-tools/package.json +++ b/tools/release-tools/package.json @@ -1,9 +1,9 @@ { "name": "applicationinsights-js-release-tools", - "version": "3.1.3-dev", - "author": "Javascript Telemetry SDKs ", - "description": "1DS Web SDK", - "homepage": "https://1dsdocs.azurewebsites.net/sdk.html", + "version": "3.1.3", + "author": "Microsoft Application Insights Team", + "description": "Microsoft Application Insights React Native release tools", + "homepage": "https://github.com/microsoft/applicationinsights-react-native#readme", "sideEffects": false, "scripts": { "update": "rush update", @@ -19,7 +19,7 @@ ], "repository": { "type": "git", - "url": "https://msasg.visualstudio.com/DefaultCollection/Shared%20Data/_git/1DS.JavaScript" + "url": "https://github.com/microsoft/applicationinsights-react-native" }, "devDependencies": { "grunt": "^1.5.3", diff --git a/tools/release-tools/setAiVersion.js b/tools/release-tools/setAiVersion.js new file mode 100644 index 00000000..88e1abd2 --- /dev/null +++ b/tools/release-tools/setAiVersion.js @@ -0,0 +1,175 @@ +const fs = require("fs"); +const globby = require("globby"); + +let newAiVer = null; +let testOnly = null; + +const theVersion = require(process.cwd() + "/version.json"); + +function showHelp() { + var scriptParts; + var scriptName = process.argv[1]; + if (scriptName.indexOf("\\") !== -1) { + scriptParts = scriptName.split("\\"); + scriptName = scriptParts[scriptParts.length - 1]; + } else if (scriptName.indexOf("/") !== -1) { + scriptParts = scriptName.split("/"); + scriptName = scriptParts[scriptParts.length - 1]; + } + + console.log(""); + console.log(scriptName + " [ [-test]"); + console.log("--------------------------"); + console.log(" - Identifies the application insights version to set for all packages"); + console.log(" -test - Scan all of the package.json files and log the changes, but DON'T update the files"); +} + +function parseArgs() { + if (process.argv.length < 2) { + console.error("!!! Invalid number of arguments -- " + process.argv.length); + return false; + } + + let idx = 2; + while(idx < process.argv.length) { + let theArg = process.argv[idx]; + if (theArg === "-test") { + testOnly = true; + } else if (!newAiVer) { + newAiVer = theArg; + } else { + console.error("!!! Invalid Argument [" + theArg + "] detected"); + return false; + } + + idx ++; + } + + // If no version, + if (!newAiVer) { + return false; + } + + return true; +} + +function shouldProcess(name) { + if (name.indexOf("node_modules/") !== -1) { + return false; + } + + if (name.indexOf("common/temp") !== -1) { + return false; + } + + if (name.indexOf("examples/") !== -1) { + return true; + } + + if (name.indexOf("sample/") !== -1) { + return true; + } + + if (name.indexOf("applicationinsights-react-native") !== -1) { + return true; + } + + if (name === "package.json") { + return true; + } + + return false; +} + +function shouldUpdateDependency(name) { + if (name.indexOf("@microsoft/applicationinsights-") === -1) { + return false; + } + + if (name.indexOf("applicationinsights-shims") !== -1) { + return false; + } + + if (name.indexOf("applicationinsights-rollup") !== -1) { + return false; + } + + if (name.indexOf("applicationinsights-react-native") !== -1) { + // Don't update references to this package + return false; + } + + return true; +} + +function updateDependencies(target, newVersion) { + let changed = false; + if (target) { + let isDigit = /^\d/.test(newVersion); + Object.keys(target).forEach((value) => { + if (shouldUpdateDependency(value)) { + let version = target[value]; + if (version.startsWith("^") && isDigit) { + if (version !== "^" + newVersion) { + target[value] = "^" + newVersion; + } + } else if (version.startsWith("~") && isDigit) { + if (version !== "~" + newVersion) { + target[value] = "~" + newVersion; + } + } else if (version !== newVersion) { + target[value] = newVersion; + } + + if (version != target[value]) { + console.log(" Updated: " + value + " \"" + version + "\" => \"" + target[value] + "\""); + changed = true; + } else { + console.log(" Skipped: " + value + " \"" + version + "\""); + } + } + }); + } + + return changed; +} + +const setPackageJsonRelease = () => { + const files = globby.sync(["./**/package.json", "!**/node_modules/**"]); + let changed = false; + files.map(packageFile => { + // Don't update node_modules + if (shouldProcess(packageFile)) { + console.log("Loading - " + packageFile); + + let theFilename = packageFile; + const package = require(process.cwd() + "\\" + theFilename); + console.log(" Name - " + package.name); + + let updated = false; + updated |= updateDependencies(package.dependencies, newAiVer); + updated |= updateDependencies(package.peerDependencies, newAiVer); + updated |= updateDependencies(package.devDependencies, newAiVer); + + if (updated && !testOnly) { + // Rewrite the file + const newContent = JSON.stringify(package, null, 4) + "\n"; + fs.writeFileSync(theFilename, newContent); + changed = true; + } + console.log(" -------------------------------------------------------------------------------------"); + } + }); + + return changed; +}; + +if (parseArgs()) { + if (setPackageJsonRelease()) { + console.log("Version updated, now run 'npm run rupdate'"); + } else { + console.log("Nothing Changed"); + } +} else { + showHelp(); +}