11const fs = require ( 'fs-extra' )
22const git = require ( 'simple-git/promise' )
3- const throwError = require ( '../throwError' )
4- const semver = require ( 'semver' )
53const log = require ( '../log' )
64
75
8- const createRevert = ( storage , branch ) => async ( ) => {
9- git ( storage ) . checkout ( branch )
10- }
11-
126const repositoryExisted = async ( repository , storage ) => {
137 if ( ! await fs . pathExists ( storage ) ) return false
148
@@ -18,7 +12,7 @@ const repositoryExisted = async (repository, storage) => {
1812 return true
1913}
2014
21- module . exports = async ( repository , version , storage ) => {
15+ module . exports = async ( repository , storage ) => {
2216 if ( await repositoryExisted ( repository , storage ) ) {
2317 log . info ( `pull template from ${ repository } ...` )
2418 await git ( storage ) . pull ( )
@@ -27,33 +21,4 @@ module.exports = async (repository, version, storage) => {
2721 await fs . remove ( storage )
2822 await git ( ) . clone ( repository , storage )
2923 }
30-
31- const gitT = git ( storage )
32- let tags = await gitT . tags ( )
33- tags = tags . all
34- . filter ( semver . valid )
35- . sort ( semver . compare )
36- . reverse ( )
37-
38- const branchSummary = await gitT . branch ( )
39- const currentBranch = branchSummary . current
40-
41- if ( version ) {
42- version = `v${ version } `
43- if ( ! tags . includes ( version ) ) {
44- throwError ( [
45- 'No corresponding template version was found' ,
46- 'Please confirm that the version number exists in the tags of the template repository.' ,
47- `Expected template version: ${ version } `
48- ] . join ( '\n' ) )
49- }
50-
51- await gitT . checkout ( version )
52- log . info ( `template version: ${ version } ` )
53- } else if ( tags . length ) {
54- await gitT . checkout ( tags [ 0 ] )
55- log . info ( `template version: ${ tags [ 0 ] } ` )
56- }
57-
58- return createRevert ( storage , currentBranch )
5924}
0 commit comments