-
Notifications
You must be signed in to change notification settings - Fork 328
/
kirki.mjs
189 lines (168 loc) · 5.36 KB
/
kirki.mjs
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
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
#!/usr/bin/env node
import shell from "shelljs";
import sade from "sade";
const definedPackages = {
settings: {
path: "kirki-packages/settings",
sources: [
"src/admin-notice.scss",
"src/settings.ts",
"src/discount-notice.ts",
],
},
"control-base": {
path: "kirki-packages/control-base",
sources: ["src/control.js"],
},
"control-checkbox": {
path: "kirki-packages/control-checkbox",
sources: ["src/control.js"],
},
"control-color-palette": {
path: "kirki-packages/control-color-palette",
sources: ["src/control.js"],
},
"control-dashicons": {
path: "kirki-packages/control-dashicons",
sources: ["src/control.js"],
},
"control-date": {
path: "kirki-packages/control-date",
sources: ["src/control.js"],
},
"control-dimension": {
path: "kirki-packages/control-dimension",
sources: ["src/control.js"],
},
"control-editor": {
path: "kirki-packages/control-editor",
sources: ["src/control.js"],
},
"control-generic": {
path: "kirki-packages/control-generic",
sources: ["src/control.js"],
},
"control-image": {
path: "kirki-packages/control-image",
sources: ["src/control.js"],
},
"control-multicheck": {
path: "kirki-packages/control-multicheck",
sources: ["src/control.js"],
},
"control-palette": {
path: "kirki-packages/control-palette",
sources: ["src/control.js"],
},
"control-radio": {
path: "kirki-packages/control-radio",
sources: ["src/control.js"],
},
"control-react-colorful": {
path: "kirki-packages/control-react-colorful",
sources: ["src/control.js", "src/preview.js"],
},
"control-react-select": {
path: "kirki-packages/control-react-select",
sources: ["src/control.js"],
},
"control-repeater": {
path: "kirki-packages/control-repeater",
sources: ["src/control.js"],
},
"control-select": {
path: "kirki-packages/control-select",
sources: ["src/control.js"],
},
"control-slider": {
path: "kirki-packages/control-slider",
sources: ["src/control.js"],
},
"control-sortable": {
path: "kirki-packages/control-sortable",
sources: ["src/control.js"],
},
"field-dimensions": {
path: "kirki-packages/field-dimensions",
// Yes, the files are control.scss & preview.js :)
sources: ["src/control.scss", "src/preview.js"],
},
"field-typography": {
path: "kirki-packages/field-typography",
sources: ["src/control.js", "src/preview.js"],
},
"module-field-dependencies": {
path: "kirki-packages/module-field-dependencies",
sources: ["src/control.js"],
},
"module-tooltips": {
path: "kirki-packages/module-tooltips",
sources: ["src/control.js"],
},
};
const parcelBinPath = "node_modules/.bin/parcel";
function getPackageData(packageName) {
return definedPackages[packageName] ? definedPackages[packageName] : null;
}
function getSourcesPath(packageData) {
let sourcesPath = "";
// Build the source command from the definedPackages.
packageData.sources.forEach((source) => {
sourcesPath += `${packageData.path}/${source} `;
});
return sourcesPath.trim();
}
function runParcel(commandType, packageName, opts) {
const packageData = getPackageData(packageName);
if (!packageData) {
console.warn(`Package "${packageName}" is not defined.`);
return;
}
if (!packageData.sources.length) {
console.warn(
`Package "${packageName}" does not have any sources to compile.`
);
return;
}
const sourcesPath = getSourcesPath(packageData);
let command = "";
// Build the CLI command along with the opts.
command += `"${parcelBinPath}" ${commandType} ${sourcesPath} ${
opts.d && commandType == "build" ? "--no-optimize" : ""
} --dist-dir ${packageData.path}/dist`;
command = command.replace(/ +/g, " ");
command = command.trim();
shell.exec(`${command}`);
}
// Create the program.
const program = sade("kirki");
program.version("5.1.0");
program
.command("build <packageName>")
.describe("Build a package by package name")
.option("-d, --debug", "Build as unminified code for debugging purpose")
.example("build control-base")
.example("build control-base --debug")
.action((packageName, opts) => {
runParcel("build", packageName, opts);
});
program
.command("watch <packageName>")
.describe(
"Build in debug mode by package name and watch for changes. Visit your local site using normal URL. It will reload the browser automatically if there's JS change. And will implement CSS instantly when there's CSS change. Use CTRL+C to stop watching."
)
.example("watch control-base")
.action((packageName, opts) => {
runParcel("watch", packageName, opts);
});
program
.command("make wp")
.describe(
"Build Kirki as a WordPress plugin that's ready to push to WordPress.org. It will put the result into `builds` folder."
)
.example("make wp")
.action((opts) => {
// Execute build.sh
shell.exec("bash build.sh");
});
program.parse(process.argv);