Skip to content

Commit

Permalink
Update NPM publish scripts (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Apr 5, 2023
1 parent 728b730 commit 4361915
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 106 deletions.
3 changes: 1 addition & 2 deletions AISKU/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"nightwatch:ie11": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env ie11",
"nightwatch": "start node Tests/nightwatch/serve_nightwatch.js && npx concurrently \"npm run nightwatch:chrome\" \"npm run nightwatch:ie11\" \"npm run nightwatch:ie10\" && npm run nightwatch:done || npm run nightwatch:done",
"nightwatch:done": "curl http://localhost:8000/_done",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"devDependencies": {
"@microsoft/ai-test-framework": "0.0.1",
Expand Down
3 changes: 1 addition & 2 deletions AISKULight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"sri": "node ../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt aiskulite-min",
"ai-restore": "grunt aiskulite-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"repository": {
"type": "git",
Expand Down
3 changes: 1 addition & 2 deletions channels/applicationinsights-channel-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt aichannel-min",
"ai-restore": "grunt aichannel-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"devDependencies": {
"@microsoft/ai-test-framework": "0.0.1",
Expand Down
50 changes: 0 additions & 50 deletions common/config/rush/command-line.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,56 +81,6 @@
"enableParallelism": true,
"ignoreMissingScript": true,
"allowWarningsInSuccessfulBuild": true
},
{
"commandKind": "bulk",
"name": "npm-publish-ai",
"summary": "Run all npm-publish-ai tasks to publish the ApplicationInsights packages",
"description": "Run all npm-publish-ai tasks to publish the ApplicationInsights packages",
"safeForSimultaneousRushProcesses": true,
"enableParallelism": false,
"ignoreMissingScript": true,
"allowWarningsInSuccessfulBuild": true
},
{
"commandKind": "bulk",
"name": "npm-publish-1ds",
"summary": "Run all npm-publish-1ds tasks to publish the oneDs packages",
"description": "Run all npm-publish-1ds tasks to publish the oneDs packages",
"safeForSimultaneousRushProcesses": true,
"enableParallelism": false,
"ignoreMissingScript": true,
"allowWarningsInSuccessfulBuild": true
},
{
"commandKind": "bulk",
"name": "npm-publish-snippet",
"summary": "Run all npm-publish-snippet tasks to publish the web snippet packages",
"description": "Run all npm-publish-snippet tasks to publish the web snippet packages",
"safeForSimultaneousRushProcesses": true,
"enableParallelism": false,
"ignoreMissingScript": true,
"allowWarningsInSuccessfulBuild": true
},
{
"commandKind": "bulk",
"name": "npm-publish-rollup-es",
"summary": "Run all npm-publish-rollup tasks to publish the rollup-es packages",
"description": "Run all npm-publish-rollup tasks to publish the rollup-es packages",
"safeForSimultaneousRushProcesses": true,
"enableParallelism": false,
"ignoreMissingScript": true,
"allowWarningsInSuccessfulBuild": true
},
{
"commandKind": "bulk",
"name": "npm-publish-shims",
"summary": "Run all npm-publish-shims tasks to publish the shims packages",
"description": "Run all npm-publish-shims tasks to publish the shims packages",
"safeForSimultaneousRushProcesses": true,
"enableParallelism": false,
"ignoreMissingScript": true,
"allowWarningsInSuccessfulBuild": true
}
]
}
3 changes: 1 addition & 2 deletions extensions/applicationinsights-analytics-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt ai-min",
"ai-restore": "grunt ai-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"devDependencies": {
"@microsoft/ai-test-framework": "0.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt clickanalytics-min",
"ai-restore": "grunt clickanalytics-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"devDependencies": {
"@microsoft/ai-test-framework": "0.0.1",
Expand Down
3 changes: 1 addition & 2 deletions extensions/applicationinsights-debugplugin-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt debugplugin-min",
"ai-restore": "grunt debugplugin-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"devDependencies": {
"@microsoft/applicationinsights-rollup-plugin-uglify3-js": "1.0.0",
Expand Down
3 changes: 1 addition & 2 deletions extensions/applicationinsights-dependencies-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt deps-min",
"ai-restore": "grunt deps-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"devDependencies": {
"@nevware21/ts-async": ">= 0.1.0 < 2.x",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt perfmarkmeasure-min",
"ai-restore": "grunt perfmarkmeasure-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"devDependencies": {
"@microsoft/ai-test-framework": "0.0.1",
Expand Down
3 changes: 1 addition & 2 deletions extensions/applicationinsights-properties-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt properties-min",
"ai-restore": "grunt properties-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"devDependencies": {
"@microsoft/ai-test-framework": "0.0.1",
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
"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-ai": "node common/scripts/install-run-rush.js npm-publish-ai --verbose",
"npm-publish-1ds": "node common/scripts/install-run-rush.js npm-publish-1ds --verbose",
"npm-publish-snippet": "node common/scripts/install-run-rush.js npm-publish-snippet --verbose",
"npm-publish-rollup-es": "node common/scripts/install-run-rush.js npm-publish-rollup-es --verbose",
"npm-publish-shims": "node common/scripts/install-run-rush.js npm-publish-shims --verbose"
"npm-publish": "node ./tools/release-tools/npm_publish.js"
},
"repository": {
"type": "git",
Expand Down
3 changes: 1 addition & 2 deletions shared/AppInsightsCommon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt common-min",
"ai-restore": "grunt common-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"devDependencies": {
"@microsoft/ai-test-framework": "0.0.1",
Expand Down
3 changes: 1 addition & 2 deletions shared/AppInsightsCore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"sri": "node ../../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt core-min",
"ai-restore": "grunt core-restore",
"npm-pack": "npm pack",
"npm-publish-ai": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"repository": {
"type": "git",
Expand Down
3 changes: 1 addition & 2 deletions tools/applicationinsights-web-snippet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"rebuild": "npm run build",
"test": "",
"lint": "tslint -p tsconfig.json",
"npm-pack": "npm pack",
"npm-publish-snippet": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"license": "MIT",
"devDependencies": {
Expand Down
73 changes: 50 additions & 23 deletions tools/release-tools/npm_publish.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const fs = require("fs");
const child_process = require("child_process");

let packageRoot;
const packageGroupDef = "./tools/release-tools/package_groups.json";
let packageGroup;
let dryRun = "";

function showHelp() {
Expand All @@ -16,9 +17,9 @@ function showHelp() {
}

console.log("");
console.log(scriptName + " <pkgFolder> ");
console.log(scriptName + " <group> ");
console.log("--------------------------");
console.log(" <pkgFolder> - Identifies the folder containing the package.json and *.tgz");
console.log(" <group> - Identifies the group to publish, identifies folders");
}

function parseArgs() {
Expand All @@ -27,15 +28,18 @@ function parseArgs() {
return false;
}

console.log("cwd: " + process.cwd());

let idx = 2;
while (idx < process.argv.length) {
let theArg = process.argv[idx];
if (!packageRoot) {
packageRoot = theArg;
} else if(theArg === "-test") {
dryRun = "--dry-run";
if (theArg.startsWith("-")) {
if (theArg === "-test") {
dryRun = "--dry-run";
} else {
console.error("!!! Unknown switch [" + theArg + "] detected");
return false;
}
} else if (!packageGroup) {
packageGroup = theArg;
} else {
console.error("!!! Invalid Argument [" + theArg + "] detected");
return false;
Expand All @@ -51,6 +55,10 @@ function removeTrailingComma(text) {
return text.replace(/,(\s*[}\],])/g, "$1");
}

function removeComments(text) {
return text.replace(/^\s*\/\/\s.*$/gm, "");
}

function getNpmPackageName(packageJsonFile) {
var packageText = removeTrailingComma(fs.readFileSync(packageJsonFile, "utf-8"));

Expand All @@ -63,27 +71,46 @@ function getNpmPackageName(packageJsonFile) {
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] || [];
}

if (parseArgs()) {
let packageJsonFile = packageRoot + "/package.json";
var packages = getGroupProjects();

if (!fs.existsSync(packageJsonFile)) {
console.error("!!! Source package.json doesn't exist [" + packageJsonFile + "]");
throw new Error("!!! Source package.json doesn't exist [" + packageJsonFile + "]");
}
console.log(`Publishing [${packageGroup}] packages => ${packages.length}`);
packages.forEach((packageRoot) => {
let packageJsonFile = packageRoot + "/package.json";

let npmPackageName = packageRoot + "/" + getNpmPackageName(packageJsonFile);
if (!fs.existsSync(npmPackageName)) {
console.error("!!! NPM Package not found [" + npmPackageName + "]");
throw new Error("!!! NPM Package not found [" + npmPackageName + "]");
}
if (!fs.existsSync(packageJsonFile)) {
console.error("!!! Source package.json doesn't exist [" + packageJsonFile + "]");
throw new Error("!!! Source package.json doesn't exist [" + packageJsonFile + "]");
}

console.log(`npm pacakage present ${npmPackageName}`);
let npmCmd = `npm publish ${npmPackageName} --access public ${dryRun}`;
console.log(`Running: \"${npmCmd}\"`);
child_process.execSync(npmCmd);
console.log("\n\n##################################################################");
console.log("Publishing - " + getNpmPackageName(packageJsonFile));
console.log("##################################################################");
let npmPackageName = packageRoot + "/" + getNpmPackageName(packageJsonFile);
if (!fs.existsSync(npmPackageName)) {
console.error("!!! NPM Package not found [" + npmPackageName + "]");
throw new Error("!!! NPM Package not found [" + npmPackageName + "]");
}

console.log(`npm pacakage present ${npmPackageName}`);
let npmCmd = `npm publish ${npmPackageName} --access public ${dryRun}`;
console.log(`Running: \"${npmCmd}\"`);
child_process.execSync(npmCmd);
});
} else {
showHelp();
process.exit(1);
Expand Down
31 changes: 31 additions & 0 deletions tools/release-tools/package_groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ------------------------------
// NPM Publish group definitions
// ------------------------------
{
// Application Insights packages
"ai": [
"./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"
],
// Rollup packages
"rollup-es": [
"./tools/rollup-es3"
],
// Shims packages
"shims": [
"./tools/shims/"
],
// Snippet packages
"snippet": [
"./tools/applicationinsights-web-snippet"
]
}
3 changes: 1 addition & 2 deletions tools/rollup-es3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"rebuild": "npm run build",
"test": "grunt rollupes3test --verbose",
"lint": "tslint -p tsconfig.json",
"npm-pack": "npm pack",
"npm-publish-rollup-es": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"repository": {
"type": "git",
Expand Down
3 changes: 1 addition & 2 deletions tools/shims/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"rebuild": "npm run build",
"test": "grunt shimstest",
"lint": "tslint -p tsconfig.json",
"npm-pack": "npm pack",
"npm-publish-shims": "node ../../tools/release-tools/npm_publish.js ."
"npm-pack": "npm pack"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 4361915

Please sign in to comment.