-
Notifications
You must be signed in to change notification settings - Fork 782
/
Copy pathprep-release.js
109 lines (91 loc) · 2.55 KB
/
prep-release.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Helper for the QUnit release preparation commit.
//
// See also RELEASE.md.
//
// Inspired by <https://github.com/jquery/jquery-release>.
/* eslint-env node */
const fs = require( "fs" );
const path = require( "path" );
const util = require( "util" );
const cp = require( "child_process" );
const gitAuthors = require( "grunt-git-authors" );
const Repo = {
async prep( version ) {
if ( typeof version !== "string" || !/^\d+\.\d+\.\d+$/.test( version ) ) {
throw new Error( "Invalid or missing version argument" );
}
{
const file = "History.md";
console.log( `Updating ${file}...` );
const filePath = path.join( __dirname, "..", file );
const oldContent = fs.readFileSync( filePath, "utf8" );
const oldVersion = require( "../package.json" ).version.replace( /-.*$/, "" );
const changeFilter = [
/^\* Release \d+\./,
/^\* Build: /,
/^\* Docs: /,
/^\* Tests: /
];
let changes = cp.execFileSync( "git", [
"log",
"--format=* %s. (%aN)",
"--no-merges",
`${oldVersion}...HEAD`
], { encoding: "utf8" } );
changes = changes
.trim()
.split( "\n" )
.filter( line => !changeFilter.some( filter => filter.test( line ) ) )
.map( line => {
return {
component: line.replace( /^\* ([^:]+):.*$/, "$1" ),
line
};
} )
.sort()
.map( change => change.line )
.join( "\n" ) +
"\n";
const today = new Date().toISOString().slice( 0, 10 );
const newSection = `\n${version} / ${today}
==================
### Added
### Changed
### Deprecated
### Fixed
### Removed
`.replace( /^[ \t]*/gm, "" );
fs.writeFileSync( filePath, newSection + changes + oldContent );
}
{
const file = "package.json";
console.log( `Updating ${file}...` );
const filePath = path.join( __dirname, "..", file );
const json = fs.readFileSync( filePath, "utf8" );
const packageIndentation = json.match( /\n([\t\s]+)/ )[ 1 ];
const data = JSON.parse( json );
data.version = `${version}-pre`;
fs.writeFileSync(
filePath,
JSON.stringify( data, null, packageIndentation ) + "\n"
);
}
{
const file = "AUTHORS.txt";
console.log( `Updating ${file}...` );
const updateAuthors = util.promisify( gitAuthors.updateAuthors );
await updateAuthors( {
dir: path.dirname( __dirname ),
filename: file,
banner: "Authors ordered by first contribution"
} );
}
}
};
const version = process.argv[ 2 ];
( async function main() {
await Repo.prep( version );
}() ).catch( e => {
console.error( e.toString() );
process.exit( 1 );
} );