@@ -62,8 +62,6 @@ public function fetchStarterKit($starterkit = "") {
6262 $ tempDirDist = $ tempDirSK .DIRECTORY_SEPARATOR ."dist " ;
6363 $ tempComposerFile = $ tempDirSK .DIRECTORY_SEPARATOR ."composer.json " ;
6464
65- $ fs = new Filesystem ();
66-
6765 // figure out the options for the GH path
6866 list ($ org ,$ repo ,$ tag ) = $ this ->getPackageInfo ($ starterkit );
6967
@@ -103,40 +101,19 @@ public function fetchStarterKit($starterkit = "") {
103101 if (file_exists ($ tempComposerFile )) {
104102
105103 $ tempComposerJSON = json_decode (file_get_contents ($ tempComposerFile ), true );
104+
105+ // see if it has a patternlab section that might define the files to move
106106 if (isset ($ tempComposerJSON ["extra " ]) && isset ($ tempComposerJSON ["extra " ]["patternlab " ])) {
107107 Console::writeInfo ("installing the starterkit... " );
108108 InstallerUtil::parseComposerExtraList ($ tempComposerJSON ["extra " ]["patternlab " ], $ starterkit , $ tempDirDist );
109109 Console::writeInfo ("installed the starterkit... " );
110110 } else {
111- Console:: writeError ( " the starterkit's composer.json file didn't have a valid format. missing patternlab directives... " );
111+ $ this -> mirrorDist ( $ sourceDir , $ tempDirDist );
112112 }
113113
114114 } else {
115115
116- // see if the source directory is empty
117- $ emptyDir = true ;
118- if (is_dir ($ sourceDir )) {
119- $ objects = new \DirectoryIterator ($ sourceDir );
120- foreach ($ objects as $ object ) {
121- if (!$ object ->isDot () && ($ object ->getFilename () != "README " ) && ($ object ->getFilename () != ".DS_Store " )) {
122- $ emptyDir = false ;
123- }
124- }
125- }
126-
127- // if source directory isn't empty ask if it's ok to nuke what's there
128- if (!$ emptyDir ) {
129-
130- $ prompt = "a starterkit is already installed. merge or replace? " ;
131- $ options = "M/r " ;
132- $ input = Console::promptInput ($ prompt ,$ options );
133- $ options = ($ input == "r " ) ? array ("delete " => true , "override " => true ) : array ("delete " => false , "override " => false );
134-
135- }
136-
137- Console::writeInfo ("installing the starterkit files... " );
138- $ fs ->mirror ($ tempDirDist , $ sourceDir , null , $ options );
139- Console::writeInfo ("starterkit files have been installed... " );
116+ $ this ->mirrorDist ($ sourceDir , $ tempDirDist );
140117
141118 }
142119
@@ -177,4 +154,43 @@ protected function getPackageInfo($package) {
177154
178155 }
179156
157+ /**
158+ * Force mirror the dist/ folder to source/
159+ * @param {String} path to the source directory
160+ * @param {String} path to the temp dist directory
161+ */
162+ protected function mirrorDist ($ sourceDir , $ tempDirDist ) {
163+
164+ // set default vars
165+ $ fsOptions = array ();
166+ $ emptyDir = true ;
167+
168+ // see if the source directory is empty
169+ if (is_dir ($ sourceDir )) {
170+ $ objects = new \DirectoryIterator ($ sourceDir );
171+ foreach ($ objects as $ object ) {
172+ if (!$ object ->isDot () && ($ object ->getFilename () != "README " ) && ($ object ->getFilename () != ".DS_Store " )) {
173+ $ emptyDir = false ;
174+ }
175+ }
176+ }
177+
178+ // if source directory isn't empty ask if it's ok to nuke what's there
179+ if (!$ emptyDir ) {
180+
181+ $ prompt = "a starterkit is already installed. merge the new files with it or replace it? " ;
182+ $ options = "M/r " ;
183+ $ input = Console::promptInput ($ prompt ,$ options );
184+ $ fsOptions = ($ input == "r " ) ? array ("delete " => true , "override " => true ) : array ("delete " => false , "override " => false );
185+
186+ }
187+
188+ // mirror dist to source
189+ Console::writeInfo ("installing the starterkit files... " );
190+ $ fs = new Filesystem ();
191+ $ fs ->mirror ($ tempDirDist , $ sourceDir , null , $ options );
192+ Console::writeInfo ("starterkit files have been installed... " );
193+
194+ }
195+
180196}
0 commit comments