From a7d8017d68fe76662371a4bbc3829f89332a4bf2 Mon Sep 17 00:00:00 2001 From: Mehmet Erim Date: Tue, 21 Sep 2021 21:20:38 +0300 Subject: [PATCH] handle prerelase identifiers --- npm/ng-packs/scripts/publish.ts | 3 +-- npm/package-update-script.js | 34 ++++++++++++------------- npm/package.json | 3 ++- npm/publish-utils.js | 22 +++++++++-------- npm/publish.ps1 | 13 +++++----- npm/update-gulp.js | 44 ++++++++++++++++----------------- 6 files changed, 60 insertions(+), 59 deletions(-) diff --git a/npm/ng-packs/scripts/publish.ts b/npm/ng-packs/scripts/publish.ts index 9ff2057093..ecc0408f2b 100644 --- a/npm/ng-packs/scripts/publish.ts +++ b/npm/ng-packs/scripts/publish.ts @@ -11,7 +11,6 @@ program ) .option('-r, --registry ', 'target npm server registry') .option('-p, --preview', 'publishes with preview tag') - .option('-r, --rc', 'publishes with next tag') .option('-g, --skipGit', 'skips git push'); program.parse(process.argv); @@ -51,7 +50,7 @@ program.parse(process.argv); let tag: string; 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( 'yarn', diff --git a/npm/package-update-script.js b/npm/package-update-script.js index 58e24db554..8ca0180eb1 100644 --- a/npm/package-update-script.js +++ b/npm/package-update-script.js @@ -1,39 +1,39 @@ -const glob = require('glob'); -var path = require('path'); -const childProcess = require('child_process'); -const { program } = require('commander'); +const glob = require("glob"); +var path = require("path"); +const childProcess = require("child_process"); +const { program } = require("commander"); -program.version('0.0.1'); -program.option('-r, --rc', 'whether version is rc'); -program.option('-rg, --registry ', 'target npm server registry') +program.version("0.0.1"); +program.option("-r, --prerelase", "whether version is prerelase"); +program.option("-rg, --registry ", "target npm server registry"); program.parse(process.argv); -const packages = (process.argv[3] || 'abp').split(',').join('|'); +const packages = (process.argv[3] || "abp").split(",").join("|"); const check = (pkgJsonPath) => { try { return childProcess .execSync( `ncu "/^@(${packages}).*$/" --packageFile ${pkgJsonPath} -u${ - program.rc ? ' --target greatest' : '' - }${program.registry ? ` --registry ${program.registry}` : ''}` + program.prerelase ? " --target greatest" : "" + }${program.registry ? ` --registry ${program.registry}` : ""}` ) .toString(); } catch (error) { - console.log('exec error: ' + error.message); + console.log("exec error: " + error.message); 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) => { if ( - file.includes('node_modules') || - file.includes('ng-packs/dist') || - file.includes('wwwroot') || - file.includes('bin/Debug') + file.includes("node_modules") || + file.includes("ng-packs/dist") || + file.includes("wwwroot") || + file.includes("bin/Debug") ) { return; } diff --git a/npm/package.json b/npm/package.json index 724b0f7be1..6de0301e60 100644 --- a/npm/package.json +++ b/npm/package.json @@ -16,6 +16,7 @@ "dependencies": { "commander": "^6.0.0", "execa": "^3.4.0", - "fs-extra": "^8.1.0" + "fs-extra": "^8.1.0", + "semver": "^7.3.5" } } diff --git a/npm/publish-utils.js b/npm/publish-utils.js index 395045c374..ff97d3e6d9 100644 --- a/npm/publish-utils.js +++ b/npm/publish-utils.js @@ -1,22 +1,24 @@ -const { program } = require('commander'); -const fse = require('fs-extra'); +const { program } = require("commander"); +const fse = require("fs-extra"); +const semverParse = require("semver/functions/parse"); -program.version('0.0.1'); -program.option('-n, --nextVersion', 'version in common.props'); -program.option('-r, --rc', 'whether version is rc'); -program.option('-cv, --customVersion ', 'set exact version'); +program.version("0.0.1"); +program.option("-n, --nextVersion", "version in common.props"); +program.option("-pr, --prerelase", "whether version is prerelase"); +program.option("-cv, --customVersion ", "set exact version"); program.parse(process.argv); 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() { if (program.customVersion) return program.customVersion; - const commonProps = fse.readFileSync('../common.props').toString(); - const versionTag = ''; - const versionEndTag = ''; + const commonProps = fse.readFileSync("../common.props").toString(); + const versionTag = ""; + const versionEndTag = ""; const first = commonProps.indexOf(versionTag) + versionTag.length; const last = commonProps.indexOf(versionEndTag); return commonProps.substring(first, last); diff --git a/npm/publish.ps1 b/npm/publish.ps1 index fddd8f2acd..e563fc1fef 100644 --- a/npm/publish.ps1 +++ b/npm/publish.ps1 @@ -3,7 +3,7 @@ param( [string]$Registry ) -npm install +yarn install $NextVersion = $(node publish-utils.js --nextVersion) $RootFolder = (Get-Item -Path "./" -Verbose).FullName @@ -21,13 +21,12 @@ $PacksPublishCommand = "npm run lerna -- exec 'npm publish --registry $Registry' $UpdateGulpCommand = "npm run update-gulp" $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) { - $NgPacksPublishCommand += " --rc" - $UpdateGulpCommand += " -- --rc" +if ($IsPrerelase) { + $UpdateGulpCommand += " -- --prerelase" $PacksPublishCommand = $PacksPublishCommand.Substring(0, $PacksPublishCommand.Length - 1) + " --tag next'" - $UpdateNgPacksCommand += " --rc" + $UpdateNgPacksCommand += " --prerelase" } $commands = ( @@ -36,7 +35,7 @@ $commands = ( $PacksPublishCommand, $UpdateNgPacksCommand, "cd ng-packs\scripts", - "npm install", + "yarn install", $NgPacksPublishCommand, "cd ../../", "cd scripts", diff --git a/npm/update-gulp.js b/npm/update-gulp.js index d6076978eb..d090de4dae 100644 --- a/npm/update-gulp.js +++ b/npm/update-gulp.js @@ -1,27 +1,27 @@ -const glob = require('glob'); -var path = require('path'); -const childProcess = require('child_process'); -const execa = require('execa'); -const fse = require('fs-extra'); -const { program } = require('commander'); +const glob = require("glob"); +var path = require("path"); +const childProcess = require("child_process"); +const execa = require("execa"); +const fse = require("fs-extra"); +const { program } = require("commander"); -program.version('0.0.1'); -program.option('-r, --rc', 'whether version is rc'); +program.version("0.0.1"); +program.option("-pr, --prerelase", "whether version is prerelase"); program.parse(process.argv); const gulp = (folderPath) => { if ( - !fse.existsSync(folderPath + 'gulpfile.js') || - !glob.sync(folderPath + '*.csproj').length + !fse.existsSync(folderPath + "gulpfile.js") || + !glob.sync(folderPath + "*.csproj").length ) { return; } try { - execa.sync(`yarn`, ['install'], { cwd: folderPath, stdio: 'inherit' }); - execa.sync(`yarn`, ['gulp'], { cwd: folderPath, stdio: 'inherit' }); + execa.sync(`yarn`, ["install"], { cwd: folderPath, stdio: "inherit" }); + execa.sync(`yarn`, ["gulp"], { cwd: folderPath, stdio: "inherit" }); } 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 .execSync( `ncu "/^@abp.*$/" --packageFile ${pkgJsonPath} -u${ - program.rc ? ' --target greatest' : '' + program.prerelase ? " --target greatest" : "" }` ) .toString(); - console.log('\x1b[0m', result); + console.log("\x1b[0m", result); } catch (error) { - console.log('\x1b[31m', 'Error: ' + error.message); + console.log("\x1b[31m", "Error: " + error.message); } }; console.time(); -glob('../**/package.json', {}, (er, files) => { +glob("../**/package.json", {}, (er, files) => { files = files.filter( (f) => f && - !f.includes('node_modules') && - !f.includes('wwwroot') && - !f.includes('bin') && - !f.includes('obj') + !f.includes("node_modules") && + !f.includes("wwwroot") && + !f.includes("bin") && + !f.includes("obj") ); files.forEach((file) => { updatePackages(file); - gulp(file.replace('package.json', '')); + gulp(file.replace("package.json", "")); }); console.timeEnd(); });