Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010215
add-collection.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
add-collection.ts
View Options
import
{
resolve
}
from
"path"
;
import
_locreq
from
"locreq"
;
import
{
promises
as
fs
,
existsSync
}
from
"fs"
;
import
{
question
}
from
"./utils/question"
;
import
{
collectionTemplate
}
from
"./templates/collection"
;
import
{
generateCollections
}
from
"./generate-collections"
;
const
target_locreq
=
_locreq
(
process
.
cwd
());
export
async
function
addCollection
()
:
Promise
<
void
>
{
const
collection_name
=
await
question
(
'What\'s the name of the collection class (e.g. "SecretDocuments", must start with a capital letter): '
,
(
s
:
string
)
=>
s
.
length
>
3
&&
s
[
0
].
toUpperCase
()
==
s
[
0
]
);
const
url
=
await
question
(
"Enter the url-friendly name for the collection (e.g. secret-documents): "
,
(
s
:
string
)
=>
!
s
.
includes
(
"/"
)
&&
!
s
.
includes
(
" "
)
);
const
file_path
=
target_locreq
.
resolve
(
`src/back/collections/
${
url
}
.ts`
);
if
(
existsSync
(
file_path
))
{
// eslint-disable-next-line no-console
console
.
error
(
`ERROR: File
${
file_path
}
already exists.`
);
return
;
}
await
fs
.
mkdir
(
resolve
(
file_path
,
"../"
),
{
recursive
:
true
});
await
fs
.
writeFile
(
file_path
,
collectionTemplate
(
collection_name
));
// eslint-disable-next-line no-console
console
.
log
(
`
${
file_path
}
created`
);
await
generateCollections
();
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:38 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625887
Default Alt Text
add-collection.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment