Skip to content

Commit

Permalink
Merge pull request #24 from dimitrov-d/master
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
dimitrov-d authored Feb 1, 2024
2 parents fa5b6f0 + a87db59 commit b6efc44
Show file tree
Hide file tree
Showing 34 changed files with 912 additions and 1,281 deletions.
1,006 changes: 283 additions & 723 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apillon-web3-tools",
"version": "1.2.0",
"version": "2.0.0",
"description": "Monorepo for Apillon tools",
"author": "Apillon",
"license": "MIT",
Expand All @@ -23,11 +23,11 @@
"devDependencies": {
"eslint-config-common": "*",
"prettier": "latest",
"rimraf": "^4.4.0",
"rimraf": "^5.0.5",
"turbo": "latest",
"jest": "29.7.0",
"ts-jest": "29.1.1",
"@types/jest": "^29.5.5"
"@types/jest": "^29.5.11"
},
"jest": {
"testTimeout": 1800000,
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
"decentralized"
],
"devDependencies": {
"nodemon": "^2.0.20",
"ts-node": "^10.9.1",
"eslint-config-common": "*",
"tsconfig": "*",
"rimraf": "^5.0.5"
"nodemon": "^3.0.2",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
"tsconfig": "*"
},
"dependencies": {
"axios": "^1.3.4",
"@apillon/sdk": "*",
"axios": "^1.6.2",
"chalk": "^4.1.2",
"commander": "^10.0.0",
"@apillon/sdk": "*"
"commander": "^11.1.0"
}
}
}
10 changes: 10 additions & 0 deletions packages/cli/src/lib/utils.ts
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);
}
}
4 changes: 3 additions & 1 deletion packages/cli/src/modules/hosting/hosting.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export function createHostingCommands(cli: Command) {
'--status <deployment-status>',
'Status of the deployment (optional) Choose from:\n' +
` ${DeploymentStatus.INITIATED}: Initiated\n` +
` ${DeploymentStatus.IN_PROCESS}: In process\n` +
` ${DeploymentStatus.IN_PROGRESS}: In progress\n` +
` ${DeploymentStatus.IN_REVIEW}: In review\n` +
` ${DeploymentStatus.APPROVED}: Approved\n` +
` ${DeploymentStatus.SUCCESSFUL}: Successful\n` +
` ${DeploymentStatus.FAILED}: Failed\n`,
).choices(enumValues(DeploymentStatus)),
Expand Down
89 changes: 34 additions & 55 deletions packages/cli/src/modules/hosting/hosting.service.ts
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);
}
});
}
Loading

0 comments on commit b6efc44

Please sign in to comment.