@@ -42,7 +42,7 @@ import {
42
42
RouteComponentMap ,
43
43
} from " ../../../types" ;
44
44
import { useExportComponent } from " ../composables/useExportComponent" ;
45
- import { createBoilerOptions , createBoilerComposition } from " ../dfdas /createBoilerFuncs"
45
+ import { createBoilerOptions , createBoilerComposition } from " ../right-sidebar /createBoilerFuncs"
46
46
// import * as fs from "fs"
47
47
// import { fs } from "electron";
48
48
// import { path } from 'path';
@@ -256,16 +256,29 @@ const createComponentCode = async(
256
256
);
257
257
console .log (' finished write createComponent code' )
258
258
} else {
259
- // fs.writeFileSync(
260
- console .log (' about to write createComponent code for not App' )
261
- await writeFile (
262
- componentLocation + " .vue" ,
263
- await writeComments (componentName ) +
264
- await writeTemplate (componentName , children , routes .value ) +
265
- await writeScript (componentName , children ) +
266
- await writeStyle (componentName )
267
- );
268
- console .log (' finished to write createComponent code' )
259
+ if (store .composition === false ) {
260
+ // fs.writeFileSync(
261
+ console .log (' about to write createComponent code for not App' )
262
+ await writeFile (
263
+ componentLocation + " .vue" ,
264
+ await writeComments (componentName ) +
265
+ await writeTemplate (componentName , children , routes .value ) +
266
+ await createBoilerOptions (componentName , children )
267
+ // + await writeStyle(componentName)
268
+ );
269
+ console .log (' finished to write createComponent code' )
270
+ } else {
271
+ // fs.writeFileSync(
272
+ console .log (' about to write createComponent code for not App' )
273
+ await writeFile (
274
+ componentLocation + " .vue" ,
275
+ await writeComments (componentName ) +
276
+ await writeTemplate (componentName , children , routes .value ) +
277
+ await createBoilerComposition (componentName , children )
278
+ // + await writeStyle(componentName)
279
+ );
280
+ console .log (' finished to write createComponent code' )
281
+ }
269
282
}
270
283
};
271
284
@@ -679,163 +692,6 @@ const writeTemplate = (
679
692
* @description imports child components into <script>
680
693
*/
681
694
682
- const writeScript = (
683
- componentName : string ,
684
- children : {
685
- [key : string ]: RouteComponentMap | Component ;
686
- App: RouteComponentMap ;
687
- HomeView: RouteComponentMap ;
688
- }
689
- ) => {
690
- // add import mapstate and mapactions if they exist
691
- const currentComponent = componentMap .value [componentName ];
692
- const route = Object .keys (routes .value );
693
-
694
- // Writes script boilerplate for non-route components
695
- if (! route .includes (componentName )) {
696
- let imports = " " ;
697
- if (
698
- (currentComponent as Component ).actions .length ||
699
- (currentComponent as Component ).state .length
700
- ) {
701
- imports += " import { " ;
702
- if (
703
- (currentComponent as Component ).actions .length &&
704
- (currentComponent as Component ).state .length
705
- ) {
706
- imports += " mapState, mapActions" ;
707
- } else if ((currentComponent as Component ).state .length ) {
708
- imports += " mapState" ;
709
- } else {
710
- imports += " mapActions" ;
711
- }
712
- imports += ' } from "pinia";\n ' ;
713
- }
714
- // if in Typescript mode, import defineComponent
715
- if (exportAsTypescript .value === " on" ) {
716
- imports += ' import { defineComponent } from "vue";\n ' ;
717
- }
718
-
719
- let childrenComponentNames = " " ;
720
- let childComponentImportNames = " " ;
721
-
722
- const arrOfChildComp = componentMap .value [componentName ].children ;
723
-
724
- arrOfChildComp .forEach ((childName ) => {
725
- // Build child component text string
726
- if (childName !== arrOfChildComp [arrOfChildComp .length - 1 ]) {
727
- childrenComponentNames += " " + childName + " ,\n " ;
728
- } else {
729
- childrenComponentNames += " " + childName + " \n " ;
730
- }
731
- childComponentImportNames += ` import ${childName } from '../components/${childName }.vue';\n ` ;
732
- });
733
-
734
- let data = " " ;
735
- data += " data () {\n return {" ;
736
- if ((currentComponent as Component ).props .length ) {
737
- (currentComponent as Component ).props .forEach ((prop ) => {
738
- data += ` \n ${prop }: "PLACEHOLDER FOR VALUE",` ;
739
- });
740
- }
741
- routes .value .HomeView .forEach ((element ) => {
742
- element .htmlList .forEach ((html ) => {
743
- if (html .binding !== " " ) {
744
- data += ` \n ${html .binding }: "PLACEHOLDER FOR VALUE",` ;
745
- }
746
- });
747
- });
748
- data += " \n " ;
749
- data += " }\n " ;
750
- data += " },\n " ;
751
-
752
- // if true add computed section and populate with state
753
- let computed = " " ;
754
- if ((currentComponent as Component ).state .length ) {
755
- computed += " computed: {" ;
756
- computed += " \n ...mapState([" ;
757
- (currentComponent as Component ).state .forEach ((state ) => {
758
- computed += ` \n "${state }",` ;
759
- });
760
- computed += " \n ]),\n " ;
761
- computed += " },\n " ;
762
- }
763
- // if true add methods section and populate with actions
764
- let methods = " " ;
765
- if ((currentComponent as Component ).actions .length ) {
766
- methods += " methods: {" ;
767
- methods += " \n ...mapActions([" ;
768
- (currentComponent as Component ).actions .forEach ((action ) => {
769
- methods += ` \n "${action }",` ;
770
- });
771
- methods += " \n ]),\n " ;
772
- methods += " },\n " ;
773
- }
774
- // concat all code within script tags
775
- let output;
776
- if (exportAsTypescript .value === " on" ) {
777
- output = " \n\n <script lang='ts'>\n " ;
778
-
779
- output +=
780
- imports +
781
- " \n export default defineComponent ({\n name: '" +
782
- componentName +
783
- " '" ;
784
- } else {
785
- output = " \n\n <script>\n " ;
786
-
787
- output += ` \n ${childComponentImportNames }` ;
788
-
789
- output += imports + " \n export default {\n name: '" + componentName + " '" ;
790
- }
791
- output += " ,\n components: {\n " ;
792
-
793
- output += childrenComponentNames + " },\n " ;
794
- output += data ;
795
- output += computed ;
796
- output += methods ;
797
- // eslint-disable-next-line no-useless-escape
798
- if (exportAsTypescript .value === " on" ) {
799
- output += " });\n <\/ script>" ;
800
- } else {
801
- output += " };\n <\/ script>" ;
802
- }
803
- return output ;
804
- }
805
- // Write script for route components.
806
- else {
807
- let str = " " ;
808
- let childrenComponentNames = " " ;
809
- let childComponentImportNames = " " ;
810
- const arrOfChildComp = componentMap .value [componentName ].children ;
811
-
812
- if (componentName !== " App" ) {
813
- arrOfChildComp .forEach ((childName ) => {
814
- // Build child component text string
815
- if (childName !== arrOfChildComp [arrOfChildComp .length - 1 ]) {
816
- childrenComponentNames += " " + childName + " ,\n " ;
817
- } else {
818
- childrenComponentNames += " " + childName + " \n " ;
819
- }
820
-
821
- // Build child component import text string
822
- childComponentImportNames += ` import ${childName } from '../components/${childName }.vue';\n ` ;
823
- });
824
- }
825
-
826
- // eslint-disable-next-line no-useless-escape
827
- if (exportAsTypescript .value === " on" ) {
828
- return ` \n\n <script lang="ts">\n import { defineComponent } from "vue";\n ${str }\n export default defineComponent ({\n name: '${componentName }',\n components: {\n ${childrenComponentNames } }\n });\n <\/ script>` ;
829
- }
830
- str += " \n\n <script>" ;
831
- str += ` \n ${childComponentImportNames }` ;
832
- str += ` \n\n export default {` ;
833
- str += ` \n components: {` ;
834
- str += ` \n ${childrenComponentNames } }\n };` ;
835
- str += ` \n <\/ script>` ;
836
- return str ;
837
- }
838
- };
839
695
840
696
const writeStyle = (componentName : string ) => {
841
697
let htmlArray = componentMap .value [componentName ].htmlList ;
0 commit comments