-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from dimitrov-d/master
2.0.0
- Loading branch information
Showing
34 changed files
with
912 additions
and
1,281 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,5 +1,15 @@ | ||
import { exceptionHandler } from '@apillon/sdk'; | ||
|
||
export function enumValues(enumType: any): string[] { | ||
return Object.values(enumType) | ||
.filter((value) => typeof value === 'number') | ||
.map((value) => value.toString()); | ||
} | ||
|
||
export async function withErrorHandler(handler: () => Promise<any>) { | ||
try { | ||
await handler(); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,108 +1,87 @@ | ||
import { | ||
Hosting, | ||
exceptionHandler, | ||
DeployToEnvironment, | ||
toInteger, | ||
} from '@apillon/sdk'; | ||
import { Hosting, DeployToEnvironment, toInteger } from '@apillon/sdk'; | ||
import { GlobalOptions } from '../../lib/types'; | ||
import { paginate } from '../../lib/options'; | ||
import { withErrorHandler } from '../../lib/utils'; | ||
|
||
export async function listWebsites(optsWithGlobals: GlobalOptions) { | ||
const hosting = new Hosting(optsWithGlobals); | ||
try { | ||
const data = await hosting.listWebsites(paginate(optsWithGlobals)); | ||
await withErrorHandler(async () => { | ||
const data = await new Hosting(optsWithGlobals).listWebsites( | ||
paginate(optsWithGlobals), | ||
); | ||
data.items = data.items.map((w) => w.serialize()); | ||
console.log(data); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
}); | ||
} | ||
|
||
export async function getWebsite(optsWithGlobals: GlobalOptions) { | ||
const hosting = new Hosting(optsWithGlobals); | ||
try { | ||
const website = await hosting.website(optsWithGlobals.uuid).get(); | ||
await withErrorHandler(async () => { | ||
const website = await new Hosting(optsWithGlobals) | ||
.website(optsWithGlobals.uuid) | ||
.get(); | ||
console.log(website.serialize()); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
}); | ||
} | ||
|
||
export async function deployWebsite( | ||
path: string, | ||
optsWithGlobals: GlobalOptions, | ||
) { | ||
const hosting = new Hosting(optsWithGlobals); | ||
try { | ||
const website = hosting.website(optsWithGlobals.uuid); | ||
|
||
await withErrorHandler(async () => { | ||
const website = new Hosting(optsWithGlobals).website(optsWithGlobals.uuid); | ||
console.log(`Uploading files from folder: ${path}`); | ||
await website.uploadFromFolder(path); | ||
const deployment = await website.deploy( | ||
optsWithGlobals.preview | ||
? DeployToEnvironment.TO_STAGING | ||
: DeployToEnvironment.DIRECTLY_TO_PRODUCTION, | ||
); | ||
|
||
console.log(`Deployment started!`); | ||
const deploymentData = await website.deployment(deployment.uuid).get(); | ||
console.log(deploymentData.serialize()); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
}); | ||
} | ||
|
||
export async function uploadWebsiteFiles( | ||
path: string, | ||
optsWithGlobals: GlobalOptions, | ||
) { | ||
const hosting = new Hosting(optsWithGlobals); | ||
try { | ||
await hosting.website(optsWithGlobals.uuid).uploadFromFolder(path); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
await withErrorHandler(async () => { | ||
await new Hosting(optsWithGlobals) | ||
.website(optsWithGlobals.uuid) | ||
.uploadFromFolder(path); | ||
}); | ||
} | ||
|
||
export async function deployToEnvironment(optsWithGlobals: GlobalOptions) { | ||
const hosting = new Hosting(optsWithGlobals); | ||
try { | ||
await hosting | ||
await withErrorHandler(async () => { | ||
await new Hosting(optsWithGlobals) | ||
.website(optsWithGlobals.uuid) | ||
.deploy(toInteger(optsWithGlobals.env)); | ||
console.log('Deploy successful'); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
}); | ||
} | ||
|
||
export async function listDeployments(optsWithGlobals: GlobalOptions) { | ||
const hosting = new Hosting(optsWithGlobals); | ||
const params = { | ||
...paginate(optsWithGlobals), | ||
environment: toInteger(optsWithGlobals.env), | ||
deploymentStatus: toInteger(optsWithGlobals.status), | ||
}; | ||
try { | ||
const data = await hosting | ||
await withErrorHandler(async () => { | ||
const params = { | ||
...paginate(optsWithGlobals), | ||
environment: toInteger(optsWithGlobals.env), | ||
deploymentStatus: toInteger(optsWithGlobals.status), | ||
}; | ||
const data = await new Hosting(optsWithGlobals) | ||
.website(optsWithGlobals.uuid) | ||
.listDeployments(params); | ||
data.items = data.items.map((w) => w.serialize()); | ||
console.log(data); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
}); | ||
} | ||
|
||
export async function getDeployment(optsWithGlobals: GlobalOptions) { | ||
const hosting = new Hosting(optsWithGlobals); | ||
try { | ||
const deployment = await hosting | ||
await withErrorHandler(async () => { | ||
const deployment = await new Hosting(optsWithGlobals) | ||
.website(optsWithGlobals.websiteUuid) | ||
.deployment(optsWithGlobals.deploymentUuid) | ||
.get(); | ||
console.log(deployment.serialize()); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
}); | ||
} |
Oops, something went wrong.