Skip to content

Commit 01f5490

Browse files
authored
Merge pull request #124 from panacloud/dev
Merge Dev in to Main
2 parents a2d7cfc + abbc5d6 commit 01f5490

File tree

125 files changed

+18171
-1578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+18171
-1578
lines changed

README.md

+62-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
[![Downloads/week](https://img.shields.io/npm/dw/@panacloud/cli.svg)](https://www.npmjs.org/package/@panacloud/cli)
44
[![License](https://img.shields.io/npm/l/@panacloud/cli.svg)](https://github.com/panacloud/cli/blob/master/package.json)
55

6-
# Panacloud Command Line Interface
6+
# Panacloud Command Line Interface (CLI)
77

8-
Panacloud is an unified API development, fundraising, and ownership economy platform. It provides services, libraries, tools, and frameworks for developing totally open multi-tenant, serverless cloud services with integrated multi-tenant billing, crowdfunding, and ownership economy constructs. This allows developers to concentrate solely on creating specialised code related to their domain, leaving the rest to the Panacloud platform and services. This model has the potential to disrupt both the software and venture investment industries.
8+
In a recent [report](https://venturebeat.com/2021/12/09/report-75-of-devs-indicate-that-participating-in-api-economy-is-top-priority/) 75% of developers indicate that participating in API economy is ‘top priority’. Panacloud is an unified API development, fundraising, and ownership economy platform. It provides services, libraries, tools, and frameworks for developing totally open multi-tenant, serverless cloud services with integrated multi-tenant billing, crowdfunding, and ownership economy constructs. This allows developers to concentrate solely on creating specialised code related to their domain, leaving the rest to the Panacloud platform and services. This model has the potential to disrupt both the software and venture investment industries and making the API developers rich and owners of their own destiny and unicorn startups.
99

10-
Panacloud CLI accelerates the building of multi-tenant serverless SaaS APIs. The CLI applies the design-first paradigm and implements the best practices for designing GraphQL APIs using public cloud serverless and infrastructure as code technologies. The CLI takes a [GraphQL API](https://graphql.org/) [schema](https://graphql.org/learn/schema/) that has been augmented with Panacloud directives and creates [infrastructure as code (IaC)](https://acloudguru.com/blog/engineering/cloudformation-terraform-or-cdk-guide-to-iac-on-aws), mock lambdas, tests, and scaffolding for genuine lambdas that include business logic and database requests. It makes use of [AWS CDK](https://aws.amazon.com/cdk/) for IaC. It now only supports AWS, TypeScript and GraphQL, but future versions will also support Azure and Google Cloud, OpenAPI and other languages as well.
10+
Panacloud CLI accelerates the building of modern multi-tenant serverless SaaS APIs. The CLI applies the design-first paradigm and implements the best practices for designing GraphQL APIs using public cloud serverless and infrastructure as code technologies. The CLI takes a [GraphQL API](https://graphql.org/) [schema](https://graphql.org/learn/schema/) that has been augmented with Panacloud directives and creates [infrastructure as code (IaC)](https://acloudguru.com/blog/engineering/cloudformation-terraform-or-cdk-guide-to-iac-on-aws), mock lambdas, tests, and scaffolding for genuine lambdas that include business logic and database requests. It makes use of [AWS CDK](https://aws.amazon.com/cdk/) for IaC. It now only supports AWS, TypeScript and GraphQL, but future versions will also support Azure and Google Cloud, OpenAPI and other languages as well.
1111

12-
![CLI Flow](cli.png "CLI Diagram")
12+
![CLI Flow](img/cli.png "CLI Diagram")
1313

1414

1515
The generated serverless SaaS API project supports multi-tenant usage based billing and monetering and is closely integrated with the [Panacloud portal](https://www.panacloud.org). The developer just needs to write the specific code required by the Multi-Tenant SaaS project. This greatly reduces custom developer coding and increases speed to market. GraphQL and Open REST APIs can be built by using the Panacloud CLI. The APIs may use Graph or Relational databases, etc.
@@ -60,12 +60,14 @@ USAGE
6060
```
6161
<!-- usagestop -->
6262

63-
# Commands
63+
# Panacloud Commands
6464

6565
<!-- commands -->
6666
* [`panacloud help [COMMAND]`](#panacloud-help-command)
6767
* [`panacloud init`](#panacloud-init)
6868
* [`panacloud update`](#panacloud-update)
69+
* [`panacloud status`](#panacloud-status)
70+
* [`panacloud client`](#panacloud-client)
6971
* [`panacloud merge`](#panacloud-merge)
7072

7173
## `panacloud help [COMMAND]`
@@ -100,6 +102,7 @@ OPTIONS
100102
_See code: [src/commands/init.ts](https://github.com/panacloud/cli/commands/init.ts)_
101103
<!-- commandsstop -->
102104

105+
103106
## `panacloud update`
104107

105108
Update CDK code and mock lambdas based on the updated schema. This command doesnot overwrite code in the editiable_src directory.
@@ -115,6 +118,26 @@ OPTIONS
115118
_See code: [src/commands/update.ts](https://github.com/panacloud/cli/src/commands/update.ts)_
116119
<!-- commandsstop -->
117120

121+
122+
123+
124+
## `panacloud client`
125+
126+
Open a API explorer in the browser to query the API.
127+
128+
```
129+
USAGE
130+
$ panacloud client
131+
132+
OPTIONS
133+
-h, --help show CLI help
134+
```
135+
136+
_See code: [src/commands/client.ts](https://github.com/panacloud/cli/src/commands/client.ts)_
137+
<!-- commandsstop -->
138+
139+
140+
118141
## `panacloud merge`
119142

120143
Merges GraphQL schema files.
@@ -130,6 +153,19 @@ OPTIONS
130153
_See code: [src/commands/update.ts](https://github.com/panacloud/cli/src/commands/merge.ts)_
131154
<!-- commandsstop -->
132155

156+
# Project NPM Commands
157+
158+
Once the project is generated you may run the following npm scripts
159+
160+
<!-- npm commands -->
161+
* `npm run deploy-dev` Deploy Development Stage
162+
* `npm run deploy-prd` Deploy Production Stage
163+
* `npm run destroy-dev` Destroy Development Stage
164+
* `npm run destroy-prd` Destroy Production Stage
165+
* `npm run test-dev` Run Tests for the Development Stage
166+
* `npm run test-prd` Run Tests for the Production Stage
167+
168+
133169
## Details about the Project Generated by the CLI
134170

135171
The CLI generates project for Multi-Tenant Serverless API development with [AWS Cloud Development Kit (CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html) using TypeScript. It comes with all the necessary code to develop and deploy a Serverless GraphQL API in the AWS Cloud. This includes the provisioning of cloud infrastructure in code and Serverless stubs where developers may easily include their business logic. The project also provides pre-built mock lambda functions and unit tests to test your deployed APIs.
@@ -168,5 +204,26 @@ The `cdk.json` file tells the CDK Toolkit how to execute your app.
168204
8. Allow the stakeholders to cash out whenever they require liquidity by selling API tokens.
169205

170206

207+
## The Panacloud CLI Roadmap
208+
209+
### First Public Release
210+
211+
Expected Date: December 14, 2021
212+
213+
Functionality: Auto-Generation of GraphQL API for AWS, Single Tenant, Mock API, Serverless Stubs, Database Support: Relational & Graph, API Testing, Staging, init, update, config, deploy, destroy, and client commands
214+
215+
### Second Release
216+
217+
Expected Date: January 1, 2022
218+
219+
Functionality: Multi-Tenant monetering and billing data live streamed to Amazon Timestream Database deployed in Panacloud AWS Account.
220+
221+
### Third Release
222+
223+
Expected Date: January 15, 2022
224+
225+
Functionality: Basic OpenAPI speficication support.
226+
227+
171228

172229

cli-3.drawio img/cli-3.drawio

File renamed without changes.

cli.png img/cli.png

File renamed without changes.

package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@panacloud/cli",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "panacloud cli",
55
"author": "Muhammad Hasan @muh_hasan",
66
"bin": {
@@ -16,6 +16,7 @@
1616
"@oclif/config": "^1",
1717
"@oclif/plugin-help": "^3",
1818
"@types/inquirer": "^7.3.3",
19+
"@types/valid-url": "^1.0.3",
1920
"await-exec": "^0.1.2",
2021
"axios": "^0.21.4",
2122
"chalk": "^4.1.1",
@@ -30,6 +31,7 @@
3031
"graphql": "^15.6.0",
3132
"graphql-schema-utilities": "^1.1.3",
3233
"graphql-to-json-converter": "^1.2.0",
34+
"hidefile": "^3.0.0",
3335
"inquirer": "^8.1.2",
3436
"isomorphic-git": "^1.10.0",
3537
"lodash": "^4.17.21",
@@ -41,15 +43,18 @@
4143
"prettier": "^2.3.2",
4244
"random-name": "^0.1.2",
4345
"semver": "^7.3.5",
46+
"supertest": "^6.1.6",
4447
"tslib": "^1",
4548
"typescript": "^3.9.10",
49+
"valid-url": "^1.0.9",
4650
"yamljs": "^0.3.0"
4751
},
4852
"devDependencies": {
4953
"@oclif/dev-cli": "^1",
5054
"@oclif/test": "^1",
51-
"@types/chai": "^4",
55+
"@types/chai": "^4.2.22",
5256
"@types/fs-extra": "^9.0.13",
57+
"@types/hidefile": "^3.0.0",
5358
"@types/mocha": "^5",
5459
"@types/node": "^16.11.6",
5560
"@types/random-name": "^0.1.0",
@@ -62,7 +67,7 @@
6267
"nyc": "^14",
6368
"rimraf": "^3.0.2",
6469
"ts-node": "^8",
65-
"typescript": "^3.3"
70+
"typescript": "^3.9.10"
6671
},
6772
"engines": {
6873
"node": ">=8.0.0"
@@ -110,10 +115,9 @@
110115
},
111116
"scripts": {
112117
"postpack": "rimraf oclif.manifest.json",
113-
"posttest": "eslint . --ext .ts --config .eslintrc",
114118
"copy-files": "copyfiles -a -u 1 \"./src/lib/api/template/**/*\" \"./src/utils/*.graphql\" lib",
115119
"prepack": "rimraf lib && tsc -b && oclif-dev manifest && yarn copy-files",
116-
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
120+
"test": "ts-node test/test-scripts/script.ts",
117121
"version": "oclif-dev readme && git add README.md"
118122
},
119123
"types": "lib/index.d.ts",

src/commands/client.ts

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { Command, flags } from "@oclif/command";
2+
import chalk = require("chalk");
3+
import {
4+
existsSync,
5+
readFileSync,
6+
writeJsonSync,
7+
} from "fs-extra";
8+
import { startSpinner} from "../lib/spinner";
9+
import * as validUrl from "valid-url";
10+
import { API, APITYPE } from "../utils/constants";
11+
import open = require("open");
12+
import inquirer = require("inquirer");
13+
const express = require("express");
14+
15+
16+
export default class Open extends Command {
17+
static description = "describe the command here";
18+
19+
static flags = {
20+
help: flags.help({ char: "h" }),
21+
};
22+
23+
static args = [{ name: "file" }];
24+
async run() {
25+
const {stages} = JSON.parse(
26+
readFileSync("./editable_src/panacloudconfig.json").toString()
27+
)
28+
const userInput = await inquirer.prompt([
29+
{
30+
type: "list",
31+
name: "stage",
32+
message: "Select Stage",
33+
choices: [...stages],
34+
default: stages[0],
35+
validate: Boolean,
36+
},
37+
])
38+
const { apiType, apiName }: API = JSON.parse(
39+
readFileSync("./codegenconfig.json").toString()
40+
).api;
41+
if (apiType === APITYPE.graphql) {
42+
let API_URL;
43+
let API_KEY;
44+
if (!existsSync(`./cdk-${userInput.stage}-outputs.json`)) {
45+
this.log(
46+
chalk.red(
47+
`${apiName}'s ${userInput.stage} stage is currently not deployed client cannot connect to API, give the command npm run deploy-${userInput.stage} to deploy it.`
48+
)
49+
);
50+
} else {
51+
let data = JSON.parse(readFileSync(`./cdk-${userInput.stage}-outputs.json`).toString());
52+
const values: string[] = Object.values(
53+
Object.entries(data)[0][1] as any
54+
);
55+
if (values.length === 0) {
56+
this.log(
57+
chalk.red(
58+
`${apiName}'s ${userInput.stage} stage is currently not deployed client cannot connect to API, give the npm run deploy-${userInput.stage} to deploy it.`
59+
)
60+
);
61+
return;
62+
} else {
63+
let urlPresent = false
64+
values.forEach((val: string) => {
65+
if (validUrl.isUri(val)) {
66+
urlPresent = true
67+
API_URL = val;
68+
} else {
69+
API_KEY = val;
70+
}
71+
});
72+
if(urlPresent === false){
73+
this.log(chalk.red("Correct url is not provided!!"))
74+
}
75+
if (API_URL && API_KEY) {
76+
writeJsonSync(`./graphqlClient/data.json`, {
77+
API_URL,
78+
API_KEY,
79+
});
80+
this.runGraphqlClient();
81+
}
82+
}
83+
}
84+
}
85+
}
86+
87+
async runGraphqlClient() {
88+
const graphqlSpinner = startSpinner("Starting Grphql Client");
89+
let app = express();
90+
app.use(express.static(process.cwd() + "/graphqlClient/"));
91+
let port = 8080;
92+
app.listen(port);
93+
open(`http://localhost:${port}`)
94+
graphqlSpinner.stopAndPersist({
95+
text: `Graphql client is running on http://localhost:${port} 🚀`,
96+
});
97+
98+
}
99+
}

0 commit comments

Comments
 (0)