-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Beautify apps commands #862
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
import * as AppConfig from '../models/app_configuration.js'; | ||
import * as Application from '../models/application.js'; | ||
import { Logger } from '../logger.js'; | ||
import colors from 'colors/safe.js'; | ||
|
||
export async function deleteApp (params) { | ||
const { alias, app: appIdOrName, yes: skipConfirmation } = params.options; | ||
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias); | ||
|
||
const app = await Application.get(ownerId, appId); | ||
if (app == null) { | ||
Logger.println('The application doesn\'t exist'); | ||
throw new Error('The application doesn\'t exist'); | ||
} | ||
else { | ||
// delete app | ||
await Application.deleteApp(app, skipConfirmation); | ||
Logger.println('The application has been deleted'); | ||
// unlink app | ||
Logger.println(`${colors.green('✓')} Application ${colors.green(colors.bold(`${app.name}`))} successfully deleted!`); | ||
Logger.println(` ${colors.gray('•')} Application ID: ${colors.gray(app.id)}`); | ||
|
||
const wasUnlinked = await AppConfig.removeLinkedApplication({ appId, alias }); | ||
if (wasUnlinked) { | ||
Logger.println('The application has been unlinked'); | ||
Logger.println(` ${colors.blue('→')} Local alias ${colors.blue(alias || app.name)} unlinked`); | ||
} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import * as AppConfig from '../models/app_configuration.js'; | ||
import { Logger } from '../logger.js'; | ||
|
||
import colors from 'colors/safe.js'; | ||
export async function makeDefault (params) { | ||
const [alias] = params.args; | ||
|
||
await AppConfig.setDefault(alias); | ||
|
||
Logger.println(`The application ${alias} has been set as default`); | ||
Logger.println(colors.bold.green('✓'), `The application ${colors.green(alias)} has been set as default`); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import * as AppConfig from '../models/app_configuration.js'; | ||
import * as Application from '../models/application.js'; | ||
import { Logger } from '../logger.js'; | ||
|
||
import colors from 'colors/safe.js'; | ||
export async function unlink (params) { | ||
const [alias] = params.args; | ||
const app = await AppConfig.getAppDetails({ alias }); | ||
|
||
await Application.unlinkRepo(app.alias); | ||
Logger.println('Your application has been successfully unlinked!'); | ||
Logger.println(colors.bold.green('✓'), `Application ${colors.green(app.appId)} has been successfully unlinked from local alias ${colors.green(app.alias)}!`); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import childProcess from 'node:child_process'; | ||
|
||
import _ from 'lodash'; | ||
import git from 'isomorphic-git'; | ||
|
@@ -130,3 +131,39 @@ export async function isShallow () { | |
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Check if the current directory is a git repository | ||
* @returns {boolean} | ||
* @public | ||
*/ | ||
export function isGitRepo () { | ||
try { | ||
childProcess.execSync('git rev-parse --is-inside-work-tree', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we start assuming user has got This is something we need to document. I feel like it is a breaking change right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made it as is, we can also check if git is here, if not, don't print anything related. But as the user need a git repo with commits, I think it's could be better to print a warning if no git is found. I think we already tell in doc git is mandatory, but we can insist more on this. |
||
stdio: 'ignore', | ||
stderr: 'ignore', | ||
}); | ||
return true; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Check if the current git working directory is clean | ||
* @returns {boolean} | ||
* @public | ||
*/ | ||
export function isGitWorkingDirectoryClean () { | ||
try { | ||
const status = childProcess.execSync('git status --porcelain=v1', { | ||
encoding: 'utf8', | ||
stdio: ['ignore', 'pipe', 'ignore'], | ||
}); | ||
return status.trim() === ''; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be interested in the reason of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was there before. My point here was mainly to change how things are printed, not how the CLI works (except to add some info about git repo):
clever-tools/src/commands/deploy.js
Line 73 in fed085e