Skip to content

Commit

Permalink
fix init with subdir
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Aug 30, 2019
1 parent 6407a55 commit 1c0890c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
15 changes: 9 additions & 6 deletions cli/introspection/src/prompt/screens/Step3LanguageSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { promisify } from 'util'
import EmptyDirError from '../components/EmptyDirError'

const readdir = promisify(fs.readdir)
const exists = promisify(fs.exists)

const Step3LanguageSelection: React.FC = () => {
const [state] = useInitState()
Expand All @@ -20,12 +21,14 @@ const Step3LanguageSelection: React.FC = () => {
useEffect(() => {
async function runEffect() {
if (state.useStarterKit) {
const files = await readdir(state.outputDir)
if (files.length > 0) {
setShowEmptyDirError(true)
setTimeout(() => {
process.exit(1)
})
if (await exists(state.outputDir)) {
const files = await readdir(state.outputDir)
if (files.length > 0) {
setShowEmptyDirError(true)
setTimeout(() => {
process.exit(1)
})
}
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions cli/introspection/src/prompt/screens/Step60DownloadExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { credentialsToUri } from '../../convertCredentials'
import { DatabaseType } from 'prisma-datamodel'
import { ConnectorType } from '@prisma/photon/dist/isdlToDatamodel2'
import { useConnector } from '../components/useConnector'
import { minimalScript, exampleScript } from '../utils/templates/script'
import { exampleScript } from '../utils/templates/script'
import { ErrorBox } from '../components/ErrorBox'
import { photonDefaultConfig } from '../utils/defaults'
import EmptyDirError from '../components/EmptyDirError'
Expand Down Expand Up @@ -62,13 +62,15 @@ const Step60DownloadExample: React.FC = () => {

useEffect(() => {
async function prepare() {
const files = await readdir(state.outputDir)
if (files.length > 0) {
setShowEmptyDirError(true)
setTimeout(() => {
process.exit(1)
})
return
if (await exists(state.outputDir)) {
const files = await readdir(state.outputDir)
if (files.length > 0) {
setShowEmptyDirError(true)
setTimeout(() => {
process.exit(1)
})
return
}
}

// adjust datasource in schema
Expand All @@ -84,6 +86,7 @@ const Step60DownloadExample: React.FC = () => {
if (!state.dbCredentials) {
throw new Error(`No db credentials - this must not happen`)
}

await makeDir(state.outputDir)
const tarFile = await downloadRepo('prisma', 'prisma-examples', examples!.meta.branch)
setActiveIndex(1)
Expand Down
2 changes: 1 addition & 1 deletion cli/introspection/src/prompt/utils/deepExtend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Taken from https://github.com/unclechu/node-deep-extend/blob/master/lib/deep-extend.js
// es2017-ified, now it's about 2.5 times faster
// es2017-ified by Tim Suchanek, now it's about 2.5 times faster
/*!
* @description Recursive object extending
* @author Viacheslav Lotsmanov <lotsmanov89@gmail.com>
Expand Down

0 comments on commit 1c0890c

Please sign in to comment.