diff --git a/.gitignore b/.gitignore index b779c5b..0fe9717 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist build .vscode database +.env \ No newline at end of file diff --git a/package.json b/package.json index ae8bd6f..bbf711d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "watch": "jest --watch", "snapupdate": "jest --updateSnapshot", "coverage": "jest --coverage", - "postinstall": "prisma migrate deploy && prisma generate" + "postinstall": "tiktoker config" }, "files": [ "build", @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed7419a..e5912c6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,6 +9,7 @@ specifiers: '@typescript-eslint/parser': ^4.17.0 axios: ^0.27.2 copyfiles: ^2.4.1 + dotenv-cli: ^6.0.0 eslint: ^7.22.0 eslint-config-prettier: ^8.1.0 eslint-plugin-prettier: ^3.3.1 @@ -30,6 +31,7 @@ dependencies: '@ffmpeg-installer/ffmpeg': 1.1.0 '@prisma/client': 4.3.1_prisma@4.3.1 axios: 0.27.2 + dotenv-cli: 6.0.0 ffcreator: 6.7.5 get-video-duration: 4.1.0 gluegun: 5.1.2 @@ -2129,6 +2131,26 @@ packages: webidl-conversions: 5.0.0 dev: true + /dotenv-cli/6.0.0: + resolution: {integrity: sha512-qXlCOi3UMDhCWFKe0yq5sg3X+pJAz+RQDiFN38AMSbUrnY3uZshSfDJUAge951OS7J9gwLZGfsBlWRSOYz/TRg==} + hasBin: true + dependencies: + cross-spawn: 7.0.3 + dotenv: 16.0.2 + dotenv-expand: 8.0.3 + minimist: 1.2.6 + dev: false + + /dotenv-expand/8.0.3: + resolution: {integrity: sha512-SErOMvge0ZUyWd5B0NXMQlDkN+8r+HhVUsxgOO7IoPDOdDRD2JjExpN6y3KnFR66jsJMwSn1pqIivhU5rcJiNg==} + engines: {node: '>=12'} + dev: false + + /dotenv/16.0.2: + resolution: {integrity: sha512-JvpYKUmzQhYoIFgK2MOnF3bciIZoItIIoryihy0rIA+H4Jy0FmgyKYAHCTN98P5ybGSJcIFbh6QKeJdtZd1qhA==} + engines: {node: '>=12'} + dev: false + /dup/1.0.0: resolution: {integrity: sha512-Bz5jxMMC0wgp23Zm15ip1x8IhYRqJvF3nFC0UInJUDkN1z4uNPk9jTnfCUJXbOGiQ1JbXLQsiV41Fb+HXcj5BA==} dev: false diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3964767..203e356 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -4,7 +4,7 @@ generator client { datasource db { provider = "sqlite" - url = "file:../database/tiktoker.db" + url = env("DATABASE_URL") } model profiles { diff --git a/src/commands/config.ts b/src/commands/config.ts new file mode 100644 index 0000000..88f325f --- /dev/null +++ b/src/commands/config.ts @@ -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