-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
103 lines (95 loc) · 2.6 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import gulp from 'gulp';
import replace from 'gulp-replace';
import inquirer from 'inquirer';
import { exec } from 'child_process';
/* eslint-disable no-console */
function updateVersion( newVersion ) {
// Update README.md - handle both dependency formats
gulp.src( './README.md' )
.pipe(
replace(
/@bsf\/force-ui@git\+https:\/\/github\.com\/brainstormforce\/force-ui\.git#[0-9]+\.[0-9]+\.[0-9]+/g,
`@bsf/force-ui@git+https://github.com/brainstormforce/force-ui.git#${ newVersion }`
)
)
.pipe(
replace(
/@bsf\/force-ui": "git\+https:\/\/github\.com\/brainstormforce\/force-ui#[0-9]+\.[0-9]+\.[0-9]+/g,
`@bsf/force-ui": "git+https://github.com/brainstormforce/force-ui#${ newVersion }`
)
)
.pipe( gulp.dest( './' ) );
// Update package.json
gulp.src( './package.json' )
.pipe(
replace(
/"version": "[0-9]+\.[0-9]+\.[0-9]+"/,
`"version": "${ newVersion }"`
)
)
.pipe( gulp.dest( './' ) );
// Update version.json
gulp.src( './version.json' )
.pipe(
replace(
/"force-ui": "[0-9]+\.[0-9]+\.[0-9]+"/,
`"force-ui": "${ newVersion }"`
)
)
.pipe( gulp.dest( './' ) );
}
// Bump version in all files
gulp.task( 'bump-and-update', function( done ) {
// Get the new version from command line arguments
let newVersion = process.argv[ 3 ];
// If the version is not provided as an argument, prompt for it
if ( ! newVersion ) {
inquirer
.prompt( [
{
type: 'input',
name: 'version',
message: 'Enter the new version:',
},
] )
.then( ( answers ) => {
newVersion = answers.version;
updateVersion( newVersion );
console.log( '✅ Bumped version successfully' );
done();
} )
.catch( ( error ) => {
console.error( `Error: ${ error.message }` );
console.error( '❌ Failed to bump version' );
done( error );
} );
} else {
try {
updateVersion( newVersion );
console.log( '✅ Bumped version successfully' );
done();
} catch ( error ) {
console.error( `Error: ${ error.message }` );
console.error( '❌ Failed to bump version' );
done( error );
}
}
} );
// Update package-lock.json
gulp.task( 'update-package-lock', function( done ) {
exec( 'npm i', ( error, stdout, stderr ) => {
if ( error ) {
console.error( `Error: ${ error.message }` );
done( error );
return;
}
if ( stderr ) {
console.error( `stderr: ${ stderr }` );
}
console.log( `stdout: ${ stdout }` );
console.log( '✅ Updated package-lock.json successfully' );
done();
} );
} );
// Bump version and update package-lock.json
gulp.task( 'bump', gulp.series( 'bump-and-update', 'update-package-lock' ) );