-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathinit-block.js
95 lines (90 loc) · 1.68 KB
/
init-block.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* External dependencies
*/
const { join } = require( 'path' );
const makeDir = require( 'make-dir' );
const { writeFile } = require( 'fs' ).promises;
/**
* Internal dependencies
*/
const { info } = require( './log' );
const { writeOutputTemplate } = require( './output' );
async function initBlockJSON( {
$schema,
apiVersion,
plugin,
slug,
namespace,
title,
version,
description,
category,
attributes,
supports,
dashicon,
textdomain,
folderName,
editorScript,
editorStyle,
style,
viewStyle,
render,
viewScriptModule,
viewScript,
customBlockJSON,
example,
rootDirectory,
} ) {
info( '' );
info( 'Creating a "block.json" file.' );
const blockFolderName = plugin
? join( rootDirectory, folderName )
: rootDirectory;
await makeDir( blockFolderName );
await writeFile(
join( blockFolderName, 'block.json' ),
JSON.stringify(
Object.fromEntries(
Object.entries( {
$schema,
apiVersion,
name: namespace + '/' + slug,
version,
title,
category,
icon: dashicon,
description,
example,
attributes,
supports,
textdomain,
editorScript,
editorStyle,
style,
viewStyle,
render,
viewScriptModule,
viewScript,
...customBlockJSON,
} ).filter( ( [ , value ] ) => !! value )
),
null,
'\t'
)
);
}
module.exports = async function ( outputTemplates, view ) {
await Promise.all(
Object.keys( outputTemplates ).map( async ( outputFile ) => {
await writeOutputTemplate(
outputTemplates[ outputFile ],
join(
view.plugin ? view.folderName : '',
outputFile.replace( /\$slug/g, view.slug )
),
view
);
} )
);
await initBlockJSON( view );
};