@total_onion/onion-library 3.0.10 → 3.0.11
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/install-component.js +5 -11
- package/package.json +1 -1
- package/update-component.js +471 -480
package/install-component.js
CHANGED
|
@@ -150,7 +150,11 @@ if (
|
|
|
150
150
|
`${libraryPath}/components/${componentName}/${componentModuleName}.php`
|
|
151
151
|
)
|
|
152
152
|
) {
|
|
153
|
-
if (
|
|
153
|
+
if (
|
|
154
|
+
componentType === 'admin' ||
|
|
155
|
+
componentType === 'fields' ||
|
|
156
|
+
componentType === 'core'
|
|
157
|
+
) {
|
|
154
158
|
fs.copyFileSync(
|
|
155
159
|
`${libraryPath}/components/${componentName}/${componentModuleName}.php`,
|
|
156
160
|
`./web/wp-content/themes/global-theme/inc/custom-extras/${componentModuleName}.php`
|
|
@@ -168,16 +172,6 @@ if (
|
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
|
|
171
|
-
if (
|
|
172
|
-
fs.existsSync(
|
|
173
|
-
`${libraryPath}/components/${componentName}/${componentModuleName}.vue`
|
|
174
|
-
)
|
|
175
|
-
) {
|
|
176
|
-
fs.copyFileSync(
|
|
177
|
-
`${libraryPath}/components/${componentName}/${componentModuleName}.vue`,
|
|
178
|
-
`./web/wp-content/themes/global-theme/views/blocks/${componentModuleName}.vue`
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
175
|
if (
|
|
182
176
|
fs.existsSync(
|
|
183
177
|
`${libraryPath}/components/${componentName}/${componentModuleName}.cy.js`
|
package/package.json
CHANGED
package/update-component.js
CHANGED
|
@@ -1,543 +1,534 @@
|
|
|
1
1
|
const themePath =
|
|
2
|
-
process.env.THEME_PATH || 'web/wp-content/themes/global-theme'
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const libraryPath =
|
|
6
|
-
'./node_modules/@total_onion/onion-library'
|
|
7
|
-
|
|
2
|
+
process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const libraryPath = './node_modules/@total_onion/onion-library';
|
|
8
6
|
|
|
9
7
|
// Get extension of filename
|
|
10
8
|
const getExtension = (filename) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
9
|
+
var ext = path.extname(filename || '').split('.');
|
|
10
|
+
return ext[ext.length - 1];
|
|
11
|
+
};
|
|
14
12
|
|
|
15
13
|
const getFileType = (filename) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
14
|
+
if (filename.endsWith('-extra.scss')) {
|
|
15
|
+
return 'extra';
|
|
16
|
+
} else if (filename.endsWith('spec.js')) {
|
|
17
|
+
return 'spec';
|
|
18
|
+
} else {
|
|
19
|
+
return getExtension(filename);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
24
22
|
|
|
25
23
|
const getProjectName = () => {
|
|
26
|
-
|
|
24
|
+
let projectName = 'Global Theme';
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
try {
|
|
27
|
+
const packageFile = fs.readFileSync('./package.json');
|
|
28
|
+
const projectJson = JSON.parse(packageFile);
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
if (projectJson) {
|
|
31
|
+
projectName = projectJson.name;
|
|
32
|
+
if (projectName.slice(0, 3) === 'the') {
|
|
33
|
+
const prefix =
|
|
36
34
|
projectName.slice(0, 3).charAt(0).toUpperCase() +
|
|
37
|
-
projectName.slice(0, 3).slice(1)
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
projectName.slice(0, 3).slice(1);
|
|
36
|
+
projectName = `${prefix} ${
|
|
37
|
+
projectName.slice(3).charAt(0).toUpperCase() +
|
|
40
38
|
projectName.slice(3).slice(1)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
39
|
+
}`;
|
|
40
|
+
} else {
|
|
41
|
+
projectName = `${
|
|
42
|
+
projectName.charAt(0).toUpperCase() + projectName.slice(1)
|
|
43
|
+
}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error.code === 'ENOENT') {
|
|
48
|
+
console.error('The file does not exist.');
|
|
49
|
+
} else {
|
|
50
|
+
console.error('An error occurred while reading the file:');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return projectName;
|
|
54
|
+
};
|
|
57
55
|
|
|
58
56
|
const checkFolder = (srcFolder) => {
|
|
59
|
-
|
|
60
|
-
}
|
|
57
|
+
return fs.existsSync(srcFolder) && fs.statSync(srcFolder).isDirectory();
|
|
58
|
+
};
|
|
61
59
|
|
|
62
60
|
const checkComponentName = (srcFolder) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
61
|
+
if (!checkFolder(srcFolder)) {
|
|
62
|
+
console.log(
|
|
63
|
+
'\x1b[35m',
|
|
64
|
+
'😞 Hmmm that failed.. Probably you misspelled the component name'
|
|
65
|
+
);
|
|
66
|
+
process.exit();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
71
69
|
|
|
72
70
|
const copyFile = (sourceFilePath, destinationFilePath) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
71
|
+
// Check if the destination folder exists, if not, create it
|
|
72
|
+
const destinationFolder = path.dirname(destinationFilePath);
|
|
73
|
+
if (!fs.existsSync(destinationFolder)) {
|
|
74
|
+
fs.mkdirSync(destinationFolder, {recursive: true});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fs.copyFile(sourceFilePath, destinationFilePath, (err) => {
|
|
78
|
+
if (err) {
|
|
79
|
+
console.error('Error copying the file:', err);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
};
|
|
85
83
|
|
|
86
84
|
const copyFileKeeping = (sourceFilePath, destinationFilePath) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
85
|
+
// Check if the destination folder exists, if not, create it
|
|
86
|
+
const destinationFolder = path.dirname(destinationFilePath);
|
|
87
|
+
if (!fs.existsSync(destinationFolder)) {
|
|
88
|
+
fs.mkdirSync(destinationFolder, {recursive: true});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fs.access(destinationFilePath, fs.constants.F_OK, (err) => {
|
|
92
|
+
if (err) {
|
|
93
|
+
// Copy the file from source to destination if it doesn't exist
|
|
94
|
+
fs.copyFile(sourceFilePath, destinationFilePath, (err) => {
|
|
95
|
+
if (err) {
|
|
96
|
+
console.error('Error copying the file:', err);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
};
|
|
105
103
|
|
|
106
104
|
const copySubdirectory = (sourceDir, componentModuleName) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
105
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
106
|
+
const fileType = getFileType(file);
|
|
107
|
+
switch (fileType) {
|
|
108
|
+
case 'vue':
|
|
109
|
+
copyFile(
|
|
110
|
+
`${sourceDir}/${file}`,
|
|
111
|
+
`./assets/vue/blocks/${componentModuleName}/${file}`
|
|
112
|
+
);
|
|
113
|
+
break;
|
|
114
|
+
case 'twig':
|
|
115
|
+
copyFile(
|
|
116
|
+
`${sourceDir}/${file}`,
|
|
117
|
+
`./views/blocks/${componentModuleName}/${file}`
|
|
118
|
+
);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
};
|
|
125
123
|
|
|
126
124
|
// Copies all the "block" component files
|
|
127
125
|
const copyBlockComponent = (componentName) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
126
|
+
const componentModuleName = componentName.substring(6);
|
|
127
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
128
|
+
checkComponentName(`${sourceDir}/`);
|
|
129
|
+
|
|
130
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
131
|
+
if (file === componentModuleName) {
|
|
132
|
+
copySubdirectory(
|
|
133
|
+
`${sourceDir}/${componentModuleName}`,
|
|
134
|
+
componentModuleName
|
|
135
|
+
);
|
|
136
|
+
} else {
|
|
137
|
+
const fileType = getFileType(file);
|
|
138
|
+
switch (fileType) {
|
|
139
|
+
case 'php':
|
|
140
|
+
copyFile(
|
|
141
|
+
`${sourceDir}/${file}`,
|
|
142
|
+
`./inc/acf-blocks/${file}`
|
|
143
|
+
);
|
|
144
|
+
break;
|
|
145
|
+
case 'js':
|
|
146
|
+
if (file.includes('-extra.js')) {
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
copyFile(
|
|
150
|
+
`${sourceDir}/${file}`,
|
|
151
|
+
`./assets/js/blocks/${file}`
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const extraJsFile = `${componentModuleName}-extra.js`;
|
|
155
|
+
const extraJsSourcePath = `${sourceDir}/${extraJsFile}`;
|
|
156
|
+
const extraJsDestinationPath = `./assets/js/blocks/${componentModuleName}/${extraJsFile}`;
|
|
157
|
+
|
|
158
|
+
if (fs.existsSync(extraJsSourcePath)) {
|
|
159
|
+
console.log(`Found extra JS file: ${extraJsFile}`);
|
|
160
|
+
if (
|
|
161
|
+
!fs.existsSync(
|
|
162
|
+
`./assets/js/blocks/${componentModuleName}`
|
|
163
|
+
)
|
|
164
|
+
) {
|
|
165
|
+
fs.mkdirSync(
|
|
166
|
+
`./assets/js/blocks/${componentModuleName}`,
|
|
167
|
+
{recursive: true}
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
copyFileKeeping(
|
|
171
|
+
extraJsSourcePath,
|
|
172
|
+
extraJsDestinationPath
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
|
|
177
|
+
case 'scss':
|
|
178
|
+
copyFile(
|
|
179
|
+
`${sourceDir}/${file}`,
|
|
180
|
+
`./assets/scss/blocks/${file}`
|
|
181
|
+
);
|
|
182
|
+
break;
|
|
183
|
+
case 'json':
|
|
184
|
+
copyFile(`${sourceDir}/${file}`, `./acf-json/${file}`);
|
|
185
|
+
break;
|
|
186
|
+
case 'twig':
|
|
187
|
+
copyFile(`${sourceDir}/${file}`, `./views/blocks/${file}`);
|
|
188
|
+
break;
|
|
189
|
+
case 'vue':
|
|
190
|
+
copyFile(
|
|
191
|
+
`${sourceDir}/${file}`,
|
|
192
|
+
`./assets/vue/blocks/${file}`
|
|
193
|
+
);
|
|
194
|
+
break;
|
|
195
|
+
case 'extra':
|
|
196
|
+
copyFileKeeping(
|
|
197
|
+
`${sourceDir}/${file}`,
|
|
198
|
+
`./assets/scss/blocks/${componentModuleName}/${file}`
|
|
199
|
+
);
|
|
200
|
+
break;
|
|
201
|
+
case 'spec':
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
};
|
|
199
207
|
|
|
200
208
|
// Copies all the "core" component files
|
|
201
209
|
const copyCoreComponent = (componentName) => {
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
210
|
+
const componentModuleName = componentName.substring(5);
|
|
211
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
212
|
+
checkComponentName(`${sourceDir}/`);
|
|
213
|
+
|
|
214
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
215
|
+
const fileType = getFileType(file);
|
|
216
|
+
|
|
217
|
+
switch (fileType) {
|
|
218
|
+
case 'php':
|
|
219
|
+
copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
|
|
220
|
+
break;
|
|
221
|
+
case 'js':
|
|
222
|
+
copyFile(
|
|
223
|
+
`${sourceDir}/${file}`,
|
|
224
|
+
`./assets/js/modules/library-modules/${componentName}/${file}`
|
|
225
|
+
);
|
|
226
|
+
break;
|
|
227
|
+
case 'scss':
|
|
228
|
+
copyFile(
|
|
229
|
+
`${sourceDir}/${file}`,
|
|
230
|
+
`./assets/scss/modules/library-modules/${componentName}/${file}`
|
|
231
|
+
);
|
|
232
|
+
break;
|
|
233
|
+
case 'json':
|
|
234
|
+
copyFile(`${sourceDir}/${file}`, `./acf-json/${file}`);
|
|
235
|
+
break;
|
|
236
|
+
case 'twig':
|
|
237
|
+
break;
|
|
238
|
+
case 'vue':
|
|
239
|
+
break;
|
|
240
|
+
case 'extra':
|
|
241
|
+
// use copyFileKeeping
|
|
242
|
+
break;
|
|
243
|
+
case 'spec':
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
};
|
|
240
248
|
|
|
241
249
|
// Copies all the "fields" component files
|
|
242
250
|
const copyFieldsComponent = (componentName) => {
|
|
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
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
251
|
+
const componentModuleName = componentName.substring(7);
|
|
252
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
253
|
+
checkComponentName(`${sourceDir}/`);
|
|
254
|
+
|
|
255
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
256
|
+
const fileType = getFileType(file);
|
|
257
|
+
|
|
258
|
+
switch (fileType) {
|
|
259
|
+
case 'php':
|
|
260
|
+
copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
|
|
261
|
+
break;
|
|
262
|
+
case 'js':
|
|
263
|
+
copyFile(
|
|
264
|
+
`${sourceDir}/${file}`,
|
|
265
|
+
`./assets/js/modules/library-modules/${componentModuleName}/${file}`
|
|
266
|
+
);
|
|
267
|
+
break;
|
|
268
|
+
case 'scss':
|
|
269
|
+
copyFile(
|
|
270
|
+
`${sourceDir}/${file}`,
|
|
271
|
+
`./assets/scss/modules/library-modules/${componentModuleName}/${file}`
|
|
272
|
+
);
|
|
273
|
+
break;
|
|
274
|
+
case 'json':
|
|
275
|
+
copyFile(`${sourceDir}/${file}`, `./acf-json/${file}`);
|
|
276
|
+
break;
|
|
277
|
+
case 'twig':
|
|
278
|
+
copyFile(`${sourceDir}/${file}`, `./views/components/${file}`);
|
|
279
|
+
break;
|
|
280
|
+
case 'svg':
|
|
281
|
+
case 'png':
|
|
282
|
+
case 'webp':
|
|
283
|
+
case 'jpeg':
|
|
284
|
+
const destinationFolder = './assets/images/library-images';
|
|
285
|
+
if (!fs.existsSync(destinationFolder)) {
|
|
286
|
+
fs.mkdirSync(destinationFolder, {recursive: true});
|
|
287
|
+
}
|
|
288
|
+
copyFile(
|
|
289
|
+
`${sourceDir}/${file}`,
|
|
290
|
+
`${destinationFolder}/${file}`
|
|
291
|
+
);
|
|
292
|
+
break;
|
|
293
|
+
case 'vue':
|
|
294
|
+
break;
|
|
295
|
+
case 'extra':
|
|
296
|
+
// use copyFileKeeping
|
|
297
|
+
break;
|
|
298
|
+
case 'spec':
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
};
|
|
292
303
|
|
|
293
304
|
// Copies all the "component" component files
|
|
294
305
|
const copyComponentComponent = (componentName) => {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
}
|
|
306
|
+
const componentModuleName = componentName.substring(10);
|
|
307
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
308
|
+
checkComponentName(`${sourceDir}/`);
|
|
309
|
+
|
|
310
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
311
|
+
const fileType = getFileType(file);
|
|
312
|
+
|
|
313
|
+
switch (fileType) {
|
|
314
|
+
case 'php':
|
|
315
|
+
copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
|
|
316
|
+
break;
|
|
317
|
+
case 'js':
|
|
318
|
+
copyFile(
|
|
319
|
+
`${sourceDir}/${file}`,
|
|
320
|
+
`./assets/js/modules/library-modules/${componentModuleName}/${file}`
|
|
321
|
+
);
|
|
322
|
+
break;
|
|
323
|
+
case 'scss':
|
|
324
|
+
copyFile(
|
|
325
|
+
`${sourceDir}/${file}`,
|
|
326
|
+
`./assets/scss/modules/library-modules/${componentModuleName}/${file}`
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
const extraScssPath = `${sourceDir}/${componentModuleName}-extra.scss`;
|
|
330
|
+
if (fs.existsSync(extraScssPath)) {
|
|
331
|
+
copyFileKeeping(
|
|
332
|
+
extraScssPath,
|
|
333
|
+
`./assets/scss/modules/library-modules/${componentModuleName}/${componentModuleName}-extra.scss`
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
case 'json':
|
|
338
|
+
copyFile(`${sourceDir}/${file}`, `./acf-json/${file}`);
|
|
339
|
+
break;
|
|
340
|
+
case 'twig':
|
|
341
|
+
copyFile(`${sourceDir}/${file}`, `./views/components/${file}`);
|
|
342
|
+
break;
|
|
343
|
+
case 'svg':
|
|
344
|
+
case 'png':
|
|
345
|
+
case 'webp':
|
|
346
|
+
case 'jpeg':
|
|
347
|
+
const destinationFolder = './assets/images/library-images';
|
|
348
|
+
if (!fs.existsSync(destinationFolder)) {
|
|
349
|
+
fs.mkdirSync(destinationFolder, {recursive: true});
|
|
350
|
+
}
|
|
351
|
+
copyFile(
|
|
352
|
+
`${sourceDir}/${file}`,
|
|
353
|
+
`${destinationFolder}/${file}`
|
|
354
|
+
);
|
|
355
|
+
break;
|
|
356
|
+
case 'vue':
|
|
357
|
+
break;
|
|
358
|
+
case 'extra':
|
|
359
|
+
break;
|
|
360
|
+
case 'spec':
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
};
|
|
352
365
|
|
|
353
366
|
// Copies all the "entrypoint" component files
|
|
354
367
|
const copyEntrypointComponent = (componentName) => {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
368
|
+
const componentModuleName = componentName.substring(7);
|
|
369
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
370
|
+
checkComponentName(`${sourceDir}/`);
|
|
371
|
+
|
|
372
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
373
|
+
const fileType = getFileType(file);
|
|
374
|
+
|
|
375
|
+
switch (fileType) {
|
|
376
|
+
case 'twig':
|
|
377
|
+
copyFile(
|
|
378
|
+
`${sourceDir}/${file}`,
|
|
379
|
+
`./views/entry-points/${file}`
|
|
380
|
+
);
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
};
|
|
372
385
|
|
|
373
386
|
// Copies all the "cache" component files
|
|
374
387
|
const copyCacheComponent = (componentName) => {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
})
|
|
391
|
-
}
|
|
388
|
+
const componentModuleName = componentName.substring(7);
|
|
389
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
390
|
+
checkComponentName(`${sourceDir}/`);
|
|
391
|
+
|
|
392
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
393
|
+
const fileType = getFileType(file);
|
|
394
|
+
|
|
395
|
+
switch (fileType) {
|
|
396
|
+
case 'php':
|
|
397
|
+
copyFile(`${sourceDir}/${file}`, `./inc/custom-caches/${file}`);
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
};
|
|
392
402
|
|
|
393
403
|
// Copies all the "admin" component files
|
|
394
404
|
const copyAdminComponent = (componentName) => {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
405
|
+
const componentModuleName = componentName.substring(6);
|
|
406
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
407
|
+
checkComponentName(`${sourceDir}/`);
|
|
408
|
+
|
|
409
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
410
|
+
const fileType = getFileType(file);
|
|
411
|
+
|
|
412
|
+
switch (fileType) {
|
|
413
|
+
case 'php':
|
|
414
|
+
copyFile(`${sourceDir}/${file}`, `./inc/custom-extras/${file}`);
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
};
|
|
409
419
|
|
|
410
420
|
// Copies all the "controller" component files
|
|
411
421
|
const copyControllerComponent = (componentName) => {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
break;
|
|
432
|
-
case 'php':
|
|
433
|
-
copyFile(
|
|
434
|
-
`${sourceDir}/${file}`,
|
|
435
|
-
`./controller/${file}`
|
|
436
|
-
);
|
|
437
|
-
break;
|
|
438
|
-
}
|
|
439
|
-
});
|
|
422
|
+
const componentModuleName = componentName.substring(11);
|
|
423
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
424
|
+
checkComponentName(`${sourceDir}/`);
|
|
425
|
+
|
|
426
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
427
|
+
const fileType = getFileType(file);
|
|
428
|
+
|
|
429
|
+
switch (fileType) {
|
|
430
|
+
case 'css':
|
|
431
|
+
copyFile(`${sourceDir}/${file}`, `./assets/css/${file}`);
|
|
432
|
+
break;
|
|
433
|
+
case 'twig':
|
|
434
|
+
copyFile(`${sourceDir}/${file}`, `./views/components/${file}`);
|
|
435
|
+
break;
|
|
436
|
+
case 'php':
|
|
437
|
+
copyFile(`${sourceDir}/${file}`, `./controller/${file}`);
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
});
|
|
440
441
|
};
|
|
441
442
|
|
|
442
443
|
// Copies all the "security" component files
|
|
443
444
|
const copySecurityComponent = (componentName) => {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
});
|
|
445
|
+
const componentModuleName = componentName.substring(9);
|
|
446
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
447
|
+
checkComponentName(`${sourceDir}/`);
|
|
448
|
+
|
|
449
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
450
|
+
if (getFileType(file) === 'php') {
|
|
451
|
+
copyFile(`${sourceDir}/${file}`, `./inc/security-extras/${file}`);
|
|
452
|
+
}
|
|
453
|
+
});
|
|
456
454
|
};
|
|
457
455
|
|
|
458
456
|
// Copies all the "seopress" component files
|
|
459
457
|
const copySeopressComponent = (componentName) => {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
});
|
|
458
|
+
const componentModuleName = componentName.substring(9);
|
|
459
|
+
const sourceDir = `${libraryPath}/components/${componentName}`;
|
|
460
|
+
checkComponentName(`${sourceDir}/`);
|
|
461
|
+
|
|
462
|
+
fs.readdirSync(`${sourceDir}/`).forEach((file) => {
|
|
463
|
+
if (getFileType(file) === 'php') {
|
|
464
|
+
copyFile(`${sourceDir}/${file}`, `./inc/seo-extras/${file}`);
|
|
465
|
+
}
|
|
466
|
+
});
|
|
472
467
|
};
|
|
473
468
|
|
|
474
|
-
|
|
475
469
|
const updateComponent = () => {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
`👑 👑 👑 Hurrah! You successfully updated ${componentName} 👑 👑 👑`
|
|
522
|
-
)
|
|
523
|
-
}
|
|
470
|
+
projectName = getProjectName();
|
|
471
|
+
|
|
472
|
+
const componentName = process.argv[2]?.toLocaleLowerCase();
|
|
473
|
+
|
|
474
|
+
if (!componentName) {
|
|
475
|
+
console.log(
|
|
476
|
+
'\x1b[35m',
|
|
477
|
+
'😞 Hmmm that failed.. Did you forget to include the component name?'
|
|
478
|
+
);
|
|
479
|
+
process.exit();
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (componentName.split('-')[0] === 'block') {
|
|
483
|
+
copyBlockComponent(componentName);
|
|
484
|
+
} else if (componentName.split('-')[0] === 'core') {
|
|
485
|
+
copyCoreComponent(componentName);
|
|
486
|
+
} else if (componentName.split('-')[0] === 'fields') {
|
|
487
|
+
copyFieldsComponent(componentName);
|
|
488
|
+
} else if (componentName.split('-')[0] === 'component') {
|
|
489
|
+
copyComponentComponent(componentName);
|
|
490
|
+
} else if (componentName.split('-')[0] === 'admin') {
|
|
491
|
+
copyAdminComponent(componentName);
|
|
492
|
+
} else if (componentName.split('-')[0] === 'entrypoint') {
|
|
493
|
+
copyEntrypointComponent(componentName);
|
|
494
|
+
} else if (componentName.split('-')[0] === 'cache') {
|
|
495
|
+
copyCacheComponent(componentName);
|
|
496
|
+
} else if (componentName.split('-')[0] === 'controller') {
|
|
497
|
+
copyControllerComponent(componentName);
|
|
498
|
+
} else if (componentName.split('-')[0] === 'security') {
|
|
499
|
+
copySecurityComponent(componentName);
|
|
500
|
+
} else if (componentName.split('-')[0] === 'seopress') {
|
|
501
|
+
copySeopressComponent(componentName);
|
|
502
|
+
} else {
|
|
503
|
+
console.error(
|
|
504
|
+
'\x1b[35m',
|
|
505
|
+
`😞 Hmmm that failed.. ${componentName} Has the wrong component prefix (block, admin, core, fields, entrypoint, cache, component)`
|
|
506
|
+
);
|
|
507
|
+
process.exit();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
console.log(
|
|
511
|
+
'\x1b[32m',
|
|
512
|
+
`👑 👑 👑 Hurrah! You successfully updated ${componentName} 👑 👑 👑`
|
|
513
|
+
);
|
|
514
|
+
};
|
|
524
515
|
|
|
525
516
|
module.exports = {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
517
|
+
getExtension,
|
|
518
|
+
getFileType,
|
|
519
|
+
checkFolder,
|
|
520
|
+
copyFile,
|
|
521
|
+
copyFileKeeping,
|
|
522
|
+
getProjectName,
|
|
523
|
+
copyBlockComponent,
|
|
524
|
+
copyCoreComponent,
|
|
525
|
+
copyFieldsComponent,
|
|
526
|
+
copyComponentComponent,
|
|
527
|
+
copyAdminComponent,
|
|
528
|
+
updateComponent
|
|
529
|
+
};
|
|
539
530
|
|
|
540
531
|
// It calls the function only if executed through the command line
|
|
541
532
|
if (require.main === module) {
|
|
542
|
-
|
|
533
|
+
updateComponent();
|
|
543
534
|
}
|