Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function initArchive(rpc, dir) {
// check if the dir is valid
await isDirInitable(dir)
// ask user questions
console.log(trim`
Initializing ${dir}
This utility will walk you through creating a dat.json file.
It only covers the most common items, and tries to guess sensible defaults.
`)
const q = (name, message, def, type='input') => ({ name, message, 'default': def, type })
var answers = await inquirer.prompt([
q('title', 'title:', path.basename(dir)),
q('description', 'description:'),
q('author', 'author:', await username())
])
console.log(`\nAbout to write ${path.join(dir, 'dat.json')}\n`)
console.log(JSON.stringify(answers, null, 2), '\n')
var confirm = await inquirer.prompt([{ type: 'confirm', name: 'ok', message: 'Is this ok?', default: true }])
if (!confirm.ok) {
console.log('Aborted.')
process.exit(0)
}
// create site in beaker
var datKey = await rpc.createNewArchive(answers)
console.log(trim`
Created new site
dat://${datKey}/
`)
export default async (dir: string) => (await getAuthorFromGitConfig(dir)) || username();