1
1
#!/usr/bin/env node
2
2
3
3
/**
4
- * This runs after `npm version` command.
5
- * This will update the `package.json` optional native dependencies
4
+ * This runs after `npm version` command updates the version but before changes are commited.
5
+ * This will update the `cargo.toml` version to match the new `package.json` verson.
6
+ * This will also update the `package.json` optional native dependencies
6
7
* to match the same version as the version of this package.
7
8
* This maintains the same version between this master package
8
9
* and the optional native dependencies.
12
13
* to prevent `npm` from attempting to download unpublished packages.
13
14
*/
14
15
16
+ const process = require ( 'process' ) ;
17
+ const path = require ( 'path' ) ;
18
+ const fs = require ( 'fs' ) ;
15
19
const os = require ( 'os' ) ;
16
20
const childProcess = require ( 'child_process' ) ;
17
21
const packageJSON = require ( '../package.json' ) ;
@@ -20,6 +24,27 @@ const platform = os.platform();
20
24
21
25
/* eslint-disable no-console */
22
26
async function main ( ) {
27
+
28
+ console . error (
29
+ 'Updating the cargo.toml version to match new version' ,
30
+ ) ;
31
+ const projectRoot = path . join ( __dirname , '..' ) ;
32
+ const cargoTOMLPath = path . join ( projectRoot , 'Cargo.toml' ) ;
33
+ const cargoTOML = await fs . promises . readFile ( cargoTOMLPath , 'utf-8' ) ;
34
+ const cargoTOMLMatch = cargoTOML . match ( / v e r s i o n \s * = \s * " ( .* ) " / ) ;
35
+ const cargoTOMLUpdated = cargoTOML . replace ( cargoTOMLMatch [ 0 ] , `version = "${ packageJSON . version } "` ) ;
36
+ await fs . promises . writeFile ( cargoTOMLPath , cargoTOMLUpdated , 'utf-8' ) ;
37
+
38
+ console . error (
39
+ 'Staging changes in git' ,
40
+ ) ;
41
+ childProcess . execFileSync ( 'git' , [ 'add' , cargoTOMLPath ] , {
42
+ stdio : [ 'inherit' , 'inherit' , 'inherit' ] ,
43
+ windowsHide : true ,
44
+ encoding : 'utf-8' ,
45
+ shell : platform === 'win32' ? true : false ,
46
+ } ) ;
47
+
23
48
console . error (
24
49
'Updating the package.json with optional native dependencies and package-lock.json' ,
25
50
) ;
0 commit comments