@sealcode/sealgen 0.18.2 → 0.18.5
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/@types/add-collection.d.ts +1 -0
- package/@types/add-crud.d.ts +3 -0
- package/@types/add-jdd-component.d.ts +1 -0
- package/@types/add-list-route.test.d.ts +1 -0
- package/@types/add-route.d.ts +3 -0
- package/@types/add-route.test.d.ts +1 -0
- package/@types/add-verbose-crud.d.ts +3 -0
- package/@types/build.d.ts +3 -0
- package/@types/builders/backend-ts-builder.d.ts +7 -0
- package/@types/builders/builder.d.ts +11 -0
- package/@types/builders/colors-builder.d.ts +10 -0
- package/@types/builders/css-builder.d.ts +19 -0
- package/@types/builders/fonts-builder.d.ts +7 -0
- package/@types/builders/frontend-ts-builder.d.ts +11 -0
- package/@types/cli.d.ts +2 -0
- package/@types/components/components.d.ts +2 -0
- package/@types/components/tabs.d.ts +2 -0
- package/@types/components/toggle-modal.d.ts +6 -0
- package/@types/crud-field-snippets.d.ts +3 -0
- package/@types/embeddable-file-extensions.d.ts +1 -0
- package/@types/esbuild-plugins/load-assets.d.ts +5 -0
- package/@types/esbuild-plugins/rewrite-asset-imports.d.ts +5 -0
- package/@types/example.test.d.ts +1 -0
- package/@types/find-css-includes.d.ts +1 -0
- package/@types/forms/controls/array.d.ts +35 -0
- package/@types/forms/controls/autocomplete.d.ts +22 -0
- package/@types/forms/controls/big-radio-group.d.ts +14 -0
- package/@types/forms/controls/checkbox-group.d.ts +21 -0
- package/@types/forms/controls/checkbox.d.ts +17 -0
- package/@types/forms/controls/checkboxed-list-input.d.ts +21 -0
- package/@types/forms/controls/checkboxed-list-input.test.d.ts +1 -0
- package/@types/forms/controls/collapsible-checkbox-group.d.ts +11 -0
- package/@types/forms/controls/collapsible-field-group.d.ts +21 -0
- package/@types/forms/controls/controls.d.ts +31 -0
- package/@types/forms/controls/derived-frame.d.ts +21 -0
- package/@types/forms/controls/derived.d.ts +13 -0
- package/@types/forms/controls/dropdown.d.ts +30 -0
- package/@types/forms/controls/editable-collection-subset.d.ts +20 -0
- package/@types/forms/controls/field-group.d.ts +23 -0
- package/@types/forms/controls/file.d.ts +13 -0
- package/@types/forms/controls/file.test.d.ts +1 -0
- package/@types/forms/controls/form-control.d.ts +20 -0
- package/@types/forms/controls/form-field-control.d.ts +13 -0
- package/@types/forms/controls/form-header.d.ts +8 -0
- package/@types/forms/controls/form-paragraph.d.ts +7 -0
- package/@types/forms/controls/frame.d.ts +17 -0
- package/@types/forms/controls/hidden-input.d.ts +9 -0
- package/@types/forms/controls/html.d.ts +11 -0
- package/@types/forms/controls/multiple-files.d.ts +40 -0
- package/@types/forms/controls/multiple-photos.d.ts +19 -0
- package/@types/forms/controls/number.d.ts +13 -0
- package/@types/forms/controls/photo.d.ts +21 -0
- package/@types/forms/controls/photo.test.d.ts +1 -0
- package/@types/forms/controls/radio.d.ts +16 -0
- package/@types/forms/controls/reverse-single-reference.d.ts +1 -0
- package/@types/forms/controls/simple-input.d.ts +33 -0
- package/@types/forms/controls/single-reference.d.ts +13 -0
- package/@types/forms/controls/single-reference.test.d.ts +1 -0
- package/@types/forms/controls/table.d.ts +34 -0
- package/@types/forms/controls/textarea.d.ts +25 -0
- package/@types/forms/controls/tickable.d.ts +25 -0
- package/@types/forms/fields/boolean.d.ts +17 -0
- package/@types/forms/fields/boolean.test.d.ts +1 -0
- package/@types/forms/fields/checkboxed-list.d.ts +21 -0
- package/@types/forms/fields/collection-field.d.ts +15 -0
- package/@types/forms/fields/email.d.ts +7 -0
- package/@types/forms/fields/email.test.d.ts +1 -0
- package/@types/forms/fields/enum-multiple.d.ts +18 -0
- package/@types/forms/fields/enum-multiple.test.d.ts +1 -0
- package/@types/forms/fields/enum.d.ts +18 -0
- package/@types/forms/fields/enum.test.d.ts +1 -0
- package/@types/forms/fields/existing-sealious-value.d.ts +6 -0
- package/@types/forms/fields/field.d.ts +48 -0
- package/@types/forms/fields/field.test.d.ts +1 -0
- package/@types/forms/fields/fields.d.ts +16 -0
- package/@types/forms/fields/file.d.ts +19 -0
- package/@types/forms/fields/file.test.d.ts +1 -0
- package/@types/forms/fields/multiple-files.d.ts +14 -0
- package/@types/forms/fields/number.d.ts +23 -0
- package/@types/forms/fields/number.test.d.ts +1 -0
- package/@types/forms/fields/pick-from-list.d.ts +14 -0
- package/@types/forms/fields/pick-from-list.test.d.ts +1 -0
- package/@types/forms/fields/proxy-field.d.ts +13 -0
- package/@types/forms/fields/regexp.d.ts +16 -0
- package/@types/forms/fields/regexp.test.d.ts +1 -0
- package/@types/forms/fields/reverse-single-reference.d.ts +13 -0
- package/@types/forms/fields/simple-form-field.d.ts +9 -0
- package/@types/forms/fields/structured-array.d.ts +14 -0
- package/@types/forms/fields/table.d.ts +13 -0
- package/@types/forms/form-types.d.ts +26 -0
- package/@types/forms/form.d.ts +31 -0
- package/@types/forms/form.test.d.ts +6 -0
- package/@types/forms/multiform.d.ts +24 -0
- package/@types/forms/multiform.test.d.ts +1 -0
- package/@types/generate-collections.d.ts +2 -0
- package/@types/generate-components.d.ts +1 -0
- package/@types/generate-routes.d.ts +5 -0
- package/@types/generate-routes.test.d.ts +1 -0
- package/@types/generate-stimulus.d.ts +1 -0
- package/@types/get-fonts.d.ts +2 -0
- package/@types/index.d.ts +46 -0
- package/@types/make-env.d.ts +1 -0
- package/@types/make-hidden-inputs.d.ts +5 -0
- package/@types/mount.d.ts +7 -0
- package/@types/notifier.d.ts +2 -0
- package/@types/page/access-control.d.ts +6 -0
- package/@types/page/default-list-filters.d.ts +18 -0
- package/@types/page/list.d.ts +48 -0
- package/@types/page/mountable-with-fields.d.ts +42 -0
- package/@types/page/mountable-with-fields.test.d.ts +1 -0
- package/@types/page/mountable.d.ts +11 -0
- package/@types/page/page.d.ts +19 -0
- package/@types/page/props-parser.d.ts +16 -0
- package/@types/page/sealious-list.d.ts +20 -0
- package/@types/page/sealious-list.test.d.ts +1 -0
- package/@types/page/stateful-page.d.ts +63 -0
- package/@types/page/stateful-page.test.d.ts +1 -0
- package/@types/register-external.d.ts +2 -0
- package/@types/register-external.test.d.ts +1 -0
- package/@types/run.d.ts +1 -0
- package/@types/sanitize.d.ts +1 -0
- package/@types/src/builder.d.ts +9 -7
- package/@types/src/crud-field-snippets.d.ts +3 -0
- package/@types/src/page/stateful-page.d.ts +1 -1
- package/@types/src/register-external.d.ts +2 -0
- package/@types/src/register-external.test.d.ts +1 -0
- package/@types/src/templates/shared/handlers/settable-by.d.ts +2 -0
- package/@types/src/templates/shared/shared-crud-form-fields.d.ts +1 -1
- package/@types/target-locreq.d.ts +4 -0
- package/@types/templates/collection.d.ts +1 -0
- package/@types/templates/form.d.ts +16 -0
- package/@types/templates/jdd-component.d.ts +1 -0
- package/@types/templates/jdd-editor.d.ts +1 -0
- package/@types/templates/list.d.ts +1 -0
- package/@types/templates/long-running-process.d.ts +1 -0
- package/@types/templates/multiform.d.ts +1 -0
- package/@types/templates/page.d.ts +1 -0
- package/@types/templates/post.d.ts +1 -0
- package/@types/templates/redirect.d.ts +1 -0
- package/@types/templates/route-test.d.ts +1 -0
- package/@types/templates/shared/collection-create-form.d.ts +1 -0
- package/@types/templates/shared/collection-edit-form.d.ts +1 -0
- package/@types/templates/shared/collection-list.d.ts +16 -0
- package/@types/templates/shared/handlers/boolean.d.ts +2 -0
- package/@types/templates/shared/handlers/date.d.ts +2 -0
- package/@types/templates/shared/handlers/deep-reverse-single-reference.d.ts +2 -0
- package/@types/templates/shared/handlers/default.d.ts +2 -0
- package/@types/templates/shared/handlers/enum.d.ts +2 -0
- package/@types/templates/shared/handlers/file.d.ts +2 -0
- package/@types/templates/shared/handlers/image.d.ts +2 -0
- package/@types/templates/shared/handlers/int.d.ts +2 -0
- package/@types/templates/shared/handlers/jdd.d.ts +2 -0
- package/@types/templates/shared/handlers/single-reference.d.ts +2 -0
- package/@types/templates/shared/handlers/structured-array.d.ts +2 -0
- package/@types/templates/shared/item-delete.d.ts +1 -0
- package/@types/templates/shared/shared-crud-form-fields.d.ts +68 -0
- package/@types/templates/stateful-page.d.ts +1 -0
- package/@types/templates/stimulus-controller.d.ts +1 -0
- package/@types/templates/templates.d.ts +21 -0
- package/@types/test_utils/exec_async.d.ts +1 -0
- package/@types/test_utils/locator_is_visible.d.ts +2 -0
- package/@types/test_utils/test-on-real-app.d.ts +27 -0
- package/@types/utils/assert-throws.d.ts +1 -0
- package/@types/utils/base64.d.ts +2 -0
- package/@types/utils/browser-creator.d.ts +1 -0
- package/@types/utils/escape-url-params.d.ts +2 -0
- package/@types/utils/exec.d.ts +5 -0
- package/@types/utils/extract-fields-from-collection.d.ts +14 -0
- package/@types/utils/format-external-url.d.ts +1 -0
- package/@types/utils/import-path.d.ts +2 -0
- package/@types/utils/input-wrapper.d.ts +3 -0
- package/@types/utils/list-collections.d.ts +1 -0
- package/@types/utils/make-slug.d.ts +1 -0
- package/@types/utils/module-dirname.d.ts +1 -0
- package/@types/utils/natural-numbers.d.ts +1 -0
- package/@types/utils/prettier.d.ts +3 -0
- package/@types/utils/question.d.ts +1 -0
- package/@types/utils/render-attributes.d.ts +1 -0
- package/@types/utils/sleep.d.ts +1 -0
- package/@types/utils/translate.d.ts +3 -0
- package/@types/utils/url-with-new-params.d.ts +2 -0
- package/@types/utils/utils.d.ts +17 -0
- package/@types/utils/walk.d.ts +1 -0
- package/@types/utils/with-fallback.d.ts +2 -0
- package/@types/utils/write-file.d.ts +1 -0
- package/README.md +57 -0
- package/lib/cli.js +13 -5
- package/lib/crud-field-snippets.js +52 -0
- package/lib/esbuild-plugins/rewrite-asset-imports.js +0 -2
- package/lib/page/list.js +6 -2
- package/lib/page/stateful-page.js +1 -1
- package/lib/register-external.js +105 -0
- package/lib/register-external.test.js +340 -0
- package/lib/templates/shared/handlers/default.js +1 -1
- package/lib/templates/shared/shared-crud-form-fields.js +2 -0
- package/lib/utils/extract-fields-from-collection.js +3 -3
- package/package.json +1 -1
- package/src/cli.ts +12 -4
- package/src/crud-field-snippets.ts +57 -0
- package/src/esbuild-plugins/rewrite-asset-imports.ts +0 -2
- package/src/find-css-includes.ts +0 -3
- package/src/page/list.ts +16 -3
- package/src/page/stateful-page.ts +3 -1
- package/src/register-external.test.ts +469 -0
- package/src/register-external.ts +148 -0
- package/src/templates/shared/handlers/default.ts +1 -0
- package/src/templates/shared/shared-crud-form-fields.ts +8 -0
- package/src/utils/extract-fields-from-collection.ts +3 -3
- package/remove-named-imports.js +0 -68
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function itemDeleteTemplate(delete_action_name: string, collection_name: string, list_action_name: string, importPath: (path: string) => string): Promise<string>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ExtractedFieldInfo } from "../../utils/extract-fields-from-collection.js";
|
|
2
|
+
export type FieldHandlerResult = {
|
|
3
|
+
imports: Partial<{
|
|
4
|
+
shared: string;
|
|
5
|
+
edit: string;
|
|
6
|
+
}>;
|
|
7
|
+
hide_field: boolean;
|
|
8
|
+
field: string;
|
|
9
|
+
hide_control: boolean;
|
|
10
|
+
controls: string;
|
|
11
|
+
is_required: boolean;
|
|
12
|
+
is_required_expr: string;
|
|
13
|
+
fields_var: string;
|
|
14
|
+
top_level_shared: string;
|
|
15
|
+
name: string;
|
|
16
|
+
hide_initial_value_edit: boolean;
|
|
17
|
+
initial_value_edit: Partial<{
|
|
18
|
+
main_value: string;
|
|
19
|
+
parsed_value: string;
|
|
20
|
+
fallback_value: string;
|
|
21
|
+
}> | string;
|
|
22
|
+
hide_initial_value_create: boolean;
|
|
23
|
+
initial_value_create: string;
|
|
24
|
+
pre_edit: string;
|
|
25
|
+
post_edit: string;
|
|
26
|
+
pre_create: string;
|
|
27
|
+
post_create: string;
|
|
28
|
+
sealious_value: (result: Exclude<FieldHandlerResult, "sealious_value">) => string;
|
|
29
|
+
hide_sealious_value: boolean;
|
|
30
|
+
fallback_value_sealious: string;
|
|
31
|
+
main_value_sealious: string;
|
|
32
|
+
};
|
|
33
|
+
export type FieldHandler<Defaults extends Partial<FieldHandlerResult>, Result extends Partial<FieldHandlerResult>> = (collection_name: string, field: ExtractedFieldInfo, importPath: (path: string) => string, defaults: Defaults, all_other_handlers: Record<string, FieldHandler<FieldHandlerResult, Partial<FieldHandlerResult>> | undefined>, fields_var?: string) => Promise<Result>;
|
|
34
|
+
export declare const field_handlers: Record<Exclude<string, "default">, FieldHandler<FieldHandlerResult, Partial<FieldHandlerResult>> | undefined> & {
|
|
35
|
+
default: FieldHandler<Record<string, never>, FieldHandlerResult>;
|
|
36
|
+
};
|
|
37
|
+
export declare function getFieldHandler(collection_name: string, field: ExtractedFieldInfo, importPath: (path: string) => string, fields_var?: string): Promise<{
|
|
38
|
+
imports: Partial<{
|
|
39
|
+
shared: string;
|
|
40
|
+
edit: string;
|
|
41
|
+
}>;
|
|
42
|
+
hide_field: boolean;
|
|
43
|
+
field: string;
|
|
44
|
+
hide_control: boolean;
|
|
45
|
+
controls: string;
|
|
46
|
+
is_required: boolean;
|
|
47
|
+
is_required_expr: string;
|
|
48
|
+
fields_var: string;
|
|
49
|
+
top_level_shared: string;
|
|
50
|
+
name: string;
|
|
51
|
+
hide_initial_value_edit: boolean;
|
|
52
|
+
initial_value_edit: string | Partial<{
|
|
53
|
+
main_value: string;
|
|
54
|
+
parsed_value: string;
|
|
55
|
+
fallback_value: string;
|
|
56
|
+
}>;
|
|
57
|
+
hide_initial_value_create: boolean;
|
|
58
|
+
initial_value_create: string;
|
|
59
|
+
pre_edit: string;
|
|
60
|
+
post_edit: string;
|
|
61
|
+
pre_create: string;
|
|
62
|
+
post_create: string;
|
|
63
|
+
sealious_value: (result: FieldHandlerResult) => string;
|
|
64
|
+
hide_sealious_value: boolean;
|
|
65
|
+
fallback_value_sealious: string;
|
|
66
|
+
main_value_sealious: string;
|
|
67
|
+
}>;
|
|
68
|
+
export declare function sharedCrudFormFields(collection_name: string, newfilefullpath: string): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function statefulPageTemplate(action_name: string, newfilefullpath: string): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jddComponentTemplate(controller_name: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { formTemplate } from "./form.js";
|
|
2
|
+
import { jddComponentTemplate } from "./jdd-component.js";
|
|
3
|
+
import { LongRunningProcessTemplate } from "./long-running-process.js";
|
|
4
|
+
import { multiformTemplate } from "./multiform.js";
|
|
5
|
+
import { pageTemplate } from "./page.js";
|
|
6
|
+
import { postTemplate } from "./post.js";
|
|
7
|
+
import { redirectTemplate } from "./redirect.js";
|
|
8
|
+
import { statefulPageTemplate } from "./stateful-page.js";
|
|
9
|
+
import { jddEditorTemplate } from "./jdd-editor.js";
|
|
10
|
+
export declare const Templates: {
|
|
11
|
+
page: typeof pageTemplate;
|
|
12
|
+
form: typeof formTemplate;
|
|
13
|
+
list: (action_name: string, newfilefullpath: string) => Promise<string>;
|
|
14
|
+
multiform: typeof multiformTemplate;
|
|
15
|
+
redirect: typeof redirectTemplate;
|
|
16
|
+
post: typeof postTemplate;
|
|
17
|
+
sreact: typeof statefulPageTemplate;
|
|
18
|
+
lpr: typeof LongRunningProcessTemplate;
|
|
19
|
+
jdd: typeof jddComponentTemplate;
|
|
20
|
+
"jdd-editor": typeof jddEditorTemplate;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const execAsync: (cmd: string) => Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import EventEmitter from "events";
|
|
3
|
+
export declare const callSealgenBin: () => string;
|
|
4
|
+
export declare class RealAppTest {
|
|
5
|
+
node_pid: number;
|
|
6
|
+
app_port: number;
|
|
7
|
+
mongo_port: number;
|
|
8
|
+
app_path: string;
|
|
9
|
+
container_name: string;
|
|
10
|
+
emitter: EventEmitter<[never]>;
|
|
11
|
+
static init(): Promise<RealAppTest>;
|
|
12
|
+
start(): Promise<void>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
runSealgenCommand(command: string): Promise<void>;
|
|
15
|
+
build(): Promise<void>;
|
|
16
|
+
throwIfItKillsTheApp<T>(cb: () => Promise<T>): Promise<T>;
|
|
17
|
+
httpGET(path: string): Promise<{
|
|
18
|
+
status: number;
|
|
19
|
+
response: string;
|
|
20
|
+
}>;
|
|
21
|
+
httpPOST(path: string, body: Record<string, unknown>): Promise<{
|
|
22
|
+
status: number;
|
|
23
|
+
response: string;
|
|
24
|
+
}>;
|
|
25
|
+
addFile(target_path: string, content: string): Promise<void>;
|
|
26
|
+
fullURL(path: string): string;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertThrowsAsync(fn: () => Promise<unknown>, error_handler?: (e: unknown) => Promise<void> | void): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getBrowser(): Promise<any>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ExtractedFieldInfo = {
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
target: string | null;
|
|
5
|
+
referencing_collection: string | null;
|
|
6
|
+
referencing_field: string | null;
|
|
7
|
+
intermediary_field_that_points_there: string | null;
|
|
8
|
+
is_readonly: boolean;
|
|
9
|
+
is_required: boolean;
|
|
10
|
+
subfields: {
|
|
11
|
+
name: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export default function extract_fields_from_collection(collection_name: string): Promise<ExtractedFieldInfo[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatExternalURL(url: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function listCollections(): Promise<string[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function makeSlug(t: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function module_dirname(module_url: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function naturalNumbers(min: number, max: number): Generator<number, void, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function question(text: string, validator: (answer: string) => boolean): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renderAttributes(attrs: Record<string, string | boolean>): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(time: number): Promise<unknown>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Awaited<T> = T extends Promise<infer U> ? U : T;
|
|
2
|
+
export type UnwrapArray<T> = T extends Array<infer U> ? U : T;
|
|
3
|
+
export declare function keys<S extends string>(object: Record<S, unknown>): S[];
|
|
4
|
+
export type ExtractTail<T extends any[]> = T extends [infer _, ...infer Tail] ? Tail : never;
|
|
5
|
+
export { sleep } from "./sleep.js";
|
|
6
|
+
export { naturalNumbers } from "./natural-numbers.js";
|
|
7
|
+
export { UrlWithNewParams } from "./url-with-new-params.js";
|
|
8
|
+
export { exec } from "./exec.js";
|
|
9
|
+
export { importPath, curryImportPath } from "./import-path.js";
|
|
10
|
+
export { listCollections } from "./list-collections.js";
|
|
11
|
+
export { walkDir } from "./walk.js";
|
|
12
|
+
export { assertThrowsAsync } from "./assert-throws.js";
|
|
13
|
+
export * from "./make-slug.js";
|
|
14
|
+
export * from "./render-attributes.js";
|
|
15
|
+
export * from "./format-external-url.js";
|
|
16
|
+
export * from "./base64.js";
|
|
17
|
+
export * from "./with-fallback.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function walkDir(dir: string): Promise<string[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeFile(path: string, content: string): Promise<void>;
|
package/README.md
CHANGED
|
@@ -10,3 +10,60 @@ In order to add Font Squirrel fonts with get-fonts command you need to create fo
|
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
where you put an empty brackets for a regular style font or a list of desired font styles.
|
|
13
|
+
|
|
14
|
+
## Register External Controllers and Styles
|
|
15
|
+
|
|
16
|
+
When creating a module that is a dependency for a Sealgen app, you can automatically register your module's controllers and styles with the parent project using these commands:
|
|
17
|
+
|
|
18
|
+
### register-external-controllers
|
|
19
|
+
|
|
20
|
+
Registers a module's stimulus controllers directory with the parent project's `sealgen.controllerDirs` configuration.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx sealgen register-external-controllers <module-name> <subdirectory>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
```bash
|
|
28
|
+
npx sealgen register-external-controllers my-module src/stimulus-controllers
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This will add `node_modules/my-module/src/stimulus-controllers` to the parent project's `package.json` sealgen configuration.
|
|
32
|
+
|
|
33
|
+
### register-external-styles
|
|
34
|
+
|
|
35
|
+
Registers a module's styles directory with the parent project's `sealgen.styleDirs` configuration.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx sealgen register-external-styles <module-name> <subdirectory>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Example:
|
|
42
|
+
```bash
|
|
43
|
+
npx sealgen register-external-styles my-module src/styles
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This will add `node_modules/my-module/src/styles` to the parent project's `package.json` sealgen configuration.
|
|
47
|
+
|
|
48
|
+
### Usage in Module Development
|
|
49
|
+
|
|
50
|
+
You can add these commands to your module's `package.json` postinstall script to automatically register your controllers and styles when the module is installed:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"name": "my-module",
|
|
55
|
+
"scripts": {
|
|
56
|
+
"postinstall": "npx sealgen register-external-controllers my-module src/stimulus-controllers && npx sealgen register-external-styles my-module src/styles"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### How It Works
|
|
62
|
+
|
|
63
|
+
1. The command traverses up the directory tree from the current working directory
|
|
64
|
+
2. It looks for a `package.json` file that contains a `sealgen` configuration
|
|
65
|
+
3. It adds the specified path to the appropriate array (`controllerDirs` or `styleDirs`)
|
|
66
|
+
4. If the `sealgen` configuration doesn't exist, it creates it
|
|
67
|
+
5. If the path is already present, it doesn't add a duplicate
|
|
68
|
+
|
|
69
|
+
This ensures that when your module is installed as a dependency, the parent project will automatically know where to find your controllers and styles.
|
package/lib/cli.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import yargs from "yargs/yargs";
|
|
2
3
|
import { addCollection } from "./add-collection.js";
|
|
4
|
+
import { addCRUD } from "./add-crud.js";
|
|
3
5
|
import { addJDDComponent } from "./add-jdd-component.js";
|
|
4
6
|
import { addRoute } from "./add-route.js";
|
|
7
|
+
import { addVerboseCRUD } from "./add-verbose-crud.js";
|
|
5
8
|
import { buildProject } from "./build.js";
|
|
6
9
|
import { generateCollections } from "./generate-collections.js";
|
|
7
10
|
import { generateComponents } from "./generate-components.js";
|
|
8
11
|
import { generateRoutes } from "./generate-routes.js";
|
|
9
|
-
import { makeEnv } from "./make-env.js";
|
|
10
|
-
import yargs from "yargs/yargs";
|
|
11
12
|
import { getFonts } from "./get-fonts.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
13
|
+
import { makeEnv } from "./make-env.js";
|
|
14
|
+
import { crudFieldSnippets } from "./crud-field-snippets.js";
|
|
15
|
+
import {
|
|
16
|
+
registerExternalControllers,
|
|
17
|
+
registerExternalStyles
|
|
18
|
+
} from "./register-external.js";
|
|
14
19
|
const actions = {
|
|
15
20
|
"add-collection": addCollection,
|
|
16
21
|
"add-route": addRoute,
|
|
@@ -28,7 +33,10 @@ const actions = {
|
|
|
28
33
|
},
|
|
29
34
|
"make-env": makeEnv,
|
|
30
35
|
"add-component": addJDDComponent,
|
|
31
|
-
"get-fonts": getFonts
|
|
36
|
+
"get-fonts": getFonts,
|
|
37
|
+
"crud-field-snippets": crudFieldSnippets,
|
|
38
|
+
"register-external-controllers": registerExternalControllers,
|
|
39
|
+
"register-external-styles": registerExternalStyles
|
|
32
40
|
};
|
|
33
41
|
void async function() {
|
|
34
42
|
const action = process.argv.at(2);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import _locreq from "locreq";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import { getFieldHandler } from "./templates/shared/shared-crud-form-fields.js";
|
|
4
|
+
import extract_fields_from_collection from "./utils/extract-fields-from-collection.js";
|
|
5
|
+
import { listCollections } from "./utils/list-collections.js";
|
|
6
|
+
import { formatWithPrettier } from "./utils/prettier.js";
|
|
7
|
+
async function crudFieldSnippets(params, app_directory = process.cwd()) {
|
|
8
|
+
const target_locreq = _locreq(app_directory);
|
|
9
|
+
prompts.override(params);
|
|
10
|
+
const { collection_name } = await prompts([
|
|
11
|
+
{
|
|
12
|
+
type: "autocomplete",
|
|
13
|
+
name: "collection_name",
|
|
14
|
+
message: "Which sealious collection do you like to show a CRUD field config for?",
|
|
15
|
+
choices: (await listCollections()).map((collection) => ({
|
|
16
|
+
title: collection,
|
|
17
|
+
value: collection
|
|
18
|
+
}))
|
|
19
|
+
}
|
|
20
|
+
]);
|
|
21
|
+
const all_fields = await extract_fields_from_collection(collection_name);
|
|
22
|
+
const { field_name } = await prompts([
|
|
23
|
+
{
|
|
24
|
+
type: "autocomplete",
|
|
25
|
+
name: "field_name",
|
|
26
|
+
message: `Which field do you want to show CRUD config for??`,
|
|
27
|
+
choices: all_fields.map((field) => ({
|
|
28
|
+
title: field.name,
|
|
29
|
+
value: field.name
|
|
30
|
+
}))
|
|
31
|
+
}
|
|
32
|
+
]);
|
|
33
|
+
const handler = await getFieldHandler(
|
|
34
|
+
collection_name,
|
|
35
|
+
all_fields.find((e) => e.name == field_name),
|
|
36
|
+
(p) => p
|
|
37
|
+
);
|
|
38
|
+
console.log(`
|
|
39
|
+
|
|
40
|
+
### Field in shared.ts
|
|
41
|
+
|
|
42
|
+
${handler.field}
|
|
43
|
+
|
|
44
|
+
### Control in shared.ts
|
|
45
|
+
|
|
46
|
+
${await formatWithPrettier(handler.controls)}
|
|
47
|
+
`);
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
crudFieldSnippets
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=crud-field-snippets.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { promises as fs } from "fs";
|
|
2
2
|
import { extname, resolve } from "node:path";
|
|
3
3
|
import { embeddable_file_extensions } from "../embeddable-file-extensions.js";
|
|
4
|
-
import { removeNamedImports } from "../../remove-named-imports.js";
|
|
5
4
|
const rewrite_asset_imports_plugin = (project_dir) => ({
|
|
6
5
|
name: "sealgen-rewrite-asset-imports",
|
|
7
6
|
setup(build) {
|
|
@@ -31,7 +30,6 @@ const rewrite_asset_imports_plugin = (project_dir) => ({
|
|
|
31
30
|
return replaced;
|
|
32
31
|
}
|
|
33
32
|
);
|
|
34
|
-
contents = removeNamedImports(contents);
|
|
35
33
|
return {
|
|
36
34
|
contents,
|
|
37
35
|
loader: extname(args.path) === ".tsx" ? "tsx" : "ts"
|
package/lib/page/list.js
CHANGED
|
@@ -144,7 +144,11 @@ class ListPage extends Page {
|
|
|
144
144
|
makeSortLink(ctx, field, order) {
|
|
145
145
|
const url = new URL(ctx.url, "https://example.com");
|
|
146
146
|
const params = qs.parse(url.search.slice(1));
|
|
147
|
-
|
|
147
|
+
if (order === null) {
|
|
148
|
+
delete params.sort;
|
|
149
|
+
} else {
|
|
150
|
+
params.sort = encodeSort(field, order);
|
|
151
|
+
}
|
|
148
152
|
url.search = qs.stringify(params);
|
|
149
153
|
return url.pathname + url.search;
|
|
150
154
|
}
|
|
@@ -169,7 +173,7 @@ class ListPage extends Page {
|
|
|
169
173
|
async renderHeading(ctx, field, label = field) {
|
|
170
174
|
const current_sort = await this.getSort(ctx);
|
|
171
175
|
const current_order = current_sort?.field == field ? current_sort.order : null;
|
|
172
|
-
const order = current_order
|
|
176
|
+
const order = current_order === "asc" ? "desc" : current_order === null ? "asc" : null;
|
|
173
177
|
return (
|
|
174
178
|
/* HTML */
|
|
175
179
|
`<th>
|
|
@@ -5,7 +5,7 @@ import { from_base64, to_base64 } from "../utils/base64.js";
|
|
|
5
5
|
import { Mountable } from "./mountable.js";
|
|
6
6
|
import { isPlainObject } from "is-what";
|
|
7
7
|
class StatefulPage extends Mountable {
|
|
8
|
-
async canAccess() {
|
|
8
|
+
async canAccess(_ctx) {
|
|
9
9
|
return { canAccess: true, message: "" };
|
|
10
10
|
}
|
|
11
11
|
constructor() {
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { promises as fs, existsSync, readFileSync } from "fs";
|
|
2
|
+
import { resolve, dirname } from "path";
|
|
3
|
+
import { formatWithPrettier } from "./utils/prettier.js";
|
|
4
|
+
function findParentProjectWithSealgen() {
|
|
5
|
+
let currentDir = process.cwd();
|
|
6
|
+
while (currentDir !== dirname(currentDir)) {
|
|
7
|
+
const packageJsonPath = resolve(currentDir, "package.json");
|
|
8
|
+
if (existsSync(packageJsonPath)) {
|
|
9
|
+
try {
|
|
10
|
+
const packageJsonContent = readFileSync(
|
|
11
|
+
packageJsonPath,
|
|
12
|
+
"utf-8"
|
|
13
|
+
);
|
|
14
|
+
const packageJson = JSON.parse(
|
|
15
|
+
packageJsonContent
|
|
16
|
+
);
|
|
17
|
+
if (packageJson.sealgen) {
|
|
18
|
+
return currentDir;
|
|
19
|
+
}
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.warn(
|
|
22
|
+
`Warning: Could not read package.json at ${packageJsonPath}:`,
|
|
23
|
+
error
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
currentDir = dirname(currentDir);
|
|
28
|
+
}
|
|
29
|
+
throw new Error(
|
|
30
|
+
"Could not find a parent project with sealgen configuration"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
async function updatePackageJson(projectDir, moduleName, subdirectory, type) {
|
|
34
|
+
const packageJsonPath = resolve(projectDir, "package.json");
|
|
35
|
+
const packageJsonContent = await fs.readFile(packageJsonPath, "utf-8");
|
|
36
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
37
|
+
if (!packageJson.sealgen) {
|
|
38
|
+
packageJson.sealgen = {};
|
|
39
|
+
}
|
|
40
|
+
if (!packageJson.sealgen[type]) {
|
|
41
|
+
packageJson.sealgen[type] = [];
|
|
42
|
+
}
|
|
43
|
+
const pathToAdd = `node_modules/${moduleName}/${subdirectory}`;
|
|
44
|
+
const existingPaths = packageJson.sealgen[type];
|
|
45
|
+
if (existingPaths.includes(pathToAdd)) {
|
|
46
|
+
console.log(`${type} already contains: ${pathToAdd}`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
existingPaths.push(pathToAdd);
|
|
50
|
+
const updatedContent = await formatWithPrettier(
|
|
51
|
+
JSON.stringify(packageJson, null, 2),
|
|
52
|
+
"json"
|
|
53
|
+
);
|
|
54
|
+
await fs.writeFile(packageJsonPath, updatedContent);
|
|
55
|
+
console.log(`Added ${pathToAdd} to ${type} in ${packageJsonPath}`);
|
|
56
|
+
}
|
|
57
|
+
async function registerExternalControllers(args) {
|
|
58
|
+
const moduleName = process.argv.at(3);
|
|
59
|
+
const subdirectory = process.argv.at(4);
|
|
60
|
+
if (!moduleName || !subdirectory) {
|
|
61
|
+
console.error(
|
|
62
|
+
"Usage: npx sealgen register-external-controllers <module-name> <subdirectory>"
|
|
63
|
+
);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const projectDir = findParentProjectWithSealgen();
|
|
68
|
+
await updatePackageJson(
|
|
69
|
+
projectDir,
|
|
70
|
+
moduleName,
|
|
71
|
+
subdirectory,
|
|
72
|
+
"controllerDirs"
|
|
73
|
+
);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error("Error:", error instanceof Error ? error.message : error);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function registerExternalStyles(args) {
|
|
80
|
+
const moduleName = process.argv.at(3);
|
|
81
|
+
const subdirectory = process.argv.at(4);
|
|
82
|
+
if (!moduleName || !subdirectory) {
|
|
83
|
+
console.error(
|
|
84
|
+
"Usage: npx sealgen register-external-styles <module-name> <subdirectory>"
|
|
85
|
+
);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const projectDir = findParentProjectWithSealgen();
|
|
90
|
+
await updatePackageJson(
|
|
91
|
+
projectDir,
|
|
92
|
+
moduleName,
|
|
93
|
+
subdirectory,
|
|
94
|
+
"styleDirs"
|
|
95
|
+
);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error("Error:", error instanceof Error ? error.message : error);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
registerExternalControllers,
|
|
103
|
+
registerExternalStyles
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=register-external.js.map
|