From b23ee7a031ae6636eeccdad36f125bb9258ae684 Mon Sep 17 00:00:00 2001 From: Hans Date: Wed, 10 Oct 2018 15:08:44 -0700 Subject: [PATCH] ci: add header to snapshot build README (#12482) Fixes #12481 --- scripts/snapshots.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/scripts/snapshots.ts b/scripts/snapshots.ts index 31d02311f4..1b62b00a16 100644 --- a/scripts/snapshots.ts +++ b/scripts/snapshots.ts @@ -11,11 +11,31 @@ import { execSync, spawnSync } from 'child_process'; import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { packages } from '../lib/packages'; +import { PackageInfo, packages } from '../lib/packages'; import build from './build'; import create from './create'; +// Added to the README.md of the snapshot. This is markdown. +const readmeHeaderFn = (pkg: PackageInfo) => ` +# Snapshot build of ${pkg.name} + +This repository is a snapshot of a commit on the original repository. The original code used to +generate this is located at http://github.com/angular/angular-cli. + +We do not accept PRs or Issues opened on this repository. You should not use this over a tested and +released version of this package. + +To test this snapshot in your own project, use + +\`\`\`bash +npm install github.com/${pkg.snapshotRepo} +\`\`\` + +---- +`; + + function _copy(from: string, to: string) { fs.readdirSync(from) .forEach(name => { @@ -137,7 +157,17 @@ export default async function(opts: SnapshotsOptions, logger: logging.Logger) { _exec('git', ['config', 'commit.gpgSign', 'false'], { cwd: destPath }, publishLogger); } - // Make sure that every snapshots is unique. + // Add the header to the existing README.md (or create a README if it doesn't exist). + const readmePath = path.join(destPath, 'README.md'); + let readme = readmeHeaderFn(pkg); + try { + readme += fs.readFileSync(readmePath, 'utf-8'); + } catch {} + + fs.writeFileSync(readmePath, readme); + + // Make sure that every snapshots is unique (otherwise we would need to make sure git accepts + // empty commits). fs.writeFileSync(path.join(destPath, 'uniqueId'), '' + new Date()); // Commit and push.