mirror of https://github.com/abpframework/abp.git
5 changed files with 177 additions and 100 deletions
@ -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); |
|||
} |
|||
}); |
|||
})(); |
|||
|
|||
@ -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 validteVersion(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(); |
|||
|
|||
validteVersion(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); |
|||
}); |
|||
})(); |
|||
Loading…
Reference in new issue