-
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.
CLI functionality for rdme version CRUD
- Loading branch information
Showing
5 changed files
with
176 additions
and
60 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,45 +1,86 @@ | ||
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?", | ||
choices: [ | ||
{ title: 'Use existing', value: 'update' }, | ||
{ title: 'Create a new version', value: 'create' }, | ||
], | ||
}, | ||
{ | ||
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, | ||
}; | ||
}), | ||
}, | ||
]; | ||
const { prompt } = require('enquirer'); | ||
|
||
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 }], | ||
}, | ||
]; | ||
exports.generatePrompts = async versionList => | ||
prompt([ | ||
{ | ||
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?", | ||
choices: [ | ||
{ message: 'Use existing', value: 'update' }, | ||
{ message: 'Create a new version', value: 'create' }, | ||
], | ||
}, | ||
{ | ||
type: 'select', | ||
name: 'versionSelection', | ||
message: 'Select your desired version', | ||
skip() { | ||
return this.enquirer.answers.option !== 'update'; | ||
}, | ||
choices: versionList.map(v => { | ||
return { | ||
message: v.version, | ||
// eslint-disable-next-line | ||
value: v._id, | ||
}; | ||
}), | ||
}, | ||
]); | ||
|
||
exports.createVersionPrompt = async (versionList, opts, isUpdate) => | ||
prompt([ | ||
{ | ||
type: 'select', | ||
name: 'from', | ||
message: 'Which version would you like to fork from?', | ||
skip() { | ||
return opts.fork || isUpdate; | ||
}, | ||
choices: versionList.map(v => { | ||
return { | ||
message: v.version, | ||
// eslint-disable-next-line | ||
value: v.version, | ||
}; | ||
}), | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'newVersion', | ||
message: "What's your new version?", | ||
skip() { | ||
return opts.newVersion || !isUpdate; | ||
}, | ||
hint: '1.0.0', | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'is_stable', | ||
message: 'Would you like to make this version the main version for this project?', | ||
skip: () => opts.main, | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'is_beta', | ||
message: 'Should this version be in beta?', | ||
skip: () => opts.beta, | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'is_hidden', | ||
message: 'Would you like to make this version public?', | ||
skip() { | ||
return opts.isPublic || opts.main || this.enquirer.answers.is_stable; | ||
}, | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'is_deprecated', | ||
message: 'Would you like to deprecate this version?', | ||
skip() { | ||
return opts.deprecated || opts.main || !isUpdate || this.enquirer.answers.is_stable; | ||
}, | ||
}, | ||
]); |
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,57 @@ | ||
const request = require('request-promise-native'); | ||
const config = require('config'); | ||
const promptOpts = require('../prompts'); | ||
|
||
exports.desc = 'Update an existing version for your project'; | ||
exports.category = 'services'; | ||
exports.weight = 4; | ||
exports.action = 'versions:update'; | ||
|
||
exports.run = async function({ opts }) { | ||
let { key } = opts; | ||
let versionList; | ||
const { version, codename, fork, newVersion, main, beta, isPublic, deprecated } = 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'), | ||
); | ||
} | ||
|
||
if (!fork) { | ||
versionList = await request | ||
.get(`${config.host}/api/v1/version`, { | ||
json: true, | ||
auth: { user: key }, | ||
}) | ||
.catch(err => Promise.reject(new Error(err))); | ||
} | ||
|
||
const promptResponse = await promptOpts.createVersionPrompt(versionList, opts, true); | ||
const options = { | ||
json: { | ||
codename: codename || '', | ||
version: newVersion || promptResponse.newVersion, | ||
is_stable: main || promptResponse.is_stable, | ||
is_beta: beta || promptResponse.is_beta, | ||
is_deprecated: deprecated || promptResponse.is_deprecated, | ||
is_hidden: promptResponse.is_stable ? false : !(isPublic || promptResponse.is_hidden), | ||
}, | ||
auth: { user: key }, | ||
}; | ||
|
||
return request | ||
.put(`${config.host}/api/v1/version/${version}`, options) | ||
.catch(err => Promise.reject(new Error(err))); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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