11import fsp from 'fs/promises' ;
22
3- import yaml from 'js-yaml' ;
4-
53import 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' ;
75import { getGitHubUrl , getLanguageFolder } from '../config.js' ;
86import type { Language } from '../types.js' ;
97
108import { writeJsonFile } from './common.js' ;
9+ import { updateDartPackages } from './dart.js' ;
10+ import { updateJavaScriptPackages } from './javascript.js' ;
1111import type { Changelog , Versions } from './types.js' ;
1212
1313async function updateConfigFiles ( versionsToRelease : Versions ) : Promise < void > {
@@ -21,7 +21,7 @@ async function updateConfigFiles(versionsToRelease: Versions): Promise<void> {
2121 await writeJsonFile ( toAbsolutePath ( 'config/clients.config.json' ) , clientsConfig ) ;
2222}
2323
24- async function updateChangelog (
24+ export async function updateChangelog (
2525 lang : Language ,
2626 changelog : string ,
2727 current : string ,
@@ -58,11 +58,9 @@ export async function updateAPIVersions(versions: Versions, changelog: Changelog
5858 continue ;
5959 }
6060
61- if ( lang === 'javascript' ) {
61+ if ( lang === 'javascript' && releaseType ) {
6262 setVerbose ( CI ) ;
63- await run ( `yarn install && yarn release:bump ${ releaseType } ` , {
64- cwd : getLanguageFolder ( lang ) ,
65- } ) ;
63+ await updateJavaScriptPackages ( releaseType ) ;
6664 }
6765
6866 await updateChangelog (
@@ -74,84 +72,3 @@ export async function updateAPIVersions(versions: Versions, changelog: Changelog
7472 ) ;
7573 }
7674}
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