@metricinsights/cs-helper 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/package.json +52 -0
- package/templates/custom-script-js/.prettierrc.js +6 -0
- package/templates/custom-script-js/README.md +13 -0
- package/templates/custom-script-js/package.json +20 -0
- package/templates/custom-script-js/src/index.js +0 -0
- package/templates/custom-script-ts/.prettierrc.js +6 -0
- package/templates/custom-script-ts/README.md +13 -0
- package/templates/custom-script-ts/package.json +21 -0
- package/templates/custom-script-ts/src/index.ts +0 -0
- package/templates/custom-script-ts/tsconfig.json +11 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# cs-helper
|
|
2
|
+
|
|
3
|
+
Metric Insights Custom Script helper
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm i --save-dev @metricinsights/cs-helper
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### CLI usage
|
|
14
|
+
|
|
15
|
+
Add `cs-helper` as package.json script to build you code into bundle
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"name": "package-name",
|
|
20
|
+
"version": "1.0.0",
|
|
21
|
+
"description": "Package description",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "@metricinsights/cs-helper <path-to-index.js>"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Run command to build your code `npm run build`
|
|
29
|
+
|
|
30
|
+
### Basic usage
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
import { cs, parseParams } from '@metricinsights/cs-helper';
|
|
34
|
+
|
|
35
|
+
const parsedParams = parseParams({ defaultValue: 1 }); // { defaultValue: 1 } & cs.params
|
|
36
|
+
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
cs.close();
|
|
39
|
+
}, 1000);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Utils usage
|
|
43
|
+
|
|
44
|
+
#### Data convertor
|
|
45
|
+
|
|
46
|
+
Contains methods to apply metadata for MI datasets
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
import { cs } from '@metricinsights/cs-helper';
|
|
50
|
+
import {
|
|
51
|
+
buildMetadataTransformer,
|
|
52
|
+
applyMetadata,
|
|
53
|
+
transformDataset,
|
|
54
|
+
} from '@metricinsights/cs-helper/dist/utils';
|
|
55
|
+
|
|
56
|
+
async function main() {
|
|
57
|
+
const dataset = await new Promise((resolve, reject) => {
|
|
58
|
+
cs.runApiRequest(
|
|
59
|
+
`/api/dataset_data?dataset=${1}`,
|
|
60
|
+
Object.assign({}, params, {
|
|
61
|
+
success: resolve,
|
|
62
|
+
error: reject,
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
}); // { data: [{ key1: value1, key2: value2 }], metadata: [{ name: key1, type: 'numeric' }, { name: key2, type: 'text' }] }
|
|
66
|
+
|
|
67
|
+
const metadataTransformer = buildMetadataTransformer(dataset.metadata); // { [key1]: (v) => Number(v), [key2]: (v) => String(v) }
|
|
68
|
+
const transformedData = applyMetadata(metadataTransformer, dataset.data); // [{ key1: Number(value1), key2: String(value2) }]
|
|
69
|
+
|
|
70
|
+
const transformedResponse = transformedData(dataset); // { data: [{ key1: Number(value1), key2: String(value2) }], metadata: [{ name: key1, type: 'numeric' }, { name: key2, type: 'text' }] }
|
|
71
|
+
|
|
72
|
+
cs.log(JSON.stringify(metadataTransformer));
|
|
73
|
+
cs.log(JSON.stringify(transformedData));
|
|
74
|
+
cs.log(JSON.stringify(transformedResponse));
|
|
75
|
+
|
|
76
|
+
cs.close();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
main();
|
|
80
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metricinsights/cs-helper",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Helper for Custom Scripts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npm run build:sources && npm run build:bin",
|
|
9
|
+
"build:sources": "tsc",
|
|
10
|
+
"build:bin": "tsc --project tsconfig.bin.json",
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"cs-helper": "dist/bin/build.js",
|
|
15
|
+
"cs-helper-create": "dist/bin/create.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/",
|
|
19
|
+
"templates",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/mi-examples/cs-helper.git"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"helper",
|
|
28
|
+
"custom script"
|
|
29
|
+
],
|
|
30
|
+
"author": "Serhii Shpak",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/jquery": "^3.5.16",
|
|
34
|
+
"@types/prompts": "^2.4.3",
|
|
35
|
+
"@types/webpack": "^5.28.0",
|
|
36
|
+
"prettier": "^2.8.6"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"chalk": "^5.2.0",
|
|
40
|
+
"commander": "^10.0.0",
|
|
41
|
+
"isbinaryfile": "^5.0.0",
|
|
42
|
+
"promise-polyfill": "8.3.0",
|
|
43
|
+
"prompts": "^2.4.2",
|
|
44
|
+
"ts-loader": "^9.4.2",
|
|
45
|
+
"typescript": "^5.0.2",
|
|
46
|
+
"webpack": "^5.76.2"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/mi-examples/cs-helper/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/mi-examples/cs-helper#readme"
|
|
52
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "%PACKAGE_NAME%",
|
|
3
|
+
"version": "%PACKAGE_VERSION%",
|
|
4
|
+
"description": "%PACKAGE_DESCRIPTION%",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "cs-helper src/index.js",
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"repository": "",
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"prettier": "^2.8.6"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@metricinsights/cs-helper": "^0.1.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "%PACKAGE_NAME%",
|
|
3
|
+
"version": "%PACKAGE_VERSION%",
|
|
4
|
+
"description": "%PACKAGE_DESCRIPTION%",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "cs-helper src/index.ts",
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"repository": "",
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"prettier": "^2.8.6",
|
|
16
|
+
"typescript": "^5.0.2"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@metricinsights/cs-helper": "^0.1.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
File without changes
|