-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19276 from abpframework/issue-19275
Fix invalid lepton-x package version in all repository after deployment
- Loading branch information
Showing
5 changed files
with
177 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,114 @@ | ||
import glob from "glob"; | ||
import fse from "fs-extra"; | ||
import {program} from "commander"; | ||
import { program } from "commander"; | ||
|
||
(function findPackageJsonFiles() { | ||
setupCommander(); | ||
const options = { | ||
ignore: [ | ||
"../../**/node_modules/**", | ||
"../../**/dist/**", | ||
"../../**/build/**", | ||
"../../**/scripts/**", | ||
"../../**/wwwroot/**" | ||
] | ||
}; | ||
export const semverRegex = | ||
/\d+\.\d+\.\d+(?:-[a-zA-Z0-9]+(?:\.[a-zA-Z0-9-]+)*)?(?:\+[a-zA-Z0-9]+(?:\.[a-zA-Z0-9-]+)*)?$/; | ||
|
||
const workingDir = "../../"; | ||
glob(`${workingDir}**/package.json`, options, (err, files) => { | ||
if (err) throw err; | ||
function setupCommander() { | ||
program | ||
.option("-n, --packageName <packageName>", "Package name") | ||
.option( | ||
"-v, --targetVersion <targetVersion>", | ||
"Version number of the package" | ||
); | ||
|
||
//Todo @masumulu28: check options value and throw error if not provided | ||
const {packageName,targetVersion}= program.opts(); | ||
|
||
for (const file of files) { | ||
readPackageJsonFile(file, packageName, targetVersion); | ||
} | ||
}); | ||
})(); | ||
program.parse(process.argv); | ||
} | ||
|
||
function readPackageJsonFile(path, key, newVersion) { | ||
const replace = (block, key, newVersion) => { | ||
const founded = Object.keys(block).filter(x => x === key); | ||
const founded = Object.keys(block).filter((x) => x === key); | ||
|
||
if (founded.length > 0) { | ||
let value = block[key]; | ||
value = value.replace(semverRegex, newVersion); | ||
return [true, { | ||
...block, | ||
[key]:value | ||
}]; | ||
|
||
return [ | ||
true, | ||
{ | ||
...block, | ||
[key]: value, | ||
}, | ||
]; | ||
} | ||
|
||
return [false, block]; | ||
}; | ||
|
||
fse.readJson(path, (err, packageObj) => { | ||
if (err) throw err; | ||
|
||
const { dependencies, peerDependencies, devDependencies } = packageObj; | ||
const results = []; | ||
|
||
let result = { ...packageObj }; | ||
if (dependencies) { | ||
const [founded, d] = replace(dependencies, key, newVersion); | ||
results.push(founded); | ||
result = { | ||
...result, dependencies: d | ||
}; | ||
} | ||
if (peerDependencies) { | ||
const [founded, p] = replace(peerDependencies, key, newVersion); | ||
results.push(founded); | ||
result = { | ||
...result, peerDependencies: p | ||
}; | ||
} | ||
if (devDependencies) { | ||
const [founded, d] = replace(devDependencies, key, newVersion); | ||
results.push(founded); | ||
result = { | ||
...result, devDependencies: d | ||
}; | ||
} | ||
const anyChanges = !results.some(x => x); | ||
if (anyChanges) { | ||
return; | ||
} | ||
console.log("changed", path); | ||
writeFile(path, result); | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
const { dependencies, peerDependencies, devDependencies } = packageObj; | ||
const results = []; | ||
|
||
let result = { ...packageObj }; | ||
if (dependencies) { | ||
const [founded, d] = replace(dependencies, key, newVersion); | ||
results.push(founded); | ||
result = { | ||
...result, | ||
dependencies: d, | ||
}; | ||
} | ||
|
||
if (peerDependencies) { | ||
const [founded, p] = replace(peerDependencies, key, newVersion); | ||
results.push(founded); | ||
result = { | ||
...result, | ||
peerDependencies: p, | ||
}; | ||
} | ||
) | ||
; | ||
|
||
if (devDependencies) { | ||
const [founded, d] = replace(devDependencies, key, newVersion); | ||
results.push(founded); | ||
result = { | ||
...result, | ||
devDependencies: d, | ||
}; | ||
} | ||
|
||
const anyChanges = !results.some((x) => x); | ||
if (anyChanges) { | ||
return; | ||
} | ||
|
||
console.log("changed", path); | ||
writeFile(path, result); | ||
}); | ||
} | ||
export const semverRegex = | ||
/\d+\.\d+\.\d+(?:-[a-zA-Z0-9]+(?:\.[a-zA-Z0-9-]+)*)?(?:\+[a-zA-Z0-9]+(?:\.[a-zA-Z0-9-]+)*)?$/; | ||
|
||
function writeFile(path, result) { | ||
return fse.writeJson(path, result, { spaces: 2 }); | ||
} | ||
|
||
(function findPackageJsonFiles() { | ||
setupCommander(); | ||
const options = { | ||
ignore: [ | ||
"../../**/node_modules/**", | ||
"../../**/dist/**", | ||
"../../**/build/**", | ||
"../../**/scripts/**", | ||
"../../**/wwwroot/**", | ||
], | ||
}; | ||
|
||
const workingDir = "../../"; | ||
glob(`${workingDir}**/package.json`, options, (err, files) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
function setupCommander() { | ||
program | ||
.option( | ||
"-n, --packageName <packageName>", | ||
"Package name" | ||
) | ||
.option( | ||
"-v, --targetVersion <targetVersion>", | ||
"Version number of the package" | ||
); | ||
//Todo @masumulu28: check options value and throw error if not provided | ||
const { packageName, targetVersion } = program.opts(); | ||
|
||
program.parse(process.argv); | ||
} | ||
for (const file of files) { | ||
readPackageJsonFile(file, packageName, targetVersion); | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { program } from "commander"; | ||
import childProcess from "child_process"; | ||
|
||
/** | ||
* This script is used to update the version of the LeptonX (angular |mvc | blazor) npm packages. | ||
* Depending to **change-package-version.ts** file. (Should we move this to a single script?) | ||
* | ||
* I'm not sure about depending "commander" package. We might need to get options from process.env directly ? | ||
* | ||
* Example | ||
* -Set env | ||
* $env:targetVersion = "1.0.0" | ||
* -Read from nodejs | ||
* process.env.targetVersion | ||
* -Use as argument in commands | ||
* const command = `yarn change-package-version -n ${packageName} -v ${process.env.targetVersion}`; | ||
*/ | ||
|
||
//All lepton-x-lite packages for open source (angular | mvc | blazor) UI frameworks | ||
const LEPTON_X_PACKAGE_NAMES = [ | ||
"@abp/ng.theme.lepton-x", | ||
"@abp/aspnetcore.mvc.ui.theme.leptonxlite", | ||
"@abp/aspnetcore.components.server.leptonxlitetheme", | ||
]; | ||
|
||
function validateVersion(targetVersion) { | ||
if (!targetVersion) { | ||
console.log("\x1b[31m", "Error: lepton-x targetVersion is not defined"); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function initCommander() { | ||
program.option( | ||
"-v, --targetVersion <targetVersion>", | ||
"Version number of the package" | ||
); | ||
|
||
program.parse(process.argv); | ||
} | ||
|
||
(() => { | ||
initCommander(); | ||
|
||
const { targetVersion } = program.opts(); | ||
|
||
validateVersion(targetVersion); | ||
|
||
LEPTON_X_PACKAGE_NAMES.forEach((packageName) => { | ||
const command = `yarn change-package-version -n ${packageName} -v ${targetVersion}`; | ||
const result = childProcess.execSync(command).toString(); | ||
|
||
console.log(result); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters