Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main(): Promise {
process.env.NODE_ENV = 'production'
// create a new CLI with our subcommands
const args = arg(process.argv.slice(2), {})
if (isError(args)) {
console.error(args.message)
return 1
}
const commands = {
init: Init.new(),
introspect: Introspect.new(),
}
if (commands[args._[0]]) {
const result = await commands[args._[0]].parse(process.argv.slice(3))
console.log(result)
} else {
console.error(`Command not found: ${args._[0]}. Available commands: ${Object.keys(commands).join(', ')}`)
async parse(argv: string[]): Promise {
// parse the args according to the following spec
const args = arg(argv, {
'--help': Boolean,
'-h': '--help',
'--version': Boolean,
'-v': '--version',
})
if (isError(args)) {
return this.help(args.message)
}
if (args['--version']) {
return Version.new().parse(argv)
}
// display help for help flag or no subcommand
if (args._.length === 0 || args['--help']) {
return this.help()
}
async parse(argv: string[]): Promise {
// parse the arguments according to the spec
const args = arg(argv, {})
if (isError(args)) {
return null
}
if (args['--help']) {
return this.help()
}
const outputDirName = args._[0]
const outputDir = outputDirName ? path.join(process.cwd(), outputDirName) : process.cwd()
if (fs.existsSync(outputDir)) {
const schemaExists = fs.existsSync(path.join(outputDir, 'schema.prisma'))
const prismaSchemaExists = fs.existsSync(path.join(outputDir, 'prisma/schema.prisma'))
if (schemaExists || prismaSchemaExists) {
public async parse(argv: string[]): Promise {
// parse the arguments according to the spec
const args = arg(argv, {
'--help': Boolean,
'-h': '--help',
'--preview': Boolean,
'-p': '--preview',
'--verbose': Boolean,
'-v': '--verbose',
'--create-db': Boolean,
'-c': '--create-db',
'--auto-approve': Boolean,
})
if (isError(args)) {
return this.help(args.message)
} else if (args['--help']) {
return this.help()
}
public async parse(argv: string[]): Promise {
// parse the arguments according to the spec
const args = arg(argv, {
'--help': Boolean,
'-h': '--help',
})
if (isError(args)) {
return this.help(args.message)
} else if (args['--help']) {
return this.help()
}
const datamodel = await this.readStdin()
const engine = new LiftEngine({ projectDir: process.cwd() })
const parser = DefaultParser.create(DatabaseType.postgres)
const isdl = parser.parseFromSchemaString(datamodel)
return isdlToDatamodel2(isdl, [])
}
public async parse(argv: string[]): Promise {
// parse the arguments according to the spec
const args = arg(argv, {
'--help': Boolean,
'-h': '--help',
'--name': String,
'-n': '--name',
'--preview': Boolean,
'-p': '--preview',
'--create-db': Boolean,
'-c': '--create-db',
})
if (isError(args)) {
return this.help(args.message)
} else if (args['--help']) {
return this.help()
}
const preview = args['--preview'] || false
await ensureDatabaseExists('create', true, args['--create-db'])
public async parse(argv: string[]): Promise {
// parse the arguments according to the spec
const args = arg(argv, {
'--help': Boolean,
'-h': '--help',
})
if (isError(args)) {
return this.help(args.message)
}
// display help for help flag or no subcommand
if (args._.length === 0 || args['--help']) {
return this.help()
}
// check if we have that subcommand
const cmd = this.cmds[args._[0]]
if (cmd) {
const nextFreePort = await getNextFreePort(process.cwd())
if (typeof nextFreePort !== 'number') {
const command = `prisma2 lift ${argv.join(' ')}`
public async parse(argv: string[], minimalOutput = false): Promise {
const args = arg(argv, {
'--help': Boolean,
'-h': '--help',
'--url': String,
'--print': Boolean,
})
const log = (...messages) => {
if (!args['--print']) {
console.log(...messages)
}
}
if (args instanceof Error) {
return this.help(args.message)
}
public async parse(argv: string[]): Promise {
const args = arg(argv, {
'--preview': Boolean,
'-p': '--preview',
'--create-db': Boolean,
'-c': '--create-db',
'--auto-approve': Boolean,
})
const preview = args['--preview'] || false
await occupyPath(process.cwd())
await ensureDatabaseExists('dev', false, args['--create-db'] || process.platform === 'win32')
const lift = new Lift()
return lift.watch({
preview,
providerAliases: this.providerAliases,