Comparing version 1.3.0 to 1.5.0
113
cli.js
#!/usr/bin/env node | ||
const rimraf = require("rimraf") | ||
const FormData = require("form-data") | ||
const fs = require("fs") | ||
const path = require("path") | ||
const poss = require("poss") | ||
const program = require("commander") | ||
const inquirer = require("inquirer") | ||
const got = require("got") | ||
const { zip } = require("zip-a-folder") | ||
const package = require("./package.json") | ||
const concat = require("concat-stream") | ||
const cliProgress = require("cli-progress") | ||
const { execSync } = require('child_process'); | ||
const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic) | ||
const baseURL = "http://devospa.com" | ||
program | ||
.version(package.version, "-v, --version") | ||
program | ||
.command("push") | ||
.arguments("<token>") | ||
.arguments("<buildFolder>") | ||
.description("push command", { | ||
token: "user token", | ||
buildFolder: "build folder" | ||
}) | ||
.action(async (token, buildFolder, options, command) => { | ||
console.log(`${buildFolder} folder will be zipped and uploaded to devospa.com`) | ||
// login and stores userToken to prevent next logins | ||
const appDir = path.dirname(require.main.filename); | ||
const storedDataPath = path.join(appDir, "/stores.json") | ||
let userToken = "" | ||
try { | ||
const data = require(storedDataPath) | ||
userToken = data.userToken | ||
} catch(e) {} | ||
if (!userToken) { | ||
const getUsername = { name: "email", message:"Email", description: "Enter your email address to login"} | ||
const getPassword = { name: "password", message: "Password", description: "Enter the password you would login to devospa"} | ||
const [blErr, loginData] = await poss(inquirer.prompt([getUsername, getPassword])) | ||
if (blErr) { return console.log("problem in getting user data") } | ||
const loginUserUrl = `${baseURL}/devospaApi/loginUser` | ||
const {email, password} = loginData | ||
const [err, res] = await poss(got.post(loginUserUrl, { json: { email, password } }).json()) | ||
if (err) { return console.log("Email or password is wrong, please use the email you registered with in devospa.com") } | ||
userToken = res.userToken | ||
// stores userToken | ||
fs.writeFile(storedDataPath, JSON.stringify({userToken}), (err) => {}) | ||
if (!userToken) {return console.log("userToken not exist")} | ||
} | ||
// gets the current branch name | ||
const commandOutput = execSync('git rev-parse --abbrev-ref HEAD') | ||
const defaultBranchName = commandOutput.toString().trim() | ||
// Checks the project token | ||
const url = `${baseURL}/devospaApi/checkProjectToken` | ||
const [err, res] = await poss(got.post(url, { json: { token } })) | ||
if (err) { return console.error("The project token is wrong, please copy the command from devospa.com", err)} | ||
// Gets branch name, demo description | ||
const getBranch = { name: "branchName", message:"Branch Name", description: "Enter the feature(branch) name:", default: defaultBranchName} | ||
const getDesc = { name: "description", message: "Version Description", description: "Enter a brief description about this demo"} | ||
const [bErr, branchRes] = await poss(inquirer.prompt([getBranch, getDesc])) | ||
if (bErr) { return console.error("Getting branch name encountred with error")} | ||
const {branchName, description} = branchRes | ||
// Compresses the build folder | ||
const zipFileName = "./" + branchName + token + ".zip" | ||
await zip(buildFolder, zipFileName) | ||
// Creates a FormData and merge the zip file into it | ||
const fd = new FormData() | ||
fd.append("token", token) | ||
fd.append("branchName", branchName) | ||
fd.append("description", description) | ||
fd.append("userToken", userToken) | ||
fd.append("file", fs.createReadStream(zipFileName)) | ||
fd.pipe(concat({ encoding: "buffer" }, data => { | ||
if (!data) { | ||
console.error("Errored buffering", err) | ||
process.exit() | ||
} | ||
const uploadUrl = baseURL+"/devospaApi/upload" | ||
progressBar.start(100, 1) | ||
// Starts uploading whole data | ||
got.post(uploadUrl, { body: data, headers: fd.getHeaders()}) | ||
.on("uploadProgress", progress => { | ||
progressBar.update(Math.round(progress.percent * 100)) | ||
}) | ||
.then((uploadResponse) => { | ||
progressBar.stop(100) | ||
console.log("Upload completed, Please check devospa.com") | ||
}).catch(e => { | ||
progressBar.stop() | ||
console.error("Sorry but uploading the zip file errored, Please try again in a few second") | ||
process.exit() | ||
}).finally(() => { | ||
// Removes the zip file | ||
rimraf(zipFileName, (e) => { | ||
e && console.log(e) | ||
console.log("Removed created zip file") | ||
process.exit() | ||
}) | ||
}) | ||
})) | ||
}) | ||
program.parseAsync(process.argv) | ||
require('./dist/index') |
{ | ||
"name": "devospa", | ||
"version": "1.3.0", | ||
"description": "This cli helps you to publish demo of your SPA in devospa easily", | ||
"repository": "fingerpich/devospa-cli", | ||
"version": "1.5.0", | ||
"description": "A simple cli to push a demo of developing spa to the devospa.com", | ||
"repository": "Devospa/devospa-cli", | ||
"scripts": { | ||
"dev": "node cli.js" | ||
"build": "tsc --outDir dist src/index.ts" | ||
}, | ||
@@ -23,3 +23,6 @@ "bin": { | ||
}, | ||
"devDependencies": {} | ||
"devDependencies": { | ||
"tsc": "^2.0.3", | ||
"typescript": "^4.5.4" | ||
} | ||
} |
# Devospa Cli | ||
Devospa lets frontend developers easily demo the changes they have made on their SPA project before it gets merged or even pushed. | ||
A cli to upload the build folder to [Devospa.com](http://devospa.com). | ||
The cli zips the built folder of the project and send it to [Devospa.com](http://devospa.com). | ||
Devospa lets frontend developers easily demo the changes they have made on a SPA project even if its not completed. | ||
## Getting Started with Devospa | ||
Go to [Devospa.com](http://devospa.com) and click on the start button. | ||
## How to use | ||
You can use it via npx as the following command without installation | ||
## How to use the cli | ||
You can use it via `npx` as the following command without installation | ||
``` | ||
npx devospa push given_token_in_devospa.com build | ||
npx devospa push given_token_in_devospa.com buildFolderPath | ||
``` | ||
@@ -17,3 +14,14 @@ or install it globally | ||
npm i -g devospa | ||
npm run build | ||
devospa push given_token_in_devospa.com build | ||
``` | ||
If you want to be asked before build process you can use the following commands | ||
``` | ||
devospa prepare given_token_in_devospa.com | ||
npm run build | ||
devospa upload build | ||
``` | ||
## Getting Started with Devospa | ||
Go to [Devospa.com](http://devospa.com) and click on the start button. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
73693
21
1675
26
2
4
2