From e6ef3b0e1bdba3e65a746274c006328c1afaedbc Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Thu, 6 Sep 2018 13:21:29 +0200 Subject: [PATCH] feat: support reading name and description from package.json --- src/cli.ts | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 009ff514..660651df 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -4,7 +4,7 @@ import 'source-map-support/register' import chalk from 'chalk' import exec = require('execa') import { prompt } from 'inquirer' -import { exists, mkdir, writeFile } from 'mz/fs' +import { exists, mkdir, readFile, writeFile } from 'mz/fs' import * as path from 'path' import { createBuildkiteClient, initBuildkite } from './buildkite' import { CodeCovRepo, createCodeCovClient, getCodeCovBadge } from './codecov' @@ -61,17 +61,33 @@ async function main(): Promise { await exec('git', ['init']) } - const { packageName } = await prompt<{ packageName: string }>({ - name: 'packageName', - message: - 'What should the name of the package be? Examples: @sourcegraph/codeintellify, @sourcegraph/react-loading-spinner, cxp', - default: '@sourcegraph/' + path.basename(process.cwd()), - }) - - const { description } = await prompt<{ description: string }>({ - name: 'description', - message: 'Description', - }) + let packageName: string | undefined + let description: string | undefined + try { + ;({ packageName, description } = JSON.parse(await readFile('package.json', 'utf-8'))) + } catch (err) { + if (err.code !== 'ENOENT') { + throw err + } + } + if (packageName) { + console.log(`Package name is "${packageName}"`) + } else { + ;({ packageName } = await prompt<{ packageName: string }>({ + name: 'packageName', + message: + 'What should the name of the package be? Examples: @sourcegraph/codeintellify, @sourcegraph/react-loading-spinner, cxp', + default: '@sourcegraph/' + path.basename(process.cwd()), + })) + } + if (description) { + console.log(`Description is "${description}"`) + } else { + ;({ description } = await prompt<{ description: string }>({ + name: 'description', + message: 'Description', + })) + } const { visibility } = await prompt<{ visibility: 'public' | 'private' }>({ type: 'list',