new-s-block 1.0.9 → 1.1.1
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/bin/cli.js +30 -23
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -95,7 +95,7 @@ if (process.argv.includes('--version') || process.argv.includes('-v')) {
|
|
|
95
95
|
// ── Main ───────────────────────────────────────────────────────────────────
|
|
96
96
|
|
|
97
97
|
async function main() {
|
|
98
|
-
console.log('\n\uD83E\uDDF1
|
|
98
|
+
console.log('\n\uD83E\uDDF1 S-Tier Block Generator\n');
|
|
99
99
|
var updateCheck = checkForUpdate();
|
|
100
100
|
|
|
101
101
|
const rl = readline.createInterface({
|
|
@@ -134,7 +134,16 @@ async function main() {
|
|
|
134
134
|
.map(function (k) { return k.trim().toLowerCase(); })
|
|
135
135
|
.filter(Boolean);
|
|
136
136
|
|
|
137
|
-
// 6.
|
|
137
|
+
// 6. Include JS
|
|
138
|
+
var includeJs = '';
|
|
139
|
+
while (includeJs !== 'y' && includeJs !== 'n') {
|
|
140
|
+
includeJs = (await prompt(rl, 'Include block JS? (y/n): ')).trim().toLowerCase();
|
|
141
|
+
if (includeJs !== 'y' && includeJs !== 'n') {
|
|
142
|
+
console.log(' ⚠ Please answer y or n.');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 7. Blocks folder
|
|
138
147
|
const folderRaw = await prompt(rl, 'Blocks folder [blocks]: ');
|
|
139
148
|
|
|
140
149
|
rl.close();
|
|
@@ -155,6 +164,9 @@ async function main() {
|
|
|
155
164
|
const scssFile = subFolder
|
|
156
165
|
? path.join(cwd, 'assets', 'sass', 'blocks', subFolder, blockName + '.scss')
|
|
157
166
|
: path.join(cwd, 'assets', 'sass', 'blocks', blockName + '.scss');
|
|
167
|
+
const jsFile = subFolder
|
|
168
|
+
? path.join(cwd, 'assets', 'js', 'blocks', subFolder, blockName + '.js')
|
|
169
|
+
: path.join(cwd, 'assets', 'js', 'blocks', blockName + '.js');
|
|
158
170
|
|
|
159
171
|
if (fs.existsSync(blockDir)) {
|
|
160
172
|
console.error('\n\u274C Block folder already exists: ' + path.relative(cwd, blockDir) + '\n');
|
|
@@ -180,7 +192,8 @@ async function main() {
|
|
|
180
192
|
' "title": "' + blockLabel + '",\n' +
|
|
181
193
|
' "description": "' + (blockDescription.trim() || blockLabel) + ' Block",\n' +
|
|
182
194
|
' "category": "' + blockCategory + '",\n' +
|
|
183
|
-
' "
|
|
195
|
+
' "style": "file:./' + blockName + '.min.css",\n' +
|
|
196
|
+
(includeJs === 'y' ? ' "viewScript": "file:./' + blockName + '.min.js",\n' : '') +
|
|
184
197
|
' "icon": ' + JSON.stringify(svgIcon) + ',\n' +
|
|
185
198
|
' "keywords": ' + keywordsJson + ',\n' +
|
|
186
199
|
' "acf": {\n' +
|
|
@@ -199,26 +212,9 @@ async function main() {
|
|
|
199
212
|
|
|
200
213
|
const innerClass = toInnerClass(blockName);
|
|
201
214
|
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
'\n' +
|
|
205
|
-
"$class = 'st_block st_" + blockName.replace(/-/g, '_') + "';\n" +
|
|
206
|
-
"if ( ! empty( $block['className'] ) ) {\n" +
|
|
207
|
-
" $class .= ' ' . $block['className'];\n" +
|
|
208
|
-
'}\n' +
|
|
209
|
-
'\n' +
|
|
210
|
-
"$anchor = '';\n" +
|
|
211
|
-
"if ( ! empty( $block['anchor'] ) ) {\n" +
|
|
212
|
-
" $anchor = 'id=\"' . esc_attr( $block['anchor'] ) . '\" ';\n" +
|
|
213
|
-
'}\n' +
|
|
214
|
-
'\n' +
|
|
215
|
-
'if ( ! empty( $padding) ) {\n' +
|
|
216
|
-
" $class .= ' ' . $padding;\n" +
|
|
217
|
-
'}\n' +
|
|
218
|
-
'\n' +
|
|
219
|
-
'?>\n' +
|
|
220
|
-
'\n' +
|
|
221
|
-
'<section <?php echo $anchor; ?> class="<?php echo esc_attr( $class ); ?>">\n' +
|
|
215
|
+
const mainClass = 'st_' + blockName.replace(/-/g, '_');
|
|
216
|
+
const renderPhp =
|
|
217
|
+
'<section <?php echo stier_block_attrs( $block, \'' + mainClass + '\'); ?>>\n' +
|
|
222
218
|
"\t<?php get_template_part('components/background'); ?>\n" +
|
|
223
219
|
'\t<div class="container ' + innerClass + '">\n' +
|
|
224
220
|
"\t\t<?php get_template_part('components/intro'); ?>\n" +
|
|
@@ -233,6 +229,12 @@ async function main() {
|
|
|
233
229
|
|
|
234
230
|
writeFile(scssFile, scssContent);
|
|
235
231
|
|
|
232
|
+
// ── block-name.js (optional) ─────────────────────────────────────────────
|
|
233
|
+
|
|
234
|
+
if (includeJs === 'y') {
|
|
235
|
+
writeFile(jsFile, '');
|
|
236
|
+
}
|
|
237
|
+
|
|
236
238
|
// ── Summary ──────────────────────────────────────────────────────────────
|
|
237
239
|
|
|
238
240
|
var cyan = '\x1b[36m';
|
|
@@ -245,6 +247,11 @@ async function main() {
|
|
|
245
247
|
var sassDisplay = subFolder ? 'assets/sass/blocks/' + subFolder + '/' : 'assets/sass/blocks/';
|
|
246
248
|
console.log(' \uD83D\uDCC1 ' + sassDisplay);
|
|
247
249
|
console.log(' \u2514\u2500\u2500 ' + blockName + '.scss');
|
|
250
|
+
if (includeJs === 'y') {
|
|
251
|
+
var jsDisplay = subFolder ? 'assets/js/blocks/' + subFolder + '/' : 'assets/js/blocks/';
|
|
252
|
+
console.log(' \uD83D\uDCC1 ' + jsDisplay);
|
|
253
|
+
console.log(' \u2514\u2500\u2500 ' + blockName + '.js');
|
|
254
|
+
}
|
|
248
255
|
console.log('');
|
|
249
256
|
console.log(" Don't forget to add " + cyan + "register_block_type( __DIR__ . '/../blocks/" + blockRelPath + "' );" + reset + " in 'includes/template-functions.php'");
|
|
250
257
|
console.log('');
|