-
Notifications
You must be signed in to change notification settings - Fork 78
/
gulpfile.mjs
279 lines (271 loc) · 7.9 KB
/
gulpfile.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// kittens cry but really really really crude HTML DOM polyfill for nodejs
import "@haxtheweb/utils/lib/nodejs-fake-dom-polyfill.cjs";
// load our wiring class
import * as tmp from 'gulp';
const gulp = tmp.default;
import * as tmp2 from 'gulp-concat-util';
const concat = tmp2.default;
import * as tmp3 from "fs";
const fs = tmp3.default;
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
// fake class
class HAXWiring {
/**
* Return a haxProperties prototype / example structure
*/
prototypeHaxProperties = () => {
// example properties valid for HAX context menu.
let props = {
api: "1",
type: "element",
editingElement: "core",
hideDefaultSettings: false,
canScale: true,
canEditSource: true,
contentEditable: false,
gizmo: {
title: "Tag name",
description: "",
icon: "icons:android",
color: "purple",
tags: ["Other"],
handles: [
{
type: "data",
type_exclusive: false,
url: "src",
},
],
meta: {
author: "auto",
},
requiresChildren: false,
requiresParent: false,
},
settings: {
configure: [
{
slot: "",
title: "Inner content",
description: "The slotted content that lives inside the tag",
inputMethod: "textfield",
icon: "android",
required: true,
validationType: "text",
},
{
slot: "button",
title: "Button content",
description: "The content that can override the button",
inputMethod: "textfield",
icon: "android",
required: true,
validationType: "text",
},
{
property: "title",
title: "Title",
description: "",
inputMethod: "textfield",
icon: "android",
required: true,
validationType: "text",
},
{
property: "primaryColor",
title: "Title",
description: "",
inputMethod: "textfield",
icon: "android",
required: false,
validation: ".*",
validationType: "text",
},
],
advanced: [
{
property: "secondaryColor",
title: "Secondary color",
description:
"An optional secondary color used in certain edge cases.",
inputMethod: "colorpicker",
icon: "color",
},
{
property: "endPoint",
title: "API endpoint",
description:
"An optional endpoint to hit and load in more data dymaically.",
inputMethod: "textfield",
icon: "android",
validation: "[a-z0-9]",
validationType: "url",
},
],
developer: [],
},
saveOptions: {
wipeSlot: false,
unsetAttributes: ["end-point", "secondary-color"],
},
documentation: {
howTo: "https://oer.hax.psu.edu/bto108/sites/haxcellence/welcome",
purpose: "https://oer.hax.psu.edu/bto108/sites/haxcellence/welcome",
},
demoSchema: [
{
tag: "my-tag",
content: "<p>inner html</p>",
properties: {
endPoint: "https://cdn2.thecatapi.com/images/9j5.jpg",
primaryColor: "yellow",
title: "A cat",
},
},
],
};
return props;
};
}
// merge the web component factory libraries the user has installed
gulp.task("default", () => {
return gulp
.src("../../templates/libraries/**/package.json")
.pipe(
concat(".wcflibcache.json", {
process: function (src, filePath) {
return src + ",";
},
})
)
.pipe(concat.header("["))
.pipe(concat.footer("{}]"))
.pipe(gulp.dest("./"));
});
// merge the web component factory libraries the user has installed
gulp.task("haxschema", async () => {
const hax = new HAXWiring();
const args = yargs(hideBin(process.argv))
.command('curl <url>', 'fetch the contents of the URL', () => {}, (argv) => {
console.info(argv)
})
.demandCommand(1)
.parse();
const tagName = args.element;
const ceFileData = fs.readFileSync(`./elements/${tagName}/custom-elements.json`,'utf8', (error, data) => {
if(error){
console.warn(error);
return;
}
return data;
});
if (ceFileData) {
let ce = JSON.parse(ceFileData);
await ce.tags.forEach(async (tag) => {
if (tag.name === tagName) {
let props = hax.prototypeHaxProperties();
props.gizmo.title = tagName.replace('-', ' ');
props.gizmo.tags = ["Other"];
props.gizmo.handles = [];
props.gizmo.meta.author = "HAXTheWeb core team";
delete props.gizmo.shortcutKey;
delete props.gizmo.requiresChildren;
delete props.gizmo.requiresParent;
props.settings.configure = [];
props.settings.advanced = [];
props.documentation = {
howTo: null,
purpose: null
};
props.saveOptions = {
unsetAttributes: []
};
props.demoSchema = [
{
tag: tagName,
content: "",
properties: {
}
}
];
let propData = [];
if (tag.properties) {
propData = tag.properties;
}
else if (tag.attributes) {
propData = tag.attributes;
}
// didn't have one, so guess
if (!tag.path) {
tag.path = `./elements/${tagName}/${tagName}.js`;
}
// loop through and if props are things we can map then do it
await propData.forEach(async (prop) => {
if (["t","colors",'_haxState',"elementVisible", "element-visible"].includes(prop.name)) {
props.saveOptions.unsetAttributes.push(prop.name);
}
else {
let type = "textfield";
if (prop.type) {
type = getInputMethodFromType(prop.type);
}
else if (prop.description && prop.description.includes("boolean")) {
type = "boolean";
}
else if (prop.description && prop.description.includes("number")) {
type = "number";
}
if (type) {
let propSchema = {
property: prop.name,
title: prop.name,
description: prop.description || "",
inputMethod: type,
};
if (prop.default !== undefined) {
props.demoSchema[0].properties[prop.name] = prop.default;
}
props.settings.configure.push(propSchema);
}
}
});
if (!args.write) {
console.log(`\n\n--------------------------\n${tagName} HAX schema\n--------------------------\n`);
console.log(JSON.stringify(props, null, 2));
}
else if (args.write) {
fs.writeFileSync(`./elements/${tagName}/lib/${tagName}.haxProperties.json`, JSON.stringify(props, null, 2));
console.log(`schema written to: ./elements/${tagName}/lib/${tagName}.haxProperties.json`)
}
console.log(`\n--------------------------\n Psuedo code to add: ${tag.path}\n--------------------------`);
console.log(`
/**
* Convention we use
*/
static get tag() {
return "${tagName}";
}
/**
* haxProperties integration via file reference
*/
static get haxProperties() {
return new URL(\`./lib/\${this.tag}.haxProperties.json\`, import.meta.url).href;
}
`);
}
});
}
return true;
});
function getInputMethodFromType(type) {
switch (type) {
case "string":
return "textfield";
case "number":
return "number";
case "boolean":
return "boolean";
}
return false;
}