-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathscaffold.js
154 lines (143 loc) · 3.03 KB
/
scaffold.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
/**
* External dependencies
*/
const { snakeCase, camelCase, upperFirst } = require( 'lodash' );
/**
* Internal dependencies
*/
const initBlock = require( './init-block' );
const initPackageJSON = require( './init-package-json' );
const initWPScripts = require( './init-wp-scripts' );
const initWPEnv = require( './init-wp-env' );
const { code, info, success } = require( './log' );
const { writeOutputAsset, writeOutputTemplate } = require( './output' );
module.exports = async (
{ blockOutputTemplates, outputTemplates, outputAssets },
{
$schema,
apiVersion,
namespace,
slug,
title,
description,
dashicon,
category,
attributes,
supports,
author,
license,
licenseURI,
version,
wpScripts,
wpEnv,
npmDependencies,
folderName,
editorScript,
editorStyle,
style,
}
) => {
slug = slug.toLowerCase();
namespace = namespace.toLowerCase();
info( '' );
info( `Creating a new WordPress plugin in "${ slug }" folder.` );
const view = {
$schema,
apiVersion,
namespace,
namespaceSnakeCase: snakeCase( namespace ),
slug,
slugSnakeCase: snakeCase( slug ),
slugPascalCase: upperFirst( camelCase( slug ) ),
title,
description,
dashicon,
category,
attributes,
supports,
version,
author,
license,
licenseURI,
textdomain: slug,
wpScripts,
wpEnv,
npmDependencies,
folderName,
editorScript,
editorStyle,
style,
};
await Promise.all(
Object.keys( outputTemplates ).map(
async ( outputFile ) =>
await writeOutputTemplate(
outputTemplates[ outputFile ],
outputFile,
view
)
)
);
await Promise.all(
Object.keys( outputAssets ).map(
async ( outputFile ) =>
await writeOutputAsset(
outputAssets[ outputFile ],
outputFile,
view
)
)
);
await initBlock( blockOutputTemplates, view );
await initPackageJSON( view );
if ( wpScripts ) {
await initWPScripts( view );
}
if ( wpEnv ) {
await initWPEnv( view );
}
info( '' );
success(
`Done: block "${ title }" bootstrapped in the "${ slug }" folder.`
);
if ( wpScripts ) {
info( '' );
info( 'Inside that directory, you can run several commands:' );
info( '' );
code( ' $ npm start' );
info( ' Starts the build for development.' );
info( '' );
code( ' $ npm run build' );
info( ' Builds the code for production.' );
info( '' );
code( ' $ npm run format' );
info( ' Formats files.' );
info( '' );
code( ' $ npm run lint:css' );
info( ' Lints CSS files.' );
info( '' );
code( ' $ npm run lint:js' );
info( ' Lints JavaScript files.' );
info( '' );
code( ' $ npm run packages-update' );
info( ' Updates WordPress packages to the latest version.' );
}
info( '' );
info( 'To enter the folder type:' );
info( '' );
code( ` $ cd ${ slug }` );
if ( wpScripts ) {
info( '' );
info( 'You can start development with:' );
info( '' );
code( ' $ npm start' );
}
if ( wpEnv ) {
info( '' );
info( 'You can start WordPress with:' );
info( '' );
code( ' $ npx wp-env start' );
}
info( '' );
info( 'Code is Poetry' );
};