@total_onion/onion-library 3.0.11 → 3.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exportToLibrary.js +471 -360
- package/package.json +1 -1
- package/update-template.js +4 -4
package/exportToLibrary.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
require('dotenv').config();
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const fse = require('fs-extra');
|
|
4
|
-
const {
|
|
4
|
+
const {globSync} = require('glob');
|
|
5
5
|
const yargs = require('yargs');
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const templateOptions = yargs.argv._;
|
|
8
|
-
const themePath =
|
|
8
|
+
const themePath =
|
|
9
|
+
process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
|
|
9
10
|
|
|
10
11
|
// paths for blocks
|
|
11
12
|
const srcPathJsBlock = `${themePath}/assets/js/blocks/`;
|
|
@@ -22,7 +23,7 @@ const srcPathTwigComponent = `${themePath}/views/components`;
|
|
|
22
23
|
// paths for fields
|
|
23
24
|
const srcPathJsFields = `${themePath}/assets/js/modules/library-modules`;
|
|
24
25
|
const srcPathScssFields = `${themePath}/assets/scss/modules/library-modules`;
|
|
25
|
-
const srcPathPhpFields = `${themePath}/inc/
|
|
26
|
+
const srcPathPhpFields = `${themePath}/inc/custom-extras`;
|
|
26
27
|
const srcPathTwigFields = `${themePath}/views/components`;
|
|
27
28
|
|
|
28
29
|
// paths for controller
|
|
@@ -37,401 +38,511 @@ const srcPathPhpSecurity = `${themePath}/inc/security-extras`;
|
|
|
37
38
|
const srcPathPhpSeopress = `${themePath}/inc/seo-extras`;
|
|
38
39
|
|
|
39
40
|
const destPath = path.join(
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
__dirname,
|
|
42
|
+
'../../../../../../../../onion-library/components/'
|
|
42
43
|
);
|
|
43
44
|
|
|
44
45
|
const bColors = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
HEADER: '\033[95m',
|
|
47
|
+
OKBLUE: '\033[94m',
|
|
48
|
+
OKGREEN: '\033[92m',
|
|
49
|
+
WARNING: '\033[93m',
|
|
50
|
+
FAIL: '\033[91m',
|
|
51
|
+
ENDC: '\033[0m',
|
|
52
|
+
BOLD: '\033[1m',
|
|
53
|
+
UNDERLINE: '\033[4m',
|
|
54
|
+
ORANGE: '\033[93m',
|
|
55
|
+
MAGENTA: '\033[95m',
|
|
56
|
+
CYAN: '\033[96m'
|
|
56
57
|
};
|
|
57
58
|
|
|
58
59
|
const icons = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
SMILE: '\uD83D\uDE00',
|
|
61
|
+
BEER_MUG: '\uD83C\uDF7A',
|
|
62
|
+
BEER_CHEERS: '\uD83C\uDF7B',
|
|
63
|
+
CROWN: '\uD83D\uDC51',
|
|
64
|
+
CLAP_HANDS: '\uD83D\uDC4F',
|
|
65
|
+
CROSS_MARK: '\u274C'
|
|
65
66
|
};
|
|
66
67
|
|
|
67
68
|
if (!fs.existsSync(`${destPath}`)) {
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
console.error('❌ Please check the library component path.');
|
|
70
|
+
process.exit(1);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
templateOptions.forEach((componentName) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
74
|
+
let componentType = '';
|
|
75
|
+
let component = '';
|
|
76
|
+
|
|
77
|
+
if (componentName.startsWith('block-')) {
|
|
78
|
+
componentType = 'block';
|
|
79
|
+
component = componentName.substring(6);
|
|
80
|
+
} else if (componentName.startsWith('component-')) {
|
|
81
|
+
componentType = 'component';
|
|
82
|
+
component = componentName.substring(10);
|
|
83
|
+
} else if (componentName.startsWith('fields-')) {
|
|
84
|
+
componentType = 'fields';
|
|
85
|
+
component = componentName.substring(7);
|
|
86
|
+
} else if (componentName.startsWith('controller-')) {
|
|
87
|
+
componentType = 'controller';
|
|
88
|
+
component = componentName.substring(11);
|
|
89
|
+
} else if (componentName.startsWith('security-')) {
|
|
90
|
+
componentType = 'security';
|
|
91
|
+
component = componentName.substring(9);
|
|
92
|
+
} else if (componentName.startsWith('seopress-')) {
|
|
93
|
+
componentType = 'seopress';
|
|
94
|
+
component = componentName.substring(9);
|
|
95
|
+
} else {
|
|
96
|
+
console.error(
|
|
97
|
+
`${bColors.FAIL}Invalid component type. Use block-, component- or fields- prefixes.${bColors.ENDC}`
|
|
98
|
+
);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let isValid = validateComponentExists(component, componentType);
|
|
103
|
+
if (!isValid) {
|
|
104
|
+
console.log(
|
|
105
|
+
`${bColors.OKBLUE}${componentName} : ${bColors.FAIL}[INVALID] Component does not exist${bColors.ENDC}`
|
|
106
|
+
);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let success = 0;
|
|
111
|
+
if (componentType === 'block') {
|
|
112
|
+
success = copyBlockContent(`${destPath}block-${component}/`, component);
|
|
113
|
+
} else if (componentType === 'component') {
|
|
114
|
+
success = copyComponentContent(
|
|
115
|
+
`${destPath}component-${component}/`,
|
|
116
|
+
component
|
|
117
|
+
);
|
|
118
|
+
} else if (componentType === 'fields') {
|
|
119
|
+
success = copyFieldsContent(
|
|
120
|
+
`${destPath}fields-${component}/`,
|
|
121
|
+
component
|
|
122
|
+
);
|
|
123
|
+
} else if (componentType === 'controller') {
|
|
124
|
+
success = copyControllerContent(
|
|
125
|
+
`${destPath}controller-${component}/`,
|
|
126
|
+
component
|
|
127
|
+
);
|
|
128
|
+
} else if (componentType === 'security') {
|
|
129
|
+
success = copySecurityContent(
|
|
130
|
+
`${destPath}security-${component}/`,
|
|
131
|
+
component
|
|
132
|
+
);
|
|
133
|
+
} else if (componentType === 'seopress') {
|
|
134
|
+
success = copySeopressContent(
|
|
135
|
+
`${destPath}seopress-${component}/`,
|
|
136
|
+
component
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (success === 1) {
|
|
141
|
+
console.log(
|
|
142
|
+
`${bColors.OKBLUE}${componentName} : ${bColors.OKGREEN}[OK]${bColors.ENDC}`
|
|
143
|
+
);
|
|
144
|
+
console.log(
|
|
145
|
+
`${bColors.CYAN}` + '---------------------------------------'
|
|
146
|
+
);
|
|
123
147
|
console.log(
|
|
124
148
|
'\x1b[32m',
|
|
125
149
|
`👑 👑 👑 Hurrah!${icons.BEER_CHEERS} You successfully exported all blocks to Library 👑 👑 👑`
|
|
126
150
|
);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
151
|
+
} else {
|
|
152
|
+
console.log(
|
|
153
|
+
`${bColors.OKBLUE}${componentName} : ${bColors.FAIL}[PARTIAL/FAIL]${bColors.ENDC}`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
130
156
|
});
|
|
131
157
|
|
|
132
158
|
function validateComponentExists(component, type) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
let exists = false;
|
|
160
|
+
if (type === 'block') {
|
|
161
|
+
exists =
|
|
162
|
+
fs.existsSync(`${srcPathJsBlock}${component}.js`) ||
|
|
163
|
+
fs.existsSync(`${srcPathScssBlock}${component}.scss`) ||
|
|
164
|
+
fs.existsSync(`${srcPathTwigBlock}${component}.twig`) ||
|
|
165
|
+
fs.existsSync(`${srcPathPhpBlock}${component}.php`) ||
|
|
166
|
+
fs.existsSync(`${srcPathVueBlock}${component}`) ||
|
|
167
|
+
fs.existsSync(`${srcPathVueBlock}${component}.vue`);
|
|
168
|
+
} else if (type === 'component') {
|
|
169
|
+
exists =
|
|
170
|
+
fs.existsSync(`${srcPathTwigComponent}/${component}.twig`) ||
|
|
171
|
+
fs.existsSync(
|
|
172
|
+
`${srcPathScssComponent}/${component}/${component}.scss`
|
|
173
|
+
) ||
|
|
174
|
+
fs.existsSync(`${srcPathJsComponent}/${component}/${component}.js`);
|
|
175
|
+
} else if (type === 'fields') {
|
|
176
|
+
exists =
|
|
177
|
+
fs.existsSync(`${srcPathPhpFields}/${component}.php`) ||
|
|
178
|
+
fs.existsSync(`${srcPathJsFields}/${component}/${component}.js`) ||
|
|
179
|
+
fs.existsSync(`${srcPathTwigFields}/${component}.twig`) ||
|
|
180
|
+
fs.existsSync(
|
|
181
|
+
`${srcPathScssFields}/${component}/${component}.scss`
|
|
182
|
+
);
|
|
183
|
+
} else if (type === 'controller') {
|
|
184
|
+
exists =
|
|
185
|
+
fs.existsSync(`${srcPathCssController}${component}.css`) ||
|
|
186
|
+
fs.existsSync(`${srcPathPhpController}${component}.php`) ||
|
|
187
|
+
fs.existsSync(`${srcPathTwigController}${component}.twig`);
|
|
188
|
+
} else if (type === 'security') {
|
|
189
|
+
exists = fs.existsSync(`${srcPathPhpSecurity}/${component}.php`);
|
|
190
|
+
} else if (type === 'seopress') {
|
|
191
|
+
exists = fs.existsSync(`${srcPathPhpSeopress}/${component}.php`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const acfJsonFiles = globSync(`${themePath}/acf-json/*.json`);
|
|
195
|
+
const acfJsonExists = acfJsonFiles.some((file) => {
|
|
196
|
+
let rawdata = fs.readFileSync(file);
|
|
197
|
+
let blockData = JSON.parse(rawdata);
|
|
198
|
+
const title = blockData.title
|
|
199
|
+
.replace(/(Block: |Component: |Fields: |Options: )/, '')
|
|
200
|
+
.replace(' - Library', '')
|
|
201
|
+
.replaceAll(' ', '-')
|
|
202
|
+
.toLowerCase();
|
|
203
|
+
return title === component;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
return exists || acfJsonExists;
|
|
173
207
|
}
|
|
174
208
|
|
|
175
209
|
function copyBlockContent(destDir, blockName) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
210
|
+
let SUCCESS = 0;
|
|
211
|
+
if (fs.existsSync(destDir)) {
|
|
212
|
+
fs.rmSync(destDir, {recursive: true, force: true});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!fs.existsSync(destDir)) {
|
|
216
|
+
try {
|
|
217
|
+
fs.mkdirSync(destDir);
|
|
218
|
+
if (fs.existsSync(`${srcPathJsBlock}${blockName}.js`)) {
|
|
219
|
+
fs.copyFileSync(
|
|
220
|
+
`${srcPathJsBlock}${blockName}.js`,
|
|
221
|
+
`${destDir}${blockName}.js`
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const extraJsPath = `${srcPathJsBlock}/${blockName}/${blockName}-extra.js`;
|
|
225
|
+
if (fs.existsSync(extraJsPath)) {
|
|
226
|
+
fs.copyFileSync(
|
|
227
|
+
extraJsPath,
|
|
228
|
+
`${destDir}${blockName}-extra.js`
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (fs.existsSync(`${srcPathScssBlock}${blockName}.scss`)) {
|
|
233
|
+
fs.copyFileSync(
|
|
234
|
+
`${srcPathScssBlock}${blockName}.scss`,
|
|
235
|
+
`${destDir}${blockName}.scss`
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
if (
|
|
239
|
+
fs.existsSync(
|
|
240
|
+
`${srcPathScssBlock}${blockName}/${blockName}-extra.scss`
|
|
241
|
+
)
|
|
242
|
+
) {
|
|
243
|
+
fs.copyFileSync(
|
|
244
|
+
`${srcPathScssBlock}${blockName}/${blockName}-extra.scss`,
|
|
245
|
+
`${destDir}${blockName}-extra.scss`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
if (fs.existsSync(`${srcPathTwigBlock}${blockName}.twig`)) {
|
|
249
|
+
fs.copyFileSync(
|
|
250
|
+
`${srcPathTwigBlock}${blockName}.twig`,
|
|
251
|
+
`${destDir}${blockName}.twig`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const blockSubfolderDir = `${srcPathTwigBlock}${blockName}`;
|
|
256
|
+
const destBlockSubfolderDir = `${destDir}${blockName}`;
|
|
257
|
+
|
|
258
|
+
if (
|
|
259
|
+
fs.existsSync(blockSubfolderDir) &&
|
|
260
|
+
fs.statSync(blockSubfolderDir).isDirectory()
|
|
261
|
+
) {
|
|
262
|
+
if (!fs.existsSync(destBlockSubfolderDir)) {
|
|
263
|
+
fs.mkdirSync(destBlockSubfolderDir);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const blockSubfolderFiles = globSync(`${blockSubfolderDir}/*`);
|
|
267
|
+
blockSubfolderFiles.forEach((file) => {
|
|
268
|
+
const fileName = path.basename(file);
|
|
269
|
+
fs.copyFileSync(
|
|
270
|
+
file,
|
|
271
|
+
path.join(destBlockSubfolderDir, fileName)
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
if (fs.existsSync(`${srcPathPhpBlock}${blockName}.php`)) {
|
|
276
|
+
fs.copyFileSync(
|
|
277
|
+
`${srcPathPhpBlock}${blockName}.php`,
|
|
278
|
+
`${destDir}${blockName}.php`
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
if (
|
|
282
|
+
fs.existsSync(`${srcPathVueBlock}${blockName}`) &&
|
|
283
|
+
fs.statSync(`${srcPathVueBlock}${blockName}`).isDirectory()
|
|
284
|
+
) {
|
|
285
|
+
fse.copySync(
|
|
286
|
+
`${srcPathVueBlock}${blockName}`,
|
|
287
|
+
`${destDir}${blockName}`
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
if (fs.existsSync(`${srcPathVueBlock}${blockName}.vue`)) {
|
|
291
|
+
fs.copyFileSync(
|
|
292
|
+
`${srcPathVueBlock}${blockName}.vue`,
|
|
293
|
+
`${destDir}${blockName}.vue`
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
copyBlockJson(blockName, 'block');
|
|
297
|
+
|
|
298
|
+
SUCCESS = 1;
|
|
299
|
+
} catch (e) {
|
|
300
|
+
SUCCESS = 0;
|
|
301
|
+
return SUCCESS;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return SUCCESS;
|
|
236
306
|
}
|
|
237
307
|
|
|
238
308
|
function copyComponentContent(destDir, componentName) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
309
|
+
let SUCCESS = 0;
|
|
310
|
+
if (fs.existsSync(destDir)) {
|
|
311
|
+
fs.rmSync(destDir, {recursive: true, force: true});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!fs.existsSync(destDir)) {
|
|
315
|
+
try {
|
|
316
|
+
fs.mkdirSync(destDir);
|
|
317
|
+
|
|
318
|
+
if (
|
|
319
|
+
fs.existsSync(`${srcPathTwigComponent}/${componentName}.twig`)
|
|
320
|
+
) {
|
|
321
|
+
fs.copyFileSync(
|
|
322
|
+
`${srcPathTwigComponent}/${componentName}.twig`,
|
|
323
|
+
`${destDir}${componentName}.twig`
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (
|
|
328
|
+
fs.existsSync(
|
|
329
|
+
`${srcPathScssComponent}/${componentName}/${componentName}.scss`
|
|
330
|
+
)
|
|
331
|
+
) {
|
|
332
|
+
fs.copyFileSync(
|
|
333
|
+
`${srcPathScssComponent}/${componentName}/${componentName}.scss`,
|
|
334
|
+
`${destDir}${componentName}.scss`
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
// Check and copy the -extra.scss file if it exists
|
|
338
|
+
const extraScssPath = `${srcPathScssComponent}/${componentName}/${componentName}-extra.scss`;
|
|
339
|
+
if (fs.existsSync(extraScssPath)) {
|
|
340
|
+
fs.copyFileSync(
|
|
341
|
+
extraScssPath,
|
|
342
|
+
`${destDir}${componentName}-extra.scss`
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (
|
|
348
|
+
fs.existsSync(
|
|
349
|
+
`${srcPathJsComponent}/${componentName}/${componentName}.js`
|
|
350
|
+
)
|
|
351
|
+
) {
|
|
352
|
+
fs.copyFileSync(
|
|
353
|
+
`${srcPathJsComponent}/${componentName}/${componentName}.js`,
|
|
354
|
+
`${destDir}${componentName}.js`
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
copyBlockJson(componentName, 'component');
|
|
359
|
+
SUCCESS = 1;
|
|
360
|
+
} catch (e) {
|
|
361
|
+
SUCCESS = 0;
|
|
362
|
+
return SUCCESS;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return SUCCESS;
|
|
275
367
|
}
|
|
276
368
|
|
|
277
369
|
function copyFieldsContent(destDir, fieldsName) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
370
|
+
let SUCCESS = 0;
|
|
371
|
+
if (fs.existsSync(destDir)) {
|
|
372
|
+
fs.rmSync(destDir, {recursive: true, force: true});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (!fs.existsSync(destDir)) {
|
|
376
|
+
try {
|
|
377
|
+
fs.mkdirSync(destDir);
|
|
378
|
+
|
|
379
|
+
if (
|
|
380
|
+
fs.existsSync(
|
|
381
|
+
`${srcPathJsFields}/${fieldsName}/${fieldsName}.js`
|
|
382
|
+
)
|
|
383
|
+
) {
|
|
384
|
+
fs.copyFileSync(
|
|
385
|
+
`${srcPathJsFields}/${fieldsName}/${fieldsName}.js`,
|
|
386
|
+
`${destDir}${fieldsName}.js`
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (fs.existsSync(`${srcPathPhpFields}/${fieldsName}.php`)) {
|
|
391
|
+
fs.copyFileSync(
|
|
392
|
+
`${srcPathPhpFields}/${fieldsName}.php`,
|
|
393
|
+
`${destDir}${fieldsName}.php`
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (fs.existsSync(`${srcPathTwigFields}/${fieldsName}.twig`)) {
|
|
398
|
+
fs.copyFileSync(
|
|
399
|
+
`${srcPathTwigFields}/${fieldsName}.twig`,
|
|
400
|
+
`${destDir}${fieldsName}.twig`
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (
|
|
405
|
+
fs.existsSync(
|
|
406
|
+
`${srcPathScssFields}/${fieldsName}/${fieldsName}.scss`
|
|
407
|
+
)
|
|
408
|
+
) {
|
|
409
|
+
fs.copyFileSync(
|
|
410
|
+
`${srcPathScssFields}/${fieldsName}/${fieldsName}.scss`,
|
|
411
|
+
`${destDir}${fieldsName}.scss`
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
copyBlockJson(fieldsName, 'fields');
|
|
416
|
+
SUCCESS = 1;
|
|
417
|
+
} catch (e) {
|
|
418
|
+
SUCCESS = 0;
|
|
419
|
+
return SUCCESS;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return SUCCESS;
|
|
312
424
|
}
|
|
313
425
|
|
|
314
426
|
function copyControllerContent(destDir, controllerName) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
427
|
+
let SUCCESS = 0;
|
|
428
|
+
if (fs.existsSync(destDir)) {
|
|
429
|
+
fs.rmSync(destDir, {recursive: true, force: true});
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (!fs.existsSync(destDir)) {
|
|
433
|
+
try {
|
|
434
|
+
fs.mkdirSync(destDir);
|
|
435
|
+
|
|
436
|
+
if (fs.existsSync(`${srcPathCssController}${controllerName}.css`)) {
|
|
437
|
+
fs.copyFileSync(
|
|
438
|
+
`${srcPathCssController}${controllerName}.css`,
|
|
439
|
+
`${destDir}${controllerName}.css`
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (fs.existsSync(`${srcPathPhpController}${controllerName}.php`)) {
|
|
444
|
+
fs.copyFileSync(
|
|
445
|
+
`${srcPathPhpController}${controllerName}.php`,
|
|
446
|
+
`${destDir}${controllerName}.php`
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (
|
|
451
|
+
fs.existsSync(`${srcPathTwigController}${controllerName}.twig`)
|
|
452
|
+
) {
|
|
453
|
+
fs.copyFileSync(
|
|
454
|
+
`${srcPathTwigController}${controllerName}.twig`,
|
|
455
|
+
`${destDir}${controllerName}.twig`
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
SUCCESS = 1;
|
|
460
|
+
} catch (e) {
|
|
461
|
+
console.error(e);
|
|
462
|
+
SUCCESS = 0;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return SUCCESS;
|
|
353
467
|
}
|
|
354
468
|
|
|
355
469
|
function copySecurityContent(destDir, securityName) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
470
|
+
let SUCCESS = 0;
|
|
471
|
+
if (fs.existsSync(destDir)) {
|
|
472
|
+
fs.rmSync(destDir, {recursive: true, force: true});
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (!fs.existsSync(destDir)) {
|
|
476
|
+
try {
|
|
477
|
+
fs.mkdirSync(destDir);
|
|
478
|
+
|
|
479
|
+
if (fs.existsSync(`${srcPathPhpSecurity}/${securityName}.php`)) {
|
|
480
|
+
fs.copyFileSync(
|
|
481
|
+
`${srcPathPhpSecurity}/${securityName}.php`,
|
|
482
|
+
`${destDir}${securityName}.php`
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
SUCCESS = 1;
|
|
487
|
+
} catch (e) {
|
|
488
|
+
console.error(e);
|
|
489
|
+
SUCCESS = 0;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return SUCCESS;
|
|
380
494
|
}
|
|
381
495
|
|
|
382
496
|
function copySeopressContent(destDir, seopressName) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
497
|
+
let SUCCESS = 0;
|
|
498
|
+
if (fs.existsSync(destDir)) {
|
|
499
|
+
fs.rmSync(destDir, {recursive: true, force: true});
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (!fs.existsSync(destDir)) {
|
|
503
|
+
try {
|
|
504
|
+
fs.mkdirSync(destDir);
|
|
505
|
+
|
|
506
|
+
if (fs.existsSync(`${srcPathPhpSeopress}/${seopressName}.php`)) {
|
|
507
|
+
fs.copyFileSync(
|
|
508
|
+
`${srcPathPhpSeopress}/${seopressName}.php`,
|
|
509
|
+
`${destDir}${seopressName}.php`
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
SUCCESS = 1;
|
|
514
|
+
} catch (e) {
|
|
515
|
+
console.error(e);
|
|
516
|
+
SUCCESS = 0;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return SUCCESS;
|
|
407
521
|
}
|
|
408
522
|
|
|
409
|
-
|
|
410
523
|
function copyBlockJson(name, type) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
});
|
|
524
|
+
const existingAcfFiles = globSync(`${themePath}/acf-json/*.json`);
|
|
525
|
+
|
|
526
|
+
const typeMapping = {
|
|
527
|
+
block: ['Block: '],
|
|
528
|
+
component: ['Component: '],
|
|
529
|
+
fields: ['Fields: ', 'Options: ']
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
existingAcfFiles.forEach((file) => {
|
|
533
|
+
let rawdata = fs.readFileSync(file);
|
|
534
|
+
let blockData = JSON.parse(rawdata);
|
|
535
|
+
const title = (typeMapping[type] || [])
|
|
536
|
+
.reduce((acc, replaceValue) => {
|
|
537
|
+
return acc.replace(replaceValue, '');
|
|
538
|
+
}, blockData.title)
|
|
539
|
+
.replace(' - Library', '')
|
|
540
|
+
.replaceAll(' ', '-')
|
|
541
|
+
.toLowerCase();
|
|
542
|
+
|
|
543
|
+
if (title === name) {
|
|
544
|
+
const fileName = path.basename(file);
|
|
545
|
+
fs.copyFileSync(file, `${destPath}${type}-${name}/${fileName}`);
|
|
546
|
+
}
|
|
547
|
+
});
|
|
437
548
|
}
|
package/package.json
CHANGED
package/update-template.js
CHANGED
|
@@ -215,7 +215,7 @@ const copyCoreComponent = (componentName) => {
|
|
|
215
215
|
|
|
216
216
|
switch (fileType) {
|
|
217
217
|
case 'php':
|
|
218
|
-
copyFile(`${sourceDir}/${file}`, `./inc/
|
|
218
|
+
copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
|
|
219
219
|
break;
|
|
220
220
|
// case 'js':
|
|
221
221
|
// copyFile(
|
|
@@ -256,7 +256,7 @@ const copyFieldsComponent = (componentName) => {
|
|
|
256
256
|
|
|
257
257
|
switch (fileType) {
|
|
258
258
|
case 'php':
|
|
259
|
-
copyFile(`${sourceDir}/${file}`, `./inc/
|
|
259
|
+
copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
|
|
260
260
|
break;
|
|
261
261
|
// case 'js':
|
|
262
262
|
// copyFile(
|
|
@@ -311,7 +311,7 @@ const copyComponentComponent = (componentName) => {
|
|
|
311
311
|
|
|
312
312
|
switch (fileType) {
|
|
313
313
|
case 'php':
|
|
314
|
-
copyFile(`${sourceDir}/${file}`, `./inc/
|
|
314
|
+
copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
|
|
315
315
|
break;
|
|
316
316
|
// case 'js':
|
|
317
317
|
// copyFile(
|
|
@@ -410,7 +410,7 @@ const copyAdminComponent = (componentName) => {
|
|
|
410
410
|
|
|
411
411
|
switch (fileType) {
|
|
412
412
|
case 'php':
|
|
413
|
-
copyFile(`${sourceDir}/${file}`, `./inc/
|
|
413
|
+
copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
|
|
414
414
|
break;
|
|
415
415
|
}
|
|
416
416
|
});
|