1
1
#!/usr/bin/env node
2
- import addStream from 'add-stream' ;
3
- import chalk from 'chalk' ;
4
- import conventionalChangelog from 'conventional-changelog' ;
5
2
import fs from 'node:fs' ;
6
- import path from 'node:path ' ;
7
- import tempfile from 'tempfile ' ;
3
+ import { Package } from './changelog/Package.mjs ' ;
4
+ import { generateChangelog } from './changelog/generate.mjs ' ;
8
5
9
6
const PRESET = 'angular' ;
10
7
11
8
/**
12
- * @typedef {{
13
- * path: string;
14
- * excluded?: true;
15
- * sameAs?: string;
16
- * name?: string;
17
- * changelogPath?: string;
18
- * version?: string;
19
- * gitPath?: string;
20
- * }} Package
21
- *
22
- * @type {Package[] }
9
+ * @type {import('./changelog/Package.mjs').PackageConfiguration[] }
23
10
*/
24
11
const PACKAGES = [
25
12
{ path : './packages/astro' } ,
26
13
{ path : './packages/cli' } ,
27
14
{ path : './packages/components/react' } ,
28
15
{ path : './packages/runtime' } ,
16
+ { path : './packages/theme' } ,
17
+ { path : './packages/types' } ,
29
18
30
19
// we do not include this one because it is not published
31
20
{ path : './packages/template' , excluded : true } ,
@@ -37,98 +26,56 @@ const PACKAGES = [
37
26
processPackages ( ) ;
38
27
39
28
async function processPackages ( ) {
29
+ /** @type {Map<string, Package> } */
30
+ const packages = new Map ( ) ;
31
+
40
32
// infer extra properties
41
- for ( const pkg of PACKAGES ) {
42
- pkg . path = path . normalize ( pkg . path ) ;
33
+ for ( const pkgDef of PACKAGES ) {
34
+ const pkg = new Package ( pkgDef ) ;
35
+ packages . set ( pkg . name , pkg ) ;
36
+ }
43
37
44
- const pkgJSON = JSON . parse ( fs . readFileSync ( path . join ( pkg . path , 'package.json' ) ) ) ;
38
+ // overwrites temporarily the version on the `tutorialkit` package as it's released separately later
39
+ const tutorialkit = packages . get ( 'tutorialkit' ) ;
40
+ const tutorialkitAstro = packages . get ( '@tutorialkit/astro' ) ;
45
41
46
- pkg . name = pkgJSON . name ;
47
- pkg . version = pkgJSON . version ;
48
- pkg . changelogPath = path . join ( pkg . path , 'CHANGELOG.md' ) ;
49
- }
42
+ const originalVersion = tutorialkit . version ;
43
+ tutorialkit . version = tutorialkitAstro . version ;
44
+
45
+ tutorialkit . write ( ) ;
50
46
51
47
// generate change logs
52
48
await Promise . all (
53
- PACKAGES . map ( ( pkg ) => {
49
+ [ ... packages . values ( ) ] . map ( ( pkg ) => {
54
50
if ( pkg . excluded ) {
55
- return ;
51
+ return Promise . resolve ( ) ;
56
52
}
57
53
58
- return generateChangelog ( pkg ) ;
54
+ return generateChangelog ( pkg , PRESET ) ;
59
55
} ) ,
60
56
) ;
61
57
62
58
// copy changelogs that are identical
63
- for ( const pkg of PACKAGES ) {
59
+ for ( const pkg of packages . values ( ) ) {
64
60
if ( pkg . sameAs ) {
65
- const otherPkg = PACKAGES . find ( ( otherPkg ) => otherPkg . name === pkg . sameAs ) ;
61
+ const otherPkg = packages . get ( pkg . sameAs ) ;
66
62
67
63
fs . copyFileSync ( otherPkg . changelogPath , pkg . changelogPath ) ;
68
64
}
69
65
}
70
66
71
67
// generate root changelog
72
- const tutorialkit = PACKAGES . find ( ( pkg ) => pkg . name === 'tutorialkit' ) ;
73
-
74
- await generateChangelog ( {
75
- version : tutorialkit . version ,
76
- path : tutorialkit . path ,
77
- gitPath : '.' ,
78
- changelogPath : 'CHANGELOG.md' ,
79
- } ) ;
80
- }
81
-
82
- /**
83
- * Generate a changelog for the provided package and aggregate the data
84
- * for the root changelog.
85
- *
86
- * @param {Package } pkg the package
87
- */
88
- function generateChangelog ( pkg ) {
89
- const options = {
90
- preset : PRESET ,
91
- pkg : {
92
- path : pkg . path ,
68
+ await generateChangelog (
69
+ {
70
+ version : tutorialkit . version ,
71
+ path : tutorialkit . path ,
72
+ gitPath : '.' ,
73
+ changelogPath : 'CHANGELOG.md' ,
93
74
} ,
94
- append : undefined ,
95
- releaseCount : undefined ,
96
- skipUnstable : undefined ,
97
- outputUnreleased : undefined ,
98
- tagPrefix : undefined ,
99
- } ;
100
-
101
- const context = {
102
- version : pkg . version ,
103
- title : pkg . name ,
104
- } ;
105
-
106
- const gitRawCommitsOpts = {
107
- path : pkg . gitPath ?? pkg . path ,
108
- } ;
109
-
110
- const changelogStream = conventionalChangelog ( options , context , gitRawCommitsOpts ) . on ( 'error' , ( error ) => {
111
- console . error ( error . stack ) ;
112
- process . exit ( 1 ) ;
113
- } ) ;
114
-
115
- const CHANGELOG_FILE = pkg . changelogPath ;
116
-
117
- return new Promise ( ( resolve ) => {
118
- const readStream = fs . createReadStream ( CHANGELOG_FILE ) . on ( 'error' , ( ) => {
119
- // if there was no changelog we create it here
120
- changelogStream . pipe ( fs . createWriteStream ( CHANGELOG_FILE ) ) . on ( 'finish' , resolve ) ;
121
- } ) ;
122
-
123
- const tmp = tempfile ( ) ;
124
-
125
- changelogStream
126
- . pipe ( addStream ( readStream ) )
127
- . pipe ( fs . createWriteStream ( tmp ) )
128
- . on ( 'finish' , ( ) => {
129
- fs . createReadStream ( tmp ) . pipe ( fs . createWriteStream ( CHANGELOG_FILE ) ) . on ( 'finish' , resolve ) ;
130
- } ) ;
131
- } ) . then ( ( ) => {
132
- console . log ( `${ chalk . green ( 'UPDATED' ) } ${ CHANGELOG_FILE } ${ chalk . gray ( pkg . version ) } ` ) ;
133
- } ) ;
75
+ PRESET ,
76
+ ) ;
77
+
78
+ // reset the version of the CLI:
79
+ tutorialkit . version = originalVersion ;
80
+ tutorialkit . write ( ) ;
134
81
}
0 commit comments