Skip to content

Commit

Permalink
wip db creation
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Sep 18, 2019
1 parent 6ff63fa commit e1d5d8a
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 58 deletions.
15 changes: 12 additions & 3 deletions cli/cli/src/getCwd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const schemaFile = 'schema.prisma'
*/
export async function getCwd(): Promise<string> {
const cwd = process.cwd()
const [schemaCwdExists, prismaFolderExists, prismaSchemaExists] = await Promise.all([
const [
schemaCwdExists,
prismaFolderExists,
prismaSchemaExists,
] = await Promise.all([
exists(path.join(cwd, schemaFile)),
exists(path.join(cwd, 'prisma/')),
exists(path.join(cwd, 'prisma/', schemaFile)),
Expand All @@ -32,10 +36,15 @@ export async function getCwd(): Promise<string> {
}

export async function getDatamodel(): Promise<string> {
const cwd = await getCwd()
const datamodelPath = path.join(cwd, schemaFile)
let datamodelPath = path.join(process.cwd(), schemaFile)

if (!(await exists(datamodelPath))) {
datamodelPath = path.join(process.cwd(), `prisma/${schemaFile}`)
}

if (!(await exists(datamodelPath))) {
throw new Error(`Could not find ${datamodelPath}`)
}

return readFile(datamodelPath, 'utf-8')
}
8 changes: 4 additions & 4 deletions cli/introspection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@
"dotenv": "^8.0.0",
"execa": "^1.0.0",
"figures": "^3.0.0",
"ink": "^2.2.0",
"ink": "^2.3.0",
"ink-progress-bar": "^3.0.0",
"ink-spinner": "^3.0.1",
"ink-text-input": "^3.2.0",
"ink-text-input": "^3.2.1",
"jsonwebtoken": "^8.5.1",
"node-fetch": "^2.6.0",
"ora": "^3.4.0",
"parse-github-url": "^1.0.2",
"prisma-datamodel": "^1.36.0-test.2",
"prisma-db-introspection": "^1.36.0-test.2",
"react": "^16.8.6",
"react": "^16.9.0",
"scuid": "^1.1.0",
"string-width": "^4.1.0",
"strip-ansi": "^5.2.0",
"tar": "^4.4.10",
"terminal-link": "^1.3.0"
"terminal-link": "^2.0.0"
},
"scripts": {
"build": "tsc -d && chmod +x dist/bin.js",
Expand Down
51 changes: 51 additions & 0 deletions cli/introspection/src/prompt/Root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Box } from 'ink'
import React from 'react'
import { TabIndexProvider } from '@prisma/ink-components'
import { Router, Route } from './components/Router'
import Step0StarterVsBlank from './screens/Step0StarterVsBlank'
import Step1StarterSelection from './screens/Step1StarterSelection'
import Step1MySQLCredentials from './screens/Step1MySQLCredentials'
import Step1PostgresCredentials from './screens/Step1PostgresCredentials'
import Step2DBSelection from './screens/Step2DBSelection'
import Step2SqliteFileSelection from './screens/Step2SqliteFileSelection'
import Step2ChooseDatabase from './screens/Step2ChooseDatabase'
import Step21SqliteFilePath from './screens/Step21SqliteFilePath'
import Step22ToolSelection from './screens/Step22ToolSelection'
import Step3LanguageSelection from './screens/Step3LanguageSelection'
import Step4DemoScriptSelection from './screens/Step4DemoScriptSelection'
import Step4SelectDatabase from './screens/Step4SelectDatabase'
import Step4DatabaseName from './screens/Step4DatabaseName'
import Step41Introspection from './screens/Step41Introspection'
import Step60ProcessBlank from './screens/Step60ProcessBlank'
import Step60DownloadExample from './screens/Step60DownloadExample'
import Step61Success from './screens/Step61Success'
import Step2CreateOrSelectDB from './screens/Step2CreateOrSelectDB'

export const Root: React.FC<{ outputDir: string }> = ({ outputDir }) => {
return (
<Box marginTop={1} flexDirection="column">
<TabIndexProvider>
<Router defaultRoute="home">
<Route path="home" component={<Step0StarterVsBlank outputDir={outputDir} />} />
<Route path="starter-selection" component={<Step1StarterSelection />} />
<Route path="mysql-credentials" component={<Step1MySQLCredentials />} />
<Route path="postgres-credentials" component={<Step1PostgresCredentials />} />
<Route path="db-selection" component={<Step2DBSelection />} />
<Route path="sqlite-file-selection" component={<Step2SqliteFileSelection />} />
<Route path="choose-database" component={<Step2ChooseDatabase />} />
<Route path="sqlite-file-path" component={<Step21SqliteFilePath />} />
<Route path="tool-selection" component={<Step22ToolSelection />} />
<Route path="create-or-select-db" component={<Step2CreateOrSelectDB />} />
<Route path="language-selection" component={<Step3LanguageSelection />} />
<Route path="demo-script-selection" component={<Step4DemoScriptSelection />} />
<Route path="select-database" component={<Step4SelectDatabase />} />
<Route path="database-name" component={<Step4DatabaseName />} />
<Route path="introspection" component={<Step41Introspection />} />
<Route path="process-blank" component={<Step60ProcessBlank />} />
<Route path="download-example" component={<Step60DownloadExample />} />
<Route path="success" component={<Step61Success />} />
</Router>
</TabIndexProvider>
</Box>
)
}
50 changes: 3 additions & 47 deletions cli/introspection/src/prompt/initPrompt.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,9 @@
import { render, Box } from 'ink'
import { render } from 'ink'
import React from 'react'
import { TabIndexProvider } from '@prisma/ink-components'
import { Router, Route } from './components/Router'
import Step0StarterVsBlank from './screens/Step0StarterVsBlank'
import Step1StarterSelection from './screens/Step1StarterSelection'
import Step1MySQLCredentials from './screens/Step1MySQLCredentials'
import Step1PostgresCredentials from './screens/Step1PostgresCredentials'
import Step2DBSelection from './screens/Step2DBSelection'
import Step2SqliteFileSelection from './screens/Step2SqliteFileSelection'
import Step2ChooseDatabase from './screens/Step2ChooseDatabase'
import Step21SqliteFilePath from './screens/Step21SqliteFilePath'
import Step22ToolSelection from './screens/Step22ToolSelection'
import Step3LanguageSelection from './screens/Step3LanguageSelection'
import Step4DemoScriptSelection from './screens/Step4DemoScriptSelection'
import Step4SelectDatabase from './screens/Step4SelectDatabase'
import Step4DatabaseName from './screens/Step4DatabaseName'
import Step41Introspection from './screens/Step41Introspection'
import Step60ProcessBlank from './screens/Step60ProcessBlank'
import Step60DownloadExample from './screens/Step60DownloadExample'
import Step61Success from './screens/Step61Success'
import Step2CreateOrSelectDB from './screens/Step2CreateOrSelectDB'
import { Root } from './Root'

export async function initPrompt(outputDir: string) {
return new Promise(resolve => {
render(
<Box marginTop={1} flexDirection="column">
<TabIndexProvider>
<Router defaultRoute="home">
<Route path="home" component={<Step0StarterVsBlank outputDir={outputDir} />} />
<Route path="starter-selection" component={<Step1StarterSelection />} />
<Route path="mysql-credentials" component={<Step1MySQLCredentials />} />
<Route path="postgres-credentials" component={<Step1PostgresCredentials />} />
<Route path="db-selection" component={<Step2DBSelection />} />
<Route path="sqlite-file-selection" component={<Step2SqliteFileSelection />} />
<Route path="choose-database" component={<Step2ChooseDatabase />} />
<Route path="sqlite-file-path" component={<Step21SqliteFilePath />} />
<Route path="tool-selection" component={<Step22ToolSelection />} />
<Route path="create-or-select-db" component={<Step2CreateOrSelectDB />} />
<Route path="language-selection" component={<Step3LanguageSelection />} />
<Route path="demo-script-selection" component={<Step4DemoScriptSelection />} />
<Route path="select-database" component={<Step4SelectDatabase />} />
<Route path="database-name" component={<Step4DatabaseName />} />
<Route path="introspection" component={<Step41Introspection />} />
<Route path="process-blank" component={<Step60ProcessBlank />} />
<Route path="download-example" component={<Step60DownloadExample />} />
<Route path="success" component={<Step61Success />} />
</Router>
</TabIndexProvider>
</Box>,
)
render(<Root outputDir={outputDir} />)
})
}
41 changes: 37 additions & 4 deletions cli/introspection/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2658,10 +2658,10 @@ ink-spinner@^3.0.1:
cli-spinners "^1.0.0"
prop-types "^15.5.10"

ink-text-input@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ink-text-input/-/ink-text-input-3.2.0.tgz#7c5d89324eedf7073a1ad22c883038a3dfb517cf"
integrity sha512-ppfLo5o2h+RJDF0F6H52k/N7nb8SeKkT8ilmsTKV/klhbqu13fA9d8zwJjd+LYDN2tMaFfulSpdykbnxBls22w==
ink-text-input@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/ink-text-input/-/ink-text-input-3.2.1.tgz#099dd54f693053a340fb76cff051b5e3e775dd94"
integrity sha512-gU5Q3+xq0koDsTEkW0U6k3nNXjN4r9g/b6goo/jHlK2g4R5M6d22KnLEO6yFDYHQO1D27aTdSUk4HH+Nz8lQKg==
dependencies:
prop-types "^15.5.10"

Expand Down Expand Up @@ -2689,6 +2689,30 @@ ink@^2.2.0:
wrap-ansi "^5.0.0"
yoga-layout-prebuilt "^1.9.3"

ink@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/ink/-/ink-2.3.0.tgz#222136be17bb72fc742e19090483e7e0e7dc3690"
integrity sha512-931rgXHAS3hM++8ygWPOBeHOFwTzHh3pDAVZtiBVOUH6tVvJijym43ODUy22ySo2NwYUFeR/Zj3xuWzBEKMiHw==
dependencies:
"@types/react" "^16.8.6"
arrify "^1.0.1"
auto-bind "^2.0.0"
chalk "^2.4.1"
cli-cursor "^2.1.0"
cli-truncate "^1.1.0"
is-ci "^2.0.0"
lodash.throttle "^4.1.1"
log-update "^3.0.0"
prop-types "^15.6.2"
react-reconciler "^0.20.0"
scheduler "^0.13.2"
signal-exit "^3.0.2"
slice-ansi "^1.0.0"
string-length "^2.0.0"
widest-line "^2.0.0"
wrap-ansi "^5.0.0"
yoga-layout-prebuilt "^1.9.3"

invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
Expand Down Expand Up @@ -4803,6 +4827,15 @@ react@^16.8.6:
prop-types "^15.6.2"
scheduler "^0.13.6"

react@^16.9.0:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa"
integrity sha512-+7LQnFBwkiw+BobzOF6N//BdoNw0ouwmSJTEm9cglOOmsg/TMiFHZLe2sEoN5M7LgJTj9oHH0gxklfnQe66S1w==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"

read-pkg-up@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-4.0.0.tgz#1b221c6088ba7799601c808f91161c66e58f8978"
Expand Down

0 comments on commit e1d5d8a

Please sign in to comment.