tkeron 3.0.0 → 3.0.1
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/changelog.md +5 -0
- package/package.json +1 -1
- package/dist/test/buildLoaders.test.d.ts +0 -1
- package/dist/test/buildLoaders.test.js +0 -51
- package/dist/test/bundleTs.test.d.ts +0 -1
- package/dist/test/bundleTs.test.js +0 -91
- package/dist/test/cmdDev.test.d.ts +0 -1
- package/dist/test/cmdDev.test.js +0 -50
- package/dist/test/errors.test.d.ts +0 -1
- package/dist/test/errors.test.js +0 -29
- package/dist/test/fileExist.test.d.ts +0 -1
- package/dist/test/fileExist.test.js +0 -38
- package/dist/test/getRandomValues.test.d.ts +0 -1
- package/dist/test/getRandomValues.test.js +0 -35
- package/dist/test/logs.test.d.ts +0 -1
- package/dist/test/logs.test.js +0 -23
- package/dist/test/main.test.d.ts +0 -1
- package/dist/test/main.test.js +0 -15
- package/dist/test/pathToUrlResource.test.d.ts +0 -1
- package/dist/test/pathToUrlResource.test.js +0 -10
- package/dist/test/runOncePerTime.test.d.ts +0 -1
- package/dist/test/runOncePerTime.test.js +0 -17
- package/src/base64.ts +0 -5
- package/src/build.ts +0 -190
- package/src/buildFront.ts +0 -40
- package/src/buildLoaders.ts +0 -22
- package/src/bundleTs.ts +0 -32
- package/src/cicd.ts +0 -7
- package/src/cmdBuild.ts +0 -12
- package/src/cmdDev.ts +0 -82
- package/src/cmdGenerate.ts +0 -37
- package/src/cmdInit.ts +0 -35
- package/src/copyDir.ts +0 -14
- package/src/createModFile.ts +0 -11
- package/src/createTsConfigFile.ts +0 -36
- package/src/eventEmitter.ts +0 -28
- package/src/fileExist.ts +0 -13
- package/src/generateItems.ts +0 -12
- package/src/getDocument.ts +0 -42
- package/src/getFilesRecursive.ts +0 -66
- package/src/getOptions.ts +0 -28
- package/src/getType.ts +0 -2
- package/src/getVersion.ts +0 -13
- package/src/index.ts +0 -5
- package/src/injectCode.ts +0 -10
- package/src/injectTsFile.ts +0 -26
- package/src/jsDom/crypto.ts +0 -50
- package/src/jsDom/errors.ts +0 -33
- package/src/jsDom/fetch.ts +0 -11
- package/src/jsDom/joinScripts.ts +0 -20
- package/src/jsDom/logs.ts +0 -11
- package/src/jsDom/writeLogElement.ts +0 -52
- package/src/libFiles.ts.ts +0 -11
- package/src/main.ts +0 -75
- package/src/mod.ts +0 -7
- package/src/pathToUrlResource.ts +0 -8
- package/src/random.ts +0 -25
- package/src/range.ts +0 -2
- package/src/readJsonFile.ts +0 -13
- package/src/rectReady.ts +0 -30
- package/src/rnd.ts +0 -7
- package/src/rnda.ts +0 -5
- package/src/runOncePerTime.ts +0 -13
- package/src/serializeDocument.ts +0 -2
- package/src/simpleHotRestart.ts +0 -16
- package/src/test/buildLoaders.test.ts +0 -50
- package/src/test/bundleTs.test.ts +0 -93
- package/src/test/errors.test.ts +0 -29
- package/src/test/fileExist.test.ts +0 -38
- package/src/test/getRandomValues.test.ts +0 -34
- package/src/test/logs.test.ts +0 -22
- package/src/test/main.test.ts +0 -15
- package/src/test/pathToUrlResource.test.ts +0 -9
- package/src/test/runOncePerTime.test.ts +0 -16
- package/src/tk.ts +0 -5
- package/src/tkeron.ts +0 -319
- package/src/wait.ts +0 -2
package/changelog.md
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const buildLoaders_1 = require("../buildLoaders");
|
|
4
|
-
describe("buildLoaders", () => {
|
|
5
|
-
it("verify loaders", () => {
|
|
6
|
-
const expectedKeys = [
|
|
7
|
-
".jpg",
|
|
8
|
-
".png",
|
|
9
|
-
".gif",
|
|
10
|
-
".ico",
|
|
11
|
-
".webp",
|
|
12
|
-
".svg",
|
|
13
|
-
".js",
|
|
14
|
-
".css",
|
|
15
|
-
".html",
|
|
16
|
-
];
|
|
17
|
-
const expectedValues = [
|
|
18
|
-
"file",
|
|
19
|
-
"file",
|
|
20
|
-
"file",
|
|
21
|
-
"file",
|
|
22
|
-
"file",
|
|
23
|
-
"file",
|
|
24
|
-
"file",
|
|
25
|
-
"text",
|
|
26
|
-
"text",
|
|
27
|
-
];
|
|
28
|
-
const keys = Object.keys(buildLoaders_1.buildLoaders);
|
|
29
|
-
const values = Object.values(buildLoaders_1.buildLoaders);
|
|
30
|
-
expect(keys).toMatchObject(expectedKeys);
|
|
31
|
-
expect(values).toMatchObject(expectedValues);
|
|
32
|
-
});
|
|
33
|
-
it("verify ext modules", () => {
|
|
34
|
-
const expected = `declare module '*.css';
|
|
35
|
-
declare module '*.gif';
|
|
36
|
-
declare module '*.html';
|
|
37
|
-
declare module '*.ico';
|
|
38
|
-
declare module '*.jpg';
|
|
39
|
-
declare module '*.js';
|
|
40
|
-
declare module '*.png';
|
|
41
|
-
declare module '*.svg';
|
|
42
|
-
declare module '*.webp';
|
|
43
|
-
`
|
|
44
|
-
.replace(/[\n\t]/g, " ")
|
|
45
|
-
.replace(/\s+/g, " ");
|
|
46
|
-
const extModules = (0, buildLoaders_1.getExtModules)()
|
|
47
|
-
.replace(/[\n\t]/g, " ")
|
|
48
|
-
.replace(/\s+/g, " ");
|
|
49
|
-
expect(extModules).toBe(expected);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const promises_1 = require("fs/promises");
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
const bundleTs_1 = require("../bundleTs");
|
|
6
|
-
const fileExist_1 = require("../fileExist");
|
|
7
|
-
const testDir = (0, path_1.join)(process.cwd(), "tmp_bundle_ts");
|
|
8
|
-
const sumDir = (0, path_1.join)(testDir, "sum.ts");
|
|
9
|
-
const minDir = (0, path_1.join)(testDir, "min.ts");
|
|
10
|
-
const powDir = (0, path_1.join)(testDir, "pow.ts");
|
|
11
|
-
const operationsDir = (0, path_1.join)(testDir, "operations.ts");
|
|
12
|
-
const sumOutDir = (0, path_1.join)(testDir, "sum.js");
|
|
13
|
-
const minOutDir = (0, path_1.join)(testDir, "min.js");
|
|
14
|
-
const powOutDir = (0, path_1.join)(testDir, "pow.js");
|
|
15
|
-
const operationsOutDir = (0, path_1.join)(testDir, "operations.js");
|
|
16
|
-
beforeAll(async () => {
|
|
17
|
-
if (await (0, fileExist_1.fileExists)(testDir))
|
|
18
|
-
await (0, promises_1.rm)(testDir, { recursive: true, force: true });
|
|
19
|
-
await (0, promises_1.mkdir)(testDir);
|
|
20
|
-
const sum = `
|
|
21
|
-
//sum.ts
|
|
22
|
-
export const sum = (a: number, b: number) => a + b;
|
|
23
|
-
`;
|
|
24
|
-
const min = `
|
|
25
|
-
//min.ts
|
|
26
|
-
export const min = (a: number, b: number) => a - b;
|
|
27
|
-
`;
|
|
28
|
-
const pow = `
|
|
29
|
-
//pow.ts
|
|
30
|
-
export const pow = (a: number, b: number) => a ** b;
|
|
31
|
-
`;
|
|
32
|
-
const operations = `
|
|
33
|
-
//operations.ts
|
|
34
|
-
import {sum} from "./sum";
|
|
35
|
-
import {min} from "./min";
|
|
36
|
-
import {pow} from "./pow";
|
|
37
|
-
|
|
38
|
-
const a = 56;
|
|
39
|
-
const b = 12;
|
|
40
|
-
|
|
41
|
-
const sumResult = sum(a, b);
|
|
42
|
-
// const minResult = min(a, b);
|
|
43
|
-
const powResult = pow(a, b);
|
|
44
|
-
|
|
45
|
-
console\.log(\`a + b = $\{sumResult\}\`);
|
|
46
|
-
// console\.log(\`a - b = $\{minResult\}\`);
|
|
47
|
-
console\.log(\`a ** b = $\{powResult\}\`);
|
|
48
|
-
`;
|
|
49
|
-
(0, promises_1.writeFile)(sumDir, sum, { encoding: "utf-8" });
|
|
50
|
-
(0, promises_1.writeFile)(minDir, min, { encoding: "utf-8" });
|
|
51
|
-
(0, promises_1.writeFile)(powDir, pow, { encoding: "utf-8" });
|
|
52
|
-
(0, promises_1.writeFile)(operationsDir, operations, { encoding: "utf-8" });
|
|
53
|
-
});
|
|
54
|
-
afterAll(async () => {
|
|
55
|
-
await (0, promises_1.rm)(testDir, { recursive: true, force: true });
|
|
56
|
-
});
|
|
57
|
-
describe("bundleTs", () => {
|
|
58
|
-
it("bundle with undefined file", async () => {
|
|
59
|
-
const result = await (0, bundleTs_1.bundleTs)(undefined, sumOutDir).catch((_) => _);
|
|
60
|
-
expect(result).toBe("file must be defined");
|
|
61
|
-
});
|
|
62
|
-
it("bundle with undefined out file", async () => {
|
|
63
|
-
const result = await (0, bundleTs_1.bundleTs)(sumDir, undefined).catch((_) => _);
|
|
64
|
-
expect(result).toBe("outfile must be defined");
|
|
65
|
-
});
|
|
66
|
-
it("bundle with unexistent file", async () => {
|
|
67
|
-
const file = (0, path_1.join)(testDir, "unexistent.ts");
|
|
68
|
-
const result = await (0, bundleTs_1.bundleTs)(file, sumOutDir).catch((_) => _);
|
|
69
|
-
expect(result).toBe(`file ${file} doesn't exist`);
|
|
70
|
-
});
|
|
71
|
-
it("bundle sum function", async () => {
|
|
72
|
-
const result = await (0, bundleTs_1.bundleTs)(sumDir, sumOutDir);
|
|
73
|
-
const expected = "(()=>{var sum=(a,b)=>a+b;})();";
|
|
74
|
-
expect(result.trim()).toBe(expected);
|
|
75
|
-
});
|
|
76
|
-
it("bundle min function", async () => {
|
|
77
|
-
const result = await (0, bundleTs_1.bundleTs)(minDir, minOutDir);
|
|
78
|
-
const expected = "(()=>{var min=(a,b)=>a-b;})();";
|
|
79
|
-
expect(result.trim()).toBe(expected);
|
|
80
|
-
});
|
|
81
|
-
it("bundle pow function", async () => {
|
|
82
|
-
const result = await (0, bundleTs_1.bundleTs)(powDir, powOutDir);
|
|
83
|
-
const expected = "(()=>{var pow=(a,b)=>a**b;})();";
|
|
84
|
-
expect(result.trim()).toBe(expected);
|
|
85
|
-
});
|
|
86
|
-
it("bundle operations, expecting tree shaking", async () => {
|
|
87
|
-
const result = await (0, bundleTs_1.bundleTs)(operationsDir, operationsOutDir);
|
|
88
|
-
const expected = "(()=>{var sum=(a2,b2)=>a2+b2;var pow=(a2,b2)=>a2**b2;var a=56,b=12,sumResult=sum(a,b),powResult=pow(a,b);console.log(`a + b = ${sumResult}`);console.log(`a ** b = ${powResult}`);})();";
|
|
89
|
-
expect(result.trim()).toBe(expected);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test/cmdDev.test.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cmdDev_1 = require("../cmdDev");
|
|
4
|
-
describe("cmdDev", () => {
|
|
5
|
-
let app;
|
|
6
|
-
let expressGet;
|
|
7
|
-
let expressUse;
|
|
8
|
-
let expressListen;
|
|
9
|
-
let consoleLog;
|
|
10
|
-
let watchMock;
|
|
11
|
-
let defaultConsoleLog = console.log;
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
expressGet = jest.fn();
|
|
14
|
-
expressUse = jest.fn();
|
|
15
|
-
expressListen = jest.fn();
|
|
16
|
-
consoleLog = jest.fn();
|
|
17
|
-
watchMock = jest.fn();
|
|
18
|
-
jest.mock('express', () => {
|
|
19
|
-
const originalModule = jest.requireActual('express');
|
|
20
|
-
return {
|
|
21
|
-
...originalModule,
|
|
22
|
-
express: jest.fn(() => ({
|
|
23
|
-
...originalModule(),
|
|
24
|
-
listen: expressListen,
|
|
25
|
-
get: expressGet,
|
|
26
|
-
use: expressUse
|
|
27
|
-
})),
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
const imported = await import('express');
|
|
31
|
-
app = imported.express();
|
|
32
|
-
console.log = consoleLog;
|
|
33
|
-
jest.mock("node-watch", () => watchMock);
|
|
34
|
-
});
|
|
35
|
-
afterEach(async () => {
|
|
36
|
-
jest.clearAllMocks();
|
|
37
|
-
console.log = defaultConsoleLog;
|
|
38
|
-
});
|
|
39
|
-
it("run dev", async () => {
|
|
40
|
-
const example = {
|
|
41
|
-
addr: "0.0.0.0",
|
|
42
|
-
outputDir: "out",
|
|
43
|
-
port: "3300",
|
|
44
|
-
sourceDir: "src"
|
|
45
|
-
};
|
|
46
|
-
const dev = await (0, cmdDev_1.cmdDev)(example);
|
|
47
|
-
dev.closeServer();
|
|
48
|
-
dev.closeWatcher();
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test/errors.test.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path_1 = require("path");
|
|
4
|
-
const getDocument_1 = require("../getDocument");
|
|
5
|
-
const front = (0, path_1.join)(__dirname, "..", "..", "front");
|
|
6
|
-
const web = (0, path_1.join)(__dirname, "..", "..", "web");
|
|
7
|
-
describe("jsdom errors", () => {
|
|
8
|
-
it("custom error", async () => {
|
|
9
|
-
const html = `
|
|
10
|
-
<!DOCTYPE html>
|
|
11
|
-
<html lang="en">
|
|
12
|
-
<head>
|
|
13
|
-
<meta charset="UTF-8" />
|
|
14
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
15
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
16
|
-
<title>jsdom errors</title>
|
|
17
|
-
<script>
|
|
18
|
-
throw "custom error";
|
|
19
|
-
</script>
|
|
20
|
-
</head>
|
|
21
|
-
<body></body>
|
|
22
|
-
</html>
|
|
23
|
-
`;
|
|
24
|
-
const { document } = (0, getDocument_1.getDocument)(html);
|
|
25
|
-
const node = document.querySelector(".tkeron_error");
|
|
26
|
-
expect(node).toBeTruthy();
|
|
27
|
-
expect(node.innerHTML).toMatch(/custom error/);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path_1 = require("path");
|
|
4
|
-
const fileExist_1 = require("../fileExist");
|
|
5
|
-
describe("fileExists", () => {
|
|
6
|
-
it("unexistent file", async () => {
|
|
7
|
-
const path = (0, path_1.join)(__dirname, "..", "qwerty.asdf");
|
|
8
|
-
const result = await (0, fileExist_1.fileExists)(path);
|
|
9
|
-
expect(result).toBeFalsy();
|
|
10
|
-
});
|
|
11
|
-
it("existent directory", async () => {
|
|
12
|
-
const path = (0, path_1.join)(__dirname, "..");
|
|
13
|
-
const result = await (0, fileExist_1.fileExists)(path);
|
|
14
|
-
expect(result).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
it("unexistent directory", async () => {
|
|
17
|
-
const path = (0, path_1.join)(__dirname, "..", "qwerty");
|
|
18
|
-
const result = await (0, fileExist_1.fileExists)(path);
|
|
19
|
-
expect(result).toBeFalsy();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe("fileExistsSync", () => {
|
|
23
|
-
it("unexistent file", () => {
|
|
24
|
-
const path = (0, path_1.join)(__dirname, "..", "qwerty.asdf");
|
|
25
|
-
const result = (0, fileExist_1.fileExistsSync)(path);
|
|
26
|
-
expect(result).toBeFalsy();
|
|
27
|
-
});
|
|
28
|
-
it("existent directory", () => {
|
|
29
|
-
const path = (0, path_1.join)(__dirname, "..");
|
|
30
|
-
const result = (0, fileExist_1.fileExistsSync)(path);
|
|
31
|
-
expect(result).toBeTruthy();
|
|
32
|
-
});
|
|
33
|
-
it("unexistent directory", () => {
|
|
34
|
-
const path = (0, path_1.join)(__dirname, "..", "qwerty");
|
|
35
|
-
const result = (0, fileExist_1.fileExistsSync)(path);
|
|
36
|
-
expect(result).toBeFalsy();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const crypto_1 = require("../jsDom/crypto");
|
|
4
|
-
describe("getRandomValues", () => {
|
|
5
|
-
it("random Int8Array", () => {
|
|
6
|
-
const result = (0, crypto_1.getRandomValues)(new Int8Array(5));
|
|
7
|
-
expect(result).toBeTruthy();
|
|
8
|
-
expect(result).toHaveLength(5);
|
|
9
|
-
});
|
|
10
|
-
it("random Uint8Array", () => {
|
|
11
|
-
const result = (0, crypto_1.getRandomValues)(new Uint8Array(5));
|
|
12
|
-
expect(result).toBeTruthy();
|
|
13
|
-
expect(result).toHaveLength(5);
|
|
14
|
-
});
|
|
15
|
-
it("random Int16Array", () => {
|
|
16
|
-
const result = (0, crypto_1.getRandomValues)(new Int16Array(5));
|
|
17
|
-
expect(result).toBeTruthy();
|
|
18
|
-
expect(result).toHaveLength(5);
|
|
19
|
-
});
|
|
20
|
-
it("random Uint16Array", () => {
|
|
21
|
-
const result = (0, crypto_1.getRandomValues)(new Uint16Array(5));
|
|
22
|
-
expect(result).toBeTruthy();
|
|
23
|
-
expect(result).toHaveLength(5);
|
|
24
|
-
});
|
|
25
|
-
it("random Int32Array", () => {
|
|
26
|
-
const result = (0, crypto_1.getRandomValues)(new Int32Array(5));
|
|
27
|
-
expect(result).toBeTruthy();
|
|
28
|
-
expect(result).toHaveLength(5);
|
|
29
|
-
});
|
|
30
|
-
it("random Uint32Array", () => {
|
|
31
|
-
const result = (0, crypto_1.getRandomValues)(new Uint32Array(5));
|
|
32
|
-
expect(result).toBeTruthy();
|
|
33
|
-
expect(result).toHaveLength(5);
|
|
34
|
-
});
|
|
35
|
-
});
|
package/dist/test/logs.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test/logs.test.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const jsdom_1 = require("jsdom");
|
|
4
|
-
const generateItems_1 = require("../generateItems");
|
|
5
|
-
const logs_1 = require("../jsDom/logs");
|
|
6
|
-
describe("logs", () => {
|
|
7
|
-
it("handleLogs", async () => {
|
|
8
|
-
const logs = ["log 1", "log B", "log 3"];
|
|
9
|
-
const { window } = new jsdom_1.JSDOM((0, generateItems_1.pageItem)("test").html, {
|
|
10
|
-
runScripts: "dangerously",
|
|
11
|
-
resources: "usable",
|
|
12
|
-
});
|
|
13
|
-
const { document } = window;
|
|
14
|
-
await new Promise((ok) => document.addEventListener("load", ok));
|
|
15
|
-
(0, logs_1.handleLogs)(logs, document);
|
|
16
|
-
const logNodes = document.querySelectorAll(".tkeron_log");
|
|
17
|
-
expect(logNodes).toHaveLength(3);
|
|
18
|
-
const [log1, log2, log3] = logNodes;
|
|
19
|
-
expect(log1.innerHTML).toBe(logs[0]);
|
|
20
|
-
expect(log2.innerHTML).toBe(logs[1]);
|
|
21
|
-
expect(log3.innerHTML).toBe(logs[2]);
|
|
22
|
-
});
|
|
23
|
-
});
|
package/dist/test/main.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test/main.test.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const promises_1 = require("fs/promises");
|
|
4
|
-
const main_1 = require("../main");
|
|
5
|
-
beforeAll(async () => {
|
|
6
|
-
await (0, promises_1.mkdir)("front", { recursive: true });
|
|
7
|
-
});
|
|
8
|
-
afterAll(async () => {
|
|
9
|
-
await (0, promises_1.rm)("front", { force: true, recursive: true });
|
|
10
|
-
});
|
|
11
|
-
describe("main", () => {
|
|
12
|
-
it("command build", () => {
|
|
13
|
-
(0, main_1.main)("tk", ["build"]);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path_1 = require("path");
|
|
4
|
-
const pathToUrlResource_1 = require("../pathToUrlResource");
|
|
5
|
-
describe("pathToUrlResource", () => {
|
|
6
|
-
it("test dir from 1 level up", async () => {
|
|
7
|
-
const result = (0, pathToUrlResource_1.pathToUrlResource)(__dirname, (0, path_1.join)(__dirname, ".."));
|
|
8
|
-
expect(result).toMatchObject({ url: "/test", resource: "test" });
|
|
9
|
-
});
|
|
10
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const runOncePerTime_1 = require("../runOncePerTime");
|
|
4
|
-
describe("runOncePerTime", () => {
|
|
5
|
-
it("run once in 20ms", (done) => {
|
|
6
|
-
const runOnce20ms = (0, runOncePerTime_1.runOncePerTime)(20);
|
|
7
|
-
const result = [];
|
|
8
|
-
const add = (n) => result.push(n);
|
|
9
|
-
setTimeout(() => {
|
|
10
|
-
expect(result).toHaveLength(1);
|
|
11
|
-
done();
|
|
12
|
-
}, 20);
|
|
13
|
-
setTimeout(() => runOnce20ms(() => add(1)), 5);
|
|
14
|
-
setTimeout(() => runOnce20ms(() => add(1)), 4);
|
|
15
|
-
setTimeout(() => runOnce20ms(() => add(1)), 3);
|
|
16
|
-
});
|
|
17
|
-
});
|
package/src/base64.ts
DELETED
package/src/build.ts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { basename, join } from "path";
|
|
2
|
-
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
3
|
-
import { fileExists } from "./fileExist";
|
|
4
|
-
import { pageItem } from "./generateItems";
|
|
5
|
-
import { getDocument } from "./getDocument";
|
|
6
|
-
import { getFilesRecursive } from "./getFilesRecursive";
|
|
7
|
-
import { getOptions } from "./getOptions";
|
|
8
|
-
import { injectTsFile } from "./injectTsFile";
|
|
9
|
-
import { rnds } from "./rnd";
|
|
10
|
-
import { buildFront } from "./buildFront";
|
|
11
|
-
import { serializeDocument } from "./serializeDocument";
|
|
12
|
-
|
|
13
|
-
const backRegex = /\.back\.ts$/;
|
|
14
|
-
const htmlPageRegex = /\.page\.html$/;
|
|
15
|
-
|
|
16
|
-
export interface buildArguments {
|
|
17
|
-
sourceDir: string;
|
|
18
|
-
outputDir: string;
|
|
19
|
-
hotRestart?: boolean;
|
|
20
|
-
ignoreConsoleLogs?: boolean;
|
|
21
|
-
ignoreErrors?: boolean;
|
|
22
|
-
minify?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const build = async (args: buildArguments, minify = true) => {
|
|
26
|
-
const { hotRestart, ignoreConsoleLogs, ignoreErrors } = args;
|
|
27
|
-
const { outputDir, sourceDir } = getOptions({
|
|
28
|
-
sourceDir: args.sourceDir,
|
|
29
|
-
outputDir: args.outputDir,
|
|
30
|
-
});
|
|
31
|
-
if (!(await fileExists(sourceDir))) throw "directory does not exist";
|
|
32
|
-
await mkdir(outputDir, { recursive: true });
|
|
33
|
-
const pagesReady: string[] = [];
|
|
34
|
-
const backFiles = [...getFilesRecursive(sourceDir, { pattern: backRegex })];
|
|
35
|
-
|
|
36
|
-
const buildFrontPromises: Promise<[boolean, string, CallableFunction]>[] = [];
|
|
37
|
-
|
|
38
|
-
for (const file of backFiles) {
|
|
39
|
-
const name = basename(file).replace(backRegex, "");
|
|
40
|
-
const htmlFile = file.replace(backRegex, ".page.html");
|
|
41
|
-
pagesReady.push(htmlFile);
|
|
42
|
-
const htmlExist = await fileExists(htmlFile);
|
|
43
|
-
let html = htmlExist
|
|
44
|
-
? await readFile(htmlFile, { encoding: "utf-8" })
|
|
45
|
-
: pageItem(name).html;
|
|
46
|
-
const scriptId = "tmp" + rnds(25);
|
|
47
|
-
html = await injectTsFile({
|
|
48
|
-
html,
|
|
49
|
-
outputDir,
|
|
50
|
-
sourceDir,
|
|
51
|
-
tsFile: file,
|
|
52
|
-
scriptId,
|
|
53
|
-
});
|
|
54
|
-
const { document, jsDomErrors, window } = getDocument(html, {
|
|
55
|
-
ignoreConsoleLogs,
|
|
56
|
-
ignoreErrors,
|
|
57
|
-
});
|
|
58
|
-
if (ignoreErrors && jsDomErrors.length)
|
|
59
|
-
jsDomErrors.forEach((_: any) =>
|
|
60
|
-
console["log"](`page ${name} error: `, _.detail || _),
|
|
61
|
-
);
|
|
62
|
-
await new Promise((ok) => {
|
|
63
|
-
const handle = setTimeout(() => {
|
|
64
|
-
console["log"](`time up: ${name}`);
|
|
65
|
-
ok(0);
|
|
66
|
-
}, 6e3);
|
|
67
|
-
document.addEventListener("load", () => {
|
|
68
|
-
clearTimeout(handle);
|
|
69
|
-
ok(0);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
const scriptNode = document.querySelector(`#${scriptId}`);
|
|
73
|
-
if (scriptNode) document.head.removeChild(scriptNode);
|
|
74
|
-
html = serializeDocument(document);
|
|
75
|
-
window.close();
|
|
76
|
-
const tsFile = htmlFile.replace(htmlPageRegex, ".page.ts");
|
|
77
|
-
const outHtmlFile = file
|
|
78
|
-
.replace(sourceDir, outputDir)
|
|
79
|
-
.replace(backRegex, ".html");
|
|
80
|
-
const outTsFile = file
|
|
81
|
-
.replace(sourceDir, outputDir)
|
|
82
|
-
.replace(backRegex, ".js");
|
|
83
|
-
|
|
84
|
-
html = html.replace(/\/\*tkeron\-front\-script/g, "");
|
|
85
|
-
html = html.replace(/tkeron\-front\-script\*\//g, "");
|
|
86
|
-
|
|
87
|
-
buildFrontPromises.push(
|
|
88
|
-
tryBuildFront(
|
|
89
|
-
name,
|
|
90
|
-
html,
|
|
91
|
-
outHtmlFile,
|
|
92
|
-
hotRestart,
|
|
93
|
-
outTsFile,
|
|
94
|
-
"tkeron_page_js",
|
|
95
|
-
tsFile,
|
|
96
|
-
minify,
|
|
97
|
-
),
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
const htmlFiles = [
|
|
101
|
-
...getFilesRecursive(sourceDir, { pattern: htmlPageRegex }),
|
|
102
|
-
];
|
|
103
|
-
for (const file of htmlFiles) {
|
|
104
|
-
const name = basename(file).replace(htmlPageRegex, "");
|
|
105
|
-
if (pagesReady.includes(file)) continue;
|
|
106
|
-
let html = await readFile(file, { encoding: "utf-8" });
|
|
107
|
-
const outHtmlFile = file
|
|
108
|
-
.replace(sourceDir, outputDir)
|
|
109
|
-
.replace(htmlPageRegex, ".html");
|
|
110
|
-
const outTsFile = file
|
|
111
|
-
.replace(sourceDir, outputDir)
|
|
112
|
-
.replace(htmlPageRegex, ".html");
|
|
113
|
-
const tsFile = file.replace(htmlPageRegex, ".page.ts");
|
|
114
|
-
|
|
115
|
-
html = html.replace(/\/\*tkeron\-front\-script/g, "");
|
|
116
|
-
html = html.replace(/tkeron\-front\-script\*\//g, "");
|
|
117
|
-
|
|
118
|
-
buildFrontPromises.push(
|
|
119
|
-
tryBuildFront(
|
|
120
|
-
name,
|
|
121
|
-
html,
|
|
122
|
-
outHtmlFile,
|
|
123
|
-
hotRestart,
|
|
124
|
-
outTsFile,
|
|
125
|
-
"tkeron_page_js",
|
|
126
|
-
tsFile,
|
|
127
|
-
minify,
|
|
128
|
-
),
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const results = await Promise.all(buildFrontPromises);
|
|
133
|
-
for (const result of results) {
|
|
134
|
-
const [ok, name, retry] = result;
|
|
135
|
-
if (ok) continue;
|
|
136
|
-
console["log"](`\nretry build ${name}...`);
|
|
137
|
-
await new Promise((done) => setTimeout(done, 300));
|
|
138
|
-
const [done] = await retry();
|
|
139
|
-
if (!done) throw `error building ${name}, try build command again...`;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const compdate = new Date().getTime().toString();
|
|
143
|
-
const compdateDir = join(outputDir, "compdate.txt");
|
|
144
|
-
await writeFile(compdateDir, compdate, { encoding: "utf-8" });
|
|
145
|
-
|
|
146
|
-
console["log"]("\nall site built");
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
export const tryBuildFront = async (
|
|
150
|
-
name: string,
|
|
151
|
-
html: string,
|
|
152
|
-
outHtmlFile: string,
|
|
153
|
-
hotRestart: boolean,
|
|
154
|
-
outTsFile: string,
|
|
155
|
-
scriptId: string,
|
|
156
|
-
tsFile: string,
|
|
157
|
-
minify = true,
|
|
158
|
-
): Promise<[boolean, string, CallableFunction]> => {
|
|
159
|
-
return new Promise(async (ok) => {
|
|
160
|
-
try {
|
|
161
|
-
await buildFront({
|
|
162
|
-
html,
|
|
163
|
-
outHtmlFile,
|
|
164
|
-
hotRestart,
|
|
165
|
-
outTsFile,
|
|
166
|
-
scriptId: "tkeron_page_js",
|
|
167
|
-
tsFile,
|
|
168
|
-
minify,
|
|
169
|
-
});
|
|
170
|
-
console["log"](`site ${name} built`);
|
|
171
|
-
ok([true, name, async () => {}]);
|
|
172
|
-
} catch (_) {
|
|
173
|
-
console["log"](`error building site ${name}: `, _);
|
|
174
|
-
ok([
|
|
175
|
-
false,
|
|
176
|
-
name,
|
|
177
|
-
() =>
|
|
178
|
-
tryBuildFront(
|
|
179
|
-
name,
|
|
180
|
-
html,
|
|
181
|
-
outHtmlFile,
|
|
182
|
-
hotRestart,
|
|
183
|
-
outTsFile,
|
|
184
|
-
scriptId,
|
|
185
|
-
tsFile,
|
|
186
|
-
),
|
|
187
|
-
]);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
};
|
package/src/buildFront.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { mkdir, readFile, unlink, writeFile } from "fs/promises";
|
|
2
|
-
import { dirname, join } from "path";
|
|
3
|
-
import { bundleTs } from "./bundleTs";
|
|
4
|
-
import { fileExists } from "./fileExist";
|
|
5
|
-
import { injectCode } from "./injectCode";
|
|
6
|
-
|
|
7
|
-
export interface buildFrontOptions {
|
|
8
|
-
html: string;
|
|
9
|
-
tsFile: string;
|
|
10
|
-
outTsFile: string;
|
|
11
|
-
outHtmlFile: string;
|
|
12
|
-
hotRestart?: boolean;
|
|
13
|
-
scriptId: string;
|
|
14
|
-
minify?: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const buildFront = async (options: buildFrontOptions) => {
|
|
18
|
-
const { hotRestart, outHtmlFile, scriptId, tsFile, outTsFile, minify } =
|
|
19
|
-
options;
|
|
20
|
-
let { html } = options;
|
|
21
|
-
const outHtmlDir = dirname(outHtmlFile);
|
|
22
|
-
if (hotRestart === true) {
|
|
23
|
-
const code = await bundleTs(
|
|
24
|
-
join(__dirname, "..", "distFiles", "simpleHotRestart.ts"),
|
|
25
|
-
"shr.js",
|
|
26
|
-
true,
|
|
27
|
-
true,
|
|
28
|
-
);
|
|
29
|
-
html = injectCode(html, code, "tkeron_simple_hot_restart");
|
|
30
|
-
}
|
|
31
|
-
if (await fileExists(tsFile)) {
|
|
32
|
-
const tsCode = await bundleTs(tsFile, outTsFile, minify);
|
|
33
|
-
await unlink(outTsFile);
|
|
34
|
-
if (tsCode.trim() !== "") html = injectCode(html, tsCode, scriptId);
|
|
35
|
-
}
|
|
36
|
-
await mkdir(outHtmlDir, { recursive: true });
|
|
37
|
-
await writeFile(outHtmlFile, html, { encoding: "utf-8" });
|
|
38
|
-
|
|
39
|
-
return html;
|
|
40
|
-
};
|