Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relase first version #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ NPM | Licance | Discord

| Parameter | Args | Description |
| :-------- | :------- | :------------------------- |
| `-c` `-r` `-a`| `github.com/user/repo <optional: -r> <optional: -a> ` | *Create app's version. |
| `-c` ` ` `-r & -a`| `github.com/user/repo <optional: -r> <optional: -a> ` | *Create app's version. |
| `-u` | `1.0.1` | *Update your app's version. (Default version 1.0.0) |

#### How it works
Expand Down Expand Up @@ -96,4 +96,4 @@ If you wanna report an issue or smth. you can contact us via [Discord](https://d
- [@valancess](https://www.github.com/DeveloperKubilay) Coder & Developer.
- [@YiitWT](https://www.github.com/YiitWT) Coder & Developer.



122 changes: 122 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
const axios = require("axios");
const kubitdb = require("kubitdb");
const notifier = require("node-notifier");
var db = new kubitdb(".version-xapier");
const yauzl = require("yauzl");
var kill = require("tree-kill");
var exec = require("child_process").exec;
const fs = require("fs");
const events = require('events');
const path = require("path");
const emitter = new events.EventEmitter();
module.exports = {
Check: function (file, autodownload, runfile, pid) {
var url = "https://api.github.com/repos/" +
db.get("repo") +
"/releases/latest"

axios
.get(url)
.then((data) => {
data = data.data;
if(data.tag_name != db.get("version")){
if (db.get("type") == "release") {
emitter.emit("data","updatetime")
kill(pid, "SIGKILL", function (err) {
if (!data.assets) return;
data.assets.map((x) => {
if (x.name == file) {
axios
.get(x.browser_download_url, { responseType: "stream" })
.then((response) => {
var stream = fs.createWriteStream(
path.join(__dirname, "../" + file)
);
response.data.pipe(stream);

response.data.on("end", () => {
console.log("sa")
notifier.notify({
title: "Update Finished!",
message: "Your app is up to date now! App is starting.",
icon: path.join(__dirname, "./src/update.png"), // Absolute path (doesn't work on balloons)
sound: true, // Only Notification Center or Windows Toasters
appID: "Xapier Updater", // String. App.ID and app Name. Defaults to no value, causing SnoreToast text to be visible.
});

emitter.emit("data","filedownloaded")
if (file.split(".zip").length == 2) {
yauzl.open(
path.join(__dirname, "../" + file),
{ lazyEntries: true },
(err, zipfile) => {
if (err) return;
zipfile.readEntry();
zipfile.on("entry", (entry) => {
if (/\/$/.test(entry.fileName)) {
zipfile.readEntry();
} else {
const extractFilePath = path.join(
"./",
entry.fileName
);
fs.mkdirSync(path.dirname(extractFilePath), { recursive: true });
zipfile.openReadStream(
entry,
(err, readStream) => {
if (err) return;
readStream.pipe(
fs.createWriteStream(extractFilePath)
);
readStream.on("end", () =>
zipfile.readEntry()
);
}
);
}
});

zipfile.on("end", () => {
db.set("version",data.tag_name);
if (process.platform == "win32") {
exec(`start "" "${runfile}"`)
}else {
exec(`#!/bin/bash\n"${runfile}"`)
}
emitter.emit("data","unzipped")
});
}
);
}
});
});
}
});
})
} else {

if (process.platform == "win32") {
exec(`start "" "${url}"`)
}else {
exec(`#!/bin/bash\n"${url}"`)
}
db.set("version",data.tag_name);
notifier.notify({
title: "Old Version ERROR!",
message: "Your app is not up to date. Please update your application.",
icon: path.join(__dirname, "./src/update.png"), // Absolute path (doesn't work on balloons)
sound: true, // Only Notification Center or Windows Toasters
appID: "Xapier Updater", // String. App.ID and app Name. Defaults to no value, causing SnoreToast text to be visible.
});

}}
});
},

Ignore: function () {
return;
},
output: function (){
return emitter
}
};
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "xapier",
"version": "0.0.1",
"description": "A basic update-checker module.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/YiitWT/xapier.git"
},
"keywords": [
"xapier",
"update-checker",
"github-update"
],
"author": "YiitWT",
"license": "MIT",
"bin": {
"xapier": "./terminal.js"
},
"bugs": {
"url": "https://github.com/YiitWT/xapier/issues"
},
"homepage": "https://github.com/YiitWT/xapier#readme",
"dependencies": {
"axios": "^1.4.0",
"kubitdb": "^1.5.4",
"node-notifier": "^10.0.1",
"tree-kill": "^1.2.2",
"yauzl": "^2.10.0"
}
}
Binary file added src/update.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions terminal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node
const axios = require("axios");
const kubitdb = require("kubitdb");
var db = new kubitdb(".version-xapier")
var args = process.argv.slice(2);

if(args[0] == "-c" && args[1]){
if(args[1].replaceAll("https://","").startsWith("github.com")) {
if(args.filter(z=>z == "-r").length) db.set("type","release"); else db.del("type");
if(args.filter(z=>z == "-a").length) db.set("autoupdate",true); else db.del("autoupdate");
db.set("repo", args[1].replaceAll("/main","").replaceAll("/tree","").replaceAll("https://","").replaceAll("github.com/",""));
db.set("version", "1.0.0");
console.log("Repo saved successfully.");
}
else return console.log("You should enter a valid github repo like: github.com/YiitWT/xapier");
}
else if(args[0] == "-u" && args[1]){
if(!args[1]) throw new Error("You should enter a version like: 0.0.3");
else {
db.set("version", args[1]);
console.log("Repo saved successfully.");
};
};