Skip to content

Commit

Permalink
[Cherry Pick] add publish scripts to release3.x branch (#42)
Browse files Browse the repository at this point in the history
* add script

* Quick fix for setVersion.json (#24)

Co-authored-by: siyuniu-ms <[email protected]>

* update

* update

* add git status

---------

Co-authored-by: Nev <[email protected]>
Co-authored-by: siyuniu-ms <[email protected]>
  • Loading branch information
3 people authored Mar 22, 2024
1 parent 03efa53 commit 490cac9
Show file tree
Hide file tree
Showing 9 changed files with 3,857 additions and 3,433 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Update rush shrinkwrap dependencies (for different node versions)
run: node common/scripts/install-run-rush.js update --full
- run: npm install rollup -g
- run: npm install grunt-cli findup-sync nopt [email protected]
- run: npm install
Expand Down
4 changes: 2 additions & 2 deletions applicationinsights-react-native/Tests/UnitTests.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
// Load and define the app insights Shims module
modules.add("@microsoft/applicationinsights-shims", "./node_modules/@microsoft/applicationinsights-shims/browser/applicationinsights-shims");

// Load ts-utils
modules.add("@nevware21/ts-utils", "./node_modules/@nevware21/ts-utils/dist/es5/umd/ts-utils");
// Load ts-utils (ts-utils changed from umd to main)
modules.add("@nevware21/ts-utils", "./node_modules/@nevware21/ts-utils/dist/es5/main/ts-utils");

// Load DynamicProto
modules.add("@microsoft/dynamicproto-js", "./node_modules/@microsoft/dynamicproto-js/lib/dist/umd/dynamicproto-js", true);
Expand Down
6,668 changes: 3,241 additions & 3,427 deletions common/config/rush/npm-shrinkwrap.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"fullClean": "git clean -xdf && npm install && rush update --recheck --full",
"fullCleanBuild": "npm run fullClean && npm run rebuild",
"ai-min": "node common/scripts/install-run-rush.js ai-min",
"ai-restore": "node common/scripts/install-run-rush.js ai-restore"
"ai-restore": "node common/scripts/install-run-rush.js ai-restore",
"gh-status": "node ./tools/status-tools/github-status.js",
"npm-package": "node ./tools/release-tools/npm-package.js"
},
"devDependencies": {
"@microsoft/rush": "^5.97.0",
Expand Down
166 changes: 166 additions & 0 deletions tools/release-tools/npm-package.js
Original file line number Diff line number Diff line change
@@ -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 + " <group> ");
console.log("--------------------------");
console.log(" <group> - Identifies the group to publish, identifies folders, the group must be defined in package_groups.json");
console.log(" <dropFolder> - Identifies the base folder to drop the packages into, defaults to ./drop/packages/<group>");
}

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);
}
9 changes: 9 additions & 0 deletions tools/release-tools/package_groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// ------------------------------
// NPM Publish group definitions
// ------------------------------
{
// DynamicProto packages
"rn": [
"./applicationinsights-react-native"
]
}
4 changes: 2 additions & 2 deletions tools/release-tools/setVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ let buildNum = null;
let preRel = null;
let isRelease = false;
let testOnly = null;
let updateAll = true;
let updateAll = false;
let isReact = false;
let isReactNative = false;
let isReactNative = true;

const theVersion = require(process.cwd() + "/version.json");
const orgPkgVersions = {};
Expand Down
Loading

0 comments on commit 490cac9

Please sign in to comment.