Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F1262882
generate-components.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
generate-components.ts
View Options
import
_locreq
from
"locreq"
;
import
*
as
prettier
from
"prettier"
;
import
{
promises
as
fs
}
from
"fs"
;
import
{
assertType
,
predicates
}
from
"@sealcode/ts-predicates"
;
import
{
getPrettierConfig
}
from
"./utils/prettier"
;
import
recursive
from
"recursive-readdir"
;
import
path
from
"path"
;
import
{
toKebabCase
,
toPascalCase
}
from
"js-convert-case"
;
const
target_locreq
=
_locreq
(
process
.
cwd
());
export
async
function
generateComponents
()
:
Promise
<
void
>
{
const
components_dir
=
target_locreq
.
resolve
(
"src/back/jdd-components"
);
const
component_names
=
(
await
recursive
(
components_dir
)).
filter
((
c
)
=>
c
.
endsWith
(
".jdd.tsx"
)
);
const
component_data
=
component_names
.
map
(
(
p
)
=>
"./"
+
path
.
relative
(
components_dir
,
p
).
replace
(
/\.[tj]sx?$/
,
".js"
)
)
.
map
((
relative_path
)
=>
{
const
name
=
relative_path
.
match
(
/\/([^\/]+).jdd/
)
?
.[
1
];
return
{
name
,
relative_path
};
});
const
content
=
`// DO NOT EDIT! This file is generated automaticaly with 'npm run generate-components'
import { Registry } from "@sealcode/jdd";
export const registry = new Registry();
${
component_data
.
map
(
(
c
)
=>
`
import {
${
toPascalCase
(
c
.
name
)
}
} from "
${
c
.
relative_path
}
";
registry.add("
${
toKebabCase
(
c
.
name
)
}
",
${
toPascalCase
(
c
.
name
)
}
);`
)
.
join
(
"\n"
)
}
`
;
const
target
=
"src/back/jdd-components/components.ts"
;
await
fs
.
writeFile
(
target_locreq
.
resolve
(
target
),
prettier
.
format
(
content
,
await
getPrettierConfig
())
);
// eslint-disable-next-line no-console
console
.
log
(
`Successfuly generated new
${
target
}
file`
);
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Fri, Jan 24, 15:16 (17 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
601282
Default Alt Text
generate-components.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment