"Fossies" - the Fresh Open Source Software Archive

Member "angular-cli-8.3.23/scripts/changelog.ts" (15 Jan 2020, 3942 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-console
    9 // tslint:disable:no-implicit-dependencies
   10 import { JsonObject, logging } from '@angular-devkit/core';
   11 import * as fs from 'fs';
   12 import * as path from 'path';
   13 import * as semver from 'semver';
   14 import { packages } from '../lib/packages';
   15 
   16 const changelogTemplate = require('./templates/changelog').default;
   17 
   18 const conventionalCommitsParser = require('conventional-commits-parser');
   19 const gitRawCommits = require('git-raw-commits');
   20 const ghGot = require('gh-got');
   21 const through = require('through2');
   22 
   23 export interface ChangelogOptions {
   24   from: string;
   25   to?: string;
   26   githubTokenFile?: string;
   27   githubToken?: string;
   28 
   29   stdout?: boolean;
   30 }
   31 
   32 export default function(args: ChangelogOptions, logger: logging.Logger) {
   33   const commits: JsonObject[] = [];
   34   let toSha: string | null = null;
   35 
   36   const githubToken = (
   37     args.githubToken ||
   38     (args.githubTokenFile && fs.readFileSync(args.githubTokenFile, 'utf-8')) ||
   39     ''
   40   ).trim();
   41 
   42   return new Promise(resolve => {
   43     (gitRawCommits({
   44       from: args.from,
   45       to: args.to || 'HEAD',
   46       format: '%B%n-hash-%n%H%n-gitTags-%n%D%n-committerDate-%n%ci%n-authorName-%n%aN%n',
   47     }) as NodeJS.ReadStream)
   48       .on('error', err => {
   49         logger.fatal('An error happened: ' + err.message);
   50         process.exit(1);
   51       })
   52       .pipe(
   53         through((chunk: Buffer, enc: string, callback: Function) => {
   54           // Replace github URLs with `@XYZ#123`
   55           const commit = chunk
   56             .toString('utf-8')
   57             .replace(/https?:\/\/github.com\/(.*?)\/issues\/(\d+)/g, '@$1#$2');
   58 
   59           callback(undefined, Buffer.from(commit));
   60         }),
   61       )
   62       .pipe(
   63         conventionalCommitsParser({
   64           headerPattern: /^(\w*)(?:\(([^)]*)\))?: (.*)$/,
   65           headerCorrespondence: ['type', 'scope', 'subject'],
   66           noteKeywords: ['BREAKING CHANGE'],
   67           revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
   68           revertCorrespondence: [`header`, `hash`],
   69         }),
   70       )
   71       .pipe(
   72         through.obj((chunk: JsonObject, _: string, cb: Function) => {
   73           try {
   74             const maybeTag = chunk.gitTags && (chunk.gitTags as string).match(/tag: (.*)/);
   75             const tags = maybeTag && maybeTag[1].split(/,/g);
   76             chunk['tags'] = tags;
   77 
   78             if (tags && tags.find(x => x == args.to)) {
   79               toSha = chunk.hash as string;
   80             }
   81 
   82             commits.push(chunk);
   83             cb();
   84           } catch (err) {
   85             cb(err);
   86           }
   87         }),
   88       )
   89       .on('finish', resolve);
   90   })
   91     .then(() => {
   92       const markdown: string = changelogTemplate({
   93         ...args,
   94         include: (x: string, v: {}) => require('./' + path.join('templates', x)).default(v),
   95         commits,
   96         packages,
   97       });
   98 
   99       if (args.stdout || !githubToken) {
  100         console.log(markdown);
  101         process.exit(0);
  102       }
  103 
  104       // Check if we need to edit or create a new one.
  105       return ghGot('repos/angular/angular-cli/releases').then((x: JsonObject) => [x, markdown]);
  106     })
  107     .then(([body, markdown]) => {
  108       const json = body.body;
  109 
  110       const maybeRelease = json.find((x: JsonObject) => x.tag_name == args.to);
  111       const id = maybeRelease ? `/${maybeRelease.id}` : '';
  112 
  113       const semversion = (args.to && semver.parse(args.to)) || { prerelease: '' };
  114 
  115       return ghGot('repos/angular/angular-cli/releases' + id, {
  116         body: {
  117           body: markdown,
  118           draft: !maybeRelease,
  119           name: args.to,
  120           prerelease: semversion.prerelease.length > 0,
  121           tag_name: args.to,
  122           ...(toSha ? { target_commitish: toSha } : {}),
  123         },
  124         token: githubToken,
  125       });
  126     });
  127 }