Skip to content

Commit

Permalink
feat: config command
Browse files Browse the repository at this point in the history
  • Loading branch information
Theryston committed Sep 6, 2022
1 parent d13ac31 commit 8b65433
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
build
.vscode
database
.env
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"watch": "jest --watch",
"snapupdate": "jest --updateSnapshot",
"coverage": "jest --coverage",
"postinstall": "prisma migrate deploy && prisma generate"
"postinstall": "tiktoker config"
},
"files": [
"build",
Expand All @@ -34,6 +34,7 @@
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@prisma/client": "^4.3.1",
"axios": "^0.27.2",
"dotenv-cli": "^6.0.0",
"ffcreator": "^6.7.5",
"get-video-duration": "^4.1.0",
"gluegun": "latest",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ generator client {

datasource db {
provider = "sqlite"
url = "file:../database/tiktoker.db"
url = env("DATABASE_URL")
}

model profiles {
Expand Down
48 changes: 48 additions & 0 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { GluegunCommand } from 'gluegun'
import * as path from 'path'

const command: GluegunCommand = {
name: 'config',
run: async (toolbox) => {
const { print, prompt, filesystem, system } = toolbox

print.info(
`TikToker is installed and ready to config! (don't cancel this process, if you do, run 'tiktoker config')`
)

const { databasePath } = await prompt.ask({
type: 'input',
name: 'databasePath',
message:
'Where do you want to store the database? (ex: C:\\tiktoker.db) if you already have used tiktoker, enter the same used path',
})

const env = `DATABASE_URL=file:${databasePath}`
const envPath = path.join(__dirname, '..', '..', '.env')
filesystem.write(envPath, env)
const installedBasePath = path.join(__dirname, '..', '..')
const basePrismaPath = path.join(
installedBasePath,
'node_modules',
'.bin',
'prisma'
)
const schemaPrismaPath = path.join(
installedBasePath,
'prisma',
'schema.prisma'
)
const baseDotenvCliPath = path.join(
installedBasePath,
'node_modules',
'.bin',
'dotenv'
)

system.run(
`${baseDotenvCliPath} -e ${envPath} -- ${basePrismaPath} migrate deploy --schema ${schemaPrismaPath} && ${baseDotenvCliPath} -e ${envPath} -- ${basePrismaPath} generate --schema ${schemaPrismaPath}`
)
},
}

module.exports = command

0 comments on commit 8b65433

Please sign in to comment.