Skip to content

Commit

Permalink
feat(scripts): auto convert to lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 31, 2023
1 parent ddba4a7 commit 9ba18fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@koishijs/scripts",
"description": "Workspace Scripts for Koishi",
"version": "4.3.1",
"version": "4.3.2",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"engines": {
Expand Down
12 changes: 11 additions & 1 deletion packages/scripts/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ class Initiator {

async init(name: string) {
name ||= await this.getName()
name = name.replace(/_/g, '-')
const oldName = name
name = name.toLowerCase().replace(/_/g, '-')
if (!/^(?:@[a-z0-9-]+\/)?[a-z0-9-]+$/.test(name)) {
console.log(red('error'), 'plugin name contains invalid character')
process.exit(1)
}
if (oldName !== name) {
console.log(blue('info'), `plugin name will be converted to "${name}"`)
const { confirm } = await prompts({
type: 'confirm',
name: 'confirm',
message: 'OK?',
})
if (!confirm) process.exit(0)
}
if (name.includes('koishi-plugin-')) {
this.fullname = name
this.name = name.replace('koishi-plugin-', '').replace(/^@.+\//, '')
Expand Down

0 comments on commit 9ba18fe

Please sign in to comment.