Skip to content

Commit

Permalink
Merge pull request Azure#93 from Azure/daschult/DevScripts
Browse files Browse the repository at this point in the history
Add dev scripts
  • Loading branch information
Dan Schulte authored May 17, 2018
2 parents a6b0691 + ed69923 commit c4dd6f3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
44 changes: 44 additions & 0 deletions .scripts/dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const fs = require("fs");
const path = require("path");

/**
* Get the absolute path to the package.json in this repository.
* @returns {string} The absolute path to the package.json.
*/
function getPackageJsonFilePath() {
return path.resolve(__dirname, "../package.json");
}

/**
* Get the package.json file contents parsed as a JSON object.
* @param {string=} packageJsonFilePath The path to the package.json file to read. If this is not
* provided, then the package.json file at the root of this repository will be used.
* @returns {{}} The parsed package.json file contents.
*/
function getPackageJson(packageJsonFilePath) {
if (!packageJsonFilePath) {
packageJsonFilePath = getPackageJsonFilePath();
}
return JSON.parse(fs.readFileSync(packageJsonFilePath));
}

/**
* Update the package.json property values for "main".
* @param {string} mainValue The value that will be used for "main".
* @returns {void}
*/
function updatePackageJsonMain(mainValue) {
const packageJsonFilePath = getPackageJsonFilePath();

const packageJson = getPackageJson(packageJsonFilePath);

if (packageJson.main == mainValue) {
console.log(`"main" is already set to "${mainValue}" in "${packageJsonFilePath}".`);
} else {
console.log(`Changing "main" to "${mainValue}" in "${packageJsonFilePath}"`)
packageJson.main = mainValue;

fs.writeFileSync(packageJsonFilePath, JSON.stringify(packageJson, undefined, " "));
}
}
exports.updatePackageJsonMain = updatePackageJsonMain;
3 changes: 3 additions & 0 deletions .scripts/latest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const dependencies = require("./dependencies");

dependencies.updatePackageJsonMain("./dist/lib/msRest.js")
3 changes: 3 additions & 0 deletions .scripts/local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const dependencies = require("./dependencies");

dependencies.updatePackageJsonMain("./lib/msRest.ts");
3 changes: 3 additions & 0 deletions .scripts/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const dependencies = require("./dependencies");

dependencies.updatePackageJsonMain("./dist/lib/msRest.js")
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
"test:mocha-chrome": "sleep 0.5 && mocha-chrome http://localhost:3001",
"test:chrome-unit": "run-p -r test:server test:mocha-chrome",
"prepare": "npm run build",
"publish-preview": "npm test && shx rm -rf dist/test && node ./.scripts/publish"
"publish-preview": "npm test && shx rm -rf dist/test && node ./.scripts/publish",
"local": "node ./.scripts/local.js",
"preview": "node ./.scripts/preview.js",
"latest": "node ./.scripts/latest.js"
}
}
}

0 comments on commit c4dd6f3

Please sign in to comment.