Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/commands/sites.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ netlify sites:create
- `account-slug` (*string*) - account slug to create the project under
- `disable-linking` (*boolean*) - create the project without linking it to current directory
- `filter` (*string*) - For monorepos, specify the name of the application to run the command in
- `json` (*boolean*) - Output project data as JSON
- `manual` (*boolean*) - force manual CI setup. Used --with-ci flag
- `name` (*string*) - name of project
- `debug` (*boolean*) - Print debugging information
Expand Down
1 change: 1 addition & 0 deletions src/commands/sites/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Create a blank project that isn't associated with any git remote. Will link the
.option('-m, --manual', 'force manual CI setup. Used --with-ci flag')
.option('--disable-linking', 'create the project without linking it to current directory')
.option('-p, --prompt <prompt>', 'description of the site to create (delegates to `netlify create`)')
.option('--json', 'Output project data as JSON')
.addHelpText(
'after',
`Create a blank project that isn't associated with any git remote. Will link the project to the current working directory.`,
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/commands/sites/sites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,39 @@ describe('sites command', () => {
}).rejects.toThrowError('--name should be less than 64 characters')
})
})

test('should output JSON when --json flag is passed', async () => {
await withMockApi(routes, async ({ apiUrl }) => {
Object.assign(process.env, getEnvironmentVariables({ apiUrl }))

const program = new BaseCommand('netlify')
createSitesCreateCommand(program)

const logJsonSpy = vi.spyOn(await import('../../../../src/utils/command-helpers.js'), 'logJson')

await program.parseAsync([
'',
'',
'sites:create',
'--name',
'test-site',
'--account-slug',
'test-account',
'--disable-linking',
'--json',
])

expect(logJsonSpy).toHaveBeenCalledWith(
expect.objectContaining({
id: 'site_id',
name: 'site-name',
admin_url: 'https://app.netlify.com/projects/site-name/overview',
ssl_url: 'https://site-name.netlify.app/',
}),
)

logJsonSpy.mockRestore()
})
})
})
})
Loading