Skip to content

Commit

Permalink
[cli] Add CLI methods for manage and docs (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars authored and bjoerge committed Nov 13, 2017
1 parent 426cf91 commit aa24531
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
15 changes: 15 additions & 0 deletions packages/@sanity/cli/src/commands/docs/docsCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import opn from 'opn'

export default {
name: 'docs',
signature: 'docs',
description: 'Opens the Sanity documentation',
action(args, context) {
const {output} = context
const {print} = output
const url = 'https://www.sanity.io/docs/content-studio'

print(`Opening ${url}`)
opn(url)
}
}
19 changes: 16 additions & 3 deletions packages/@sanity/cli/src/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import debugCommand from './debug/debugCommand'
import docsCommand from './docs/docsCommand'
import helpCommand from './help/helpCommand'
import initCommand from './init/initCommand'
import installCommand from './install/installCommand'
import upgradeCommand from './upgrade/upgradeCommand'
import loginCommand from './login/loginCommand'
import logoutCommand from './logout/logoutCommand'
import manageCommand from './manage/manageCommand'
import upgradeCommand from './upgrade/upgradeCommand'
import versionsCommand from './versions/versionsCommand'
import debugCommand from './debug/debugCommand'

export default [initCommand, loginCommand, logoutCommand, installCommand, upgradeCommand, versionsCommand, debugCommand, helpCommand]
export default [
initCommand,
loginCommand,
logoutCommand,
installCommand,
upgradeCommand,
versionsCommand,
docsCommand,
manageCommand,
debugCommand,
helpCommand
]
3 changes: 3 additions & 0 deletions packages/@sanity/cli/src/commands/init/initSanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@ export default async function initSanity(args, context) {
const successMessage = template.getSuccessMessage
? template.getSuccessMessage(initOptions, context)
: ''

if (successMessage) {
print(`\n${successMessage}`)
}

print('\nNeed some help to get you started? Run "sanity docs" for documentation!\n')

async function getOrCreateUser() {
print("We can't find any auth credentials in your Sanity config - looks like you")
print("haven't used Sanity on this system before?\n")
Expand Down
29 changes: 29 additions & 0 deletions packages/@sanity/cli/src/commands/manage/manageCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import path from 'path'
import opn from 'opn'
import fse from 'fs-extra'

export default {
name: 'manage',
signature: 'manage',
description: 'Opens the Sanity project management UI',
async action(args, context) {
const {workDir, output} = context
const {print} = output
const configLocation = path.join(workDir, 'sanity.json')

let projectId
try {
const config = await fse.readJson(configLocation)
projectId = config.api && config.api.projectId
} catch (err) {
// Noop.
}

const url = projectId
? `https://manage.sanity.io/projects/${projectId}`
: 'https://manage.sanity.io/'

print(`Opening ${url}`)
opn(url)
}
}

0 comments on commit aa24531

Please sign in to comment.