Skip to content

Commit

Permalink
Merge pull request #12 from Green-Software-Foundation/upgrade-template
Browse files Browse the repository at this point in the history
Upgrade template
  • Loading branch information
narekhovhannisyan authored Oct 4, 2024
2 parents 7479b88 + c2adb7a commit 69e9eec
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 83 deletions.
5 changes: 4 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# configure pre commit hook here
# f.ex.

npm run lint
# npm test
npm test
npm run fix:package
6 changes: 6 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
'*.ts': [
'gts lint',
],
'package.json': 'fixpack',
}
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ Here can be implementation details of the plugin. For example which API is used,

## Usage

To run the `<YOUR-CUSTOM-PLUGIN>`, an instance of `PluginInterface` must be created. Then, the plugin's `execute()` method can be called, passing required arguments to it.
To run the `<YOUR-CUSTOM-PLUGIN>`, an instance of `PluginFactory` must be created. Then, the plugin's `execute()` method can be called, passing required arguments to it.

This is how you could run the model in Typescript:
This is how you could run the plugin in Typescript:

```typescript
async function runPlugin() {
const newPlugin = await new MyCustomPlugin().configure(params);
const usage = await newPlugin.calculate([
const usage = await MyCustomPlugin({}).execute([
{
timestamp: '2021-01-01T00:00:00Z',
duration: '15s',
Expand All @@ -34,16 +33,16 @@ async function runPlugin() {
runPlugin();
```

## Testing model integration
## Testing plugin integration

>Note: [If Core](https://github.com/Green-Software-Foundation/if-core) plugin has a set of error classes which should be used for having necessary integration with the IF framework. More information on error classes can be found at [Errors Reference](https://if.greensoftware.foundation/reference/errors/).
>Note: The [If Core](https://github.com/Green-Software-Foundation/if-core) repository contains the `PluginFactory` interface, utility functions, and a set of error classes that can be fully integrated with the IF framework. Detailed information on each error class can be found in the [Errors Reference](../reference/errors.md).
### Using local links

For using locally developed model in `IF Framework` please follow these steps:
For using locally developed plugin in `IF Framework` please follow these steps:

1. On the root level of a locally developed model run `npm link`, which will create global package. It uses `package.json` file's `name` field as a package name. Additionally name can be checked by running `npm ls -g --depth=0 --link=true`.
2. Use the linked model in impl by specifying `name`, `method`, `path` in initialize models section.
1. On the root level of a locally developed plugin run `npm link`, which will create global package. It uses `package.json` file's `name` field as a package name. Additionally name can be checked by running `npm ls -g --depth=0 --link=true`.
2. Use the linked plugin in manifest by specifying `name`, `method`, `path` in initialize plugins section.

```yaml
name: plugin-demo-link
Expand All @@ -54,23 +53,23 @@ initialize:
my-custom-plugin:
method: MyCustomPlugin
path: "<name-field-from-package.json>"
global-config:
config:
...
...
```

### Using directly from Github

You can simply push your model to the public Github repository and pass the path to it in your impl.
For example, for a model saved in `github.com/my-repo/my-model` you can do the following:
You can simply push your plugin to the public Github repository and pass the path to it in your manifest.
For example, for a plugin saved in `github.com/my-repo/my-plugin` you can do the following:

npm install your model:
npm install your plugin:

```
npm install -g https://github.com/my-repo/my-model
npm install -g https://github.com/my-repo/my-plugin
```

Then, in your `impl`, provide the path in the model instantiation. You also need to specify which class the model instantiates. In this case you are using the `PluginInterface`, so you can specify `OutputModel`.
Then, in your `manifest`, provide the path in the plugin instantiation. You also need to specify which method the plugin instantiates. In this case you are using the `MyCustomPlugin`.

```yaml
name: plugin-demo-git
Expand All @@ -80,14 +79,14 @@ initialize:
plugins:
my-custom-plugin:
method: MyCustomPlugin
path: https://github.com/my-repo/my-model
global-config:
path: https://github.com/my-repo/my-plugin
config:
...
...
```

Now, when you run the `manifest` using the IF CLI, it will load the model automatically. Run using:
Now, when you run the `manifest` using the IF CLI, it will load the plugin automatically. Run using:

```sh
ie --manifest <path-to-your-impl> --output <path-to-save-output>
if -m <path-to-your-manifest> -o <path-to-save-output>
```
Loading

0 comments on commit 69e9eec

Please sign in to comment.