Comparing version 1.0.0 to 1.1.0
52
cli.js
#!/usr/bin/env node | ||
const isDev = true | ||
const rimraf = require("rimraf"); | ||
@@ -23,16 +21,16 @@ var FormData = require('form-data'); | ||
.arguments('<token>') | ||
.arguments('<buildFolder>') | ||
.description('push command', { | ||
token: 'user token' | ||
token: 'user token', | ||
buildFolder: 'build folder' | ||
}) | ||
.option("-d, --directory", "Build Folder") | ||
.action((token, options, command) => { | ||
let { directory = "build" } = options | ||
.action((token, buildFolder, options, command) => { | ||
console.log(buildFolder + " folder will be zipped and uploaded to devospa.com") | ||
const api = axios.create({ | ||
maxContentLength: Infinity, | ||
maxBodyLength: Infinity, | ||
baseURL: isDev ? "http://localhost:3020" : "https://devospa.com", | ||
baseURL: "http://devospa.com", | ||
// baseURL: "http://localhost:3020", | ||
}) | ||
return api.post("/devospaApi/checkProjectToken", { token }).then(async() => { | ||
console.log("token success", token) | ||
return inquirer.prompt([ | ||
@@ -47,6 +45,11 @@ { | ||
progressBar.start(100, 1); | ||
const zipPath = branchName + token + '.zip' | ||
await zip('build', zipPath); | ||
const zipPath = "./" + branchName + token + '.zip' | ||
await zip(buildFolder, zipPath); | ||
progressBar.update(10); | ||
let n = 10 | ||
const intervalObj = setInterval(() => { | ||
const nn = (100 + n) / 2 | ||
n += Math.min(10, nn - n) | ||
progressBar.update(n) | ||
}, 500) | ||
new Promise((resolve) => { | ||
@@ -59,17 +62,30 @@ const fd = new FormData(); | ||
}).then(({ data, headers }) => { | ||
api.post("/api/upload", data, { | ||
return api.post("/devospaApi/upload", data, { | ||
headers, | ||
onUploadProgress: progressEvent => console.log(progressEvent.loaded) | ||
onUploadProgress: progressEvent => { | ||
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total) | ||
console.log(percentCompleted) | ||
progressBar.update(percentCompleted); | ||
} | ||
}).then((uploadResponse) => { | ||
clearInterval(intervalObj) | ||
progressBar.update(100) | ||
progressBar.stop(100) | ||
console.log("Upload completed, Please check the following address", "https://devospa.com") | ||
console.log("Upload completed, Please check devospa.com") | ||
}).catch(e => { | ||
console.error("Upload Error", e) | ||
progressBar.stop(0) | ||
console.error("Sorry but uploading the zip file errored, Please try again in a few second") | ||
process.exit() | ||
}) | ||
}).catch(err=> { | ||
progressBar.stop(0) | ||
console.error("Errored buffering", err) | ||
process.exit() | ||
}).finally(() => { | ||
progressBar.stop(100) | ||
rimraf(zipPath, (e) => { | ||
e && console.log(e) | ||
console.log("removed created zip file") | ||
process.exit() | ||
}) | ||
@@ -86,6 +102,8 @@ }) | ||
}); | ||
}).catch(e => { | ||
console.error("the project token is wrong, please copy the command from devospa.com") | ||
}) | ||
}) | ||
console.log(process.argv) | ||
// console.log(process.argv) | ||
program.parseAsync(process.argv); |
{ | ||
"name": "devospa", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "build": "node cli", |
@@ -1,3 +0,18 @@ | ||
# DevoSPA | ||
# Devospa Cli | ||
Devospa lets frontend developers easily demo the changes they have made on their SPA project before it gets merged or even pushed. | ||
Cli for Demo Developing SPA | ||
The cli zips the built folder of the project and send it to [Devospa.com](http://devospa.com). | ||
## 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 | ||
``` | ||
npx devospa push given_token_in_devospa.com build | ||
``` | ||
or install it globally | ||
``` | ||
npm i -g devospa | ||
devospa push given_token_in_devospa.com build | ||
``` |
4662
100
19