Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ USAGE
FLAGS
-f, --filename=<value> Output filename for the generated types. If not provided, the filename app-features.ts will
be used.
-o, --output=<value> Output path for the app-features.ts file. All directories in this path should exist. If not
provided, the directory ./growthbook-types will be created in the current working directory.
-o, --output=<value> Output path for the app-features.ts file. Parent directories will be created if they don't
exist. If not provided, the directory ./growthbook-types will be created in the current
working directory.
-p, --profile=<value> Optional profile (for projects that use multiple GrowthBook instances) default: default)
-u, --apiBaseUrl=<value> Your GrowthBook instance base URL (e.g. http://localhost:3100, default:
https://api.growthbook.io)
Expand Down
17 changes: 10 additions & 7 deletions src/commands/features/generate-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class GenerateTypes extends Command {
...baseGrowthBookCliFlags,
output: Flags.string({
char: 'o',
description: `Output path for the ${GROWTHBOOK_APP_FEATURES_FILENAME} file. All directories in this path should exist. If not provided, the directory ${DEFAULT_GROWTHBOOK_TYPES_DESTINATION} will be created in the current working directory.`,
description: `Output path for the ${GROWTHBOOK_APP_FEATURES_FILENAME} file. Parent directories will be created if they don't exist. If not provided, the directory ${DEFAULT_GROWTHBOOK_TYPES_DESTINATION} will be created in the current working directory.`,
required: false,
}),
filename: Flags.string({
Expand Down Expand Up @@ -67,15 +67,18 @@ export default class GenerateTypes extends Command {
let outputPath = output
if (!outputPath) {
outputPath = Path.resolve(process.cwd(), DEFAULT_GROWTHBOOK_TYPES_DESTINATION)
}

if (!Fs.existsSync(outputPath)) {
ux.action.start('Creating output directory')

Fs.mkdirSync(outputPath)
Fs.writeFileSync(outputPath + '/.gitkeep', '')
const fullyQualifiedOutputPath = Path.resolve(process.cwd(), outputPath)
if (!Fs.existsSync(fullyQualifiedOutputPath)) {
ux.action.start('Creating output directory')

ux.action.stop(`${Icons.checkmark} Created directory ${outputPath}`)
Fs.mkdirSync(fullyQualifiedOutputPath, {recursive: true})
if (!output) {
Fs.writeFileSync(fullyQualifiedOutputPath + '/.gitkeep', '')
}

ux.action.stop(`${Icons.checkmark} Created directory ${fullyQualifiedOutputPath}`)
}

let outputFilename = GROWTHBOOK_APP_FEATURES_FILENAME
Expand Down