11package deploywp
22
33import (
4+ "github.com/newclarity/scribeHelpers/toolCopy"
45 "github.com/newclarity/scribeHelpers/toolGit"
56 "github.com/newclarity/scribeHelpers/toolPath"
67 "github.com/newclarity/scribeHelpers/toolPrompt"
78 "github.com/newclarity/scribeHelpers/ux"
9+ "strings"
810)
911
1012
@@ -136,6 +138,110 @@ func (dwp *TypeDeployWp) CheckoutRepo(gitRef *toolGit.TypeGit, versionType strin
136138}
137139
138140
141+ func (dwp * TypeDeployWp ) CleanRepo (gitRef * toolGit.TypeGit , force bool ) * ux.State {
142+ if state := dwp .IsNil (); state .IsError () {
143+ return state
144+ }
145+
146+ for range onlyOnce {
147+ if gitRef .IsNotExisting () {
148+ dwp .State .SetError ("Repository not open." )
149+ break
150+ }
151+ if ! force {
152+ ux .PrintflnWarning ("About to remove all files within the '%s' repo..." , gitRef .Base .GetPathAbs ())
153+ ok := toolPrompt .ToolUserPromptBool ("Do you really want to do this?%s" , "" )
154+ if ! ok {
155+ ux .PrintflnWarning ("Aborting..." )
156+ dwp .State .SetError ("Abort due to user response." )
157+ break
158+ }
159+ }
160+
161+ ux .PrintflnBlue ("# Removing files..." )
162+ dwp .State = gitRef .GitRm ("rm" , "-r" , "." )
163+ //foo := dwp.State.OutputGrep("did not match any files")
164+ if strings .Contains (dwp .State .GetError ().Error (), "exit status 128" ) {
165+ dwp .State .SetOk ()
166+ }
167+ if dwp .State .IsError () {
168+ dwp .State .SetError ("Failed to remove files on target" )
169+ break
170+ }
171+
172+ ux .PrintflnOk ("# File removal completed OK." )
173+ dwp .State .SetOk ()
174+ }
175+
176+ gitRef .State = dwp .State
177+ return dwp .State
178+ }
179+
180+
181+ /*
182+ 6. Copy directories into /tmp/deploywp/target/
183+ - Honour {{ .target.files.exclude }} && {{ .target.files.copy }} && {{ .target.files.keep }}
184+ - Copy {{ .source.paths.webroot_path }}/{{ .source.paths.wordpress.core_path }}
185+ - To {{ .target.paths.webroot_path }}/{{ .target.paths.wordpress.core_path }}
186+ - Copy {{ .source.paths.webroot_path }}/{{ .source.paths.wordpress.content_path }}
187+ - To {{ .target.paths.webroot_path }}/{{ .target.paths.wordpress.content_path }}
188+ - Copy {{ .source.paths.webroot_path }}/{{ .source.paths.wordpress.vendor }}
189+ - To {{ .target.paths.webroot_path }}/{{ .target.paths.wordpress.vendor }}
190+ */
191+ func (dwp * TypeDeployWp ) CopyFiles () * ux.State {
192+ if state := dwp .IsNil (); state .IsError () {
193+ return state
194+ }
195+
196+ for range onlyOnce {
197+ srcAbs := dwp .GetSourceAbsPaths ()
198+ targetAbs := dwp .GetTargetAbsPaths ()
199+
200+ fileCopy := toolCopy .New (dwp .Runtime )
201+ if fileCopy .State .IsError () {
202+ dwp .State = fileCopy .State
203+ break
204+ }
205+
206+ if ! fileCopy .SetSourcePath (srcAbs .GetCorePath ()) {
207+ dwp .State .SetError ("Failed to set source path - '%s'." , srcAbs .GetCorePath ())
208+ break
209+ }
210+
211+ if ! fileCopy .SetDestinationPath (targetAbs .) {
212+ dwp .State .SetError ("Failed to set target path - '%s'." , targetAbs .)
213+ break
214+ }
215+
216+ // .
217+
218+ src := dwp .GetSourcePaths ()
219+ //srcAbs := dwp.GetSourceAbsPaths()
220+ ux .PrintflnBlue ("# SOURCE PATHS:" )
221+ ux .PrintflnOk ("BasePath (abs): %s" , srcAbs .GetBasePath ())
222+ ux .PrintflnOk ("BasePath: %s" , src .GetBasePath ())
223+ ux .PrintflnOk ("WebRootPath: %s" , src .GetWebRootPath ())
224+ ux .PrintflnOk ("ContentPath: %s" , src .GetContentPath ())
225+ ux .PrintflnOk ("CorePath: %s" , src .GetCorePath ())
226+ ux .PrintflnOk ("RootPath: %s" , src .GetRootPath ())
227+ ux .PrintflnOk ("VendorPath: %s" , src .GetVendorPath ())
228+
229+ target := dwp .GetTargetPaths ()
230+ //targetAbs := dwp.GetTargetAbsPaths()
231+ ux .PrintflnBlue ("# TARGET PATHS:" )
232+ ux .PrintflnOk ("BasePath (abs): %s" , targetAbs .GetBasePath ())
233+ ux .PrintflnOk ("BasePath: %s" , target .GetBasePath ())
234+ ux .PrintflnOk ("WebRootPath: %s" , target .GetWebRootPath ())
235+ ux .PrintflnOk ("ContentPath: %s" , target .GetContentPath ())
236+ ux .PrintflnOk ("CorePath: %s" , target .GetCorePath ())
237+ ux .PrintflnOk ("RootPath: %s" , target .GetRootPath ())
238+ ux .PrintflnOk ("VendorPath: %s" , target .GetVendorPath ())
239+ }
240+
241+ return dwp .State
242+ }
243+
244+
139245func (dwp * TypeDeployWp ) PrintPaths () * ux.State {
140246 if state := dwp .IsNil (); state .IsError () {
141247 return state
@@ -155,7 +261,7 @@ func (dwp *TypeDeployWp) PrintPaths() *ux.State {
155261
156262 target := dwp .GetTargetPaths ()
157263 targetAbs := dwp .GetTargetAbsPaths ()
158- ux .PrintflnBlue ("# SOURCE PATHS:" )
264+ ux .PrintflnBlue ("# TARGET PATHS:" )
159265 ux .PrintflnOk ("BasePath (abs): %s" , targetAbs .GetBasePath ())
160266 ux .PrintflnOk ("BasePath: %s" , target .GetBasePath ())
161267 ux .PrintflnOk ("WebRootPath: %s" , target .GetWebRootPath ())
0 commit comments