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

Add for plugins a "minimum required backend" version number? #353

Closed
mStirner opened this issue Dec 16, 2023 · 2 comments
Closed

Add for plugins a "minimum required backend" version number? #353

mStirner opened this issue Dec 16, 2023 · 2 comments

Comments

@mStirner
Copy link
Member

Similar to a "node" field in package.json.
If the backend version does not match then number/semver expression, the plugin is not be loaded.

This all could be done in the .init function in plugins. Defined here:

let init = (dependencies, cb) => {
try {
const granted = dependencies.every((c) => {
if (this.intents.includes(c)) {
return true;
} else {
logger.warn(`Plugin ${this.uuid} (${this.name}) wants to access not registerd intens "${c}"`);
return false;
}
});
if (granted) {
let components = dependencies.map((name) => {
return require(path.resolve(process.cwd(), `components/${name}`));
});
cb(this, components);
return init;
} else {
throw new Error(`Unregisterd intents access approach`);
}
} catch (err) {
logger.error(err, `Plugin could not initalize!`, err.message);
throw err;
}
};

@mStirner
Copy link
Member Author

    constructor(obj) {

        Object.assign(this, obj);
        this._id = String(obj._id);

        Object.defineProperty(this, "logger", {
            value: logger.create(`plugins/${this.uuid}`),
            configurable: false,
            enumerable: false,
            writable: false
        });

        try {

            let file = path.resolve(process.cwd(), "plugins", this.uuid, "package.json");

            let content = fs.readFileSync(file);
            let json = JSON.parse(content);

            Object.defineProperty(this, "package", {
                value: json,
                configurable: false,
                enumerable: false,
                writable: false,
            });

        } catch (err) {
            if (err.code === "ENOENT") {

                this.logger.warn(err, `package.json for plugin "${this.name}" not found. It may work not properly or breaks something!`);

            } else {

                this.logger.warn(err);

            }
        }
    }

@mStirner
Copy link
Member Author

The backend property should be changed from a single string, into a object. e.g:

{
  "name": "plugin-boilerplate",
  "private": "true",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "openhaus": {
    "backend": ">=3.2.1"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 0",
    "build": "grunt build",
    "compress": "grunt compress",
    "checksum": "grunt checksum",
    "release": "grunt release"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/mStirner/plugin-boilerplate.git"
  },
  "author": "Marc Stirner <marc.stirner@open-haus.io>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/mStirner/plugin-boilerplate/issues"
  },
  "homepage": "https://github.com/mStirner/plugin-boilerplate#readme",
  "devDependencies": {
    "grunt": "^1.6.1",
    "grunt-contrib-uglify": "^5.2.2",
    "grunt-env": "^1.0.1"
  }
}

@mStirner mStirner mentioned this issue Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant