@@ -102,9 +102,9 @@ export default {
102
102
103
103
const importObj = {}; // final output
104
104
const htmlList = []; // array populated with substrings '<div>' '</div>' '<p>' etc.
105
+
105
106
let compName = data[0 ].slice (data[0 ].lastIndexOf (' /' ) + 1 ).replace (/ [^ a-z0-9 -_. ] / gi , ' ' ).replace (/ . vue/ , ' ' );
106
107
const vueFile = fs .readFileSync (data[0 ], " utf8" );
107
-
108
108
109
109
for (const key in this .$store .state .componentMap ) {
110
110
if (this .$store .state .componentMap [key].componentName === compName) {
@@ -113,49 +113,47 @@ export default {
113
113
}
114
114
importObj .componentName = compName;
115
115
116
- const htmlElementMap = {
117
- div: [" <div" , " </div>" ],
118
- button: [" <button" , " </button>" ],
119
- form: [" <form" , " </form>" ],
120
- img: [" <img" , " " ], // single
121
- link: [' <a href="#"' , " " ], // single
122
- list: [" <li" , " </li>" ],
123
- paragraph: [" <p" , " </p>" ],
124
- " list-ol" : [" <ol" , " </ol>" ],
125
- " list-ul" : [" <ul" , " </ul>" ],
126
- input: [" <input" , " " ], // single
127
- navbar: [" <nav" , " </nav>" ],
128
- header: [" <header" , " </header>" ],
129
- footer: [" <footer" , " </footer>" ],
130
- meta: [" <meta" , " </meta>" ],
131
- h1: [" <h1" , " </h1>" ],
132
- h2: [" <h2" , " </h2>" ],
133
- h3: [" <h3" , " </h3>" ],
134
- h4: [" <h4" , " </h4>" ],
135
- h5: [" <h5" , " </h5>" ],
136
- h6: [" <h6" , " </h6>" ],
116
+ const htmlElementMap = { // OverVue state management only handles these HTML tags.
117
+ div: [" <div> " , " </div>" ],
118
+ button: [" <button> " , " </button>" ],
119
+ form: [" <form> " , " </form>" ],
120
+ img: [" <img> " , " " ],
121
+ link: [' <a href="#"/> ' , " " ],
122
+ list: [" <li> " , " </li>" ],
123
+ paragraph: [" <p> " , " </p>" ],
124
+ " list-ol" : [" <ol> " , " </ol>" ],
125
+ " list-ul" : [" <ul> " , " </ul>" ],
126
+ input: [" <input /> " , " " ],
127
+ navbar: [" <nav> " , " </nav>" ],
128
+ header: [" <header> " , " </header>" ],
129
+ footer: [" <footer> " , " </footer>" ],
130
+ meta: [" <meta> " , " </meta>" ],
131
+ h1: [" <h1> " , " </h1>" ],
132
+ h2: [" <h2> " , " </h2>" ],
133
+ h3: [" <h3> " , " </h3>" ],
134
+ h4: [" <h4> " , " </h4>" ],
135
+ h5: [" <h5> " , " </h5>" ],
136
+ h6: [" <h6> " , " </h6>" ],
137
137
};
138
138
139
139
140
140
let htmlString = vueFile .substring (vueFile .indexOf (' <template >' ) + 10 , vueFile .indexOf (' </template>' ));
141
141
let scriptString = vueFile .substring (vueFile .indexOf (` <script>` ) + 8 , vueFile .indexOf (` /script>` ) - 1 )
142
-
142
+
143
143
htmlParser (htmlString);
144
144
importObj .props = this .parsingStringToProps (scriptString);
145
145
importObj .actions = this .parsingStringToAction (scriptString);
146
146
importObj .state = this .parsingStringToState (scriptString);
147
147
148
148
htmlList .pop (); htmlList .shift (); // OverVue adds a <div></div> wrapper to all components. remove this before importing.
149
- console . log (htmlList)
149
+
150
150
let groupings = findGroupings (htmlList);
151
151
let groupingObj = objectGenerator (groupings);
152
152
let groupingArray = [];
153
153
for (const key in groupingObj) {
154
154
groupingArray .push (groupingObj[key])
155
155
}
156
156
importObj .htmlList = groupingArray;
157
- console .log (' importObj:' )
158
- console .log (importObj)
159
157
this .createImport (importObj) // send the importObj to CreateComponent.
160
158
161
159
/**
@@ -217,8 +215,6 @@ console.log(htmlList)
217
215
*/
218
216
219
217
function findGroupings (array ) {
220
- console .log (" grouping:" )
221
- console .log (array)
222
218
let count = 0 ; // tracks where the parent ends
223
219
let stopIndexes = []; // an array that will be used to slice out the parent/child relationships
224
220
for (let i = 0 ; i < array .length ; i++ ) {
@@ -256,8 +252,6 @@ console.log(htmlList)
256
252
*/
257
253
258
254
function objectGenerator (array ) {
259
- console .log (" obj gen:" )
260
- console .log (array)
261
255
let groupingObj = {};
262
256
for (let i = 0 ; i < array .length ; i++ ) {
263
257
for (const key in htmlElementMap) {
@@ -268,18 +262,16 @@ console.log(htmlList)
268
262
}
269
263
array[i].pop ();
270
264
array[i].shift ();
271
-
272
265
if (array[i].length > 0 ) {
273
266
const childGroupings = findGroupings (array[i]);
274
267
const childrenObj = objectGenerator (childGroupings);
275
268
const childrenArray = [];
276
269
for (const key in childrenObj) {
277
270
childrenArray .push (childrenObj[key])
278
271
}
279
- console .log (groupingObj[i])
280
272
groupingObj[i].children = childrenArray;
281
273
} else {
282
- // groupingObj[i].children = [];
274
+ groupingObj[i].children = [];
283
275
}
284
276
}
285
277
return groupingObj;
0 commit comments