@sealcode/sealgen 0.1.8 → 0.2.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/.log/ti-101379.log +19 -0
- package/.log/ti-131883.log +505 -0
- package/.log/ti-138140.log +505 -0
- package/.log/ti-138288.log +526 -0
- package/.log/tsserver.log +1624 -104
- package/@types/templates/form.d.ts +1 -1
- package/@types/templates/list.d.ts +1 -0
- package/@types/templates/page.d.ts +1 -1
- package/@types/utils/list-collections.d.ts +1 -0
- package/lib/add-collection.js +13 -24
- package/lib/add-collection.js.map +1 -1
- package/lib/add-route.js +25 -32
- package/lib/add-route.js.map +1 -1
- package/lib/find-scss-includes.js +9 -20
- package/lib/find-scss-includes.js.map +1 -1
- package/lib/generate-collections.js +30 -43
- package/lib/generate-collections.js.map +1 -1
- package/lib/generate-routes.js +29 -42
- package/lib/generate-routes.js.map +1 -1
- package/lib/index.js +10 -23
- package/lib/index.js.map +1 -1
- package/lib/templates/form.js +2 -2
- package/lib/templates/form.js.map +1 -1
- package/lib/templates/list.js +61 -0
- package/lib/templates/list.js.map +1 -0
- package/lib/templates/page.js +3 -1
- package/lib/templates/page.js.map +1 -1
- package/lib/utils/exec.js +16 -27
- package/lib/utils/exec.js.map +1 -1
- package/lib/utils/list-collections.js +20 -0
- package/lib/utils/list-collections.js.map +1 -0
- package/lib/utils/question.js +15 -26
- package/lib/utils/question.js.map +1 -1
- package/lib/utils/walk.js +14 -25
- package/lib/utils/walk.js.map +1 -1
- package/package.json +4 -2
- package/src/add-route.ts +13 -8
- package/src/generate-routes.ts +6 -1
- package/src/templates/form.ts +5 -2
- package/src/templates/list.ts +65 -0
- package/src/templates/page.ts +4 -2
- package/src/utils/list-collections.ts +16 -0
- package/tsconfig.json +20 -25
package/lib/utils/exec.js
CHANGED
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.exec = void 0;
|
|
13
4
|
/* eslint-disable no-console */
|
|
14
5
|
const child_process_1 = require("child_process");
|
|
15
|
-
function exec(program, args) {
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
});
|
|
6
|
+
async function exec(program, args) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
let stdout = "";
|
|
9
|
+
let stderr = "";
|
|
10
|
+
const process = child_process_1.spawn(program, args);
|
|
11
|
+
process.stdout.on("data", (data) => (stdout += data.toString()));
|
|
12
|
+
process.stderr.on("data", (data) => (stderr += data.toString()));
|
|
13
|
+
process.on("close", (exitCode) => {
|
|
14
|
+
if (exitCode === 0) {
|
|
15
|
+
resolve({ stdout, stderr, exitCode });
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.error([program, ...args].join(" "));
|
|
19
|
+
console.error(stderr);
|
|
20
|
+
reject({ stdout, stderr, exitCode });
|
|
21
|
+
}
|
|
33
22
|
});
|
|
34
23
|
});
|
|
35
24
|
}
|
package/lib/utils/exec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/utils/exec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/utils/exec.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,iDAAsC;AAE/B,KAAK,UAAU,IAAI,CACzB,OAAe,EACf,IAAc;IAEd,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,qBAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACzE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACzE,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE;YAChC,IAAI,QAAQ,KAAK,CAAC,EAAE;gBACnB,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;aACtC;iBAAM;gBACN,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC5C,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACtB,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;aACrC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC;AApBD,oBAoBC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.listCollections = void 0;
|
|
7
|
+
const locreq_1 = __importDefault(require("locreq"));
|
|
8
|
+
const walk_1 = require("./walk");
|
|
9
|
+
const target_locreq = locreq_1.default(process.cwd());
|
|
10
|
+
async function listCollections() {
|
|
11
|
+
const files = await walk_1.walk(target_locreq.resolve("src/back/collections"));
|
|
12
|
+
return files
|
|
13
|
+
.filter((f) => f.endsWith(".ts") &&
|
|
14
|
+
!f.endsWith(".test.ts") &&
|
|
15
|
+
!f.endsWith("collections.ts"))
|
|
16
|
+
.map((f) => f.replace(/.ts$/, "").split("/").at(-1) || "")
|
|
17
|
+
.filter((e) => e !== "");
|
|
18
|
+
}
|
|
19
|
+
exports.listCollections = listCollections;
|
|
20
|
+
//# sourceMappingURL=list-collections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-collections.js","sourceRoot":"","sources":["../../src/utils/list-collections.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA6B;AAC7B,iCAA8B;AAC9B,MAAM,aAAa,GAAG,gBAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAEtC,KAAK,UAAU,eAAe;IACpC,MAAM,KAAK,GAAG,MAAM,WAAI,CAAC,aAAa,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC;IACxE,OAAO,KAAK;SACV,MAAM,CACN,CAAC,CAAC,EAAE,EAAE,CACL,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;QACjB,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;QACvB,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAC9B;SACA,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACzD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;AAC3B,CAAC;AAXD,0CAWC"}
|
package/lib/utils/question.js
CHANGED
|
@@ -1,34 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.question = void 0;
|
|
13
4
|
const readline_1 = require("readline");
|
|
14
|
-
function question(text, validator) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
output: process.stdout,
|
|
19
|
-
});
|
|
20
|
-
let answer = "";
|
|
21
|
-
while (answer == "" || !validator(answer)) {
|
|
22
|
-
// eslint-disable-next-line no-await-in-loop
|
|
23
|
-
answer = yield new Promise((resolve) => rl.question(text, resolve));
|
|
24
|
-
if (!validator(answer)) {
|
|
25
|
-
// eslint-disable-next-line no-console
|
|
26
|
-
console.log("Try again");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
rl.close();
|
|
30
|
-
return answer;
|
|
5
|
+
async function question(text, validator) {
|
|
6
|
+
const rl = readline_1.createInterface({
|
|
7
|
+
input: process.stdin,
|
|
8
|
+
output: process.stdout,
|
|
31
9
|
});
|
|
10
|
+
let answer = "";
|
|
11
|
+
while (answer == "" || !validator(answer)) {
|
|
12
|
+
// eslint-disable-next-line no-await-in-loop
|
|
13
|
+
answer = await new Promise((resolve) => rl.question(text, resolve));
|
|
14
|
+
if (!validator(answer)) {
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.log("Try again");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
rl.close();
|
|
20
|
+
return answer;
|
|
32
21
|
}
|
|
33
22
|
exports.question = question;
|
|
34
23
|
//# sourceMappingURL=question.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"question.js","sourceRoot":"","sources":["../../src/utils/question.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"question.js","sourceRoot":"","sources":["../../src/utils/question.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAEpC,KAAK,UAAU,QAAQ,CAAC,IAAY,EAAE,SAAsC;IAClF,MAAM,EAAE,GAAG,0BAAe,CAAC;QAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACtB,CAAC,CAAC;IACH,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,OAAO,MAAM,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;QAC1C,4CAA4C;QAC5C,MAAM,GAAG,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;YACvB,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;SACzB;KACD;IAED,EAAE,CAAC,KAAK,EAAE,CAAC;IACX,OAAO,MAAM,CAAC;AACf,CAAC;AAjBD,4BAiBC"}
|
package/lib/utils/walk.js
CHANGED
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.walk = void 0;
|
|
13
4
|
const fs_1 = require("fs");
|
|
14
5
|
const path_1 = require("path");
|
|
15
|
-
function walk(dir) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
async function walk(dir) {
|
|
7
|
+
const entries = await fs_1.promises.readdir(dir);
|
|
8
|
+
let ret = [];
|
|
9
|
+
for (const entry of entries) {
|
|
10
|
+
const fullpath = path_1.resolve(dir, entry);
|
|
11
|
+
// eslint-disable-next-line no-await-in-loop
|
|
12
|
+
const info = await fs_1.promises.stat(fullpath);
|
|
13
|
+
if (info.isDirectory()) {
|
|
21
14
|
// eslint-disable-next-line no-await-in-loop
|
|
22
|
-
|
|
23
|
-
if (info.isDirectory()) {
|
|
24
|
-
// eslint-disable-next-line no-await-in-loop
|
|
25
|
-
ret = [...ret, ...(yield walk(fullpath))];
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
ret = [...ret, fullpath];
|
|
29
|
-
}
|
|
15
|
+
ret = [...ret, ...(await walk(fullpath))];
|
|
30
16
|
}
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
else {
|
|
18
|
+
ret = [...ret, fullpath];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return ret;
|
|
33
22
|
}
|
|
34
23
|
exports.walk = walk;
|
|
35
24
|
//# sourceMappingURL=walk.js.map
|
package/lib/utils/walk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../src/utils/walk.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../src/utils/walk.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,+BAA+B;AAExB,KAAK,UAAU,IAAI,CAAC,GAAW;IACrC,MAAM,OAAO,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,GAAG,GAAa,EAAE,CAAC;IACvB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE;QAC5B,MAAM,QAAQ,GAAG,cAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACrC,4CAA4C;QAC5C,MAAM,IAAI,GAAG,MAAM,aAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAErC,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE;YACvB,4CAA4C;YAC5C,GAAG,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SAC1C;aAAM;YACN,GAAG,GAAG,CAAC,GAAG,GAAG,EAAE,QAAQ,CAAC,CAAC;SACzB;KACD;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAhBD,oBAgBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealcode/sealgen",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Module to automate adding routes and collections to a sealious application",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/mocha": "^9.0.0",
|
|
19
|
+
"@types/prompts": "^2.0.14",
|
|
19
20
|
"@typescript-eslint/eslint-plugin": "^4.29.3",
|
|
20
21
|
"@typescript-eslint/parser": "^4.29.3",
|
|
21
22
|
"eslint": "^7.32.0",
|
|
@@ -33,6 +34,7 @@
|
|
|
33
34
|
"types": "./@types/index.d.ts",
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@sealcode/ts-predicates": "^0.2.1",
|
|
36
|
-
"locreq": "^2.0.2"
|
|
37
|
+
"locreq": "^2.0.2",
|
|
38
|
+
"prompts": "^2.4.2"
|
|
37
39
|
}
|
|
38
40
|
}
|
package/src/add-route.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { escape_url_params } from "./utils/escape-url-params";
|
|
|
8
8
|
|
|
9
9
|
import _locreq from "locreq";
|
|
10
10
|
import { generateRoutes } from "./generate-routes";
|
|
11
|
+
import { listTemplate } from "./templates/list";
|
|
11
12
|
const target_locreq = _locreq(process.cwd());
|
|
12
13
|
|
|
13
14
|
export async function addRoute(): Promise<void> {
|
|
@@ -19,19 +20,23 @@ export async function addRoute(): Promise<void> {
|
|
|
19
20
|
"Enter a full absolute path for the new route (e.g. /admin/users/add): ",
|
|
20
21
|
(s: string) => s.trim()[0] == "/"
|
|
21
22
|
);
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const mode_answer = (await question(
|
|
24
|
+
"Is this a page (p), a form (f), or a list (l)? ",
|
|
25
|
+
(a: string) => ["p", "f", "l"].includes(a.toLowerCase())
|
|
26
|
+
)) as "p" | "f" | "l";
|
|
27
|
+
const mode = (<const>{ p: "page", f: "form", l: "list" })[mode_answer];
|
|
28
|
+
|
|
28
29
|
const file_path = target_locreq.resolve(
|
|
29
30
|
`src/back/routes/${escape_url_params(url)}.${mode}.ts`
|
|
30
31
|
);
|
|
31
32
|
const test_file_path = target_locreq.resolve(
|
|
32
33
|
`src/back/routes/${escape_url_params(url)}.test.ts`
|
|
33
34
|
);
|
|
34
|
-
const template =
|
|
35
|
+
const template = {
|
|
36
|
+
page: pageTemplate,
|
|
37
|
+
form: formTemplate,
|
|
38
|
+
list: listTemplate,
|
|
39
|
+
}[mode];
|
|
35
40
|
|
|
36
41
|
if (existsSync(file_path)) {
|
|
37
42
|
// eslint-disable-next-line no-console
|
|
@@ -39,7 +44,7 @@ export async function addRoute(): Promise<void> {
|
|
|
39
44
|
return;
|
|
40
45
|
}
|
|
41
46
|
await fs.mkdir(resolve(file_path, "../"), { recursive: true });
|
|
42
|
-
await fs.writeFile(file_path, template(action, file_path));
|
|
47
|
+
await fs.writeFile(file_path, await template(action, file_path));
|
|
43
48
|
await fs.writeFile(test_file_path, testTemplate(action, file_path));
|
|
44
49
|
// eslint-disable-next-line no-console
|
|
45
50
|
console.log(`${file_path} created`);
|
package/src/generate-routes.ts
CHANGED
|
@@ -26,7 +26,12 @@ export async function generateRoutes(): Promise<void> {
|
|
|
26
26
|
(
|
|
27
27
|
await walk(target_locreq.resolve("src/back/routes"))
|
|
28
28
|
)
|
|
29
|
-
.filter(
|
|
29
|
+
.filter(
|
|
30
|
+
(f) =>
|
|
31
|
+
f.endsWith(".page.ts") ||
|
|
32
|
+
f.endsWith(".form.ts") ||
|
|
33
|
+
f.endsWith(".list.ts")
|
|
34
|
+
)
|
|
30
35
|
.map(async (fullpath) => ({
|
|
31
36
|
fullpath,
|
|
32
37
|
actionName: await extractActionName(fullpath),
|
package/src/templates/form.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { curryImportPath } from "../utils/import-path";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export async function formTemplate(
|
|
4
|
+
action_name: string,
|
|
5
|
+
newfilefullpath: string
|
|
6
|
+
): Promise<string> {
|
|
4
7
|
const rel = curryImportPath(newfilefullpath);
|
|
5
8
|
return `import { BaseContext } from "koa";
|
|
6
9
|
import {Users} from "${rel("src/back/collections/collections")}";
|
|
@@ -39,4 +42,4 @@ export default new(class ${action_name}Form extends Form {
|
|
|
39
42
|
}
|
|
40
43
|
})();
|
|
41
44
|
`;
|
|
42
|
-
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { curryImportPath } from "../utils/import-path";
|
|
2
|
+
import prompts = require("prompts");
|
|
3
|
+
import { listCollections } from "../utils/list-collections";
|
|
4
|
+
|
|
5
|
+
export const listTemplate = async (
|
|
6
|
+
action_name: string,
|
|
7
|
+
newfilefullpath: string
|
|
8
|
+
): Promise<string> => {
|
|
9
|
+
const response = await prompts({
|
|
10
|
+
type: "autocomplete",
|
|
11
|
+
name: "collection",
|
|
12
|
+
message: "Which sealious collection do you want to list?",
|
|
13
|
+
choices: (
|
|
14
|
+
await listCollections()
|
|
15
|
+
).map((collection) => ({
|
|
16
|
+
title: collection,
|
|
17
|
+
value: collection,
|
|
18
|
+
})),
|
|
19
|
+
});
|
|
20
|
+
const collection = response.collection as string;
|
|
21
|
+
const uppercase_collection =
|
|
22
|
+
collection[0].toLocaleUpperCase() + collection.slice(1);
|
|
23
|
+
const rel = curryImportPath(newfilefullpath);
|
|
24
|
+
return `import { BaseContext } from "koa";
|
|
25
|
+
import { CollectionItem, Middlewares } from "sealious";
|
|
26
|
+
import { tempstream } from "tempstream";
|
|
27
|
+
import { ${uppercase_collection} } from "${rel(
|
|
28
|
+
"src/back/collections/collections"
|
|
29
|
+
)}";
|
|
30
|
+
import html from "${rel("src/back/html.ts")}";
|
|
31
|
+
import {
|
|
32
|
+
BaseListPageDefaultProps,
|
|
33
|
+
BaseListPageProps,
|
|
34
|
+
BaseListPagePropsShape,
|
|
35
|
+
SealiousItemListPage,
|
|
36
|
+
} from "${rel("src/back/page/list.ts")}";
|
|
37
|
+
import { AllQueryParams } from "${rel("src/back/page/props-parser.ts")}";
|
|
38
|
+
|
|
39
|
+
export const actionName = "${action_name}";
|
|
40
|
+
|
|
41
|
+
export default new (class ${action_name}Page extends SealiousItemListPage<typeof ${uppercase_collection}> {
|
|
42
|
+
propsParser = new AllQueryParams<BaseListPageProps>(
|
|
43
|
+
BaseListPagePropsShape,
|
|
44
|
+
BaseListPageDefaultProps
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
async render(ctx: BaseContext) {
|
|
48
|
+
return html(
|
|
49
|
+
ctx,
|
|
50
|
+
"${uppercase_collection}",
|
|
51
|
+
tempstream/* HTML */ \`<div>
|
|
52
|
+
<h2>${uppercase_collection} List</h2>
|
|
53
|
+
<ul>
|
|
54
|
+
\${super.render(ctx)}
|
|
55
|
+
</ul>
|
|
56
|
+
</div>\`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async renderItem(_: BaseContext, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
61
|
+
return tempstream\`<li>\${item.id}</li>\`;
|
|
62
|
+
}
|
|
63
|
+
})(${uppercase_collection});
|
|
64
|
+
`;
|
|
65
|
+
};
|
package/src/templates/page.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { importPath } from "../utils/import-path";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export async function pageTemplate(
|
|
4
4
|
action_name: string,
|
|
5
5
|
fullpath: string
|
|
6
|
-
)
|
|
6
|
+
): Promise<string> {
|
|
7
|
+
return `import { BaseContext } from "koa";
|
|
7
8
|
import { tempstream } from "tempstream";
|
|
8
9
|
import { Page } from "${importPath(fullpath, "src/back/page/page")}";
|
|
9
10
|
|
|
@@ -21,3 +22,4 @@ export default new (class ${action_name}Page extends Page {
|
|
|
21
22
|
}
|
|
22
23
|
})();
|
|
23
24
|
`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _locreq from "locreq";
|
|
2
|
+
import { walk } from "./walk";
|
|
3
|
+
const target_locreq = _locreq(process.cwd());
|
|
4
|
+
|
|
5
|
+
export async function listCollections(): Promise<string[]> {
|
|
6
|
+
const files = await walk(target_locreq.resolve("src/back/collections"));
|
|
7
|
+
return files
|
|
8
|
+
.filter(
|
|
9
|
+
(f) =>
|
|
10
|
+
f.endsWith(".ts") &&
|
|
11
|
+
!f.endsWith(".test.ts") &&
|
|
12
|
+
!f.endsWith("collections.ts")
|
|
13
|
+
)
|
|
14
|
+
.map((f) => f.replace(/.ts$/, "").split("/").at(-1) || "")
|
|
15
|
+
.filter((e) => e !== "");
|
|
16
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"include":[
|
|
23
|
-
"src/**/*"
|
|
24
|
-
],
|
|
25
|
-
"exclude": ["src/**/*.test.ts"]
|
|
26
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"moduleResolution": "node",
|
|
5
|
+
"noImplicitAny": true,
|
|
6
|
+
"noImplicitThis": true,
|
|
7
|
+
"strictNullChecks": true,
|
|
8
|
+
"target": "es2020",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"lib": ["ES6", "ESNext"],
|
|
12
|
+
"outDir": "lib",
|
|
13
|
+
"checkJs": true,
|
|
14
|
+
"allowJs": true,
|
|
15
|
+
"declarationDir": "@types",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"sourceMap": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*"],
|
|
20
|
+
"exclude": ["src/**/*.test.ts"]
|
|
21
|
+
}
|