"Fossies" - the Fresh Open Source Software Archive

Member "angular-cli-8.3.23/scripts/release.ts" (15 Jan 2020, 4529 Bytes) of package /linux/www/angular-cli-8.3.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /**
    2  * @license
    3  * Copyright Google Inc. All Rights Reserved.
    4  *
    5  * Use of this source code is governed by an MIT-style license that can be
    6  * found in the LICENSE file at https://angular.io/license
    7  */
    8 // tslint:disable:no-implicit-dependencies
    9 import { logging } from '@angular-devkit/core';
   10 import * as fs from 'fs';
   11 import * as path from 'path';
   12 import * as semver from 'semver';
   13 import { packages } from '../lib/packages';
   14 
   15 
   16 const monorepo = require('../.monorepo.json');
   17 
   18 
   19 function _showVersions(logger: logging.Logger) {
   20   const versions = Object.keys(packages).reduce((acc, curr) => {
   21     acc[curr] = packages[curr] && packages[curr].version || '???';
   22 
   23     return acc;
   24   }, {} as { [pkg: string]: string });
   25   const maxVersionLength = Math.max(...Object.keys(versions).map(x => versions[x].length));
   26 
   27   for (const pkgName of Object.keys(packages)) {
   28     const pkg = packages[pkgName];
   29 
   30     const version = pkg.version || '???';
   31 
   32     const pad1 = '                                       '.slice(pkgName.length);
   33     const message = `${pkgName} ${pad1}${('      ' + version).slice(-maxVersionLength)}`;
   34     if (pkg.private) {
   35       logger.debug(message);
   36     } else {
   37       logger.info(message);
   38     }
   39   }
   40 }
   41 
   42 
   43 function _upgradeSingle(release: string, version: string): string {
   44   const simpleVersion = version.replace(/-beta\.\d+$|-rc\.\d+$/, '');
   45   const isExperimental = semver.satisfies(simpleVersion, '<1.0.0');
   46 
   47   if (release == 'minor-beta') {
   48     if (version.match(/-beta\.\d+$/)) {
   49       return semver.inc(version, 'prerelease') || version;
   50     } else {
   51       return semver.inc(version, 'minor') ? semver.inc(version, 'minor') + '-beta.0' : version;
   52     }
   53   } else if (release == 'minor-rc') {
   54     if (version.match(/-rc/)) {
   55       return semver.inc(version, 'prerelease') || version;
   56     } else if (version.match(/-beta\.\d+$/)) {
   57       return version.replace(/-beta\.\d+$/, '-rc.0');
   58     } else {
   59       return semver.inc(version, 'minor') ? semver.inc(version, 'minor') + '-rc.0' : version;
   60     }
   61   } else if (release == 'major-beta') {
   62     if (version.match(/-beta\.\d+$/)) {
   63       return semver.inc(version, 'prerelease') || version;
   64     } else if (isExperimental) {
   65       return semver.inc(version, 'minor') ? semver.inc(version, 'minor') + '-beta.0' : version;
   66     } else {
   67       return semver.inc(version, 'major') ? semver.inc(version, 'major') + '-beta.0' : version;
   68     }
   69   } else if (release == 'major-rc') {
   70     if (version.match(/-rc/)) {
   71       return semver.inc(version, 'prerelease') || version;
   72     } else if (version.match(/-beta\.\d+$/)) {
   73       return version.replace(/-beta\.\d+$/, '-rc.0');
   74     } else if (isExperimental) {
   75       return semver.inc(version, 'minor') ? semver.inc(version, 'minor') + '-rc.0' : version;
   76     } else {
   77       return semver.inc(version, 'major') ? semver.inc(version, 'major') + '-rc.0' : version;
   78     }
   79   } else if (release == 'major' && isExperimental) {
   80     return semver.inc(version, 'minor') || version;
   81   } else {
   82     return semver.inc(version, release as semver.ReleaseType) || version;
   83   }
   84 }
   85 
   86 function _upgrade(release: string, logger: logging.Logger) {
   87   // Update stable.
   88   const stable = monorepo.versions.stable;
   89   const experimental = monorepo.versions.experimental;
   90   if (!stable) {
   91     throw new Error('Should have a version.stable key.');
   92   }
   93   if (!experimental) {
   94     throw new Error('Should have a version.experimental key.');
   95   }
   96   const newStable = _upgradeSingle(release, stable);
   97   const newExperimental = _upgradeSingle(release, experimental);
   98   monorepo.versions = {
   99     stable: newStable,
  100     experimental: newExperimental,
  101   };
  102 
  103   logger.info(`Updated versions:`);
  104   logger.info(`     stable:       ${stable} => ${newStable}`);
  105   logger.info(`     experimental: ${experimental} => ${newExperimental}`);
  106 }
  107 
  108 
  109 export interface ReleaseOptions {
  110   _: string[];
  111   'dry-run'?: boolean;
  112 }
  113 
  114 export default function(args: ReleaseOptions, logger: logging.Logger) {
  115   const maybeRelease = args._.shift();
  116   const dryRun = args['dry-run'] !== undefined;
  117   switch (maybeRelease) {
  118     case undefined:
  119       _showVersions(logger);
  120       process.exit(0);
  121       break;
  122 
  123     case 'major-beta':
  124     case 'major-rc':
  125     case 'minor-beta':
  126     case 'minor-rc':
  127     case 'major':
  128     case 'minor':
  129     case 'patch':
  130       _upgrade(maybeRelease, logger);
  131       if (!dryRun) {
  132         fs.writeFileSync(path.join(__dirname, '../.monorepo.json'),
  133                          JSON.stringify(monorepo, null, 2) + '\n');
  134       }
  135       process.exit(0);
  136       break;
  137   }
  138 }