1
1
package reposcaffolding
2
2
3
3
import (
4
+ "path/filepath"
5
+
4
6
"github.com/mitchellh/mapstructure"
5
7
6
8
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
7
9
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/common"
10
+ "github.com/devstream-io/devstream/pkg/util/file"
8
11
"github.com/devstream-io/devstream/pkg/util/log"
9
12
)
10
13
11
14
const (
12
- transitBranch = "init-with-devstream"
13
- defaultCommitMsg = "init with devstream"
14
- appNamePlaceHolder = "_app_name_"
15
+ transitBranch = "init-with-devstream"
16
+ defaultCommitMsg = "init with devstream"
15
17
)
16
18
17
19
type Options struct {
@@ -36,18 +38,25 @@ func (opts *Options) Encode() (map[string]interface{}, error) {
36
38
return options , nil
37
39
}
38
40
39
- func (opts * Options ) CreateAndRenderLocalRepo (workpath string ) error {
40
- // 1. download template scaffolding repo
41
- err := opts .SourceRepo .DownloadRepo (workpath )
41
+ // CreateAndRenderLocalRepo will download repo from source repo and render it locally
42
+ func (opts * Options ) CreateAndRenderLocalRepo () (string , error ) {
43
+ // 1. get download url
44
+ githubCodeZipDownloadURL , err := opts .SourceRepo .getDownloadURL ()
42
45
if err != nil {
43
- return err
46
+ log .Debugf ("reposcaffolding get download url failed: %s" , err )
47
+ return "" , err
44
48
}
45
- // 2. walk iter repo files to render template
46
- if err := walkLocalRepoPath (workpath , opts ); err != nil {
47
- log .Debugf ("create local repo failed walk: %s." , err )
48
- return err
49
+ // 2. download zip file and unzip this file then render folders
50
+ projectDir , err := file .NewTemplate ().FromRemote (githubCodeZipDownloadURL ).UnzipFile ().RenderRepoDIr (
51
+ opts .DestinationRepo .Repo , opts .renderTplConfig (),
52
+ ).Run ()
53
+ if err != nil {
54
+ log .Debugf ("reposcaffolding process file error: %s" , err )
55
+ return "" , err
49
56
}
50
- return nil
57
+ // 3. join download path and repo name to get repo path
58
+ repoDirName := opts .SourceRepo .getRepoName ()
59
+ return filepath .Join (projectDir , repoDirName ), nil
51
60
}
52
61
53
62
// PushToRemoteGitLab push local repo to remote gitlab repo
0 commit comments