@sealcode/sealgen 0.14.3 → 0.14.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/src/builder.d.ts +36 -0
- package/@types/src/embeddable-file-extensions.d.ts +1 -0
- package/@types/src/esbuild-plugins/load-assets.d.ts +4 -0
- package/@types/src/esbuild-plugins/rewrite-asset-imports.d.ts +4 -0
- package/@types/src/generate-stimulus.d.ts +1 -0
- package/@types/src/page/stateful-page.d.ts +1 -1
- package/@types/src/templates/stimulus-controller.d.ts +1 -0
- package/dist/build.js +29 -213
- package/dist/builder.js +145 -0
- package/dist/cli.js +3 -1
- package/dist/embeddable-file-extensions.js +5 -0
- package/dist/esbuild-plugins/load-assets.js +67 -0
- package/dist/esbuild-plugins/rewrite-asset-imports.js +30 -0
- package/dist/find-css-includes.js +2 -2
- package/dist/generate-components.js +1 -3
- package/dist/generate-stimulus.js +41 -0
- package/dist/page/stateful-page.js +3 -2
- package/dist/templates/stimulus-controller.js +21 -0
- package/package.json +1 -1
- package/src/build.ts +30 -234
- package/src/builder.ts +176 -0
- package/src/cli.ts +3 -1
- package/src/embeddable-file-extensions.ts +1 -0
- package/src/esbuild-plugins/load-assets.ts +68 -0
- package/src/esbuild-plugins/rewrite-asset-imports.ts +29 -0
- package/src/find-css-includes.ts +17 -15
- package/src/generate-components.ts +3 -3
- package/src/generate-stimulus.ts +52 -0
- package/src/page/stateful-page.ts +8 -3
- package/src/templates/stimulus-controller.ts +18 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import _locreq from "locreq";
|
|
2
|
+
import * as prettier from "prettier";
|
|
3
|
+
import { promises as fs } from "fs";
|
|
4
|
+
import { getPrettierConfig } from "./utils/prettier.js";
|
|
5
|
+
import recursive from "recursive-readdir";
|
|
6
|
+
import path, { dirname } from "path";
|
|
7
|
+
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
8
|
+
|
|
9
|
+
const target_locreq = _locreq(process.cwd());
|
|
10
|
+
|
|
11
|
+
export async function generateStimulusControllers(): Promise<void> {
|
|
12
|
+
const output_file = "src/front/controllers.ts";
|
|
13
|
+
const stimulus_search_dir = target_locreq.resolve("src/");
|
|
14
|
+
const controller_names = (await recursive(stimulus_search_dir))
|
|
15
|
+
.filter((c) => c.endsWith(".stimulus.ts"))
|
|
16
|
+
.sort();
|
|
17
|
+
const controller_data = controller_names
|
|
18
|
+
.map(
|
|
19
|
+
(p) =>
|
|
20
|
+
"./" +
|
|
21
|
+
path
|
|
22
|
+
.relative(target_locreq.resolve(dirname(output_file)), p)
|
|
23
|
+
.replace(/\.[tj]sx?$/, ".js")
|
|
24
|
+
)
|
|
25
|
+
.map((relative_path) => {
|
|
26
|
+
const name = relative_path.match(/\/([^\/]+).stimulus/)?.[1];
|
|
27
|
+
return { name, relative_path };
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const content = `// DO NOT EDIT! This file is generated automaticaly with 'npm run generate-stimulus'
|
|
31
|
+
|
|
32
|
+
import * as Turbo from "@hotwired/turbo";
|
|
33
|
+
import { Application } from "stimulus";
|
|
34
|
+
const application = Application.start();
|
|
35
|
+
${controller_data
|
|
36
|
+
.map(
|
|
37
|
+
(c) => `
|
|
38
|
+
import { default as ${toPascalCase(c.name)} } from "${c.relative_path}";
|
|
39
|
+
application.register("${toKebabCase(c.name)}", ${toPascalCase(c.name)});`
|
|
40
|
+
)
|
|
41
|
+
.join("\n")}
|
|
42
|
+
|
|
43
|
+
export { Turbo };
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
await fs.writeFile(
|
|
47
|
+
target_locreq.resolve(output_file),
|
|
48
|
+
prettier.format(content, await getPrettierConfig())
|
|
49
|
+
);
|
|
50
|
+
// eslint-disable-next-line no-console
|
|
51
|
+
console.log(`Successfuly generated new ${output_file} file`);
|
|
52
|
+
}
|
|
@@ -66,12 +66,17 @@ export abstract class StatefulPage<
|
|
|
66
66
|
this.wrapInForm(
|
|
67
67
|
state,
|
|
68
68
|
await original_render(ctx, state, inputs)
|
|
69
|
-
)
|
|
69
|
+
),
|
|
70
|
+
state
|
|
70
71
|
);
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
abstract wrapInLayout(
|
|
75
|
+
abstract wrapInLayout(
|
|
76
|
+
ctx: BaseContext,
|
|
77
|
+
content: Templatable,
|
|
78
|
+
state: State
|
|
79
|
+
): Templatable;
|
|
75
80
|
|
|
76
81
|
wrapInForm(state: State, content: Templatable): Templatable {
|
|
77
82
|
return tempstream/* HTML */ `<form action="./" method="POST">
|
|
@@ -218,7 +223,7 @@ export abstract class StatefulPage<
|
|
|
218
223
|
options
|
|
219
224
|
);
|
|
220
225
|
} else if (target.indexOf(item) === -1) {
|
|
221
|
-
destination
|
|
226
|
+
destination[index] = item;
|
|
222
227
|
}
|
|
223
228
|
});
|
|
224
229
|
return destination;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
+
|
|
3
|
+
export function jddComponentTemplate(controller_name: string) {
|
|
4
|
+
return `import { Controller } from "stimulus";
|
|
5
|
+
|
|
6
|
+
export default class ${toPascalCase(controller_name)} extends Controller {
|
|
7
|
+
|
|
8
|
+
connect() {
|
|
9
|
+
console.warn(
|
|
10
|
+
"Remove ${toKebabCase(
|
|
11
|
+
controller_name
|
|
12
|
+
)}.stimulus.ts file if your JDD component doesn't need any browser-side logic"
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
`;
|
|
18
|
+
}
|