@@ -2,6 +2,7 @@ import fsp from 'fs/promises';
2
2
3
3
import dotenv from 'dotenv' ;
4
4
import yaml from 'js-yaml' ;
5
+ import type { ReleaseType } from 'semver' ;
5
6
6
7
import clientsConfig from '../../config/clients.config.json' assert { type : 'json' } ;
7
8
import openapiConfig from '../../config/openapitools.json' assert { type : 'json' } ;
@@ -45,12 +46,10 @@ async function updateChangelog(
45
46
lang : Language ,
46
47
changelog : string ,
47
48
current : string ,
48
- next : string
49
+ next : string ,
50
+ changelogPath : string
49
51
) : Promise < void > {
50
52
let content = '' ;
51
- const changelogPath = toAbsolutePath (
52
- `${ getLanguageFolder ( lang ) } /CHANGELOG.md`
53
- ) ;
54
53
const changelogHeader = `## [${ next } ](${ getGitHubUrl (
55
54
lang
56
55
) } /compare/${ current } ...${ next } )`;
@@ -112,51 +111,73 @@ export async function updateAPIVersions(
112
111
versionsToRelease
113
112
) ) {
114
113
if ( lang === 'dart' ) {
115
- await updateDartPackages ( ) ;
114
+ await updateDartPackages ( changelog [ lang ] ! , releaseType ) ;
116
115
117
116
continue ;
118
117
}
119
118
120
119
if ( lang === 'javascript' ) {
121
- const cwd = getLanguageFolder ( lang ) ;
122
-
123
120
setVerbose ( CI ) ;
124
- await run ( `yarn install && yarn release:bump ${ releaseType } ` , { cwd } ) ;
121
+ await run ( `yarn install && yarn release:bump ${ releaseType } ` , {
122
+ cwd : getLanguageFolder ( lang ) ,
123
+ } ) ;
125
124
}
126
125
127
- await updateChangelog ( lang as Language , changelog [ lang ] , current , next ) ;
126
+ await updateChangelog (
127
+ lang as Language ,
128
+ changelog [ lang ] ,
129
+ current ,
130
+ next ,
131
+ toAbsolutePath ( `${ getLanguageFolder ( lang as Language ) } /CHANGELOG.md` )
132
+ ) ;
128
133
}
129
134
}
130
135
131
136
/**
132
137
* Updates packages versions and generates the changelog.
133
138
* Documentation: {@link https://melos.invertase.dev/commands/version | melos version}.
134
139
*/
135
- async function updateDartPackages ( ) : Promise < void > {
136
- const cwd = getLanguageFolder ( 'dart' ) ;
137
-
138
- // Generate dart packages versions and changelogs
139
- await run (
140
- `(cd ${ cwd } && dart pub get && melos version --no-git-tag-version --yes --diff ${ RELEASED_TAG } )`
141
- ) ;
140
+ async function updateDartPackages (
141
+ changelog : string ,
142
+ releaseType : ReleaseType
143
+ ) : Promise < void > {
144
+ await run ( 'dart pub get' , { cwd : getLanguageFolder ( 'dart' ) } ) ;
142
145
143
146
// Update packages configs based on generated versions
144
147
for ( const gen of Object . values ( GENERATORS ) ) {
145
- if ( gen . language === 'dart' ) {
146
- const { additionalProperties } = gen ;
147
- const newVersion = await getPubspecVersion (
148
- `../${ gen . output } /pubspec.yaml`
149
- ) ;
150
- if ( ! newVersion ) {
151
- throw new Error ( `Failed to bump '${ gen . packageName } '.` ) ;
152
- }
153
- additionalProperties . packageVersion = newVersion ;
154
- additionalProperties . packageName = undefined ;
148
+ if ( gen . language !== 'dart' ) {
149
+ continue ;
150
+ }
155
151
156
- if ( gen . client === 'algoliasearch' ) {
157
- clientsConfig . dart . packageVersion = newVersion ;
158
- }
152
+ const currentVersion = gen . additionalProperties . packageVersion ;
153
+ const packageName = await getPubspecField ( gen . output , 'name' ) ;
154
+ if ( ! packageName ) {
155
+ throw new Error ( `Unable to find packageName for '${ gen . packageName } '.` ) ;
156
+ }
157
+
158
+ await run (
159
+ `melos version --manual-version=${ packageName } :${ releaseType } --no-changelog --no-git-tag-version --yes --diff ${ RELEASED_TAG } ` ,
160
+ { cwd : gen . output }
161
+ ) ;
162
+
163
+ const newVersion = await getPubspecField ( gen . output , 'version' ) ;
164
+ if ( ! newVersion ) {
165
+ throw new Error ( `Failed to bump '${ gen . packageName } '.` ) ;
159
166
}
167
+ gen . additionalProperties . packageVersion = newVersion ;
168
+ gen . additionalProperties . packageName = undefined ;
169
+
170
+ if ( gen . client === 'algoliasearch' ) {
171
+ clientsConfig . dart . packageVersion = newVersion ;
172
+ }
173
+
174
+ await updateChangelog (
175
+ 'dart' ,
176
+ changelog ,
177
+ currentVersion ,
178
+ newVersion ,
179
+ toAbsolutePath ( `${ gen . output } /CHANGELOG.md` )
180
+ ) ;
160
181
}
161
182
162
183
// update `openapitools.json` config file
@@ -175,13 +196,18 @@ async function updateDartPackages(): Promise<void> {
175
196
/**
176
197
* Get 'version' from pubspec.yaml file.
177
198
*/
178
- async function getPubspecVersion (
179
- filePath : string
199
+ async function getPubspecField (
200
+ filePath : string ,
201
+ field : string
180
202
) : Promise < string | undefined > {
181
203
try {
182
- const fileContent = await fsp . readFile ( filePath , 'utf8' ) ;
183
- const data = yaml . load ( fileContent ) as { version ?: string } ;
184
- return data . version ;
204
+ const fileContent = await fsp . readFile (
205
+ toAbsolutePath ( `${ filePath } /pubspec.yaml` ) ,
206
+ 'utf8'
207
+ ) ;
208
+ const pubspec = yaml . load ( fileContent ) as Record < string , any > ;
209
+
210
+ return pubspec [ field ] ;
185
211
} catch ( error ) {
186
212
throw new Error ( `Error reading the file: ${ error } ` ) ;
187
213
}
0 commit comments