1
1
import fsp from 'fs/promises' ;
2
2
3
- import yaml from 'js-yaml' ;
4
-
5
3
import clientsConfig from '../../config/clients.config.json' assert { type : 'json' } ;
6
- import { CI , exists , GENERATORS , run , setVerbose , toAbsolutePath } from '../common.js' ;
4
+ import { CI , exists , setVerbose , toAbsolutePath } from '../common.js' ;
7
5
import { getGitHubUrl , getLanguageFolder } from '../config.js' ;
8
6
import type { Language } from '../types.js' ;
9
7
10
8
import { writeJsonFile } from './common.js' ;
9
+ import { updateDartPackages } from './dart.js' ;
10
+ import { updateJavaScriptPackages } from './javascript.js' ;
11
11
import type { Changelog , Versions } from './types.js' ;
12
12
13
13
async function updateConfigFiles ( versionsToRelease : Versions ) : Promise < void > {
@@ -21,7 +21,7 @@ async function updateConfigFiles(versionsToRelease: Versions): Promise<void> {
21
21
await writeJsonFile ( toAbsolutePath ( 'config/clients.config.json' ) , clientsConfig ) ;
22
22
}
23
23
24
- async function updateChangelog (
24
+ export async function updateChangelog (
25
25
lang : Language ,
26
26
changelog : string ,
27
27
current : string ,
@@ -58,11 +58,9 @@ export async function updateAPIVersions(versions: Versions, changelog: Changelog
58
58
continue ;
59
59
}
60
60
61
- if ( lang === 'javascript' ) {
61
+ if ( lang === 'javascript' && releaseType ) {
62
62
setVerbose ( CI ) ;
63
- await run ( `yarn install && yarn release:bump ${ releaseType } ` , {
64
- cwd : getLanguageFolder ( lang ) ,
65
- } ) ;
63
+ await updateJavaScriptPackages ( releaseType ) ;
66
64
}
67
65
68
66
await updateChangelog (
@@ -74,84 +72,3 @@ export async function updateAPIVersions(versions: Versions, changelog: Changelog
74
72
) ;
75
73
}
76
74
}
77
-
78
- /**
79
- * Updates packages versions and generates the changelog.
80
- */
81
- async function updateDartPackages ( changelog : string , nextVersion : string ) : Promise < void > {
82
- for ( const gen of Object . values ( GENERATORS ) ) {
83
- if ( gen . language !== 'dart' ) {
84
- continue ;
85
- }
86
-
87
- if ( ! nextVersion ) {
88
- throw new Error ( `Failed to bump '${ gen . packageName } '.` ) ;
89
- }
90
-
91
- let currentVersion = await getPubspecField ( gen . output , 'version' ) ;
92
-
93
- // if there's no version then it mostly means it's a new client.
94
- if ( ! currentVersion ) {
95
- currentVersion = '0.0.1' ;
96
- }
97
-
98
- await updateChangelog ( 'dart' , changelog , currentVersion , nextVersion , toAbsolutePath ( `${ gen . output } /CHANGELOG.md` ) ) ;
99
- }
100
-
101
- // Version is sync'd on every clients so we set it once.
102
- clientsConfig . dart . packageVersion = nextVersion ;
103
-
104
- // update `clients.config.json` file for the utils version.
105
- await writeJsonFile ( toAbsolutePath ( 'config/clients.config.json' ) , clientsConfig ) ;
106
-
107
- // Core client package path
108
- const corePackagePath = 'clients/algoliasearch-client-dart/packages/client_core' ;
109
-
110
- // fetch the version from the pubspec file of the core package
111
- let currentCoreVersion = await getPubspecField ( corePackagePath , 'version' ) ;
112
- if ( ! currentCoreVersion ) {
113
- currentCoreVersion = '0.0.1' ;
114
- }
115
-
116
- // update the changelog for core package
117
- await updateChangelog (
118
- 'dart' ,
119
- changelog ,
120
- currentCoreVersion ,
121
- nextVersion ,
122
- toAbsolutePath ( `${ corePackagePath } /CHANGELOG.md` ) ,
123
- ) ;
124
-
125
- // we've bumped generated clients but still need to do the manual ones.
126
- await bumpPubspecVersion ( toAbsolutePath ( `${ corePackagePath } /pubspec.yaml` ) , nextVersion ) ;
127
- }
128
-
129
- /**
130
- * Get 'version' from pubspec.yaml file.
131
- */
132
- async function getPubspecField ( filePath : string , field : string ) : Promise < string | undefined > {
133
- try {
134
- const fileContent = await fsp . readFile ( toAbsolutePath ( `${ filePath } /pubspec.yaml` ) , 'utf8' ) ;
135
- const pubspec = yaml . load ( fileContent ) as Record < string , any > ;
136
-
137
- return pubspec [ field ] ;
138
- } catch ( error ) {
139
- throw new Error ( `Error reading file ${ filePath } : ${ error } ` ) ;
140
- }
141
- }
142
-
143
- /**
144
- * Bump 'version' of the given pubspec.yaml file path.
145
- */
146
- async function bumpPubspecVersion ( filePath : string , nextVersion : string ) : Promise < void > {
147
- try {
148
- const fileContent = await fsp . readFile ( toAbsolutePath ( filePath ) , 'utf8' ) ;
149
- const pubspec = yaml . load ( fileContent ) as Record < string , any > ;
150
-
151
- pubspec . version = nextVersion ;
152
-
153
- await fsp . writeFile ( filePath , yaml . dump ( pubspec ) ) ;
154
- } catch ( error ) {
155
- throw new Error ( `Error writing file ${ filePath } : ${ error } ` ) ;
156
- }
157
- }
0 commit comments