swaggerhub-cli 0.3.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ const { flags } = require('@oclif/command')
2
+ const { readFileSync } = require('fs-extra')
3
+ const { getDomain, postDomain } = require('../../requests/domain')
4
+ const { getDomainIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
5
+ const { getVersion, parseDefinition } = require('../../utils/oas')
6
+ const BaseCommand = require('../../support/command/base-command')
7
+ const UpdateCommand = require('../../support/command/update-command')
8
+
9
+ class UpdateDomainCommand extends UpdateCommand {
10
+
11
+ async updateDomain(owner, name, version, flags) {
12
+ const queryParams = { version }
13
+
14
+ if (flags.visibility) {
15
+ queryParams['isPrivate'] = flags.visibility !== 'public'
16
+ this.logCommandSuccess = this.setSuccessMessage('DomainUpdateVisibility')
17
+ }
18
+
19
+ const updateDomainObj = {
20
+ pathParams: [owner, name],
21
+ queryParams,
22
+ body: readFileSync(flags.file)
23
+ }
24
+
25
+ return await this.executeHttp({
26
+ execute: () => postDomain(updateDomainObj),
27
+ onResolve: this.logCommandSuccess({ owner, name, version, visibility: flags.visibility }),
28
+ options: { resolveStatus: [403] }
29
+ })
30
+ }
31
+
32
+ async run() {
33
+ const { args, flags } = this.parse(UpdateDomainCommand)
34
+
35
+ if (!Object.keys(flags).length) {
36
+ return this.error('No updates specified', { exit: 1 })
37
+ }
38
+
39
+ const definition = flags.file ? parseDefinition(flags.file) : null
40
+ const domainPath = getDomainIdentifierArg(args)
41
+ const [owner, name, version] = splitPathParams(domainPath)
42
+ const defaultVersion = definition ? getVersion(definition) : await this.getDefaultDomainVersion([owner, name])
43
+ const domainVersion = version ? version : defaultVersion
44
+ const type = 'domains'
45
+
46
+ if (flags.file) {
47
+ await this.handleUpdate(owner, name, domainVersion, flags)
48
+ } else if (flags.visibility) {
49
+ await this.updateVisibility(type, owner, name, domainVersion, flags.visibility !== 'public')
50
+ }
51
+
52
+ if (flags.published) await this.updatePublish(type, owner, name, domainVersion, flags.published === 'publish')
53
+ if (flags.setdefault) await this.updateDefault(type, owner, name, domainVersion)
54
+ }
55
+
56
+ async handleUpdate(owner, name, version, flags) {
57
+ await this.executeHttp({
58
+ execute: () => getDomain([owner, name, version]),
59
+ onResolve: () => this.updateDomain(owner, name, version, flags),
60
+ options: { resolveStatus: [403] }
61
+ })
62
+ }
63
+ }
64
+
65
+ UpdateDomainCommand.description = `update a domain
66
+ The domain version from the file will be used unless the version is specified in the command argument.
67
+ When no file is specified then the default domain version will be updated.
68
+ The domain visibility can be changed by using visibility flag.
69
+ `
70
+
71
+ UpdateDomainCommand.examples = [
72
+ 'swaggerhub domain:update organization/domain --file domain.yaml',
73
+ 'swaggerhub domain:update organization/domain/1.0.0 --file domain.json',
74
+ 'swaggerhub domain:update organization/domain/1.0.0 --published=publish --file domain.json',
75
+ 'swaggerhub domain:update organization/domain/1.0.0 --setdefault --file domain.json',
76
+ 'swaggerhub domain:update organization/domain/1.0.0 --published=unpublish --setdefault --file domain.json',
77
+ 'swaggerhub domain:update organization/domain/1.0.0 --visibility=private',
78
+ ]
79
+
80
+ UpdateDomainCommand.args = [{
81
+ name: 'OWNER/DOMAIN_NAME/[VERSION]',
82
+ required: true,
83
+ description: 'domain to update in SwaggerHub'
84
+ }]
85
+
86
+ UpdateDomainCommand.flags = {
87
+ file: flags.string({
88
+ char: 'f',
89
+ description: 'file location of domain to update',
90
+ required: false,
91
+ multiple: false
92
+ }),
93
+ visibility: flags.string({
94
+ description: 'visibility of domain in SwaggerHub',
95
+ options: ['public', 'private']
96
+ }),
97
+ published: flags.string({
98
+ description: 'sets the lifecycle setting of the domain version',
99
+ options: ['publish', 'unpublish'],
100
+ required: false
101
+ }),
102
+ setdefault: flags.boolean({
103
+ description: 'sets domain version to be the default',
104
+ required: false
105
+ }),
106
+ ...BaseCommand.flags
107
+ }
108
+
109
+ module.exports = UpdateDomainCommand
@@ -0,0 +1,48 @@
1
+ const { putProject } = require('../../../requests/project')
2
+ const {
3
+ getProjectIdentifierArg
4
+ } = require('../../../support/command/parse-input')
5
+ const BaseCommand = require('../../../support/command/base-command')
6
+
7
+ class ProjectApiAddCommand extends BaseCommand {
8
+
9
+ async run() {
10
+ const { args } = this.parse(ProjectApiAddCommand)
11
+ const projectPath = getProjectIdentifierArg(args)
12
+ const apiName = args['API']
13
+
14
+ await this.addApiToProject(projectPath, apiName)
15
+ }
16
+
17
+ async addApiToProject(projectPath, apiName) {
18
+
19
+ return this.executeHttp({
20
+ execute: () => putProject({ pathParams: [projectPath, 'apis', apiName] }),
21
+ onResolve: this.logCommandSuccess({ apiName, projectPath }),
22
+ options: {}
23
+ })
24
+ }
25
+ }
26
+
27
+ ProjectApiAddCommand.description = 'Adds an API to an existing project.'
28
+
29
+
30
+ ProjectApiAddCommand.examples = [
31
+ 'swaggerhub project:api:add organization/project_name my_api'
32
+ ]
33
+
34
+ ProjectApiAddCommand.args = [
35
+ {
36
+ name: 'OWNER/PROJECT_NAME',
37
+ required: true,
38
+ description: 'The project to add the API to'
39
+ },
40
+
41
+ {
42
+ name: 'API',
43
+ required: true,
44
+ description: 'The name of the API to add'
45
+ }
46
+ ]
47
+
48
+ module.exports = ProjectApiAddCommand
@@ -0,0 +1,69 @@
1
+ const { putProject, getProject } = require('../../../requests/project')
2
+ const {
3
+ getProjectIdentifierArg,
4
+ splitPathParams,
5
+ } = require('../../../support/command/parse-input')
6
+ const BaseCommand = require('../../../support/command/base-command')
7
+ const { getResponseContent } = require('../../../support/command/handle-response')
8
+ const { pipeAsync } = require('../../../utils/general')
9
+
10
+ class ProjectApiRemoveCommand extends BaseCommand {
11
+
12
+ async run() {
13
+ const { args } = this.parse(ProjectApiRemoveCommand)
14
+ const projectPath = getProjectIdentifierArg(args)
15
+ const apiToRemove = args['API']
16
+
17
+ await this.removeApiFromProject(projectPath, apiToRemove)
18
+ }
19
+
20
+ async getProjectDetails(owner, projectName) {
21
+ return this.executeHttp({
22
+ execute: () => getProject([owner, projectName]),
23
+ onResolve: pipeAsync(getResponseContent, JSON.parse),
24
+ options: {}
25
+ })
26
+ }
27
+
28
+ async removeApiFromProject(projectPath, apiName) {
29
+ const [owner, projectName] = splitPathParams(projectPath)
30
+
31
+ const project = await this.getProjectDetails(owner, projectName)
32
+ if (project.apis && !project.apis.includes(apiName)) {
33
+ return this.log(`Api \'${apiName}\' does not exist in project \'${projectPath}\'`)
34
+ }
35
+
36
+ project.apis = project.apis.filter(item => item !== apiName)
37
+ const updateRequest = {
38
+ pathParams: [owner, projectName],
39
+ body: JSON.stringify(project)
40
+ }
41
+
42
+ return this.executeHttp({
43
+ execute: () => putProject(updateRequest),
44
+ onResolve: this.logCommandSuccess({ apiName, projectPath }),
45
+ options: {}
46
+ })
47
+ }
48
+ }
49
+
50
+ ProjectApiRemoveCommand.description = 'Removes an API from a project in SwaggerHub.'
51
+
52
+ ProjectApiRemoveCommand.examples = [
53
+ 'swaggerhub project:api:remove organization/project_name my_api',
54
+ ]
55
+
56
+ ProjectApiRemoveCommand.args = [
57
+ {
58
+ name: 'OWNER/PROJECT_NAME',
59
+ required: true,
60
+ description: 'The project remove the API from'
61
+ },
62
+ {
63
+ name: 'API',
64
+ required: true,
65
+ description: 'The API to remove'
66
+ }
67
+ ]
68
+
69
+ module.exports = ProjectApiRemoveCommand
@@ -0,0 +1,77 @@
1
+ const { flags } = require('@oclif/command')
2
+ const { postProject } = require('../../requests/project')
3
+ const {
4
+ getProjectIdentifierArg,
5
+ splitPathParams,
6
+ splitFlagParams
7
+ } = require('../../support/command/parse-input')
8
+ const BaseCommand = require('../../support/command/base-command')
9
+
10
+ class CreateProjectCommand extends BaseCommand {
11
+
12
+ async run() {
13
+ const { args, flags } = this.parse(CreateProjectCommand)
14
+ const projectPath = getProjectIdentifierArg(args)
15
+ const [owner, name] = splitPathParams(projectPath)
16
+ const body = {
17
+ owner,
18
+ name
19
+ }
20
+ // Append optional flags to body if present
21
+ if (flags.description !== undefined) body.description = flags.description
22
+ if (flags.apis !== undefined) body.apis = splitFlagParams(flags.apis)
23
+ if (flags.domains !== undefined) body.domains = splitFlagParams(flags.domains)
24
+
25
+ await this.createProject(owner, name, JSON.stringify(body))
26
+ }
27
+
28
+ async createProject(owner, projectName, body) {
29
+ const createRequest = {
30
+ pathParams: [owner],
31
+ body
32
+ }
33
+
34
+ return this.executeHttp({
35
+ execute: () => postProject(createRequest),
36
+ onResolve: this.logCommandSuccess({ owner, projectName }),
37
+ options: {}
38
+ })
39
+ }
40
+ }
41
+
42
+ CreateProjectCommand.description = 'Creates a new project in SwaggerHub.'
43
+
44
+ CreateProjectCommand.examples = [
45
+ 'swaggerhub project:create organization/new_project_name --description "project description"',
46
+ 'swaggerhub project:create organization/new_project_name -a "testapi1,testapi2"',
47
+ 'swaggerhub project:create organization/new_project_name --apis "testapi1,testapi2"',
48
+ 'swaggerhub project:create organization/new_project_name -d "testdomain3,testdomain4"',
49
+ 'swaggerhub project:create organization/new_project_name --domains "testdomain3,testdomain4"',
50
+ 'swaggerhub project:create organization/new_project_name -a "testapi1" -d "testdomain3" --description "description"'
51
+ ]
52
+
53
+ CreateProjectCommand.args = [{
54
+ name: 'OWNER/PROJECT_NAME',
55
+ required: true,
56
+ description: 'The new project to create'
57
+ }]
58
+
59
+ CreateProjectCommand.flags = {
60
+ description: flags.string({
61
+ description: 'Description of project',
62
+ required: false
63
+ }),
64
+ apis: flags.string({
65
+ char: 'a',
66
+ description: 'Comma separated list of api names to include in project',
67
+ required: false
68
+ }),
69
+ domains: flags.string({
70
+ char: 'd',
71
+ description: 'Comma separated list of domain names to include in project',
72
+ required: false
73
+ }),
74
+ ...BaseCommand.flags
75
+ }
76
+
77
+ module.exports = CreateProjectCommand
@@ -0,0 +1,44 @@
1
+ const { deleteProject } = require('../../requests/project')
2
+ const { getProjectIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
+ const BaseCommand = require('../../support/command/base-command')
4
+
5
+ class DeleteProjectCommand extends BaseCommand {
6
+ constructor(...props) {
7
+ super(...props)
8
+ this.setSuccessMessage('ProjectDelete')
9
+ }
10
+
11
+ async run() {
12
+ const { args } = this.parse(DeleteProjectCommand)
13
+ const projectPath = getProjectIdentifierArg(args)
14
+ await this.deleteProject(projectPath)
15
+ }
16
+
17
+ async deleteProject(projectPath) {
18
+ const [owner, projectName] = splitPathParams(projectPath)
19
+
20
+ return this.executeHttp({
21
+ execute: () => deleteProject([owner, projectName]),
22
+ onResolve: this.logCommandSuccess({ projectPath }),
23
+ options: {}
24
+ })
25
+ }
26
+ }
27
+
28
+ DeleteProjectCommand.description = 'Deletes a project from SwaggerHub.'
29
+
30
+ DeleteProjectCommand.examples = [
31
+ 'swaggerhub project:delete organization/project_name'
32
+ ]
33
+
34
+ DeleteProjectCommand.args = [{
35
+ name: 'OWNER/PROJECT_NAME',
36
+ required: true,
37
+ description: 'Project to delete'
38
+ }]
39
+
40
+ DeleteProjectCommand.flags = {
41
+ ...BaseCommand.flags
42
+ }
43
+
44
+ module.exports = DeleteProjectCommand
@@ -0,0 +1,48 @@
1
+ const { putProject } = require('../../../requests/project')
2
+ const {
3
+ getProjectIdentifierArg
4
+ } = require('../../../support/command/parse-input')
5
+ const BaseCommand = require('../../../support/command/base-command')
6
+
7
+ class ProjectDomainAddCommand extends BaseCommand {
8
+
9
+ async run() {
10
+ const { args } = this.parse(ProjectDomainAddCommand)
11
+ const projectPath = getProjectIdentifierArg(args)
12
+ const domainName = args['DOMAIN']
13
+
14
+ await this.addDomainToProject(projectPath, domainName)
15
+ }
16
+
17
+ async addDomainToProject(projectPath, domainName) {
18
+
19
+ return this.executeHttp({
20
+ execute: () => putProject({ pathParams: [projectPath, 'domains', domainName] }),
21
+ onResolve: this.logCommandSuccess({ domainName, projectPath }),
22
+ options: {}
23
+ })
24
+ }
25
+ }
26
+
27
+ ProjectDomainAddCommand.description = 'Adds a domain to an existing project.'
28
+
29
+
30
+ ProjectDomainAddCommand.examples = [
31
+ 'swaggerhub project:domain:add organization/project_name my_domain'
32
+ ]
33
+
34
+ ProjectDomainAddCommand.args = [
35
+ {
36
+ name: 'OWNER/PROJECT_NAME',
37
+ required: true,
38
+ description: 'The project to add the domain to'
39
+ },
40
+
41
+ {
42
+ name: 'DOMAIN',
43
+ required: true,
44
+ description: 'The name of the domain to add'
45
+ }
46
+ ]
47
+
48
+ module.exports = ProjectDomainAddCommand
@@ -0,0 +1,69 @@
1
+ const { putProject, getProject } = require('../../../requests/project')
2
+ const {
3
+ getProjectIdentifierArg,
4
+ splitPathParams,
5
+ } = require('../../../support/command/parse-input')
6
+ const BaseCommand = require('../../../support/command/base-command')
7
+ const { getResponseContent } = require('../../../support/command/handle-response')
8
+ const { pipeAsync } = require('../../../utils/general')
9
+
10
+ class ProjectDomainRemoveCommand extends BaseCommand {
11
+
12
+ async run() {
13
+ const { args } = this.parse(ProjectDomainRemoveCommand)
14
+ const projectPath = getProjectIdentifierArg(args)
15
+ const domainToRemove = args['DOMAIN']
16
+
17
+ await this.removeDomainFromProject(projectPath, domainToRemove)
18
+ }
19
+
20
+ async getProjectDetails(owner, projectName) {
21
+ return this.executeHttp({
22
+ execute: () => getProject([owner, projectName]),
23
+ onResolve: pipeAsync(getResponseContent, JSON.parse),
24
+ options: {}
25
+ })
26
+ }
27
+
28
+ async removeDomainFromProject(projectPath, domainName) {
29
+ const [owner, projectName] = splitPathParams(projectPath)
30
+
31
+ const project = await this.getProjectDetails(owner, projectName)
32
+ if (project.domains && !project.domains.includes(domainName)) {
33
+ return this.log(`Domain \'${domainName}\' does not exist in project \'${projectPath}\'`)
34
+ }
35
+
36
+ project.domains = project.domains.filter(item => item !== domainName)
37
+ const updateRequest = {
38
+ pathParams: [owner, projectName],
39
+ body: JSON.stringify(project)
40
+ }
41
+
42
+ return this.executeHttp({
43
+ execute: () => putProject(updateRequest),
44
+ onResolve: this.logCommandSuccess({ domainName, projectPath }),
45
+ options: {}
46
+ })
47
+ }
48
+ }
49
+
50
+ ProjectDomainRemoveCommand.description = 'Removes a domain from a project in SwaggerHub.'
51
+
52
+ ProjectDomainRemoveCommand.examples = [
53
+ 'swaggerhub project:domain:remove organization/project_name my_domain',
54
+ ]
55
+
56
+ ProjectDomainRemoveCommand.args = [
57
+ {
58
+ name: 'OWNER/PROJECT_NAME',
59
+ required: true,
60
+ description: 'The project remove the domain from'
61
+ },
62
+ {
63
+ name: 'DOMAIN',
64
+ required: true,
65
+ description: 'The domain to remove'
66
+ }
67
+ ]
68
+
69
+ module.exports = ProjectDomainRemoveCommand
@@ -0,0 +1,51 @@
1
+ const { getProject } = require('../../requests/project')
2
+ const { getProjectIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
+ const { getResponseContent } = require('../../support/command/handle-response')
4
+ const { prettyPrintJSON } = require('../../utils/general')
5
+ const BaseCommand = require('../../support/command/base-command')
6
+
7
+ class GetProjectCommand extends BaseCommand {
8
+ constructor(...props) {
9
+ super(...props)
10
+ this.logProject = this.logProject.bind(this)
11
+ }
12
+
13
+ async run() {
14
+ const { args } = this.parse(GetProjectCommand)
15
+ const projectPath = getProjectIdentifierArg(args)
16
+ await this.getProject(projectPath)
17
+ }
18
+
19
+ async logProject(response) {
20
+ const project = await getResponseContent(response)
21
+ this.log(prettyPrintJSON(project))
22
+ }
23
+
24
+ async getProject(projectPath) {
25
+ const [owner, project] = splitPathParams(projectPath)
26
+
27
+ return this.executeHttp({
28
+ execute: () => getProject([owner, project]),
29
+ onResolve: this.logProject,
30
+ options: {}
31
+ })
32
+ }
33
+ }
34
+
35
+ GetProjectCommand.description = 'Retrieves the details for a project.'
36
+
37
+ GetProjectCommand.examples = [
38
+ 'swaggerhub project:get organization/project_name'
39
+ ]
40
+
41
+ GetProjectCommand.args = [{
42
+ name: 'OWNER/PROJECT_NAME',
43
+ required: true,
44
+ description: 'Project to retrieve the details for'
45
+ }]
46
+
47
+ GetProjectCommand.flags = {
48
+ ...BaseCommand.flags
49
+ }
50
+
51
+ module.exports = GetProjectCommand
@@ -0,0 +1,62 @@
1
+ const { cli } = require('cli-ux')
2
+ const { getProject } = require('../../requests/project')
3
+ const { getResponseContent } = require('../../support/command/handle-response')
4
+ const BaseCommand = require('../../support/command/base-command')
5
+
6
+ class ListProjectCommand extends BaseCommand {
7
+ constructor(...props) {
8
+ super(...props)
9
+ this.logProject = this.logProject.bind(this)
10
+ }
11
+
12
+ async run() {
13
+ const { args } = this.parse(ListProjectCommand)
14
+ await this.listProjects(args['OWNER'])
15
+ }
16
+
17
+ async logProject(response) {
18
+ const responseObj = JSON.parse(await getResponseContent(response))
19
+ if (responseObj.projects.length === 0){
20
+ this.log('No projects found.')
21
+ } else {
22
+ cli.table(responseObj.projects, {
23
+ name: {},
24
+ owner: {},
25
+ description: {},
26
+ apis: {
27
+ header: 'APIs'
28
+ },
29
+ domains: {}
30
+ }, {
31
+ printLine: this.log
32
+ })
33
+ }
34
+ }
35
+
36
+ async listProjects(args) {
37
+ return this.executeHttp({
38
+ execute: () => getProject([args]),
39
+ onResolve: this.logProject,
40
+ options: {}
41
+ })
42
+ }
43
+ }
44
+
45
+ ListProjectCommand.description = 'list projects'
46
+
47
+ ListProjectCommand.examples = [
48
+ 'swaggerhub project:list',
49
+ 'swaggerhub project:list organization'
50
+ ]
51
+
52
+ ListProjectCommand.args = [{
53
+ name: 'OWNER',
54
+ required: false,
55
+ description: 'Organization to list projects for'
56
+ }]
57
+
58
+ ListProjectCommand.flags = {
59
+ ...BaseCommand.flags
60
+ }
61
+
62
+ module.exports = ListProjectCommand
@@ -0,0 +1,60 @@
1
+ const { getProject } = require('../../../requests/project')
2
+ const { getResponseContent } = require('../../../support/command/handle-response')
3
+ const BaseCommand = require('../../../support/command/base-command')
4
+ const { getProjectIdentifierArg } = require('../../../support/command/parse-input')
5
+ const { cli } = require('cli-ux')
6
+
7
+ class ListProjectMembersCommand extends BaseCommand {
8
+ constructor(...props) {
9
+ super(...props)
10
+ this.logProjectMembers = this.logProjectMembers.bind(this)
11
+ }
12
+
13
+ async run() {
14
+ const { args } = this.parse(ListProjectMembersCommand)
15
+ const projectPath = getProjectIdentifierArg(args)
16
+ await this.getProjectMembers(projectPath)
17
+ }
18
+
19
+ async logProjectMembers(response) {
20
+ const responseObj = JSON.parse(await getResponseContent(response))
21
+ if (responseObj.members.length === 0){
22
+ this.log('No members found.')
23
+ } else {
24
+ cli.table(responseObj.members, {
25
+ name: {
26
+ minWidth: 24
27
+ },
28
+ type: {}
29
+ }, {
30
+ printLine: this.log
31
+ })
32
+ }
33
+ }
34
+
35
+ async getProjectMembers(projectPath) {
36
+ return this.executeHttp({
37
+ execute: () => getProject([projectPath,'members']),
38
+ onResolve: this.logProjectMembers,
39
+ options: {}
40
+ })
41
+ }
42
+ }
43
+
44
+ ListProjectMembersCommand.description = 'list members of a project'
45
+
46
+ ListProjectMembersCommand.examples = [
47
+ 'swaggerhub project:member:list organisation/project_name',
48
+ ]
49
+
50
+ ListProjectMembersCommand.args = [{
51
+ name: 'OWNER/PROJECT_NAME',
52
+ required: true,
53
+ description: 'Project to list members of'
54
+ }]
55
+
56
+ ListProjectMembersCommand.flags = {
57
+ ...BaseCommand.flags
58
+ }
59
+
60
+ module.exports = ListProjectMembersCommand
@@ -23,7 +23,8 @@ const setConfig = update => {
23
23
  const isURLValid = () => {
24
24
  const { SWAGGERHUB_URL } = getConfig()
25
25
  return swaggerhubUrlRegex.test(SWAGGERHUB_URL) ||
26
- (!SWAGGERHUB_URL.includes('api.swaggerhub.com') && SWAGGERHUB_URL.endsWith('/v1'))
26
+ (!SWAGGERHUB_URL.includes('api.swaggerhub.com') && SWAGGERHUB_URL.endsWith('/v1')) ||
27
+ SWAGGERHUB_URL.includes('localhost')
27
28
  }
28
29
 
29
30
  module.exports = {
@@ -0,0 +1,38 @@
1
+ const fs = require('fs')
2
+
3
+ const removeArgsFromHeaders = line => {
4
+ const words = line.split(' ')
5
+ if (words.length <= 3) return line
6
+ return `## ${words[1]} ${words[2]}\``
7
+ }
8
+
9
+ const removeArgsFromLinks = line => {
10
+ const slug = line.substr(line.indexOf('#')+1, line.length-2)
11
+ const words = slug.split('-')
12
+ if (words.length <= 2) return line
13
+ return line.replace(slug, `${words[0]}-${words[1]})`)
14
+ }
15
+
16
+ const main = () => {
17
+ const outputBuffer = []
18
+ try {
19
+ const data = fs.readFileSync('README.md', 'utf8')
20
+ const lineBuffer = data.split('\n')
21
+
22
+ lineBuffer.forEach(line => {
23
+ if (line.startsWith('* [`swaggerhub')) return outputBuffer.push(removeArgsFromLinks(line))
24
+ if (line.startsWith('## `swaggerhub')) return outputBuffer.push(removeArgsFromHeaders(line))
25
+ return outputBuffer.push(line)
26
+ })
27
+
28
+ const output = outputBuffer.join('\n')
29
+ fs.writeFileSync('README.md', output)
30
+
31
+ } catch (err) {
32
+ console.error(err)
33
+ }
34
+ }
35
+
36
+ if (require.main === module) {
37
+ main()
38
+ }