@total_onion/onion-library 3.0.11 → 3.0.13

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.
@@ -1,11 +1,12 @@
1
1
  require('dotenv').config();
2
2
  const fs = require('fs');
3
3
  const fse = require('fs-extra');
4
- const { globSync } = require('glob');
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 = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
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/admin-extras`;
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
- __dirname,
41
- '../../../../../../../../onion-library/components/'
41
+ __dirname,
42
+ '../../../../../../../../onion-library/components/'
42
43
  );
43
44
 
44
45
  const bColors = {
45
- HEADER: '\033[95m',
46
- OKBLUE: '\033[94m',
47
- OKGREEN: '\033[92m',
48
- WARNING: '\033[93m',
49
- FAIL: '\033[91m',
50
- ENDC: '\033[0m',
51
- BOLD: '\033[1m',
52
- UNDERLINE: '\033[4m',
53
- ORANGE: '\033[93m',
54
- MAGENTA: '\033[95m',
55
- CYAN: '\033[96m'
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
- SMILE: '\uD83D\uDE00',
60
- BEER_MUG: '\uD83C\uDF7A',
61
- BEER_CHEERS: '\uD83C\uDF7B',
62
- CROWN: '\uD83D\uDC51',
63
- CLAP_HANDS: '\uD83D\uDC4F',
64
- CROSS_MARK: '\u274C'
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
- console.error('❌ Please check the library component path.');
69
- process.exit(1);
69
+ console.error('❌ Please check the library component path.');
70
+ process.exit(1);
70
71
  }
71
72
 
72
73
  templateOptions.forEach((componentName) => {
73
- let componentType = '';
74
- let component = '';
75
-
76
- if (componentName.startsWith('block-')) {
77
- componentType = 'block';
78
- component = componentName.substring(6);
79
- } else if (componentName.startsWith('component-')) {
80
- componentType = 'component';
81
- component = componentName.substring(10);
82
- } else if (componentName.startsWith('fields-')) {
83
- componentType = 'fields';
84
- component = componentName.substring(7);
85
- } else if (componentName.startsWith('controller-')) {
86
- componentType = 'controller';
87
- component = componentName.substring(11);
88
- } else if (componentName.startsWith('security-')) {
89
- componentType = 'security';
90
- component = componentName.substring(9);
91
- } else if (componentName.startsWith('seopress-')) {
92
- componentType = 'seopress';
93
- component = componentName.substring(9);
94
- } else {
95
- console.error(`${bColors.FAIL}Invalid component type. Use block-, component- or fields- prefixes.${bColors.ENDC}`);
96
- process.exit(1);
97
- }
98
-
99
- let isValid = validateComponentExists(component, componentType);
100
- if (!isValid) {
101
- console.log(`${bColors.OKBLUE}${componentName} : ${bColors.FAIL}[INVALID] Component does not exist${bColors.ENDC}`);
102
- return;
103
- }
104
-
105
- let success = 0;
106
- if (componentType === 'block') {
107
- success = copyBlockContent(`${destPath}block-${component}/`, component);
108
- } else if (componentType === 'component') {
109
- success = copyComponentContent(`${destPath}component-${component}/`, component);
110
- } else if (componentType === 'fields') {
111
- success = copyFieldsContent(`${destPath}fields-${component}/`, component);
112
- } else if (componentType === 'controller') {
113
- success = copyControllerContent(`${destPath}controller-${component}/`, component);
114
- } else if (componentType === 'security') {
115
- success = copySecurityContent(`${destPath}security-${component}/`, component);
116
- } else if (componentType === 'seopress') {
117
- success = copySeopressContent(`${destPath}seopress-${component}/`,component);
118
- }
119
-
120
- if (success === 1) {
121
- console.log(`${bColors.OKBLUE}${componentName} : ${bColors.OKGREEN}[OK]${bColors.ENDC}`);
122
- console.log(`${bColors.CYAN}` + '---------------------------------------');
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
- } else {
128
- console.log(`${bColors.OKBLUE}${componentName} : ${bColors.FAIL}[PARTIAL/FAIL]${bColors.ENDC}`);
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
- let exists = false;
134
- if (type === 'block') {
135
- exists = fs.existsSync(`${srcPathJsBlock}${component}.js`) ||
136
- fs.existsSync(`${srcPathScssBlock}${component}.scss`) ||
137
- fs.existsSync(`${srcPathTwigBlock}${component}.twig`) ||
138
- fs.existsSync(`${srcPathPhpBlock}${component}.php`) ||
139
- fs.existsSync(`${srcPathVueBlock}${component}`) ||
140
- fs.existsSync(`${srcPathVueBlock}${component}.vue`);
141
- } else if (type === 'component') {
142
- exists = fs.existsSync(`${srcPathTwigComponent}/${component}.twig`) ||
143
- fs.existsSync(`${srcPathScssComponent}/${component}/${component}.scss`) ||
144
- fs.existsSync(`${srcPathJsComponent}/${component}/${component}.js`);
145
- } else if (type === 'fields') {
146
- exists = fs.existsSync(`${srcPathPhpFields}/${component}.php`) ||
147
- fs.existsSync(`${srcPathJsFields}/${component}/${component}.js`) ||
148
- fs.existsSync(`${srcPathTwigFields}/${component}.twig`) ||
149
- fs.existsSync(`${srcPathScssFields}/${component}/${component}.scss`);
150
- } else if (type === 'controller') {
151
- exists = fs.existsSync(`${srcPathCssController}${component}.css`) ||
152
- fs.existsSync(`${srcPathPhpController}${component}.php`) ||
153
- fs.existsSync(`${srcPathTwigController}${component}.twig`);
154
- } else if (type === 'security') {
155
- exists = fs.existsSync(`${srcPathPhpSecurity}/${component}.php`);
156
- } else if (type === 'seopress') {
157
- exists = fs.existsSync(`${srcPathPhpSeopress}/${component}.php`);
158
- }
159
-
160
- const acfJsonFiles = globSync(`${themePath}/acf-json/*.json`);
161
- const acfJsonExists = acfJsonFiles.some((file) => {
162
- let rawdata = fs.readFileSync(file);
163
- let blockData = JSON.parse(rawdata);
164
- const title = blockData.title
165
- .replace(/(Block: |Component: |Fields: |Options: )/, '')
166
- .replace(' - Library', '')
167
- .replaceAll(' ', '-')
168
- .toLowerCase();
169
- return title === component;
170
- });
171
-
172
- return exists || acfJsonExists;
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
- let SUCCESS = 0;
177
- if (fs.existsSync(destDir)) {
178
- fs.rmSync(destDir, { recursive: true, force: true });
179
- }
180
-
181
- if (!fs.existsSync(destDir)) {
182
- try {
183
- fs.mkdirSync(destDir);
184
- if (fs.existsSync(`${srcPathJsBlock}${blockName}.js`)) {
185
- fs.copyFileSync(`${srcPathJsBlock}${blockName}.js`, `${destDir}${blockName}.js`);
186
-
187
- const extraJsPath = `${srcPathJsBlock}/${blockName}/${blockName}-extra.js`;
188
- if(fs.existsSync(extraJsPath)) {
189
- fs.copyFileSync(extraJsPath, `${destDir}${blockName}-extra.js`);
190
- }
191
- }
192
- if (fs.existsSync(`${srcPathScssBlock}${blockName}.scss`)) {
193
- fs.copyFileSync(`${srcPathScssBlock}${blockName}.scss`, `${destDir}${blockName}.scss`);
194
- }
195
- if (fs.existsSync(`${srcPathScssBlock}${blockName}/${blockName}-extra.scss`)) {
196
- fs.copyFileSync(`${srcPathScssBlock}${blockName}/${blockName}-extra.scss`, `${destDir}${blockName}-extra.scss`);
197
- }
198
- if (fs.existsSync(`${srcPathTwigBlock}${blockName}.twig`)) {
199
- fs.copyFileSync(`${srcPathTwigBlock}${blockName}.twig`, `${destDir}${blockName}.twig`);
200
- }
201
-
202
- const blockSubfolderDir = `${srcPathTwigBlock}${blockName}`;
203
- const destBlockSubfolderDir = `${destDir}${blockName}`;
204
-
205
- if (fs.existsSync(blockSubfolderDir) && fs.statSync(blockSubfolderDir).isDirectory()) {
206
-
207
- if (!fs.existsSync(destBlockSubfolderDir)) {
208
- fs.mkdirSync(destBlockSubfolderDir);
209
- }
210
-
211
- const blockSubfolderFiles = globSync(`${blockSubfolderDir}/*`);
212
- blockSubfolderFiles.forEach((file) => {
213
- const fileName = path.basename(file);
214
- fs.copyFileSync(file, path.join(destBlockSubfolderDir, fileName));
215
- });
216
- }
217
- if (fs.existsSync(`${srcPathPhpBlock}${blockName}.php`)) {
218
- fs.copyFileSync(`${srcPathPhpBlock}${blockName}.php`, `${destDir}${blockName}.php`);
219
- }
220
- if (fs.existsSync(`${srcPathVueBlock}${blockName}`) && fs.statSync(`${srcPathVueBlock}${blockName}`).isDirectory()) {
221
- fse.copySync(`${srcPathVueBlock}${blockName}`, `${destDir}${blockName}`);
222
- }
223
- if (fs.existsSync(`${srcPathVueBlock}${blockName}.vue`)) {
224
- fs.copyFileSync(`${srcPathVueBlock}${blockName}.vue`, `${destDir}${blockName}.vue`);
225
- }
226
- copyBlockJson(blockName, 'block');
227
-
228
- SUCCESS = 1;
229
- } catch (e) {
230
- SUCCESS = 0;
231
- return SUCCESS;
232
- }
233
- }
234
-
235
- return SUCCESS;
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
- let SUCCESS = 0;
240
- if (fs.existsSync(destDir)) {
241
- fs.rmSync(destDir, { recursive: true, force: true });
242
- }
243
-
244
- if (!fs.existsSync(destDir)) {
245
- try {
246
- fs.mkdirSync(destDir);
247
-
248
- if (fs.existsSync(`${srcPathTwigComponent}/${componentName}.twig`)) {
249
- fs.copyFileSync(`${srcPathTwigComponent}/${componentName}.twig`, `${destDir}${componentName}.twig`);
250
- }
251
-
252
- if (fs.existsSync(`${srcPathScssComponent}/${componentName}/${componentName}.scss`)) {
253
- fs.copyFileSync(`${srcPathScssComponent}/${componentName}/${componentName}.scss`, `${destDir}${componentName}.scss`);
254
-
255
- // Check and copy the -extra.scss file if it exists
256
- const extraScssPath = `${srcPathScssComponent}/${componentName}/${componentName}-extra.scss`;
257
- if (fs.existsSync(extraScssPath)) {
258
- fs.copyFileSync(extraScssPath, `${destDir}${componentName}-extra.scss`);
259
- }
260
- }
261
-
262
- if (fs.existsSync(`${srcPathJsComponent}/${componentName}/${componentName}.js`)) {
263
- fs.copyFileSync(`${srcPathJsComponent}/${componentName}/${componentName}.js`, `${destDir}${componentName}.js`);
264
- }
265
-
266
- copyBlockJson(componentName, 'component');
267
- SUCCESS = 1;
268
- } catch (e) {
269
- SUCCESS = 0;
270
- return SUCCESS;
271
- }
272
- }
273
-
274
- return SUCCESS;
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
- let SUCCESS = 0;
279
- if (fs.existsSync(destDir)) {
280
- fs.rmSync(destDir, { recursive: true, force: true });
281
- }
282
-
283
- if (!fs.existsSync(destDir)) {
284
- try {
285
- fs.mkdirSync(destDir);
286
-
287
- if (fs.existsSync(`${srcPathJsFields}/${fieldsName}/${fieldsName}.js`)) {
288
- fs.copyFileSync(`${srcPathJsFields}/${fieldsName}/${fieldsName}.js`, `${destDir}${fieldsName}.js`);
289
- }
290
-
291
- if (fs.existsSync(`${srcPathPhpFields}/${fieldsName}.php`)) {
292
- fs.copyFileSync(`${srcPathPhpFields}/${fieldsName}.php`, `${destDir}${fieldsName}.php`);
293
- }
294
-
295
- if (fs.existsSync(`${srcPathTwigFields}/${fieldsName}.twig`)) {
296
- fs.copyFileSync(`${srcPathTwigFields}/${fieldsName}.twig`, `${destDir}${fieldsName}.twig`);
297
- }
298
-
299
- if (fs.existsSync(`${srcPathScssFields}/${fieldsName}/${fieldsName}.scss`)) {
300
- fs.copyFileSync(`${srcPathScssFields}/${fieldsName}/${fieldsName}.scss`, `${destDir}${fieldsName}.scss`);
301
- }
302
-
303
- copyBlockJson(fieldsName, 'fields');
304
- SUCCESS = 1;
305
- } catch (e) {
306
- SUCCESS = 0;
307
- return SUCCESS;
308
- }
309
- }
310
-
311
- return SUCCESS;
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
- let SUCCESS = 0;
316
- if (fs.existsSync(destDir)) {
317
- fs.rmSync(destDir, { recursive: true, force: true });
318
- }
319
-
320
- if (!fs.existsSync(destDir)) {
321
- try {
322
- fs.mkdirSync(destDir);
323
-
324
- if (fs.existsSync(`${srcPathCssController}${controllerName}.css`)) {
325
- fs.copyFileSync(
326
- `${srcPathCssController}${controllerName}.css`,
327
- `${destDir}${controllerName}.css`
328
- );
329
- }
330
-
331
- if (fs.existsSync(`${srcPathPhpController}${controllerName}.php`)) {
332
- fs.copyFileSync(
333
- `${srcPathPhpController}${controllerName}.php`,
334
- `${destDir}${controllerName}.php`
335
- );
336
- }
337
-
338
- if (fs.existsSync(`${srcPathTwigController}${controllerName}.twig`)) {
339
- fs.copyFileSync(
340
- `${srcPathTwigController}${controllerName}.twig`,
341
- `${destDir}${controllerName}.twig`
342
- );
343
- }
344
-
345
- SUCCESS = 1;
346
- } catch (e) {
347
- console.error(e);
348
- SUCCESS = 0;
349
- }
350
- }
351
-
352
- return SUCCESS;
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
- let SUCCESS = 0;
357
- if (fs.existsSync(destDir)) {
358
- fs.rmSync(destDir, { recursive: true, force: true });
359
- }
360
-
361
- if (!fs.existsSync(destDir)) {
362
- try {
363
- fs.mkdirSync(destDir);
364
-
365
- if (fs.existsSync(`${srcPathPhpSecurity}/${securityName}.php`)) {
366
- fs.copyFileSync(
367
- `${srcPathPhpSecurity}/${securityName}.php`,
368
- `${destDir}${securityName}.php`
369
- );
370
- }
371
-
372
- SUCCESS = 1;
373
- } catch (e) {
374
- console.error(e);
375
- SUCCESS = 0;
376
- }
377
- }
378
-
379
- return SUCCESS;
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
- let SUCCESS = 0;
384
- if (fs.existsSync(destDir)) {
385
- fs.rmSync(destDir, { recursive: true, force: true });
386
- }
387
-
388
- if (!fs.existsSync(destDir)) {
389
- try {
390
- fs.mkdirSync(destDir);
391
-
392
- if (fs.existsSync(`${srcPathPhpSeopress}/${seopressName}.php`)) {
393
- fs.copyFileSync(
394
- `${srcPathPhpSeopress}/${seopressName}.php`,
395
- `${destDir}${seopressName}.php`
396
- );
397
- }
398
-
399
- SUCCESS = 1;
400
- } catch (e) {
401
- console.error(e);
402
- SUCCESS = 0;
403
- }
404
- }
405
-
406
- return SUCCESS;
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
- const existingAcfFiles = globSync(`${themePath}/acf-json/*.json`);
412
-
413
- const typeMapping = {
414
- block: ['Block: '],
415
- component: ['Component: '],
416
- fields: ['Fields: ', 'Options: '],
417
- };
418
-
419
- existingAcfFiles.forEach((file) => {
420
- let rawdata = fs.readFileSync(file);
421
- let blockData = JSON.parse(rawdata);
422
- const title = (typeMapping[type] || []).reduce((acc, replaceValue) => {
423
- return acc.replace(replaceValue, '');
424
- }, blockData.title)
425
- .replace(' - Library', '')
426
- .replaceAll(' ', '-')
427
- .toLowerCase();
428
-
429
- if (title === name) {
430
- const fileName = path.basename(file);
431
- fs.copyFileSync(
432
- file,
433
- `${destPath}${type}-${name}/${fileName}`
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@total_onion/onion-library",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "description": "Component library",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -216,7 +216,10 @@ const copyCoreComponent = (componentName) => {
216
216
 
217
217
  switch (fileType) {
218
218
  case 'php':
219
- copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
219
+ copyFile(
220
+ `${sourceDir}/${file}`,
221
+ `./project-setup/core-functions/${file}`
222
+ );
220
223
  break;
221
224
  case 'js':
222
225
  copyFile(
@@ -215,7 +215,10 @@ const copyCoreComponent = (componentName) => {
215
215
 
216
216
  switch (fileType) {
217
217
  case 'php':
218
- copyFile(`${sourceDir}/${file}`, `./inc/admin-extras/${file}`);
218
+ copyFile(
219
+ `${sourceDir}/${file}`,
220
+ `./inc/project-setup/core-functions/${file}`
221
+ );
219
222
  break;
220
223
  // case 'js':
221
224
  // copyFile(
@@ -256,7 +259,7 @@ const copyFieldsComponent = (componentName) => {
256
259
 
257
260
  switch (fileType) {
258
261
  case 'php':
259
- copyFile(`${sourceDir}/${file}`, `./inc/admin-extras/${file}`);
262
+ copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
260
263
  break;
261
264
  // case 'js':
262
265
  // copyFile(
@@ -311,7 +314,7 @@ const copyComponentComponent = (componentName) => {
311
314
 
312
315
  switch (fileType) {
313
316
  case 'php':
314
- copyFile(`${sourceDir}/${file}`, `./inc/admin-extras/${file}`);
317
+ copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
315
318
  break;
316
319
  // case 'js':
317
320
  // copyFile(
@@ -410,7 +413,7 @@ const copyAdminComponent = (componentName) => {
410
413
 
411
414
  switch (fileType) {
412
415
  case 'php':
413
- copyFile(`${sourceDir}/${file}`, `./inc/admin-extras/${file}`);
416
+ copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
414
417
  break;
415
418
  }
416
419
  });