|
1 | | -const {generateTemplateFiles, StringUtility} = require('../../dist/generate-template-files.cjs'); |
| 1 | +const {items} = require('./items'); |
| 2 | +const {generateTemplateFiles} = require('../../dist/generate-template-files.cjs'); |
2 | 3 | // Note: In your file it will be like this: |
3 | | -// const {generateTemplateFiles, StringUtility} = require('generate-template-files'); |
| 4 | +// const {generateTemplateFiles} = require('generate-template-files'); |
4 | 5 |
|
5 | | -const filename = require('file-name'); |
6 | | -const insertLine = require('insert-line'); |
7 | | - |
8 | | -const config = require('../package.json'); |
9 | | - |
10 | | -generateTemplateFiles([ |
11 | | - // Angular |
12 | | - { |
13 | | - option: 'Angular Ngrx Store', |
14 | | - defaultCase: '(pascalCase)', |
15 | | - entry: { |
16 | | - folderPath: './tools/templates/angular/ngrx-store/', |
17 | | - }, |
18 | | - stringReplacers: ['__name__', {question: 'Insert model name', slot: '__model__'}], |
19 | | - dynamicReplacers: [ |
20 | | - {slot: '__version__', slotValue: config.version}, |
21 | | - {slot: '__description__', slotValue: config.description}, |
22 | | - ], |
23 | | - output: { |
24 | | - path: './src/app/stores/__name__(lowerCase)', |
25 | | - pathAndFileNameDefaultCase: '(kebabCase)', |
26 | | - }, |
27 | | - onComplete: async (results) => { |
28 | | - // console.log(`results`, results); |
29 | | - }, |
30 | | - }, |
31 | | - // Vue |
32 | | - { |
33 | | - option: 'Vue Vuex Store', |
34 | | - defaultCase: '(pascalCase)', |
35 | | - entry: { |
36 | | - folderPath: './tools/templates/vue/vuex-store/', |
37 | | - }, |
38 | | - stringReplacers: ['__store__', '__model__'], |
39 | | - output: { |
40 | | - path: './src/stores/__store__(kebabCase)', |
41 | | - pathAndFileNameDefaultCase: '(pascalCase)', |
42 | | - }, |
43 | | - onComplete: async (results) => { |
44 | | - console.log(`results`, results); |
45 | | - await importVuexStore(results); |
46 | | - }, |
47 | | - }, |
48 | | - // React |
49 | | - { |
50 | | - option: 'React Redux Store', |
51 | | - defaultCase: '(pascalCase)', |
52 | | - entry: { |
53 | | - folderPath: './tools/templates/react/redux-store/', |
54 | | - }, |
55 | | - stringReplacers: ['__store__', '__model__'], |
56 | | - output: { |
57 | | - path: './src/stores/__store__(kebabCase)', |
58 | | - pathAndFileNameDefaultCase: '(pascalCase)', |
59 | | - }, |
60 | | - onComplete: (results) => { |
61 | | - console.log(`results`, results); |
62 | | - }, |
63 | | - }, |
64 | | - { |
65 | | - option: 'React Component', |
66 | | - defaultCase: '(pascalCase)', |
67 | | - entry: { |
68 | | - folderPath: './tools/templates/react/component/', |
69 | | - }, |
70 | | - stringReplacers: ['__name__'], |
71 | | - output: { |
72 | | - path: './src/views/__name__(kebabCase)', |
73 | | - pathAndFileNameDefaultCase: '(pascalCase)', |
74 | | - }, |
75 | | - }, |
76 | | - { |
77 | | - option: 'React Connected Component', |
78 | | - defaultCase: '(pascalCase)', |
79 | | - entry: { |
80 | | - folderPath: './tools/templates/react/connected-component/', |
81 | | - }, |
82 | | - stringReplacers: ['__name__'], |
83 | | - output: { |
84 | | - path: './src/views/__name__(kebabCase)', |
85 | | - pathAndFileNameDefaultCase: '(pascalCase)', |
86 | | - }, |
87 | | - }, |
88 | | - { |
89 | | - option: 'Selector', |
90 | | - defaultCase: '(pascalCase)', |
91 | | - entry: { |
92 | | - folderPath: './tools/templates/react/selectors/', |
93 | | - }, |
94 | | - stringReplacers: ['__name__'], |
95 | | - output: { |
96 | | - path: './src/selectors/__name__(kebabCase)', |
97 | | - pathAndFileNameDefaultCase: '(pascalCase)', |
98 | | - }, |
99 | | - }, |
100 | | - { |
101 | | - option: 'Model', |
102 | | - defaultCase: '(pascalCase)', |
103 | | - entry: { |
104 | | - folderPath: './tools/templates/react/__model__Model.ts', |
105 | | - }, |
106 | | - stringReplacers: ['__model__'], |
107 | | - output: { |
108 | | - path: './src/models/__model__Model.ts', |
109 | | - pathAndFileNameDefaultCase: '(pascalCase)', |
110 | | - }, |
111 | | - }, |
112 | | - { |
113 | | - option: 'Interface', |
114 | | - defaultCase: '(pascalCase)', |
115 | | - entry: { |
116 | | - folderPath: './tools/templates/react/I__interface__.ts', |
117 | | - }, |
118 | | - stringReplacers: ['__interface__'], |
119 | | - output: { |
120 | | - path: './src/models/I__interface__.ts', |
121 | | - pathAndFileNameDefaultCase: '(pascalCase)', |
122 | | - }, |
123 | | - }, |
124 | | - { |
125 | | - option: 'Enum', |
126 | | - defaultCase: '(pascalCase)', |
127 | | - entry: { |
128 | | - folderPath: './tools/templates/react/__enum__Enum.ts', |
129 | | - }, |
130 | | - stringReplacers: ['__enum__'], |
131 | | - output: { |
132 | | - path: './src/constants/__enum__Enum.ts', |
133 | | - pathAndFileNameDefaultCase: '(pascalCase)', |
134 | | - }, |
135 | | - }, |
136 | | -]); |
137 | | - |
138 | | -/* |
139 | | - * NOTE: there is many ways you can do this. This is just an example on how you might approch it. |
140 | | - */ |
141 | | -async function importVuexStore(results) { |
142 | | - const files = results.output.files; |
143 | | - |
144 | | - const fullPaths = files |
145 | | - .map((folderPath) => folderPath.replace('src/', '')) // remove 'src' from path |
146 | | - .map((path) => `import ${filename(path)} from '${path}'`) // create import statement |
147 | | - .join('\n'); // put all imports on there own line |
148 | | - |
149 | | - try { |
150 | | - await insertLine('src/import-test.ts').append(fullPaths); |
151 | | - } catch (error) { |
152 | | - console.log(``, error); |
153 | | - } |
154 | | -} |
| 6 | +generateTemplateFiles(items); |
0 commit comments