diff --git a/common/config/rush/npm-shrinkwrap.json b/common/config/rush/npm-shrinkwrap.json index 25ddd5981..f292c3455 100644 --- a/common/config/rush/npm-shrinkwrap.json +++ b/common/config/rush/npm-shrinkwrap.json @@ -2869,19 +2869,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -7840,12 +7827,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, - "fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "optional": true - }, "function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", diff --git a/package.json b/package.json index cf13f12d6..522b56842 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "ai-min": "node common/scripts/install-run-rush.js ai-min", "ai-restore": "node common/scripts/install-run-rush.js ai-restore", "npm-pack": "node common/scripts/install-run-rush.js npm-pack --verbose", - "npm-publish": "node ./tools/release-tools/npm_publish.js" + "npm-publish": "node ./tools/release-tools/npm_publish.js", + "npm-package": "node ./tools/release-tools/npm_package.js" }, "repository": { "type": "git", diff --git a/tools/release-tools/npm_package.js b/tools/release-tools/npm_package.js new file mode 100644 index 000000000..3b659ae61 --- /dev/null +++ b/tools/release-tools/npm_package.js @@ -0,0 +1,166 @@ +const fs = require("fs"); +const child_process = require("child_process"); + +const packageGroupDef = "./tools/release-tools/package_groups.json"; +let packageGroup; +let dropFolder; +let dryRun = ""; + +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 + " "); + console.log("--------------------------"); + console.log(" - Identifies the group to publish, identifies folders, the group must be defined in package_groups.json"); + console.log(" - Identifies the base folder to drop the packages into, defaults to ./drop/packages/"); +} + +function parseArgs() { + console.log("Parsing args - " + process.argv.join(" ")); + 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.startsWith("-")) { + if (theArg === "-test") { + dryRun = "--dry-run"; + } else { + console.error("!!! Unknown switch [" + theArg + "] detected"); + return false; + } + } else if (!packageGroup) { + packageGroup = theArg; + } else if (!dropFolder) { + dropFolder = theArg; + } else { + console.error("!!! Invalid Argument [" + theArg + "] detected"); + return false; + } + + idx++; + } + + // Check for required arguments + if (!packageGroup) { + console.error("!!! Missing package group"); + return false; + } + + return true; +} + +function removeTrailingComma(text) { + return text.replace(/,(\s*[}\],])/g, "$1"); +} + +function removeComments(text) { + return text.replace(/^\s*\/\/\s.*$/gm, ""); +} + +function getPackage(packageJsonFile) { + var packageText = removeTrailingComma(fs.readFileSync(packageJsonFile, "utf-8")); + + return JSON.parse(packageText); +} + +function getNpmPackageName(packageJson) { + let packageName = packageJson.name; + let packageVersion = packageJson.version; + + let theNpmPackageName = packageName + "-" + packageVersion; + + theNpmPackageName = theNpmPackageName.replace("@", "").replace("/", "-"); + + return theNpmPackageName + ".tgz"; +} + +function getGroupProjects() { + if (!fs.existsSync(packageGroupDef)) { + console.error("!!! Unable to locate package group definitions [" + packageGroupDef + "]"); + throw new Error("!!! Unable to locate package group definitions."); + } + + var groupText = removeComments(removeTrailingComma(fs.readFileSync(packageGroupDef, "utf-8"))); + + let groupJson = JSON.parse(groupText); + return groupJson[packageGroup] || []; +} + +function movePackage(npmPackageName, packageName) { + let packageFolder = dropFolder; + if (!packageFolder) { + packageFolder = "./drop/packages"; + packageFolder += "/" + packageGroup; + } + + if (!fs.existsSync(packageFolder)) { + fs.mkdirSync(packageFolder, { recursive: true }); + } + + let packageFile = packageFolder + "/" + packageName; + if (fs.existsSync(packageFile)) { + console.log(` -- Removing existing package ${packageFile}`); + fs.unlinkSync(packageFile); + } + + console.log(` -- Moving ${npmPackageName} to ${packageFile}`); + fs.renameSync(npmPackageName, packageFile); +} + +if (parseArgs()) { + var packages = getGroupProjects(); + + console.log(`Creating [${packageGroup}] packages => ${packages.length}`); + packages.forEach((packageRoot) => { + let packageJsonFile = packageRoot + "/package.json"; + + if (!fs.existsSync(packageJsonFile)) { + console.error("!!! Source package.json doesn't exist [" + packageJsonFile + "]"); + throw new Error("!!! Source package.json doesn't exist [" + packageJsonFile + "]"); + } + + const packageJson = getPackage(packageJsonFile); + + const packageName = getNpmPackageName(packageJson); + console.log("\n\n##################################################################"); + console.log("Packaging - " + packageName); + console.log("##################################################################"); + + let npmPackageName = packageRoot + "/" + packageName; + if (fs.existsSync(npmPackageName)) { + console.log(` -- Removing existing package ${npmPackageName}`); + fs.unlinkSync(npmPackageName); + } + + const cwd = process.cwd(); + process.chdir(packageRoot); + try { + let npmCmd = `npm pack ${dryRun}`; + console.log(`Running: \"${npmCmd}\"`); + child_process.execSync(npmCmd); + } finally { + process.chdir(cwd); + } + + if (!dryRun) { + // Move the package to the package folder + movePackage(npmPackageName, packageName); + } + }); +} else { + showHelp(); + process.exit(1); +} diff --git a/tools/release-tools/package_groups.json b/tools/release-tools/package_groups.json index b07c3c5af..644bf514d 100644 --- a/tools/release-tools/package_groups.json +++ b/tools/release-tools/package_groups.json @@ -16,6 +16,25 @@ "./extensions/applicationinsights-perfmarkmeasure-js", "./extensions/applicationinsights-debugplugin-js" ], + // 1ds (not in the master branch) + "1ds": [ + ], + // aionly + "aionly": [ + "./shared/AppInsightsCore", + "./shared/AppInsightsCommon", + "./AISKU", + "./AISKULight", + "./extensions/applicationinsights-analytics-js", + "./extensions/applicationinsights-properties-js", + "./channels/applicationinsights-channel-js", + "./extensions/applicationinsights-dependencies-js", + "./extensions/applicationinsights-clickanalytics-js", + "./extensions/applicationinsights-perfmarkmeasure-js", + "./extensions/applicationinsights-debugplugin-js" + ], + "cfgSync": [ + ], // Rollup packages "rollup-es": [ "./tools/rollup-es3" @@ -27,5 +46,11 @@ // Snippet packages "snippet": [ "./tools/applicationinsights-web-snippet" + ], + "examples": [ + "./examples/AISKU", + "./examples/cfgSync", + "./examples/dependency", + "./examples/shared-worker" ] } \ No newline at end of file