@total_onion/onion-library 2.0.5 → 2.0.7
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/createNewChildBlock2.js
CHANGED
|
@@ -3,6 +3,8 @@ const fs = require('fs');
|
|
|
3
3
|
const {globSync} = require('glob');
|
|
4
4
|
const {exec} = require('child_process');
|
|
5
5
|
const acfTemplate = require('./new-block-templates/template-acf-pattern');
|
|
6
|
+
const acfTemplateScss = require('@total_onion/onion-library/new-block-templates/template-scss-blank');
|
|
7
|
+
const acfTemplateJs = require('@total_onion/onion-library/new-block-templates/template-js-blank');
|
|
6
8
|
const yaml = require('js-yaml');
|
|
7
9
|
const axios = require('axios');
|
|
8
10
|
|
|
@@ -67,9 +69,9 @@ fs.writeFileSync(
|
|
|
67
69
|
|
|
68
70
|
const blockName = 'group-container-v3';
|
|
69
71
|
|
|
70
|
-
console.log(`${srcPathJs}/block-${blockName}/${blockName}.js`);
|
|
71
|
-
console.log('__dirname:', __dirname);
|
|
72
|
-
console.log('process.cwd():', process.cwd());
|
|
72
|
+
// console.log(`${srcPathJs}/block-${blockName}/${blockName}.js`);
|
|
73
|
+
// console.log('__dirname:', __dirname);
|
|
74
|
+
// console.log('process.cwd():', process.cwd());
|
|
73
75
|
|
|
74
76
|
const fullPath = `${srcPathJs}/block-${blockName}/${blockName}.js`;
|
|
75
77
|
|
|
@@ -82,65 +84,20 @@ const scssdir = `Assets/scss/blocks/`;
|
|
|
82
84
|
// fs.mkdirSync(scssdir, 0o744);
|
|
83
85
|
// }
|
|
84
86
|
|
|
85
|
-
if (fs.existsSync(`${
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
`${srcPathJs}/block-${blockName}/${blockName}.js`,
|
|
90
|
-
'utf-8',
|
|
91
|
-
(err, contents) => {
|
|
92
|
-
if (err) throw err;
|
|
93
|
-
const regEx = RegExp(
|
|
94
|
-
String.raw`(${blockName.replaceAll(/( |-)/g, '')})`,
|
|
95
|
-
'gi'
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const replaced = contents
|
|
99
|
-
.replaceAll(
|
|
100
|
-
regEx,
|
|
101
|
-
`${newBlockName.toLowerCase().replaceAll(/( |-)/g, '')}`
|
|
102
|
-
)
|
|
103
|
-
.replaceAll(
|
|
104
|
-
`blocks/${blockName}/${blockName}-extra`,
|
|
105
|
-
`blocks/${newBlockName}/${newBlockName}-extra`
|
|
106
|
-
);
|
|
107
|
-
fs.writeFile(
|
|
108
|
-
`${jsdir}/${newBlockName}.js`,
|
|
109
|
-
replaced,
|
|
110
|
-
'utf-8',
|
|
111
|
-
function (err) {
|
|
112
|
-
if (err) throw err;
|
|
113
|
-
console.log(
|
|
114
|
-
`👑👑\x1b[32m Successfully duplicated the js file! 👑👑`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
}
|
|
87
|
+
if (!fs.existsSync(`${jsdir}/${newBlockName}.js`)) {
|
|
88
|
+
fs.writeFileSync(
|
|
89
|
+
`${jsdir}/${newBlockName}.js`,
|
|
90
|
+
acfTemplateJs(newBlockName)
|
|
119
91
|
);
|
|
92
|
+
console.log(`👑👑\x1b[32m Successfully created the js file! 👑👑`);
|
|
120
93
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
(
|
|
126
|
-
if (err) throw err;
|
|
127
|
-
const replaced = contents.replaceAll(
|
|
128
|
-
`${blockName}`,
|
|
129
|
-
`${newBlockName}`
|
|
130
|
-
);
|
|
131
|
-
fs.writeFile(
|
|
132
|
-
`${scssdir}/${newBlockName}.scss`,
|
|
133
|
-
replaced,
|
|
134
|
-
'utf-8',
|
|
135
|
-
function (err) {
|
|
136
|
-
if (err) throw err;
|
|
137
|
-
console.log(
|
|
138
|
-
`👑👑\x1b[32m Successfully duplicated the scss file! 👑👑`
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
}
|
|
94
|
+
|
|
95
|
+
if (!fs.existsSync(`${scssdir}/${newBlockName}.scss`)) {
|
|
96
|
+
fs.writeFileSync(
|
|
97
|
+
`${scssdir}/${newBlockName}.scss`,
|
|
98
|
+
acfTemplateScss(newBlockName)
|
|
143
99
|
);
|
|
100
|
+
console.log(`👑👑\x1b[32m Successfully created the scss file! 👑👑`);
|
|
144
101
|
}
|
|
145
102
|
|
|
146
103
|
let data = new FormData();
|
|
@@ -174,7 +131,7 @@ axios.post(parentURL, data, headers).then(function (response) {
|
|
|
174
131
|
regEx,
|
|
175
132
|
`${newBlockName.toLowerCase().replaceAll(/( |-)/g, '')}`
|
|
176
133
|
)
|
|
177
|
-
.
|
|
134
|
+
.replace(/(?<!sub-)group-container-v3/g, `${newBlockName}`);
|
|
178
135
|
fs.writeFile(
|
|
179
136
|
`${themePath}/views/blocks/${newBlockName}.twig`,
|
|
180
137
|
replaced,
|
|
@@ -182,14 +139,13 @@ axios.post(parentURL, data, headers).then(function (response) {
|
|
|
182
139
|
function (err) {
|
|
183
140
|
if (err) throw err;
|
|
184
141
|
console.log(
|
|
185
|
-
`👑👑\x1b[32m Successfully
|
|
142
|
+
`👑👑\x1b[32m Successfully did searcha and replace on the twig file! 👑👑`
|
|
143
|
+
);
|
|
144
|
+
console.log(
|
|
145
|
+
`👑 👑 👑 Hurrah! You made a new child block called ${newBlockName} 👑 👑 👑`
|
|
186
146
|
);
|
|
187
147
|
}
|
|
188
148
|
);
|
|
189
149
|
}
|
|
190
150
|
);
|
|
191
151
|
});
|
|
192
|
-
|
|
193
|
-
console.log(
|
|
194
|
-
`👑 👑 👑 Hurrah! You made a new child block called ${newBlockName} 👑 👑 👑`
|
|
195
|
-
);
|