Skip to content

Commit ce8b6f6

Browse files
authored
Merge pull request #679 from bump-sh/381-preview-in-the-context-of-an-existing-documentation
Add flag '--preview' to Deploy command
2 parents 961d67a + 822edab commit ce8b6f6

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

src/api/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface VersionRequest {
3636
hub?: string
3737
previous_version_id?: string
3838
references?: Reference[]
39+
temporary?: boolean
3940
unpublished?: boolean
4041
}
4142

src/commands/deploy.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ${chalk.dim('$ bump deploy FILE --dry-run --doc <doc_slug> --token <your_doc_tok
6464
hub: flagsBuilder.hub(),
6565
interactive: flagsBuilder.interactive(),
6666
overlay: flagsBuilder.overlay(),
67+
preview: flagsBuilder.preview(),
6768
token: flagsBuilder.token(),
6869
}
6970

@@ -147,6 +148,7 @@ ${chalk.dim('$ bump deploy FILE --dry-run --doc <doc_slug> --token <your_doc_tok
147148
documentationName: string | undefined,
148149
branch: string | undefined,
149150
overlay?: string[] | undefined,
151+
temporary?: boolean | undefined,
150152
): Promise<void> {
151153
ux.action.status = `...a new version to your ${documentation} documentation`
152154

@@ -160,13 +162,16 @@ ${chalk.dim('$ bump deploy FILE --dry-run --doc <doc_slug> --token <your_doc_tok
160162
documentationName,
161163
branch,
162164
overlay,
165+
temporary,
163166
)
164167

165168
if (dryRun) {
166169
ux.stdout(ux.colorize('green', 'Definition is valid'))
167170
} else if (response) {
168171
process.stdout.write(ux.colorize('green', `Your ${documentation} documentation...`))
169-
ux.stdout(ux.colorize('green', `has received a new deployment which will soon be ready at:`))
172+
ux.stdout(
173+
ux.colorize('green', `has received a new ${temporary ? 'preview' : 'deployment'} which will soon be ready at:`),
174+
)
170175
ux.stdout(ux.colorize('underline', response.doc_public_url!))
171176
} else {
172177
ux.warn(`Your ${documentation} documentation has not changed`)
@@ -193,6 +198,7 @@ ${chalk.dim('$ bump deploy FILE --dry-run --doc <doc_slug> --token <your_doc_tok
193198
documentationName,
194199
branch,
195200
overlay,
201+
temporary,
196202
] = [
197203
flags['dry-run'],
198204
flags.doc,
@@ -208,9 +214,11 @@ ${chalk.dim('$ bump deploy FILE --dry-run --doc <doc_slug> --token <your_doc_tok
208214
flags['doc-name'],
209215
flags.branch,
210216
flags.overlay,
217+
/* when --preview is provided, generate temporary version */
218+
flags.preview,
211219
]
212220

213-
const action = dryRun ? 'validate' : 'deploy'
221+
const action = dryRun ? 'validate' : temporary ? 'preview' : 'deploy'
214222
ux.action.start(`Let's ${action} on Bump.sh`)
215223

216224
if (isDir(args.file)) {
@@ -243,6 +251,7 @@ ${chalk.dim('$ bump deploy FILE --dry-run --doc <doc_slug> --token <your_doc_tok
243251
documentationName,
244252
branch,
245253
overlay,
254+
temporary,
246255
)
247256
} else {
248257
throw new CLIError('Missing required flag --doc=<slug>')

src/core/deploy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class Deploy {
4949
documentationName: string | undefined,
5050
branch: string | undefined,
5151
overlay?: string[] | undefined,
52+
temporary?: boolean | false,
5253
): Promise<VersionResponse | undefined> {
5354
let version: VersionResponse | undefined
5455
if (overlay) {
@@ -71,6 +72,7 @@ export class Deploy {
7172
documentation_name: documentationName,
7273
hub,
7374
references,
75+
temporary,
7476
}
7577
if (dryRun) {
7678
await this.validateVersion(request, token)

src/flags.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ const live = (opts: Partial<Interfaces.BooleanFlag<boolean>> = {}) => {
110110
})
111111
}
112112

113+
const preview = (opts: Partial<Interfaces.BooleanFlag<boolean>> = {}) => {
114+
return Flags.boolean({
115+
...opts,
116+
char: 'p',
117+
default: false,
118+
description:
119+
'Generate a preview in your API context. The resulting version is temporary and not visible by your documentation viewers.',
120+
})
121+
}
122+
113123
const format = Flags.custom<string>({
114124
char: 'f',
115125
default: 'text',
@@ -150,5 +160,6 @@ export {
150160
open,
151161
out,
152162
overlay,
163+
preview,
153164
token,
154165
}

test/commands/deploy.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ describe('deploy subcommand', () => {
169169
})
170170
})
171171

172+
describe('Successful runs with option preview', () => {
173+
it('sends new version to Bump and receive temporary version', async () => {
174+
nock('https://bump.sh')
175+
.post('/api/v1/versions', (body) => body.documentation === 'tempy' && body.temporary)
176+
.reply(201, {doc_public_url: 'http://localhost/doc/1'})
177+
178+
const {stderr, stdout} = await runCommand(
179+
['deploy', 'examples/valid/openapi.v3.json', '--doc', 'tempy', '--preview'].join(' '),
180+
)
181+
182+
expect(stderr).to.contain("Let's preview on Bump.sh... done\n")
183+
expect(stdout).to.contain('Your tempy documentation...has received a new preview which will soon be ready at:')
184+
expect(stdout).to.contain('http://localhost/doc/1')
185+
})
186+
})
187+
172188
describe('Server errors', () => {
173189
describe('Authentication error', () => {
174190
it("Doesn't create a deployed version", async () => {

0 commit comments

Comments
 (0)