Browse Source

handle prerelase identifiers

pull/10098/head
Mehmet Erim 5 years ago
parent
commit
a7d8017d68
  1. 3
      npm/ng-packs/scripts/publish.ts
  2. 34
      npm/package-update-script.js
  3. 3
      npm/package.json
  4. 22
      npm/publish-utils.js
  5. 13
      npm/publish.ps1
  6. 44
      npm/update-gulp.js

3
npm/ng-packs/scripts/publish.ts

@ -11,7 +11,6 @@ program
) )
.option('-r, --registry <registry>', 'target npm server registry') .option('-r, --registry <registry>', 'target npm server registry')
.option('-p, --preview', 'publishes with preview tag') .option('-p, --preview', 'publishes with preview tag')
.option('-r, --rc', 'publishes with next tag')
.option('-g, --skipGit', 'skips git push'); .option('-g, --skipGit', 'skips git push');
program.parse(process.argv); program.parse(process.argv);
@ -51,7 +50,7 @@ program.parse(process.argv);
let tag: string; let tag: string;
if (program.preview) tag = 'preview'; if (program.preview) tag = 'preview';
else if (program.rc || semverParse(program.nextVersion).prerelease?.length) tag = 'next'; else if (semverParse(program.nextVersion).prerelease?.length) tag = 'next';
await execa( await execa(
'yarn', 'yarn',

34
npm/package-update-script.js

@ -1,39 +1,39 @@
const glob = require('glob'); const glob = require("glob");
var path = require('path'); var path = require("path");
const childProcess = require('child_process'); const childProcess = require("child_process");
const { program } = require('commander'); const { program } = require("commander");
program.version('0.0.1'); program.version("0.0.1");
program.option('-r, --rc', 'whether version is rc'); program.option("-r, --prerelase", "whether version is prerelase");
program.option('-rg, --registry <registry>', 'target npm server registry') program.option("-rg, --registry <registry>", "target npm server registry");
program.parse(process.argv); program.parse(process.argv);
const packages = (process.argv[3] || 'abp').split(',').join('|'); const packages = (process.argv[3] || "abp").split(",").join("|");
const check = (pkgJsonPath) => { const check = (pkgJsonPath) => {
try { try {
return childProcess return childProcess
.execSync( .execSync(
`ncu "/^@(${packages}).*$/" --packageFile ${pkgJsonPath} -u${ `ncu "/^@(${packages}).*$/" --packageFile ${pkgJsonPath} -u${
program.rc ? ' --target greatest' : '' program.prerelase ? " --target greatest" : ""
}${program.registry ? ` --registry ${program.registry}` : ''}` }${program.registry ? ` --registry ${program.registry}` : ""}`
) )
.toString(); .toString();
} catch (error) { } catch (error) {
console.log('exec error: ' + error.message); console.log("exec error: " + error.message);
process.exit(error.status); process.exit(error.status);
} }
}; };
const folder = process.argv[2] || '.'; const folder = process.argv[2] || ".";
glob(folder + '/**/package.json', {}, (er, files) => { glob(folder + "/**/package.json", {}, (er, files) => {
files.forEach((file) => { files.forEach((file) => {
if ( if (
file.includes('node_modules') || file.includes("node_modules") ||
file.includes('ng-packs/dist') || file.includes("ng-packs/dist") ||
file.includes('wwwroot') || file.includes("wwwroot") ||
file.includes('bin/Debug') file.includes("bin/Debug")
) { ) {
return; return;
} }

3
npm/package.json

@ -16,6 +16,7 @@
"dependencies": { "dependencies": {
"commander": "^6.0.0", "commander": "^6.0.0",
"execa": "^3.4.0", "execa": "^3.4.0",
"fs-extra": "^8.1.0" "fs-extra": "^8.1.0",
"semver": "^7.3.5"
} }
} }

22
npm/publish-utils.js

@ -1,22 +1,24 @@
const { program } = require('commander'); const { program } = require("commander");
const fse = require('fs-extra'); const fse = require("fs-extra");
const semverParse = require("semver/functions/parse");
program.version('0.0.1'); program.version("0.0.1");
program.option('-n, --nextVersion', 'version in common.props'); program.option("-n, --nextVersion", "version in common.props");
program.option('-r, --rc', 'whether version is rc'); program.option("-pr, --prerelase", "whether version is prerelase");
program.option('-cv, --customVersion <customVersion>', 'set exact version'); program.option("-cv, --customVersion <customVersion>", "set exact version");
program.parse(process.argv); program.parse(process.argv);
if (program.nextVersion) console.log(getVersion()); if (program.nextVersion) console.log(getVersion());
if (program.rc) console.log(getVersion().includes('rc')); if (program.prerelase)
console.log(!!semverParse(getVersion()).prerelease?.length);
function getVersion() { function getVersion() {
if (program.customVersion) return program.customVersion; if (program.customVersion) return program.customVersion;
const commonProps = fse.readFileSync('../common.props').toString(); const commonProps = fse.readFileSync("../common.props").toString();
const versionTag = '<Version>'; const versionTag = "<Version>";
const versionEndTag = '</Version>'; const versionEndTag = "</Version>";
const first = commonProps.indexOf(versionTag) + versionTag.length; const first = commonProps.indexOf(versionTag) + versionTag.length;
const last = commonProps.indexOf(versionEndTag); const last = commonProps.indexOf(versionEndTag);
return commonProps.substring(first, last); return commonProps.substring(first, last);

13
npm/publish.ps1

@ -3,7 +3,7 @@ param(
[string]$Registry [string]$Registry
) )
npm install yarn install
$NextVersion = $(node publish-utils.js --nextVersion) $NextVersion = $(node publish-utils.js --nextVersion)
$RootFolder = (Get-Item -Path "./" -Verbose).FullName $RootFolder = (Get-Item -Path "./" -Verbose).FullName
@ -21,13 +21,12 @@ $PacksPublishCommand = "npm run lerna -- exec 'npm publish --registry $Registry'
$UpdateGulpCommand = "npm run update-gulp" $UpdateGulpCommand = "npm run update-gulp"
$UpdateNgPacksCommand = "yarn update --registry $Registry" $UpdateNgPacksCommand = "yarn update --registry $Registry"
$IsRc = $(node publish-utils.js --rc --customVersion $Version) -eq "true"; $IsPrerelase = $(node publish-utils.js --prerelase --customVersion $Version) -eq "true";
if ($IsRc) { if ($IsPrerelase) {
$NgPacksPublishCommand += " --rc" $UpdateGulpCommand += " -- --prerelase"
$UpdateGulpCommand += " -- --rc"
$PacksPublishCommand = $PacksPublishCommand.Substring(0, $PacksPublishCommand.Length - 1) + " --tag next'" $PacksPublishCommand = $PacksPublishCommand.Substring(0, $PacksPublishCommand.Length - 1) + " --tag next'"
$UpdateNgPacksCommand += " --rc" $UpdateNgPacksCommand += " --prerelase"
} }
$commands = ( $commands = (
@ -36,7 +35,7 @@ $commands = (
$PacksPublishCommand, $PacksPublishCommand,
$UpdateNgPacksCommand, $UpdateNgPacksCommand,
"cd ng-packs\scripts", "cd ng-packs\scripts",
"npm install", "yarn install",
$NgPacksPublishCommand, $NgPacksPublishCommand,
"cd ../../", "cd ../../",
"cd scripts", "cd scripts",

44
npm/update-gulp.js

@ -1,27 +1,27 @@
const glob = require('glob'); const glob = require("glob");
var path = require('path'); var path = require("path");
const childProcess = require('child_process'); const childProcess = require("child_process");
const execa = require('execa'); const execa = require("execa");
const fse = require('fs-extra'); const fse = require("fs-extra");
const { program } = require('commander'); const { program } = require("commander");
program.version('0.0.1'); program.version("0.0.1");
program.option('-r, --rc', 'whether version is rc'); program.option("-pr, --prerelase", "whether version is prerelase");
program.parse(process.argv); program.parse(process.argv);
const gulp = (folderPath) => { const gulp = (folderPath) => {
if ( if (
!fse.existsSync(folderPath + 'gulpfile.js') || !fse.existsSync(folderPath + "gulpfile.js") ||
!glob.sync(folderPath + '*.csproj').length !glob.sync(folderPath + "*.csproj").length
) { ) {
return; return;
} }
try { try {
execa.sync(`yarn`, ['install'], { cwd: folderPath, stdio: 'inherit' }); execa.sync(`yarn`, ["install"], { cwd: folderPath, stdio: "inherit" });
execa.sync(`yarn`, ['gulp'], { cwd: folderPath, stdio: 'inherit' }); execa.sync(`yarn`, ["gulp"], { cwd: folderPath, stdio: "inherit" });
} catch (error) { } catch (error) {
console.log('\x1b[31m', 'Error: ' + error.message); console.log("\x1b[31m", "Error: " + error.message);
} }
}; };
@ -30,30 +30,30 @@ const updatePackages = (pkgJsonPath) => {
const result = childProcess const result = childProcess
.execSync( .execSync(
`ncu "/^@abp.*$/" --packageFile ${pkgJsonPath} -u${ `ncu "/^@abp.*$/" --packageFile ${pkgJsonPath} -u${
program.rc ? ' --target greatest' : '' program.prerelase ? " --target greatest" : ""
}` }`
) )
.toString(); .toString();
console.log('\x1b[0m', result); console.log("\x1b[0m", result);
} catch (error) { } catch (error) {
console.log('\x1b[31m', 'Error: ' + error.message); console.log("\x1b[31m", "Error: " + error.message);
} }
}; };
console.time(); console.time();
glob('../**/package.json', {}, (er, files) => { glob("../**/package.json", {}, (er, files) => {
files = files.filter( files = files.filter(
(f) => (f) =>
f && f &&
!f.includes('node_modules') && !f.includes("node_modules") &&
!f.includes('wwwroot') && !f.includes("wwwroot") &&
!f.includes('bin') && !f.includes("bin") &&
!f.includes('obj') !f.includes("obj")
); );
files.forEach((file) => { files.forEach((file) => {
updatePackages(file); updatePackages(file);
gulp(file.replace('package.json', '')); gulp(file.replace("package.json", ""));
}); });
console.timeEnd(); console.timeEnd();
}); });

Loading…
Cancel
Save