1- import { $ } from 'zx ' ;
1+ import execa from 'execa ' ;
22import { success , error , info } from './console' ;
33import { Commit , GitNewTag , GitPrerelease } from './types' ;
44import { getRoot , setFile , getFile , getPackageRoot , getLernaRoot } from './utils' ;
@@ -30,16 +30,17 @@ export const parseCommitSummary = (commit: Commit) => {
3030} ;
3131
3232export const commits = ( ) : Commit [ ] => {
33- return $ . sync `git log --oneline --pretty=hash<%h> ref<%D> message<%s> date<%cd>` . stdout
34- . split ( '\n' )
33+ return execa
34+ . sync ( 'git' , [ 'log' , '--oneline --pretty=hash<%h> ref<%D> message<%s> date<%cd>' ] )
35+ . stdout . split ( '\n' )
3536 . map ( parseLogMessage ) ;
3637} ;
3738
3839export const lastTag = ( ) : string => {
3940 let last ;
4041
4142 try {
42- last = $ . sync ` git describe --abbrev=0 --tags` ;
43+ last = execa . sync ( ' git' , [ ' describe' , ' --abbrev=0' , ' --tags' ] ) ;
4344 } catch ( e ) { }
4445 if ( ! last ) {
4546 error ( 'Unable to fetch the last tag. First use the generi init command' ) ;
@@ -93,13 +94,23 @@ export const setVersion = (
9394 try {
9495 const asPrerelease = prerelease ? [ '--preid' , prerelease ] : [ ] ;
9596
96- $ . sync `lerna version ${ tag } ${ asPrerelease . join ( ' ' ) } --no-private --no-changelog --no-git-tag-version --no-push --yes --force-publish` ;
97+ execa . sync ( 'lerna' , [
98+ 'version' ,
99+ tag ,
100+ ...asPrerelease ,
101+ '--no-private' ,
102+ '--no-changelog' ,
103+ '--no-git-tag-version' ,
104+ '--no-push' ,
105+ '--yes' ,
106+ '--force-publish' ,
107+ ] ) ;
97108 } catch ( e ) {
98109 error ( `Could not execute <lerna version ${ tag } > command` ) ;
99110 }
100111
101- const lernaPrev = destr < Record < string , any > > ( lerna ) ;
102- const lernaPost = destr < Record < string , any > > ( getFile ( getLernaRoot ( ) ) ) ;
112+ const lernaPrev = destr < Record < string , unknown > > ( lerna ) ;
113+ const lernaPost = destr < Record < string , unknown > > ( getFile ( getLernaRoot ( ) ) ) ;
103114
104115 // if lerna version has no previous workspace changes, it does not execute any command to change the version.
105116 if ( lernaPrev . version === lernaPost . version ) {
@@ -148,14 +159,14 @@ export const setVersion = (
148159} ;
149160
150161export const setTag = ( target : string ) => {
151- const tags = $ . sync ` git tag -n` ;
162+ const tags = execa . sync ( ' git' , [ ' tag' , '-n' ] ) ;
152163
153164 if ( tags . stdout ?. includes ( target ) ) {
154165 error ( 'Tag already exists!' ) ;
155166 return ;
156167 }
157168
158- const tag = $ . sync ` git tag ${ target } ` ;
169+ const tag = execa . sync ( ' git' , [ ' tag' , target ] ) ;
159170
160171 if ( ! tag ) {
161172 error ( 'Tag already exists!' ) ;
@@ -166,7 +177,7 @@ export const setTag = (target: string) => {
166177} ;
167178
168179export const initGit = ( ) => {
169- const init = $ . sync ` git init` ;
180+ const init = execa . sync ( ' git' , [ ' init' ] ) ;
170181
171182 if ( ! init ) {
172183 error ( 'Git is not installed.' ) ;
@@ -175,19 +186,19 @@ export const initGit = () => {
175186
176187 success ( 'Initialized Git Project' ) ;
177188
178- $ . sync ` git add -A` ;
189+ execa . sync ( ' git' , [ ' add' , '-A' ] ) ;
179190
180191 success ( 'Added All Staged Changes' ) ;
181192
182- $ . sync ` git commit -m " chore(changelog): initial content"` ;
193+ execa . sync ( ' git' , [ ' commit' , '-m' , ' chore(changelog): initial content' ] ) ;
183194
184195 success ( 'Commit Initial Content With Message: chore(changelog): initial content' ) ;
185196} ;
186197
187198export const setCommit = ( message : string , log = true ) => {
188- $ . sync ` git add -A` ;
199+ execa . sync ( ' git' , [ ' add' , '-A' ] ) ;
189200
190- $ . sync ` git commit -m " ${ message } "` ;
201+ execa . sync ( ' git' , [ ' commit' , '-m' , message ] ) ;
191202
192203 if ( log ) success ( 'Commit With Message: ' + message ) ;
193204} ;
@@ -197,11 +208,11 @@ export const pushCommits = () => {
197208
198209 info ( `Pushing...` ) ;
199210
200- const target = $ . sync ` git branch --show` ;
211+ const target = execa . sync ( ' git' , [ ' branch' , ' --show' ] ) ;
201212
202- $ . sync ` git push origin ${ target ?. stdout || 'main' } ` ;
213+ execa . sync ( ' git' , [ ' push' , ' origin' , target ?. stdout || 'main' ] ) ;
203214
204- $ . sync ` git push --tags` ;
215+ execa . sync ( ' git' , [ ' push' , ' --tags' ] ) ;
205216
206217 success ( 'Success in Push!' ) ;
207218} ;
@@ -218,18 +229,19 @@ export const revertAll = () => {
218229
219230 const tag = lastTag ( ) ;
220231
221- $ . sync ` git reset HEAD~1` ;
232+ execa . sync ( ' git' , [ ' reset' , ' HEAD~1' ] ) ;
222233
223- $ . sync ` git tag --delete ${ tag } ` ;
234+ execa . sync ( ' git' , [ ' tag' , ' --delete' , tag ] ) ;
224235
225- $ . sync `git checkout .` ;
236+ execa . sync ( 'git' , [ 'checkout' , '.' ] ) ;
237+ `` ;
226238
227239 success ( `Success in revert ${ tag } tag!` ) ;
228240} ;
229241
230242export const verifyExistentRemote = ( ) => {
231243 try {
232- $ . sync ` git remote -v` ;
244+ execa . sync ( ' git' , [ ' remote' , '-v' ] ) ;
233245 } catch ( e ) {
234246 return false ;
235247 }
@@ -249,7 +261,7 @@ export const isValidTag = (tag: GitNewTag) => {
249261} ;
250262
251263export const isCleanChanges = ( ) : boolean => {
252- const changes = $ . sync ` git diff HEAD` ;
264+ const changes = execa . sync ( ' git' , [ ' diff' , ' HEAD' ] ) ;
253265
254266 return ! changes . stdout ;
255267} ;
0 commit comments