Skip to content

Commit

Permalink
feat: add unlink command
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Feb 18, 2024
1 parent 53add24 commit a734a0f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
39 changes: 39 additions & 0 deletions cli/commands/unlink.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { consola } from 'consola'
import { colors } from 'consola/utils'
import { isCancel, confirm } from '@clack/prompts'
import { defineCommand, runCommand } from 'citty'
import { fetchUser, projectPath, writeProjectConfig, loadProjectConfig, fetchProject } from '../utils/index.mjs'
import login from './login.mjs'

export default defineCommand({
meta: {
name: 'link',
description: 'Unlink a local directory from a NuxtHub project.',
},
async setup() {
let user = await fetchUser()
if (!user) {
consola.info('Please login to unlink your project.')
await runCommand(login, {})
user = await fetchUser()
}
let project = await fetchProject()
if (!project) {
consola.warn('This directory is not linked to any NuxtHub project.')
return
}
const shouldUnlink = await confirm({
message: `Do you want to unlink ${colors.blue(projectPath())} from NuxtHub project ${colors.blue(project.slug)}?`,
initialValue: false
})
if (!shouldUnlink || isCancel(shouldUnlink)) {
return consola.log('Cancelled.')
}

const config = loadProjectConfig()
delete config.hub.projectId
writeProjectConfig(config)

consola.success(`Project \`${project.slug}\` unlinked.`)
},
})
2 changes: 2 additions & 0 deletions cli/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineCommand, runMain } from 'citty'
import consola from 'consola'
import { colors } from 'consola/utils'
import link from './commands/link.mjs'
import unlink from './commands/unlink.mjs'
import login from './commands/login.mjs'
import logout from './commands/logout.mjs'
import whoami from './commands/whoami.mjs'
Expand All @@ -21,6 +22,7 @@ const main = defineCommand({
subCommands: {
deploy,
link,
unlink,
login,
logout,
whoami
Expand Down
5 changes: 4 additions & 1 deletion cli/utils/config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isDocker from 'is-docker'
import { updateUser, readUser, writeUser, read, update } from 'rc9'
import { updateUser, readUser, writeUser, read, update, write } from 'rc9'
import { homedir } from 'os'

export const INITIAL_CONFIG = loadUserConfig()
Expand All @@ -20,6 +20,9 @@ export function loadProjectConfig () {
export function updateProjectConfig (config) {
return update(config, '.nuxtrc')
}
export function writeProjectConfig (config) {
return write(config, '.nuxtrc')
}

export function isHeadless() {
return isDocker() || Boolean(process.env.SSH_CLIENT || process.env.SSH_TTY)
Expand Down

0 comments on commit a734a0f

Please sign in to comment.