Skip to content

Commit

Permalink
Merge pull request #4 from csskevin/dev
Browse files Browse the repository at this point in the history
Adding filesystem functionality.
  • Loading branch information
csskevin authored Aug 6, 2020
2 parents 36499dd + 1bd3eae commit 0dfb833
Show file tree
Hide file tree
Showing 23 changed files with 2,579 additions and 1,387 deletions.
4 changes: 2 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Apps from "./src/apps";
import Files from "./src/files";
import FileSystem from "./src/filesystem";
import Permission from "./src/permission";
import Services from "./src/services";
import Verification from "./src/verification";
import Workfolder from "./src/workfolder";
import Driver from "./src/driver";
import App from "./src/interfaces/app";
import Service from "./src/interfaces/service";
export { Apps, Files, Permission, Services, Verification, Workfolder, Driver, App, Service };
export { Apps, FileSystem, Permission, Services, Verification, Workfolder, Driver, App, Service };
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
var apps_1 = __importDefault(require("./src/apps"));
exports.Apps = apps_1.default;
var files_1 = __importDefault(require("./src/files"));
exports.Files = files_1.default;
var filesystem_1 = __importDefault(require("./src/filesystem"));
exports.FileSystem = filesystem_1.default;
var permission_1 = __importDefault(require("./src/permission"));
exports.Permission = permission_1.default;
var services_1 = __importDefault(require("./src/services"));
Expand Down
7 changes: 7 additions & 0 deletions dist/src/apps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import App from "./interfaces/app";
* Handles all imported methods for the installed applications.
*/
declare class Apps {
/**
* Holds the functions of the event listeners
*/
private listeners;
/**
* Returns a list of all installed apps.
*/
Expand Down Expand Up @@ -44,6 +48,9 @@ declare class Apps {
* @param app_name The app_name which should be removed.
*/
uninstallApp(app_name: string): boolean;
on(event: "install" | "uninstall", callback: Function): void;
off(event: "install" | "uninstall", callback: Function): void;
private fire;
}
declare const _default: Apps;
export default _default;
10 changes: 10 additions & 0 deletions dist/src/apps.install.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import App from "./interfaces/app";
*/
declare class AppsInstall {
private user_config;
/**
* Returns the file content of a specific local path.
* @param pathname The pathname, where the content should be read.
*/
getFileContent(pathname: string): Buffer;
/**
* Returns the file content of a URI.
* @param pathname The pathname, where the content should be read.
*/
getURIContent(pathname: string): Promise<Function>;
/**
* Installs an app into the configuration file and extracts the content to the workfolder.
* @param pathname The full path or a valid URL to the zip archived app.
Expand Down
33 changes: 29 additions & 4 deletions dist/src/apps.install.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,47 @@ var axios_1 = __importDefault(require("axios"));
var crypto_1 = __importDefault(require("crypto"));
var fs_1 = __importDefault(require("fs"));
var workfolder_1 = __importDefault(require("./workfolder"));
// Telling axios to use the internal HTTP module.
axios_1.default.defaults.adapter = require("axios/lib/adapters/http");
/**
* Handles installations of a new application.
*/
var AppsInstall = /** @class */ (function () {
function AppsInstall() {
this.user_config = "wg-app.json";
}
/**
* Returns the file content of a specific local path.
* @param pathname The pathname, where the content should be read.
*/
AppsInstall.prototype.getFileContent = function (pathname) {
var content = fs_1.default.readFileSync(pathname);
return content;
};
/**
* Returns the file content of a URI.
* @param pathname The pathname, where the content should be read.
*/
AppsInstall.prototype.getURIContent = function (pathname) {
return new Promise(function (resolve, reject) {
axios_1.default.get(pathname, {
responseType: "arraybuffer"
}).then(function (response) {
var content = Buffer.from(response.data);
resolve(content);
}).catch(function (error) { return reject(error); });
});
};
/**
* Installs an app into the configuration file and extracts the content to the workfolder.
* @param pathname The full path or a valid URL to the zip archived app.
*/
AppsInstall.prototype.installApp = function (pathname) {
return new Promise(function (resolve, reject) {
var _this = this;
if (fs_1.default.existsSync(pathname)) {
try {
var content = fs_1.default.readFileSync(pathname);
var content = this.getFileContent(pathname);
var id = this.installAppByBuffer(content);
resolve(id);
}
Expand All @@ -33,10 +58,10 @@ var AppsInstall = /** @class */ (function () {
}
}
else if (this.isValidURL(pathname)) {
axios_1.default.get(pathname).then(function (response) {
var id = this.installAppByBuffer(Buffer.from(response.data));
this.getURIContent(pathname).then(function (content) {
var id = _this.installAppByBuffer(content);
resolve(id);
}.bind(this));
}).catch(function (error) { return reject(error); });
}
else {
reject("Invalid Install path!");
Expand Down
22 changes: 21 additions & 1 deletion dist/src/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var workfolder_1 = __importDefault(require("./workfolder"));
*/
var Apps = /** @class */ (function () {
function Apps() {
/**
* Holds the functions of the event listeners
*/
this.listeners = [];
}
/**
* Returns a list of all installed apps.
Expand Down Expand Up @@ -108,7 +112,13 @@ var Apps = /** @class */ (function () {
* @param pathname The full path or a valid URL to the zip archived app.
*/
Apps.prototype.installApp = function (pathname) {
return apps_install_1.default.installApp(pathname);
var _this = this;
return new Promise(function (resolve, reject) {
apps_install_1.default.installApp(pathname).then(function (data) {
_this.fire("install");
resolve(data);
}).catch(function (error) { return reject(error); });
});
};
/**
* Removes an app and deletes it from the configuration file and the workfolder.
Expand All @@ -126,10 +136,20 @@ var Apps = /** @class */ (function () {
var new_apps = apps.filter(function (app) { return app.package_name !== app_name; });
var raw_new_apps = JSON.stringify(new_apps, null, 3);
workfolder_1.default.writeAppConfig(raw_new_apps);
this.fire("uninstall");
return true;
}
return false;
};
Apps.prototype.on = function (event, callback) {
this.listeners.push({ event: event, callback: callback });
};
Apps.prototype.off = function (event, callback) {
this.listeners = this.listeners.filter(function (item) { return item.event !== event && item.callback !== callback; });
};
Apps.prototype.fire = function (event) {
this.listeners.filter(function (listener) { return listener.event === event; }).forEach(function (listener) { return listener.callback(); });
};
return Apps;
}());
exports.default = new Apps();
49 changes: 0 additions & 49 deletions dist/src/files.d.ts

This file was deleted.

135 changes: 0 additions & 135 deletions dist/src/files.js

This file was deleted.

Loading

0 comments on commit 0dfb833

Please sign in to comment.