create-basicjs 0.1.1 → 0.1.2
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/package.json +1 -1
- package/payload/starter/AGENTS.md +2 -0
- package/payload/starter/_basic/VERSION +1 -1
- package/payload/starter/_basic/tools/check.js +24 -6
- package/payload/templates/panel/module1/empty-main.htm +1 -0
- package/payload/templates/panel/module10/greenhouse.htm +1 -0
- package/payload/templates/panel/module11/arduino-projects.htm +1 -0
- package/payload/templates/panel/module2/empty-full.htm +1 -0
- package/payload/templates/panel/module3/empty-right.htm +1 -0
- package/payload/templates/panel/module4/empty-main-topbar.htm +1 -0
- package/payload/templates/panel/module5/empty-right-topbar.htm +1 -0
- package/payload/templates/panel/module6/energy-hub.htm +1 -0
- package/payload/templates/panel/module7/3d-printers.htm +1 -0
- package/payload/templates/panel/module8/cold-rooms.htm +1 -0
- package/payload/templates/panel/module9/elevator-fleet.htm +1 -0
package/package.json
CHANGED
|
@@ -79,4 +79,6 @@ window.checkViews = {
|
|
|
79
79
|
};
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
It checks every page, also the ones in folders. A page shown only inside another page can say `<meta name="basic-check" content="skip">`.
|
|
83
|
+
|
|
82
84
|
The tool needs Chrome or Edge. When it can not run, run `node --check` on the files you changed, and tell the user that the page was not opened.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.2
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
// An app with more than one view tells it how to open them (the name of the file is the name of the view):
|
|
11
11
|
// window.checkViews = { orders: function () { App.showPage("orders"); }, settings: function () { App.showPage("settings"); } };
|
|
12
12
|
//
|
|
13
|
+
// Every page is checked, also the ones in folders. A page shown only inside another one (in a frame as high as its
|
|
14
|
+
// content) does not work alone: it says so, and the report counts it as skipped:
|
|
15
|
+
// <meta name="basic-check" content="skip">
|
|
16
|
+
//
|
|
13
17
|
// Exit code: 0 no problem, 1 problems found, 2 could not run.
|
|
14
18
|
|
|
15
19
|
const fs = require("fs");
|
|
@@ -28,6 +32,7 @@ const SMALLEST_WINDOW = 520; // WHY: headless Chrome does not go under 500 px, s
|
|
|
28
32
|
const WAIT_FOR_PAGE_MS = 6000;
|
|
29
33
|
const STOP_CHROME_MS = 25000;
|
|
30
34
|
const MAX_PROBLEMS_SHOWN = 8;
|
|
35
|
+
const NOT_PAGE_FOLDERS = new Set(["_basic", "dist", "node_modules", ".git", ".check"]);
|
|
31
36
|
const TYPES = { ".htm": "text/html", ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".json": "application/json", ".svg": "image/svg+xml", ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp", ".ttf": "font/ttf", ".woff2": "font/woff2" };
|
|
32
37
|
|
|
33
38
|
// *** THE CODE THAT RUNS IN THE PAGE (before the scripts of the page)
|
|
@@ -158,7 +163,7 @@ const PAGE_CHECK = function () {
|
|
|
158
163
|
};
|
|
159
164
|
|
|
160
165
|
const frameOf = function (pageName, width, viewName) {
|
|
161
|
-
const address = "/" + pageName + "?__view=" + encodeURIComponent(viewName);
|
|
166
|
+
const address = "/" + encodeURI(pageName) + "?__view=" + encodeURIComponent(viewName);
|
|
162
167
|
return '<!DOCTYPE html><html><body style="margin:0;background:#fff"><iframe src="' + address + '" style="display:block;width:' + width + "px;height:" + WINDOW_HEIGHT + 'px;border:0"></iframe></body></html>';
|
|
163
168
|
};
|
|
164
169
|
|
|
@@ -254,7 +259,8 @@ const printList = function (title, list) {
|
|
|
254
259
|
const checkOne = async function (browser, profile, port, pageName, width, viewName) {
|
|
255
260
|
lastReport = null;
|
|
256
261
|
missingFiles.clear();
|
|
257
|
-
const
|
|
262
|
+
const pagePart = pageName.replace(/\.html?$/i, "").replace(/[\\/]/g, "-");
|
|
263
|
+
const picture = path.join(PICTURES, pagePart + "-" + width + "-" + (viewName || "start") + ".png");
|
|
258
264
|
const address = "http://127.0.0.1:" + port + "/__frame?page=" + encodeURIComponent(pageName) + "&width=" + width + "&view=" + encodeURIComponent(viewName);
|
|
259
265
|
await openInBrowser(browser, profile, address, picture, width);
|
|
260
266
|
const report = lastReport || { errors: ["The page did not finish: it may have stopped with an error."], offScreen: [], cut: [], views: [] };
|
|
@@ -268,8 +274,17 @@ const checkOne = async function (browser, profile, port, pageName, width, viewNa
|
|
|
268
274
|
return { count: count, views: report.views };
|
|
269
275
|
};
|
|
270
276
|
|
|
271
|
-
|
|
272
|
-
|
|
277
|
+
// Every page of the project, also the ones in folders. The start page comes first.
|
|
278
|
+
const findPages = function (folder = "") {
|
|
279
|
+
const pages = [];
|
|
280
|
+
fs.readdirSync(path.join(SERVED_FOLDER, folder), { withFileTypes: true }).forEach(function (entry) {
|
|
281
|
+
const relativePath = folder ? folder + "/" + entry.name : entry.name;
|
|
282
|
+
if (entry.isDirectory()) {
|
|
283
|
+
if (!NOT_PAGE_FOLDERS.has(entry.name)) pages.push(...findPages(relativePath));
|
|
284
|
+
} else if (/\.html?$/i.test(entry.name)) {
|
|
285
|
+
pages.push(relativePath);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
273
288
|
pages.sort((a, b) => Number(/^index\./i.test(b)) - Number(/^index\./i.test(a)));
|
|
274
289
|
return pages;
|
|
275
290
|
};
|
|
@@ -284,7 +299,9 @@ const run = async function () {
|
|
|
284
299
|
console.log("dist/ does not exist. Run: node _basic/tools/build.js");
|
|
285
300
|
return 2;
|
|
286
301
|
}
|
|
287
|
-
const
|
|
302
|
+
const allPages = findPages();
|
|
303
|
+
const isSkipped = (pageName) => /<meta\s+name=["']basic-check["']\s+content=["']skip["']/i.test(fs.readFileSync(path.join(SERVED_FOLDER, pageName), "utf8"));
|
|
304
|
+
const pages = allPages.filter((pageName) => !isSkipped(pageName));
|
|
288
305
|
if (!pages.length) {
|
|
289
306
|
console.log("There is no .htm page.");
|
|
290
307
|
return 2;
|
|
@@ -297,7 +314,7 @@ const run = async function () {
|
|
|
297
314
|
|
|
298
315
|
let problems = 0;
|
|
299
316
|
for (const pageName of pages) {
|
|
300
|
-
if (pages.length > 1) console.log(pageName);
|
|
317
|
+
if (pages.length > 1) console.log("\n" + pageName);
|
|
301
318
|
for (const width of WIDTHS) {
|
|
302
319
|
const first = await checkOne(browser, profile, port, pageName, width, "");
|
|
303
320
|
problems += first.count;
|
|
@@ -308,6 +325,7 @@ const run = async function () {
|
|
|
308
325
|
}
|
|
309
326
|
server.close();
|
|
310
327
|
fs.rmSync(profile, { recursive: true, force: true, maxRetries: 3 });
|
|
328
|
+
if (allPages.length > pages.length) console.log((allPages.length - pages.length) + " page(s) skipped by their basic-check tag.");
|
|
311
329
|
console.log(problems ? problems + " problem(s). Look at the pictures in .check/ too." : "No problem found. Look at the pictures in .check/ too: this check can not judge the design.");
|
|
312
330
|
return problems ? 1 : 0;
|
|
313
331
|
};
|