Merge pull request #51 from Azure/daschult/scripts
Various improvements to our script infrastructure
This commit is contained in:
Коммит
25513ded1e
|
@ -1,257 +0,0 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { execSync } = require("child_process");
|
||||
|
||||
/**
|
||||
* Replace all of the instances of searchValue in text with replaceValue.
|
||||
* @param {string} text The text to search and replace in.
|
||||
* @param {string} searchValue The value to search for in text.
|
||||
* @param {string} replaceValue The value to replace searchValue with in text.
|
||||
* @returns {string} The value of text after all of the instances of searchValue have been replaced
|
||||
* by replaceValue.
|
||||
*/
|
||||
function replaceAll(text, searchValue, replaceValue) {
|
||||
return text.split(searchValue).join(replaceValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the provided path by ensuring that all path separators are forward slashes ('/').
|
||||
* @param {string} pathString The path to normalize.
|
||||
* @returns {string} The normalized path.
|
||||
*/
|
||||
function normalizePath(pathString) {
|
||||
return replaceAll(pathString, "\\", "/")
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the file at the provided file path.
|
||||
* @param {string} filePath The path to the file to delete.
|
||||
*/
|
||||
function deleteFile(filePath) {
|
||||
fs.unlinkSync(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the folder at the provided folder path.
|
||||
* @param {string} folderPath The path to the folder to delete.
|
||||
*/
|
||||
function deleteFolder(folderPath) {
|
||||
try {
|
||||
fs.rmdirSync(folderPath);
|
||||
} catch (error) {
|
||||
if (error.code === "ENOTEMPTY") {
|
||||
const folderEntryPaths = fs.readdirSync(folderPath);
|
||||
for (const entryName of folderEntryPaths) {
|
||||
const entryPath = normalizePath(path.resolve(folderPath, entryName));
|
||||
const entryStats = fs.lstatSync(entryPath);
|
||||
if (entryStats.isDirectory()) {
|
||||
deleteFolder(entryPath);
|
||||
} else {
|
||||
deleteFile(entryPath);
|
||||
}
|
||||
}
|
||||
fs.rmdirSync(folderPath);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the provided command on the shell synchronously.
|
||||
* @param {string} command The command to execute.
|
||||
* @param {string} workingDirectory The working directory to execute the command in.
|
||||
* @returns {void}
|
||||
*/
|
||||
function execute(command, workingDirectory) {
|
||||
console.log(`Running "${command}" in "${workingDirectory}"...`);
|
||||
execSync(command, {cwd: workingDirectory, stdio:[0,1,2]});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute path to this repository's folder path.
|
||||
* @returns {string} The absolute path to this repository's folder path.
|
||||
*/
|
||||
function getThisRepositoryFolderPath() {
|
||||
return normalizePath(path.resolve(__dirname, ".."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute path to the package.json in this repository.
|
||||
* @returns {string} The absolute path to the package.json.
|
||||
*/
|
||||
function getPackageJsonFilePath() {
|
||||
return normalizePath(path.resolve(__dirname, "../package.json"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute path to the local clone of the repository with the provided name.
|
||||
* @param {string} repoName The name of the repository.
|
||||
* @returns {string} The absolute path to the local clone of the repository.
|
||||
*/
|
||||
function getLocalRepositoryPath(repoName) {
|
||||
return normalizePath(path.resolve(__dirname, "..", "..", repoName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dependencies from the provided dependencies dictionary that have local clones.
|
||||
* @param {{ [packageName: string]: string }} dependencies A dictionary of package names to package
|
||||
* versions.
|
||||
* @param {string[]} clonedRepositoryNames The array to put the names of the local cloned
|
||||
* repositories into.
|
||||
* @returns {void}
|
||||
*/
|
||||
function getClonedRepositories(dependencies, clonedRepositoryNames) {
|
||||
if (clonedRepositoryNames && dependencies) {
|
||||
for (const dependencyName in dependencies) {
|
||||
if (clonedRepositoryNames.indexOf(dependencyName) === -1) {
|
||||
const repoFolderPath = getLocalRepositoryPath(dependencyName);
|
||||
if (fs.existsSync(repoFolderPath)) {
|
||||
clonedRepositoryNames.push(dependencyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of the dependencies of this repository that have local clones.
|
||||
* @returns {string[]} The names of the dependencies of this repository that have local clones.
|
||||
*/
|
||||
function getDependenciesWithClonedRepositories() {
|
||||
const clonedRepositoryNames = [];
|
||||
|
||||
const packageJson = getPackageJson();
|
||||
|
||||
getClonedRepositories(packageJson.dependencies, clonedRepositoryNames);
|
||||
getClonedRepositories(packageJson.devDependencies, clonedRepositoryNames);
|
||||
|
||||
return clonedRepositoryNames;
|
||||
}
|
||||
exports.getDependenciesWithClonedRepositories = getDependenciesWithClonedRepositories;
|
||||
|
||||
/**
|
||||
* Run a script with the provided name in the local clone of the repository with the provided name.
|
||||
* @param {string} repoName The name of the repository to run the script in.
|
||||
* @param {string} scriptName The name of the script to run in the local repository.
|
||||
* @returns {void}
|
||||
*/
|
||||
function runLocalRepositoryNPMScript(repoName, scriptName) {
|
||||
const repoFolderPath = getLocalRepositoryPath(repoName);
|
||||
const packageJsonFilePath = normalizePath(path.join(repoFolderPath, "package.json"));
|
||||
const packageJson = getPackageJson(packageJsonFilePath);
|
||||
const repoScripts = packageJson.scripts;
|
||||
if (repoScripts && repoScripts[scriptName]) {
|
||||
execute(`npm run ${scriptName}`, repoFolderPath);
|
||||
} else {
|
||||
console.log(`No script named "${scriptName}" is specified in "${packageJsonFilePath}".`);
|
||||
}
|
||||
}
|
||||
exports.runLocalRepositoryNPMScript = runLocalRepositoryNPMScript;
|
||||
|
||||
/**
|
||||
* Update this repository's package.json file's dependency version with the provided name to the
|
||||
* provided version. If the dependency version in the package.json file changes, then "npm install"
|
||||
* will be run for the changed dependency.
|
||||
* @param {string} dependencyName The name of the dependency to update.
|
||||
* @param {string} dependencyVersion The version to update the dependency to.
|
||||
* @returns {boolean} Whether or not the dependency needs to be installed.
|
||||
*/
|
||||
function updatePackageJsonDependency(dependencyName, dependencyVersion) {
|
||||
let dependencyChanged = false;
|
||||
|
||||
const packageJsonFilePath = getPackageJsonFilePath();
|
||||
|
||||
const packageJson = getPackageJson(packageJsonFilePath);
|
||||
if (packageJson.dependencies[dependencyName] == dependencyVersion) {
|
||||
console.log(`"${dependencyName}" is already set to "${dependencyVersion}" in "${packageJsonFilePath}".`);
|
||||
} else {
|
||||
console.log(`Changing "${dependencyName}" to "${dependencyVersion}" in "${packageJsonFilePath}"`)
|
||||
packageJson.dependencies[dependencyName] = dependencyVersion;
|
||||
|
||||
writePackageJson(packageJson, packageJsonFilePath);
|
||||
|
||||
dependencyChanged = true;
|
||||
}
|
||||
|
||||
return dependencyChanged;
|
||||
}
|
||||
exports.updatePackageJsonDependency = updatePackageJsonDependency;
|
||||
|
||||
/**
|
||||
* Run NPM install in this repository
|
||||
* @returns {void}
|
||||
*/
|
||||
function refreshNodeModules() {
|
||||
const thisRepositoryFolderPath = getThisRepositoryFolderPath();
|
||||
const nodeModulesFolderPath = normalizePath(path.resolve(thisRepositoryFolderPath, "node_modules"));
|
||||
if (fs.existsSync(nodeModulesFolderPath)) {
|
||||
|
||||
const packageLockFilePath = normalizePath(path.resolve(thisRepositoryFolderPath, "package-lock.json"));
|
||||
if (fs.existsSync(packageLockFilePath)) {
|
||||
console.log(`Deleting "${packageLockFilePath}"...`);
|
||||
deleteFile(packageLockFilePath);
|
||||
}
|
||||
|
||||
console.log(`Deleting "${nodeModulesFolderPath}"...`);
|
||||
deleteFolder(nodeModulesFolderPath);
|
||||
}
|
||||
execute(`npm install`, getThisRepositoryFolderPath());
|
||||
}
|
||||
exports.refreshNodeModules = refreshNodeModules;
|
||||
|
||||
/**
|
||||
* Get the npm package version of the package with the provided name at the provided tag.
|
||||
* @param {string} packageName The name of the package.
|
||||
* @param {string} tag The tag of the version to retrieve.
|
||||
* @returns {string?} The version of the provided package at the provided tag.
|
||||
*/
|
||||
function getNpmPackageVersion(packageName, tag) {
|
||||
const npmViewResult = JSON.parse(execSync(`npm view ${packageName} --json`, { stdio: ['pipe', 'pipe', 'ignore'] }));
|
||||
return npmViewResult['dist-tags'][tag];
|
||||
}
|
||||
exports.getNpmPackageVersion = getNpmPackageVersion;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
writePackageJson(packageJson, packageJsonFilePath);
|
||||
}
|
||||
}
|
||||
exports.updatePackageJsonMain = updatePackageJsonMain;
|
||||
|
||||
/**
|
||||
* Write the provided packageJSON object to the file at the provided packageJsonFilePath.
|
||||
* @param {any} packageJson The package json object to write.
|
||||
* @param {string} packageJsonFilePath The path to the package.json file.
|
||||
* @returns {void}
|
||||
*/
|
||||
function writePackageJson(packageJson, packageJsonFilePath) {
|
||||
fs.writeFileSync(packageJsonFilePath, JSON.stringify(packageJson, undefined, " ") + "\n");
|
||||
}
|
|
@ -0,0 +1,357 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import { execSync } from "child_process";
|
||||
|
||||
export interface PackageFolder {
|
||||
folderPath: string;
|
||||
extraFilePaths?: string[];
|
||||
}
|
||||
|
||||
function log(filePath: string, message: string): void {
|
||||
console.log(`[${filePath}] - ${message}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether or not the node_modules folder should be refreshed based on the command line
|
||||
* arguments.
|
||||
* @param argv The command line arguments that were provided.
|
||||
* @returns Whether or not the node_modules folder should be refreshed.
|
||||
*/
|
||||
export function shouldForceRefresh(argv: string[]): boolean {
|
||||
let result = false;
|
||||
if (argv) {
|
||||
for (const arg of argv) {
|
||||
const argLower: string = arg && arg.toLocaleLowerCase();
|
||||
if (argLower === "-f" || argLower === "-force" || argLower === "--force") {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function resolvePath(...paths: string[]): string {
|
||||
return path.resolve(...paths).split("\\").join("/");
|
||||
}
|
||||
|
||||
function exists(path: string): boolean {
|
||||
return fs.existsSync(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the file at the provided file path.
|
||||
* @param {string} filePath The path to the file to delete.
|
||||
*/
|
||||
function deleteFile(filePath: string): void {
|
||||
fs.unlinkSync(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the folder at the provided folder path.
|
||||
* @param {string} folderPath The path to the folder to delete.
|
||||
*/
|
||||
function deleteFolder(folderPath: string): void {
|
||||
try {
|
||||
fs.rmdirSync(folderPath);
|
||||
} catch (error) {
|
||||
if (error.code === "ENOTEMPTY") {
|
||||
const folderEntryPaths: string[] = fs.readdirSync(folderPath);
|
||||
for (const entryName of folderEntryPaths) {
|
||||
const entryPath: string = resolvePath(folderPath, entryName);
|
||||
const entryStats: fs.Stats = fs.lstatSync(entryPath);
|
||||
if (entryStats.isDirectory()) {
|
||||
deleteFolder(entryPath);
|
||||
} else {
|
||||
deleteFile(entryPath);
|
||||
}
|
||||
}
|
||||
fs.rmdirSync(folderPath);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the contents of text file at the provided filePath.
|
||||
* @param {string} filePath The path to the text file to read.
|
||||
* @returns {string} The text contents of the text file at the provided filePath.
|
||||
*/
|
||||
function readTextFileContents(filePath: string): string {
|
||||
return fs.readFileSync(filePath, { encoding: "utf8" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the provided command on the shell synchronously.
|
||||
* @param {string} command The command to execute.
|
||||
* @param {string} workingDirectory The working directory to execute the command in.
|
||||
* @returns {void}
|
||||
*/
|
||||
function execute(command: string, workingDirectory: string): void {
|
||||
log(workingDirectory, `Running "${command}"...`);
|
||||
execSync(command, { cwd: workingDirectory, stdio: [0, 1, 2] });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute path to this repository's folder path.
|
||||
* @returns {string} The absolute path to this repository's folder path.
|
||||
*/
|
||||
export function getThisRepositoryFolderPath(): string {
|
||||
return resolvePath(__dirname, "..");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute path to the package.json in this repository.
|
||||
* @returns {string} The absolute path to the package.json.
|
||||
*/
|
||||
function getPackageJsonFilePath(packageFolder?: string): string {
|
||||
return resolvePath(packageFolder, "package.json");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute path to the local clone of the repository with the provided name.
|
||||
* @param {string} repoName The name of the repository.
|
||||
* @returns {string} The absolute path to the local clone of the repository.
|
||||
*/
|
||||
export function getLocalRepositoryPath(repoName: string): string {
|
||||
return resolvePath(getThisRepositoryFolderPath(), "..", repoName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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: string): any {
|
||||
return JSON.parse(readTextFileContents(packageJsonFilePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dependencies from the provided dependencies dictionary that have local clones.
|
||||
* @param {{ [packageName: string]: string }} dependencies A dictionary of package names to package
|
||||
* versions.
|
||||
* @param {string[]} clonedRepositoryNames The array to put the names of the local cloned
|
||||
* repositories into.
|
||||
* @returns {void}
|
||||
*/
|
||||
function getClonedRepositories(dependencies?: { [packageName: string]: string }): string[] {
|
||||
const clonedRepositoryNames: string[] = [];
|
||||
if (dependencies) {
|
||||
for (const dependencyName in dependencies) {
|
||||
if (clonedRepositoryNames.indexOf(dependencyName) === -1) {
|
||||
const repoFolderPath = getLocalRepositoryPath(dependencyName);
|
||||
if (exists(repoFolderPath)) {
|
||||
clonedRepositoryNames.push(dependencyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return clonedRepositoryNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a script with the provided name in the local clone of the repository with the provided name.
|
||||
* @param {string} repoName The name of the repository to run the script in.
|
||||
* @param {string} scriptName The name of the script to run in the local repository.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function runLocalRepositoryNPMScript(repoName: string, scriptName: string): void {
|
||||
const repoFolderPath: string = getLocalRepositoryPath(repoName);
|
||||
const packageJsonFilePath: string = getPackageJsonFilePath(repoFolderPath);
|
||||
const packageJson: any = getPackageJson(packageJsonFilePath);
|
||||
const repoScripts: any = packageJson.scripts;
|
||||
if (repoScripts && repoScripts[scriptName]) {
|
||||
execute(`npm run ${scriptName}`, repoFolderPath);
|
||||
} else {
|
||||
log(packageJsonFilePath, `No script named "${scriptName}" is defined.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the npm package version of the package with the provided name at the provided tag.
|
||||
* @param {string} packageName The name of the package.
|
||||
* @param {string} tag The tag of the version to retrieve.
|
||||
* @returns {string?} The version of the provided package at the provided tag.
|
||||
*/
|
||||
export function getNpmPackageVersion(packageName: string, tag: string): string | undefined {
|
||||
const npmViewResult: any = JSON.parse(execSync(`npm view ${packageName} --json`, { stdio: ["pipe", "pipe", "ignore"] }).toString());
|
||||
return npmViewResult["dist-tags"][tag];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the package.json property values for "main".
|
||||
* @param {string} mainValue The value that will be used for "main".
|
||||
* @returns {void}
|
||||
*/
|
||||
export function updatePackageJsonMain(packageFolderPath: string, mainValue: string): void {
|
||||
const packageJsonFilePath: string = getPackageJsonFilePath(packageFolderPath);
|
||||
|
||||
const packageJson: any = getPackageJson(packageJsonFilePath);
|
||||
|
||||
if (packageJson.main === mainValue) {
|
||||
log(packageJsonFilePath, `"main" is already set to "${mainValue}".`);
|
||||
} else {
|
||||
log(packageJsonFilePath, `Changing "main" to "${mainValue}".`);
|
||||
packageJson.main = mainValue;
|
||||
|
||||
writePackageJson(packageJson, packageJsonFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the dependency versions in the files at the provided codeFilePaths.
|
||||
* @param {string[]} codeFilePath The paths to the code files that should be updated.
|
||||
* @param {string} dependencyName The name of the dependency to update.
|
||||
* @param {RegExp} regularExpression The regular expression to use to find the dependency name and
|
||||
* version in the code file's contents.
|
||||
* @param {string} newValue The replacement string that will replace the text that matches the
|
||||
* provided regularExpression.
|
||||
* @param {string} newDependencyVersion The version of the dependency to set in the provided code
|
||||
* files.
|
||||
*/
|
||||
function updateGeneratedPackageDependencyVersion(codeFilePath: string, dependencyName: string, newDependencyVersion: string): boolean {
|
||||
let fileChanged = false;
|
||||
codeFilePath = resolvePath(codeFilePath);
|
||||
if (exists(codeFilePath)) {
|
||||
const originalCodeFileContents: string = readTextFileContents(codeFilePath);
|
||||
let codeFileContents: string = originalCodeFileContents;
|
||||
|
||||
codeFileContents = regularExpressionReplace(
|
||||
codeFilePath,
|
||||
codeFileContents,
|
||||
dependencyName,
|
||||
new RegExp(`\\\\"${dependencyName}\\\\": \\\\"(.*)\\\\"`),
|
||||
`\\"${dependencyName}\\": \\"${newDependencyVersion}\\"`,
|
||||
newDependencyVersion);
|
||||
|
||||
codeFileContents = regularExpressionReplace(
|
||||
codeFilePath,
|
||||
codeFileContents,
|
||||
dependencyName,
|
||||
new RegExp(`"${dependencyName}": "(.*)"`),
|
||||
`"${dependencyName}": "${newDependencyVersion}"`,
|
||||
newDependencyVersion);
|
||||
|
||||
if (codeFileContents !== originalCodeFileContents) {
|
||||
fileChanged = true;
|
||||
fs.writeFileSync(codeFilePath, codeFileContents);
|
||||
}
|
||||
}
|
||||
return fileChanged;
|
||||
}
|
||||
|
||||
function regularExpressionReplace(filePath: string, fileContents: string, dependencyName: string, regularExpression: RegExp, newValue: string, newDependencyVersion: string): string {
|
||||
let newFileContents: string = fileContents;
|
||||
const match: RegExpMatchArray = fileContents.match(regularExpression);
|
||||
if (match) {
|
||||
if (match[1] === newDependencyVersion) {
|
||||
log(filePath, `"${dependencyName}" is already set to "${newDependencyVersion}".`);
|
||||
} else {
|
||||
log(filePath, `Changing "${dependencyName}" version from "${match[1]}" to "${newDependencyVersion}".`);
|
||||
newFileContents = fileContents.replace(regularExpression, newValue);
|
||||
}
|
||||
}
|
||||
return newFileContents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the provided packageJSON object to the file at the provided packageJsonFilePath.
|
||||
* @param {any} packageJson The package json object to write.
|
||||
* @param {string} packageJsonFilePath The path to the package.json file.
|
||||
* @returns {void}
|
||||
*/
|
||||
function writePackageJson(packageJson: any, packageJsonFilePath: string): void {
|
||||
fs.writeFileSync(packageJsonFilePath, JSON.stringify(packageJson, undefined, " ") + "\n");
|
||||
}
|
||||
|
||||
export function updateLocalDependencies(packageFolders: PackageFolder[], localDependencyNPMScript: string, getNewDependencyVersion: (dependencyName: string) => string): void {
|
||||
const forceRefresh: boolean = shouldForceRefresh(process.argv);
|
||||
|
||||
for (const packageFolder of packageFolders) {
|
||||
const packageFolderPath: string = packageFolder.folderPath;
|
||||
|
||||
let refreshPackageFolder: boolean = forceRefresh;
|
||||
|
||||
const packageJson: any = getPackageJson(resolvePath(packageFolderPath, "package.json"));
|
||||
|
||||
const localDependencies: string[] = getClonedRepositories(packageJson.dependencies);
|
||||
const localDevDependencies: string[] = getClonedRepositories(packageJson.devDependencies);
|
||||
|
||||
const allLocalDependencies: string[] = localDependencies.concat(localDevDependencies);
|
||||
|
||||
for (const localDependency of allLocalDependencies) {
|
||||
runLocalRepositoryNPMScript(localDependency, localDependencyNPMScript);
|
||||
}
|
||||
|
||||
for (const localDependency of allLocalDependencies) {
|
||||
if (updateLocalDependency(packageFolder, localDependency, getNewDependencyVersion)) {
|
||||
refreshPackageFolder = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (refreshPackageFolder) {
|
||||
const packageLockFilePath = resolvePath(packageFolderPath, "package-lock.json");
|
||||
if (exists(packageLockFilePath)) {
|
||||
log(packageLockFilePath, `Deleting...`);
|
||||
deleteFile(packageLockFilePath);
|
||||
}
|
||||
|
||||
const nodeModulesFolderPath = resolvePath(packageFolderPath, "node_modules");
|
||||
if (exists(nodeModulesFolderPath)) {
|
||||
log(nodeModulesFolderPath, `Deleting...`);
|
||||
deleteFolder(nodeModulesFolderPath);
|
||||
}
|
||||
|
||||
execute("npm install", packageFolderPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateLocalDependency(packageFolder: PackageFolder, dependencyName: string, getNewDependencyVersion: (dependencyName: string) => string): boolean {
|
||||
const newDependencyVersion: string = getNewDependencyVersion(dependencyName);
|
||||
|
||||
const packageFolderPath: string = packageFolder.folderPath;
|
||||
|
||||
const localDependencyUpdated = updateGeneratedPackageDependencyVersion(
|
||||
resolvePath(packageFolderPath, "package.json"),
|
||||
dependencyName,
|
||||
newDependencyVersion);
|
||||
|
||||
updateGeneratedPackageDependencyVersion(
|
||||
resolvePath(packageFolderPath, "README.md"),
|
||||
dependencyName,
|
||||
newDependencyVersion);
|
||||
|
||||
if (packageFolder.extraFilePaths) {
|
||||
for (const extraFilePath of packageFolder.extraFilePaths) {
|
||||
updateGeneratedPackageDependencyVersion(
|
||||
resolvePath(packageFolderPath, extraFilePath),
|
||||
dependencyName,
|
||||
newDependencyVersion);
|
||||
}
|
||||
}
|
||||
|
||||
return localDependencyUpdated;
|
||||
}
|
||||
|
||||
export function getLocalDependencyVersion(dependencyName: string): string {
|
||||
return `file:${getLocalRepositoryPath(dependencyName)}`;
|
||||
}
|
||||
|
||||
export function getPreviewDependencyVersion(dependencyName: string): string {
|
||||
let version: string = addTildePrefix(getNpmPackageVersion(dependencyName, "preview"));
|
||||
if (!version) {
|
||||
version = getLatestDependencyVersion(dependencyName);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
export function getLatestDependencyVersion(dependencyName: string): string {
|
||||
return addTildePrefix(getNpmPackageVersion(dependencyName, "latest"));
|
||||
}
|
||||
|
||||
function addTildePrefix(version: string): string {
|
||||
return version ? `~${version}` : version;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
const dependencies = require("./dependencies");
|
||||
|
||||
const localDependencies = dependencies.getDependenciesWithClonedRepositories();
|
||||
for (const localDependency of localDependencies) {
|
||||
dependencies.runLocalRepositoryNPMScript(localDependency, "latest");
|
||||
}
|
||||
let refreshNodeModules = false;
|
||||
for (const localDependency of localDependencies) {
|
||||
const version = dependencies.getNpmPackageVersion(localDependency, "latest");
|
||||
if (dependencies.updatePackageJsonDependency(localDependency, `~${version}`)) {
|
||||
refreshNodeModules = true;
|
||||
}
|
||||
}
|
||||
if (refreshNodeModules) {
|
||||
dependencies.refreshNodeModules();
|
||||
}
|
||||
dependencies.updatePackageJsonMain("./dist/lib/msRestAzure.js");
|
|
@ -0,0 +1,5 @@
|
|||
import * as dependencies from "./dependencies";
|
||||
import * as repository from "./repository";
|
||||
|
||||
dependencies.updatePackageJsonMain(dependencies.getThisRepositoryFolderPath(), "./dist/lib/msRestAzure.js");
|
||||
dependencies.updateLocalDependencies(repository.packageFolders, "latest", dependencies.getLatestDependencyVersion);
|
|
@ -1,16 +0,0 @@
|
|||
const dependencies = require("./dependencies");
|
||||
|
||||
const localDependencies = dependencies.getDependenciesWithClonedRepositories();
|
||||
for (const localDependency of localDependencies) {
|
||||
dependencies.runLocalRepositoryNPMScript(localDependency, "local");
|
||||
}
|
||||
let refreshNodeModules = false;
|
||||
for (const localDependency of localDependencies) {
|
||||
if (dependencies.updatePackageJsonDependency(localDependency, `file:../${localDependency}`)) {
|
||||
refreshNodeModules = true;
|
||||
}
|
||||
}
|
||||
if (refreshNodeModules) {
|
||||
dependencies.refreshNodeModules();
|
||||
}
|
||||
dependencies.updatePackageJsonMain("./lib/msRestAzure.ts");
|
|
@ -0,0 +1,5 @@
|
|||
import * as dependencies from "./dependencies";
|
||||
import * as repository from "./repository";
|
||||
|
||||
dependencies.updatePackageJsonMain(dependencies.getThisRepositoryFolderPath(), "./lib/msRestAzure.ts");
|
||||
dependencies.updateLocalDependencies(repository.packageFolders, "local", dependencies.getLocalDependencyVersion);
|
|
@ -1,20 +0,0 @@
|
|||
const dependencies = require("./dependencies");
|
||||
|
||||
const localDependencies = dependencies.getDependenciesWithClonedRepositories();
|
||||
for (const localDependency of localDependencies) {
|
||||
dependencies.runLocalRepositoryNPMScript(localDependency, "preview");
|
||||
}
|
||||
let refreshNodeModules = false;
|
||||
for (const localDependency of localDependencies) {
|
||||
let version = dependencies.getNpmPackageVersion(localDependency, "preview");
|
||||
if (!version) {
|
||||
version = dependencies.getNpmPackageVersion(localDependency, "latest");
|
||||
}
|
||||
if (dependencies.updatePackageJsonDependency(localDependency, `~${version}`)) {
|
||||
refreshNodeModules = true;
|
||||
}
|
||||
}
|
||||
if (refreshNodeModules) {
|
||||
dependencies.refreshNodeModules();
|
||||
}
|
||||
dependencies.updatePackageJsonMain("./dist/lib/msRestAzure.js");
|
|
@ -0,0 +1,5 @@
|
|||
import * as dependencies from "./dependencies";
|
||||
import * as repository from "./repository";
|
||||
|
||||
dependencies.updatePackageJsonMain(dependencies.getThisRepositoryFolderPath(), "./dist/lib/msRestAzure.js");
|
||||
dependencies.updateLocalDependencies(repository.packageFolders, "preview", dependencies.getPreviewDependencyVersion);
|
|
@ -0,0 +1,7 @@
|
|||
import * as dependencies from "./dependencies";
|
||||
|
||||
export const packageFolders: dependencies.PackageFolder[] = [
|
||||
{
|
||||
folderPath: dependencies.getThisRepositoryFolderPath()
|
||||
}
|
||||
];
|
|
@ -240,15 +240,15 @@
|
|||
}
|
||||
},
|
||||
"ajv": {
|
||||
"version": "6.5.2",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.2.tgz",
|
||||
"integrity": "sha512-hOs7GfvI6tUI1LfZddH82ky6mOMyTuY0mk7kE2pWpmhhUSkumzaTO5vbVwij39MdwPQWCV4Zv57Eo06NtL/GVA==",
|
||||
"version": "6.5.3",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.3.tgz",
|
||||
"integrity": "sha512-LqZ9wY+fx3UMiiPd741yB2pj3hhil+hQc8taf4o2QGRFpWgZ2V5C8HA165DY9sS3fJwsk7uT7ZlFEyC3Ig3lLg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fast-deep-equal": "^2.0.1",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
"json-schema-traverse": "^0.4.1",
|
||||
"uri-js": "^4.2.1"
|
||||
"uri-js": "^4.2.2"
|
||||
}
|
||||
},
|
||||
"ajv-keywords": {
|
||||
|
@ -414,9 +414,9 @@
|
|||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
},
|
||||
"atob": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.1.tgz",
|
||||
"integrity": "sha1-ri1acpR38onWDdf5amMUoi3Wwio=",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
|
||||
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==",
|
||||
"dev": true
|
||||
},
|
||||
"axios": {
|
||||
|
@ -1558,9 +1558,9 @@
|
|||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.5.5",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.5.tgz",
|
||||
"integrity": "sha512-GHjtHDlY/ehslqv0Gr5N0PUJppgg/q0rOBvX0na1s7y1A3LWxPqCYU76s3Z1bM4+UZB4QF0usaXLT5wFpof5PA==",
|
||||
"version": "1.5.6",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.6.tgz",
|
||||
"integrity": "sha512-xay/eYZGgdpb3rpugZj1HunNaPcqc6fud/RW7LNEQntvKzuRO4DDLL+MnJIbTHh6t3Kda3v2RvhY2doxUddnig==",
|
||||
"requires": {
|
||||
"debug": "^3.1.0"
|
||||
}
|
||||
|
@ -2917,9 +2917,9 @@
|
|||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"ms-rest-js": {
|
||||
"version": "0.19.379",
|
||||
"resolved": "https://registry.npmjs.org/ms-rest-js/-/ms-rest-js-0.19.379.tgz",
|
||||
"integrity": "sha512-/bPhVON6gbEuoQwLA8v0GC5cC6fztYHDv3KsEyCr32p26ORaqKJUwro1DjhdI/rhaab3U09R7IbUskt3oI7s7Q==",
|
||||
"version": "0.19.380",
|
||||
"resolved": "https://registry.npmjs.org/ms-rest-js/-/ms-rest-js-0.19.380.tgz",
|
||||
"integrity": "sha512-ZIfAor6B7rD7XV1cqy1e/CTEIyQYXuCoUJ54YulPReoUWYMDdfuUqoBSZL5vjx2AYbO7Al1l1NDvZUWidlpQ+A==",
|
||||
"requires": {
|
||||
"@types/express": "^4.11.1",
|
||||
"@types/form-data": "^2.2.1",
|
||||
|
@ -5554,9 +5554,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"repeat-element": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.2.tgz",
|
||||
"integrity": "sha1-7wiaF40Ug7quTZPrmLT55OEdmQo=",
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.3.tgz",
|
||||
"integrity": "sha512-ahGq0ZnV5m5XtZLMb+vP76kcAM5nkLqk0lpqAuojSKGgQtn4eRi4ZZGm2olo2zKFH+sMsWaqOCW1dqAnOru72g==",
|
||||
"dev": true
|
||||
},
|
||||
"repeat-string": {
|
||||
|
@ -5638,9 +5638,9 @@
|
|||
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
|
||||
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==",
|
||||
"version": "5.5.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz",
|
||||
"integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==",
|
||||
"dev": true
|
||||
},
|
||||
"set-blocking": {
|
||||
|
@ -5929,9 +5929,9 @@
|
|||
}
|
||||
},
|
||||
"source-map-support": {
|
||||
"version": "0.5.8",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.8.tgz",
|
||||
"integrity": "sha512-WqAEWPdb78u25RfKzOF0swBpY0dKrNdjc4GvLwm7ScX/o9bj8Eh/YL8mcMhBHYDGl87UkkSXDOFnW4G7GhWhGg==",
|
||||
"version": "0.5.9",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.9.tgz",
|
||||
"integrity": "sha512-gR6Rw4MvUlYy83vP0vxoVNzM6t8MUXqNuRsuBmBHQDu1Fh6X015FrLdgoDKcNdkwGubozq0P4N0Q37UyFVr1EA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"buffer-from": "^1.0.0",
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
"types": "./typings/lib/msRestAzure.d.ts",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms-rest-js": "~0.19.379",
|
||||
"ms-rest-js": "~0.19.380",
|
||||
"tslib": "^1.9.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -85,9 +85,9 @@
|
|||
"test:tslint": "tslint -p . -c tslint.json --exclude test/**/*.ts",
|
||||
"prepare": "npm run build",
|
||||
"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"
|
||||
"local": "ts-node ./.scripts/local.ts",
|
||||
"preview": "ts-node ./.scripts/preview.ts",
|
||||
"latest": "ts-node ./.scripts/latest.ts"
|
||||
},
|
||||
"sideEffects": false
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче