Skip to content

Commit 7bec563

Browse files
authored
Initial commit
0 parents  commit 7bec563

24 files changed

+8752
-0
lines changed

.editorconfig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
insert_final_newline = true

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
dist/
3+
src/**/**.d.ts
4+
src/**/**.js

.eslintrc.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./node_modules/gts/",
3+
"rules": {
4+
"@typescript-eslint/no-explicit-any": [
5+
"off"
6+
]
7+
}
8+
}

.github/ISSUE_TEMPLATE/feedback.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: Feedback
3+
about: Submitting feedback on plugin template
4+
title: "Feedback - "
5+
labels: feedback
6+
assignees: ''
7+
---
8+
9+
## Scope
10+
11+
What does your feedback relate to?
12+
13+
- [] Project aims/objectives
14+
- [] Repository structure
15+
- [] Documentation
16+
- [] Tests
17+
- [] Other
18+
19+
## Details
20+
21+
Does your feedback relate to a specific problem that can be demonstrated and reproduced? If so, please provide details of how to repro below.
22+
Include your platform config and the version of IEF you are using (e.g. Ubuntu 20.04, running latest dev branch on XX date).
23+
24+
## Expected Behaviour
25+
26+
What do things look like if they are going right?
27+
e.g. "the github issue board is cleared out every X days"
28+
29+
## Actual behaviour
30+
31+
How are things actually working?
32+
e.g. "issues are sitting on the board for over X days"
33+
34+
## Proposed actions
35+
36+
What fixes do you propose?
37+
e.g. "please define a response time of X days for issues and publish in the project README"
38+
39+
40+
**Note: We will take all feedback seriously. Please be polite and constructive - aggressive or abusive feedback will simply be deleted.**

.github/PULL_REQUEST_TEMPLATE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Types of changes
2+
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply. -->
3+
- [ ] Enhancement (project structure, spelling, grammar, formatting)
4+
- [ ] Bug fix (non-breaking change which fixes an issue)
5+
- [ ] New feature (non-breaking change which adds functionality)
6+
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
7+
- [ ] My code follows the code style of this project.
8+
- [ ] My change requires a change to the documentation.
9+
- [ ] I have updated the documentation accordingly.
10+
- [ ] I have added tests to cover my changes.
11+
- [ ] All new and existing tests passed.
12+
13+
14+
### A description of the changes proposed in the Pull Request
15+
<!--- Provide a small description of the changes. -->
16+
-
17+
-
18+
19+
20+
<!-- Make sure tests and lint pass on CI. -->
21+

.github/workflows/nodejs-ci.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Node.js CI
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v3
12+
13+
- name: Set up Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: 18
17+
cache: 'npm'
18+
19+
- name: Install dependencies
20+
run: npm install
21+
22+
- name: Run lint
23+
run: npm run lint
24+
25+
- name: Run tests
26+
run: npm run test --silent

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
src/**/*.js
2+
src/**/*.d.ts
3+
lib/**/*.js
4+
lib/**/*.d.ts
5+
node_modules
6+
.idea
7+
*.tsbuildinfo
8+
dist
9+
yarn-error.log
10+
build
11+
coverage
12+
.env

.husky/pre-commit

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run lint
5+
npm test
6+
npm run fix:package

.npmignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
# Exclude typescript source and config
3+
*.ts
4+
tsconfig.json
5+
6+
# Include javascript files and typescript declarations
7+
!*.js
8+
!*.d.ts
9+
10+
# Exclude jsii outdir
11+
dist
12+
13+
# Include .jsii and .jsii.gz
14+
!.jsii
15+
!.jsii.gz

.prettierrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('gts/.prettierrc.json')
3+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Green Software Foundation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# if-plugin-template
2+
3+
`if-plugin-template` is an environmental impact calculator template which exposes an API for [IF](https://github.com/Green-Software-Foundation/if) to retrieve energy and embodied carbon estimates.
4+
5+
## Implementation
6+
7+
Here can be implementation details of the plugin. For example which API is used, transformations and etc.
8+
9+
## Usage
10+
11+
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.
12+
13+
This is how you could run the model in Typescript:
14+
15+
```typescript
16+
async function runPlugin() {
17+
const newModel = await new MyCustomPlugin().configure(params);
18+
const usage = await newModel.calculate([
19+
{
20+
timestamp: '2021-01-01T00:00:00Z',
21+
duration: '15s',
22+
'cpu-util': 34,
23+
},
24+
{
25+
timestamp: '2021-01-01T00:00:15Z',
26+
duration: '15s',
27+
'cpu-util': 12,
28+
},
29+
]);
30+
31+
console.log(usage);
32+
}
33+
34+
runPlugin();
35+
```
36+
37+
## Testing model integration
38+
39+
### Using local links
40+
41+
For using locally developed model in `IF Framework` please follow these steps:
42+
43+
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`.
44+
2. Use the linked model in impl by specifying `name`, `method`, `path` in initialize models section.
45+
46+
```yaml
47+
name: plugin-demo-link
48+
description: loads plugin
49+
tags: null
50+
initialize:
51+
plugins:
52+
my-custom-plugin:
53+
method: MyCustomPlugin
54+
path: "<name-field-from-package.json>"
55+
global-config:
56+
...
57+
...
58+
```
59+
60+
### Using directly from Github
61+
62+
You can simply push your model to the public Github repository and pass the path to it in your impl.
63+
For example, for a model saved in `github.com/my-repo/my-model` you can do the following:
64+
65+
npm install your model:
66+
67+
```
68+
npm install -g https://github.com/my-repo/my-model
69+
```
70+
71+
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`.
72+
73+
```yaml
74+
name: plugin-demo-git
75+
description: loads plugin
76+
tags: null
77+
initialize:
78+
plugins:
79+
my-custom-plugin:
80+
method: MyCustomPlugin
81+
path: https://github.com/my-repo/my-model
82+
global-config:
83+
...
84+
...
85+
```
86+
87+
Now, when you run the `manifest` using the IF CLI, it will load the model automatically. Run using:
88+
89+
```sh
90+
ie --manifest <path-to-your-impl> --output <path-to-save-output>
91+
```

jest.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
transform: {
6+
'^.+\\.ts?$': [
7+
'ts-jest',
8+
{
9+
tsconfig: 'tsconfig.json',
10+
},
11+
],
12+
},
13+
modulePathIgnorePatterns: ['./build'],
14+
};

0 commit comments

Comments
 (0)