-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
179 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,45 @@ | ||
exports.generatePrompts = (versionList) => [ | ||
exports.generatePrompts = versionList => [ | ||
{ | ||
type: 'select', | ||
name: 'option', | ||
message: 'We couldn\'t find a version in ReadMe matching the version in your OAS file. Would you like to use an existing version or create a new one?', | ||
message: | ||
"We couldn't find a version in ReadMe matching the version in your OAS file. Would you like to use an existing version or create a new one?", | ||
choices: [ | ||
{ title: 'Use existing', value: 'update' }, | ||
{ title: 'Create a new version', value: 'create' } | ||
{ title: 'Create a new version', value: 'create' }, | ||
], | ||
}, | ||
{ | ||
type: prev => prev === 'update' ? 'select' : null, | ||
type: prev => (prev === 'update' ? 'select' : null), | ||
name: 'versionSelection', | ||
message: 'Select your desired version', | ||
choices: versionList.map(v => { | ||
return { | ||
title: v.version, | ||
// eslint-disable-next-line | ||
value: v._id | ||
value: v._id, | ||
}; | ||
}), | ||
} | ||
}, | ||
]; | ||
|
||
exports.createVersionPrompt = versionList => [ | ||
{ | ||
type: 'select', | ||
name: 'fork', | ||
message: 'Which version would you like to fork from?', | ||
choices: versionList.map(v => { | ||
return { | ||
title: v.version, | ||
// eslint-disable-next-line | ||
value: v._id, | ||
}; | ||
}), | ||
}, | ||
{ | ||
type: 'select', | ||
name: 'main', | ||
message: 'Would you like to make this version the main version?', | ||
choices: [{ title: 'Yes', value: true }, { title: 'No', value: false }], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const request = require('request-promise-native'); | ||
const config = require('config'); | ||
const prompts = require('prompts'); | ||
const promptOpts = require('../prompts'); | ||
|
||
exports.desc = 'Create a new version for your project'; | ||
exports.category = 'services'; | ||
exports.weight = 4; | ||
exports.action = 'versions:create'; | ||
|
||
exports.run = async function({ opts }) { | ||
let { key } = opts; | ||
const { version, codename } = opts; | ||
|
||
if (!key && opts.token) { | ||
console.warn( | ||
'Using `rdme` with --token has been deprecated. Please use --key and --id instead', | ||
); | ||
[key] = opts.token.split('-'); | ||
} | ||
|
||
if (!key) { | ||
return Promise.reject(new Error('No api key provided. Please use --key')); | ||
} | ||
|
||
if (!version) { | ||
return Promise.reject( | ||
new Error('No version provided. Please specify a semantic version using --version'), | ||
); | ||
} | ||
|
||
const versionList = await request | ||
.get(`${config.host}/api/v1/version`, { | ||
json: true, | ||
auth: { user: key }, | ||
}) | ||
.catch(err => Promise.reject(new Error(err))); | ||
|
||
const promptSelection = promptOpts.createVersionPrompt(versionList); | ||
const { fork, main } = await prompts(promptSelection); | ||
|
||
const options = { | ||
json: { | ||
version, | ||
fork, | ||
codename: codename || '', | ||
is_stable: main, | ||
}, | ||
auth: { user: key }, | ||
}; | ||
|
||
return request | ||
.post(`${config.host}/api/v1/version`, options) | ||
.catch(err => Promise.reject(new Error(err))); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const request = require('request-promise-native'); | ||
const config = require('config'); | ||
|
||
exports.desc = 'Delete a version associated with your ReadMe project'; | ||
exports.category = 'services'; | ||
exports.weight = 4; | ||
exports.action = 'versions:delete'; | ||
|
||
exports.run = async function({ opts }) { | ||
let { key } = opts; | ||
const { version } = opts; | ||
|
||
if (!key && opts.token) { | ||
console.warn( | ||
'Using `rdme` with --token has been deprecated. Please use --key and --id instead', | ||
); | ||
[key] = opts.token.split('-'); | ||
} | ||
|
||
if (!key) { | ||
return Promise.reject(new Error('No api key provided. Please use --key')); | ||
} | ||
|
||
if (!version) { | ||
return Promise.reject( | ||
new Error('No version provided. Please specify a semantic version using --version'), | ||
); | ||
} | ||
|
||
return request | ||
.delete(`${config.host}/api/v1/version/${version}`, { | ||
auth: { user: key }, | ||
}) | ||
.catch(err => Promise.reject(new Error(err))); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const request = require('request-promise-native'); | ||
const config = require('config'); | ||
|
||
exports.desc = 'List versions available in your project'; | ||
exports.category = 'services'; | ||
exports.weight = 4; | ||
exports.action = 'versions:list'; | ||
|
||
exports.run = function({ opts }) { | ||
let { key } = opts; | ||
|
||
if (!key && opts.token) { | ||
console.warn( | ||
'Using `rdme` with --token has been deprecated. Please use --key and --id instead', | ||
); | ||
[key] = opts.token.split('-'); | ||
} | ||
|
||
if (!key) { | ||
return Promise.reject(new Error('No api key provided. Please use --key')); | ||
} | ||
|
||
return request | ||
.get(`${config.host}/api/v1/version`, { | ||
json: true, | ||
auth: { user: key }, | ||
}) | ||
.catch(err => Promise.reject(new Error(err))); | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const assert = require('assert'); | ||
const promptHandler = require('../lib/prompts'); | ||
|
||
const versionlist = [ | ||
{ | ||
version: '1', | ||
_id: '32', | ||
}, | ||
]; | ||
|
||
describe('generatePrompts()', () => { | ||
it('should create an array of objects based on provided version list', () => { | ||
const res = promptHandler.generatePrompts(versionlist); | ||
console.log(res[1].choices); | ||
assert.equal(res[1].choices[0].title, '1'); | ||
}); | ||
}); |