@metricinsights/cs-helper 0.3.2 → 0.5.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/CHANGELOG.md +7 -0
- package/README.md +100 -5
- package/dist/bin/build.d.ts +4 -1
- package/dist/bin/build.js +53 -7
- package/dist/bin/build.js.map +1 -1
- package/dist/bin/params-base64.d.ts +23 -0
- package/dist/bin/params-base64.js +60 -0
- package/dist/bin/params-base64.js.map +1 -0
- package/dist/bin/params-docs.d.ts +44 -0
- package/dist/bin/params-docs.js +697 -0
- package/dist/bin/params-docs.js.map +1 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/log.d.ts +23 -0
- package/dist/utils/log.js +111 -0
- package/dist/utils/log.js.map +1 -0
- package/package.json +49 -7
- package/templates/custom-script-js/src/index.js +10 -2
- package/templates/custom-script-ts/src/index.ts +10 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# [0.4.0-beta.1](https://github.com/mi-examples/cs-helper/compare/v0.3.2...v0.4.0-beta.1) (2026-01-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add log util and export from package ([d0ebd74](https://github.com/mi-examples/cs-helper/commit/d0ebd747b8717977f406b02e90ed11a3062aeec8))
|
|
7
|
+
* **build:** add script source hash and build checksum in banner ([35196ba](https://github.com/mi-examples/cs-helper/commit/35196ba4bfb7b3f90edfaf64bbe3f854bc095e85))
|
package/README.md
CHANGED
|
@@ -29,10 +29,11 @@ Run command to build your code `npm run build`
|
|
|
29
29
|
|
|
30
30
|
#### API options
|
|
31
31
|
|
|
32
|
-
| Option
|
|
33
|
-
|
|
34
|
-
| `--clean`
|
|
35
|
-
| `--v7`
|
|
32
|
+
| Option | Description | Default |
|
|
33
|
+
|------------------|------------------------------------------------------------------|---------|
|
|
34
|
+
| `--clean` | Clean dist folder before build | `false` |
|
|
35
|
+
| `--v7` | CS will be compatible only with v7 | `false` |
|
|
36
|
+
| `--readme <path>` | Path to README.md file to include in the built script banner | Auto-detect `README.md` in project root |
|
|
36
37
|
|
|
37
38
|
### Basic usage
|
|
38
39
|
|
|
@@ -48,6 +49,42 @@ setTimeout(() => {
|
|
|
48
49
|
|
|
49
50
|
### Utils usage
|
|
50
51
|
|
|
52
|
+
#### Log utility
|
|
53
|
+
|
|
54
|
+
Provides logging utilities with log level support for custom scripts. Logs are only visible if their level is greater than or equal to the current log level.
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
import {
|
|
58
|
+
log,
|
|
59
|
+
setLogLevel,
|
|
60
|
+
getLogLevel,
|
|
61
|
+
LOG_LEVEL_DEBUG,
|
|
62
|
+
LOG_LEVEL_INFO,
|
|
63
|
+
LOG_LEVEL_WARN,
|
|
64
|
+
LOG_LEVEL_ERROR,
|
|
65
|
+
} from '@metricinsights/cs-helper/utils';
|
|
66
|
+
|
|
67
|
+
// Set the current log level (defaults to INFO/1)
|
|
68
|
+
// Only logs with level >= current level will be visible
|
|
69
|
+
setLogLevel(LOG_LEVEL_INFO); // or setLogLevel(1) or setLogLevel('info')
|
|
70
|
+
|
|
71
|
+
// Get current log level
|
|
72
|
+
const currentLevel = getLogLevel(); // Returns: 1
|
|
73
|
+
|
|
74
|
+
// Log messages with different levels
|
|
75
|
+
log('Debug information', LOG_LEVEL_DEBUG); // Level 0 - NOT visible (current level is 1)
|
|
76
|
+
log('Info message', LOG_LEVEL_INFO); // Level 1 - VISIBLE ✓
|
|
77
|
+
log('Warning message', LOG_LEVEL_WARN); // Level 2 - VISIBLE ✓
|
|
78
|
+
log('Error occurred', LOG_LEVEL_ERROR); // Level 3 - VISIBLE ✓
|
|
79
|
+
|
|
80
|
+
// Change log level to show debug messages too
|
|
81
|
+
setLogLevel(LOG_LEVEL_DEBUG); // Now level 0
|
|
82
|
+
log('Debug information', LOG_LEVEL_DEBUG); // Level 0 - VISIBLE ✓
|
|
83
|
+
|
|
84
|
+
// Log levels (lower number = more verbose):
|
|
85
|
+
// debug (0), info (1), warn (2), error (3), emergency (4), silent (10)
|
|
86
|
+
```
|
|
87
|
+
|
|
51
88
|
#### Data convertor
|
|
52
89
|
|
|
53
90
|
Contains methods to apply metadata for MI datasets
|
|
@@ -58,7 +95,7 @@ import {
|
|
|
58
95
|
buildMetadataTransformer,
|
|
59
96
|
applyMetadata,
|
|
60
97
|
transformDataset,
|
|
61
|
-
} from '@metricinsights/cs-helper/
|
|
98
|
+
} from '@metricinsights/cs-helper/utils';
|
|
62
99
|
|
|
63
100
|
async function main() {
|
|
64
101
|
const dataset = await new Promise((resolve, reject) => {
|
|
@@ -85,3 +122,61 @@ async function main() {
|
|
|
85
122
|
|
|
86
123
|
main();
|
|
87
124
|
```
|
|
125
|
+
|
|
126
|
+
## Build Output
|
|
127
|
+
|
|
128
|
+
The built script includes a banner with metadata:
|
|
129
|
+
|
|
130
|
+
- **Script source hash**: SHA-256 hash (first 16 hex chars) of the main file and all imported files (relative imports only). This helps verify the source code hasn't changed.
|
|
131
|
+
- **Checksum**: SHA-256 hash (first 16 hex chars) of the built output file. To verify the built file hasn't been modified, replace the checksum value with `0000000000000000` in the banner, then hash the file; the result should match the stored checksum.
|
|
132
|
+
- **Params Base64**: Base64-encoded JSON containing structured parameter metadata extracted from all `parseParams` calls in your code. This includes parameter names, types, default values, required flags, available values (for enum-like parameters), and descriptions. The encoded data can be decoded to access parameter information programmatically.
|
|
133
|
+
|
|
134
|
+
All metadata is included automatically in the banner when building your custom script.
|
|
135
|
+
|
|
136
|
+
### Banner Example
|
|
137
|
+
|
|
138
|
+
Here's an example of what the banner looks like in the built script:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
***** DO NOT EDIT! THIS CODE IS GENERATED BY THE PACKAGE @metricinsights/cs-helper (https://github.com/mi-examples/cs-helper) *****
|
|
142
|
+
|
|
143
|
+
Please, go to code sources and add your changes!
|
|
144
|
+
|
|
145
|
+
Code sources:
|
|
146
|
+
Package name: my-custom-script
|
|
147
|
+
Package version: 1.0.0
|
|
148
|
+
Package repository: https://github.com/user/my-custom-script
|
|
149
|
+
Build command: npm run build
|
|
150
|
+
Built at: 2026-02-02T12:00:00.000Z
|
|
151
|
+
Script source hash: a1b2c3d4e5f6g7h8
|
|
152
|
+
Checksum: 1a2b3c4d5e6f7g8h
|
|
153
|
+
|
|
154
|
+
***** ----- * PARAMS BASE64 * ----- *****
|
|
155
|
+
eyJpc1BhcmFtZXRlcnNSZXF1aXJlZCI6ZmFsc2UsInBhcmFtZXRlcnMiOlt7Im5hbWUiOiJkZWZhdWx0VmFsdWUiLCJ0eXBlIjoibnVtYmVyIiwicmVxdWlyZWQiOmZhbHNlfV19
|
|
156
|
+
***** ----- * END PARAMS BASE64 * ----- *****
|
|
157
|
+
|
|
158
|
+
***** ----- ----- ----- ----- ----- ----- *****
|
|
159
|
+
***** PARAMETERS DESCRIPTION *****
|
|
160
|
+
|
|
161
|
+
parseParams call #1 (src/index.ts:43):
|
|
162
|
+
|
|
163
|
+
## Params
|
|
164
|
+
|
|
165
|
+
| Name | Type | Required | Default |
|
|
166
|
+
|:------------|:------:|:--------:|:-------:|
|
|
167
|
+
| defaultValue | number | | 1 |
|
|
168
|
+
|
|
169
|
+
### Params description
|
|
170
|
+
|
|
171
|
+
- **defaultValue**: Example: `1`.
|
|
172
|
+
|
|
173
|
+
***** ------------------------- *****
|
|
174
|
+
|
|
175
|
+
***** README.md *****
|
|
176
|
+
|
|
177
|
+
# My Custom Script
|
|
178
|
+
|
|
179
|
+
This is my custom script description...
|
|
180
|
+
|
|
181
|
+
***** --------- *****
|
|
182
|
+
```
|
package/dist/bin/build.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
declare const path: any;
|
|
3
|
-
declare const
|
|
3
|
+
declare const nodeCrypto: any;
|
|
4
|
+
declare const rmSync: any, readFileSync: any, readdirSync: any, existsSync: any, writeFileSync: any;
|
|
5
|
+
declare const paramsDocs: any;
|
|
6
|
+
declare const paramsBase64: any;
|
|
4
7
|
type Webpack = typeof import('webpack');
|
|
5
8
|
type Configuration = Parameters<Webpack>[0][number];
|
package/dist/bin/build.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
const path = require('path');
|
|
4
|
-
const
|
|
4
|
+
const nodeCrypto = require('crypto');
|
|
5
|
+
const { rmSync, readFileSync, readdirSync, existsSync, writeFileSync } = require('fs');
|
|
6
|
+
const paramsDocs = require('./params-docs');
|
|
7
|
+
const paramsBase64 = require('./params-base64');
|
|
5
8
|
(async function () {
|
|
6
9
|
const { default: webpack } = (await import('webpack'));
|
|
7
10
|
const { default: chalk } = await import('chalk');
|
|
@@ -18,6 +21,20 @@ const { rmSync, readFileSync, readdirSync } = require('fs');
|
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
const V7 = process.argv.includes('--v7');
|
|
24
|
+
const readmeFile = process.argv.find((arg) => arg.startsWith('--readme=') || arg.startsWith('--readme '));
|
|
25
|
+
let readmeContent = '';
|
|
26
|
+
if (readmeFile) {
|
|
27
|
+
const readmePath = readmeFile.split('=')[1] || readmeFile.split(' ')[1];
|
|
28
|
+
if (existsSync(readmePath)) {
|
|
29
|
+
readmeContent = readFileSync(readmePath, {
|
|
30
|
+
encoding: 'utf-8',
|
|
31
|
+
flag: 'r',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error(chalk.red(`Readme file not found: ${readmePath}`));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
21
38
|
const helperPackage = require(path.resolve(__dirname, '..', '..', 'package.json'));
|
|
22
39
|
const packageFile = require(path.resolve(process.cwd(), 'package.json'));
|
|
23
40
|
const packageDir = readdirSync(process.cwd(), {
|
|
@@ -36,18 +53,30 @@ const { rmSync, readFileSync, readdirSync } = require('fs');
|
|
|
36
53
|
: {
|
|
37
54
|
targets: 'ie 11',
|
|
38
55
|
};
|
|
56
|
+
const paramsDescription = paramsDocs.analyzeParseParams(filename);
|
|
57
|
+
const paramsData = paramsDocs.analyzeParseParamsData(filename);
|
|
58
|
+
const paramsBase64String = paramsBase64.generateParamsBase64(paramsData);
|
|
59
|
+
const sourceFiles = paramsDocs.getSourceFilesFromEntry(filename);
|
|
60
|
+
const hasher = nodeCrypto.createHash('sha256');
|
|
61
|
+
for (const file of sourceFiles.sort()) {
|
|
62
|
+
hasher.update(readFileSync(file, { encoding: 'utf-8', flag: 'r' }));
|
|
63
|
+
}
|
|
64
|
+
const hash = hasher.digest('hex').slice(0, 16);
|
|
39
65
|
const compiler = webpack({
|
|
40
66
|
mode: 'production',
|
|
41
67
|
plugins: [
|
|
42
68
|
new webpack.BannerPlugin({
|
|
43
69
|
banner: function () {
|
|
44
70
|
const { repository, name, version } = packageFile;
|
|
45
|
-
let readme;
|
|
46
|
-
if (packageDir.length) {
|
|
71
|
+
let readme = readmeContent;
|
|
72
|
+
if (packageDir.length && !readmeContent) {
|
|
47
73
|
const regExp = /^readme\.md$/i;
|
|
48
74
|
for (const object of packageDir) {
|
|
49
75
|
if (regExp.test(object)) {
|
|
50
|
-
readme = readFileSync(object, {
|
|
76
|
+
readme = readFileSync(object, {
|
|
77
|
+
encoding: 'utf-8',
|
|
78
|
+
flag: 'r',
|
|
79
|
+
});
|
|
51
80
|
break;
|
|
52
81
|
}
|
|
53
82
|
}
|
|
@@ -60,7 +89,8 @@ const { rmSync, readFileSync, readdirSync } = require('fs');
|
|
|
60
89
|
helperRepository = helperPackage.repository;
|
|
61
90
|
}
|
|
62
91
|
else if (typeof helperPackage.repository === 'object') {
|
|
63
|
-
helperRepository =
|
|
92
|
+
helperRepository =
|
|
93
|
+
helperPackage.repository.url?.slice(helperPackage.repository.url?.indexOf('http')) ?? '';
|
|
64
94
|
}
|
|
65
95
|
return `***** DO NOT EDIT! THIS CODE IS GENERATED BY THE PACKAGE ${helperPackage.name} (${helperRepository}) *****
|
|
66
96
|
|
|
@@ -72,9 +102,15 @@ Code sources:
|
|
|
72
102
|
Package repository: ${repository ? repository : 'Not defined'}
|
|
73
103
|
Build command: npm run ${process.env.npm_lifecycle_event}
|
|
74
104
|
Built at: ${new Date().toISOString()}
|
|
105
|
+
Script source hash: ${hash}
|
|
106
|
+
Checksum: 0000000000000000
|
|
75
107
|
${V7 ? 'Compatibility: v7 ONLY\n' : ''}
|
|
76
|
-
|
|
77
|
-
|
|
108
|
+
|
|
109
|
+
***** ----- * PARAMS BASE64 * ----- *****
|
|
110
|
+
${paramsBase64String}
|
|
111
|
+
***** ----- * END PARAMS BASE64 * ----- *****
|
|
112
|
+
|
|
113
|
+
***** ----- ----- ----- ----- ----- ----- *****${paramsDescription}${readme ? `\n\n***** README.md *****\n\n${readme}\n***** --------- *****` : ''}`;
|
|
78
114
|
},
|
|
79
115
|
}),
|
|
80
116
|
new webpack.NormalModuleReplacementPlugin(/-TARGET_EXTENSION$/, function (resource) {
|
|
@@ -125,6 +161,8 @@ ${readme ? `\n***** README.md *****\n\n${readme}\n***** --------- *****` : ''}`;
|
|
|
125
161
|
extensions: ['.tsx', '.ts', '.js', '.mjs', '.cjs'],
|
|
126
162
|
},
|
|
127
163
|
});
|
|
164
|
+
const outputBasename = `${path.parse(filename).name}.js`;
|
|
165
|
+
const BUILD_HASH_PLACEHOLDER = '0000000000000000';
|
|
128
166
|
await new Promise((resolve) => {
|
|
129
167
|
compiler.run((err, stats) => resolve({ err, stats }));
|
|
130
168
|
}).then(({ err, stats }) => {
|
|
@@ -139,6 +177,14 @@ ${readme ? `\n***** README.md *****\n\n${readme}\n***** --------- *****` : ''}`;
|
|
|
139
177
|
}
|
|
140
178
|
else {
|
|
141
179
|
console.log(stats?.toString({ colors: true }));
|
|
180
|
+
const outputPath = path.join(DIST_DIR, outputBasename);
|
|
181
|
+
const content = readFileSync(outputPath, { encoding: 'utf-8' });
|
|
182
|
+
const buildHasher = nodeCrypto.createHash('sha256');
|
|
183
|
+
buildHasher.update(content);
|
|
184
|
+
const buildHash = buildHasher.digest('hex').slice(0, 16);
|
|
185
|
+
const contentWithHash = content.replace(`Checksum: ${BUILD_HASH_PLACEHOLDER}`, `Checksum: ${buildHash}`);
|
|
186
|
+
console.log(chalk.green(`Checksum: ${buildHash}`));
|
|
187
|
+
writeFileSync(outputPath, contentWithHash);
|
|
142
188
|
console.log(chalk.green('Done'));
|
|
143
189
|
}
|
|
144
190
|
});
|
package/dist/bin/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../bin/build.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../bin/build.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACrC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACvF,MAAM,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAC5C,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAMhD,CAAC,KAAK;IAEJ,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAEpD,CAAC;IAEF,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO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AK,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAE/C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YACvD,MAAM,OAAO,GAAG,YAAY,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YAChE,MAAM,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAEpD,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAE5B,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACzD,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CACrC,aAAa,sBAAsB,EAAE,EACrC,aAAa,SAAS,EAAE,CACzB,CAAC;YAEF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,SAAS,EAAE,CAAC,CAAC,CAAC;YACnD,aAAa,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;YAE3C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;SAClC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type ParamType = 'string' | 'number' | 'boolean' | 'password' | 'unknown';
|
|
2
|
+
interface ParamHash {
|
|
3
|
+
name: string;
|
|
4
|
+
default_value?: string;
|
|
5
|
+
available_values?: string[];
|
|
6
|
+
type: string;
|
|
7
|
+
required: boolean;
|
|
8
|
+
description?: string;
|
|
9
|
+
}
|
|
10
|
+
interface ParamsHashData {
|
|
11
|
+
hostname?: string;
|
|
12
|
+
customScriptId?: number;
|
|
13
|
+
customScriptName?: string;
|
|
14
|
+
isParametersRequired: boolean;
|
|
15
|
+
parameters: ParamHash[];
|
|
16
|
+
}
|
|
17
|
+
declare function removeQuotes(value: string): string;
|
|
18
|
+
declare function mapParamRowToHash(row: ParamRow, defaultParams: Record<string, any>): ParamHash;
|
|
19
|
+
declare function generateParamsBase64(parseParamsCalls: ParseParamsCallInfo[], options?: {
|
|
20
|
+
hostname?: string;
|
|
21
|
+
customScriptId?: number;
|
|
22
|
+
customScriptName?: string;
|
|
23
|
+
}): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function removeQuotes(value) {
|
|
3
|
+
const str = String(value).trim();
|
|
4
|
+
if ((str.startsWith('"') && str.endsWith('"')) ||
|
|
5
|
+
(str.startsWith("'") && str.endsWith("'"))) {
|
|
6
|
+
return str.slice(1, -1);
|
|
7
|
+
}
|
|
8
|
+
return str;
|
|
9
|
+
}
|
|
10
|
+
function mapParamRowToHash(row, defaultParams) {
|
|
11
|
+
const paramHash = {
|
|
12
|
+
name: row.name,
|
|
13
|
+
type: row.typeStr,
|
|
14
|
+
required: !row.optional,
|
|
15
|
+
};
|
|
16
|
+
if (row.name in defaultParams) {
|
|
17
|
+
paramHash.default_value = removeQuotes(defaultParams[row.name]);
|
|
18
|
+
}
|
|
19
|
+
if (row.acceptsValues && row.acceptsValues.length > 0) {
|
|
20
|
+
paramHash.available_values = row.acceptsValues;
|
|
21
|
+
}
|
|
22
|
+
if (row.description) {
|
|
23
|
+
paramHash.description = row.description;
|
|
24
|
+
}
|
|
25
|
+
return paramHash;
|
|
26
|
+
}
|
|
27
|
+
function generateParamsBase64(parseParamsCalls, options) {
|
|
28
|
+
const hashData = {
|
|
29
|
+
isParametersRequired: false,
|
|
30
|
+
parameters: [],
|
|
31
|
+
};
|
|
32
|
+
if (options?.hostname) {
|
|
33
|
+
hashData.hostname = options.hostname;
|
|
34
|
+
}
|
|
35
|
+
if (options?.customScriptId !== undefined) {
|
|
36
|
+
hashData.customScriptId = options.customScriptId;
|
|
37
|
+
}
|
|
38
|
+
if (options?.customScriptName) {
|
|
39
|
+
hashData.customScriptName = options.customScriptName;
|
|
40
|
+
}
|
|
41
|
+
const allParams = new Map();
|
|
42
|
+
for (const call of parseParamsCalls) {
|
|
43
|
+
if (call.typeInfoTable && call.typeInfoTable.length > 0) {
|
|
44
|
+
for (const row of call.typeInfoTable) {
|
|
45
|
+
if (/^\[.+\:\s*.+\]$/.test(row.name)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const paramHash = mapParamRowToHash(row, call.defaultParams);
|
|
49
|
+
allParams.set(row.name, paramHash);
|
|
50
|
+
if (!row.optional) {
|
|
51
|
+
hashData.isParametersRequired = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
hashData.parameters = Array.from(allParams.values());
|
|
57
|
+
return Buffer.from(JSON.stringify(hashData)).toString('base64');
|
|
58
|
+
}
|
|
59
|
+
module.exports = { generateParamsBase64 };
|
|
60
|
+
//# sourceMappingURL=params-base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params-base64.js","sourceRoot":"","sources":["../../bin/params-base64.ts"],"names":[],"mappings":";AAuBA,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACjC,IACE,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC1C,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAC1C;QACA,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KACzB;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAKD,SAAS,iBAAiB,CACxB,GAAa,EACb,aAAkC;IAElC,MAAM,SAAS,GAAc;QAC3B,IAAI,EAA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I,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;oBACpC,SAAS;iBACV;gBAGD,MAAM,SAAS,GAAG,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;gBAE7D,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;gBAGnC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE;oBACjB,QAAQ,CAAC,oBAAoB,GAAG,IAAI,CAAC;iBACtC;aACF;SACF;KACF;IAED,QAAQ,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
declare const pathLib: any;
|
|
2
|
+
declare const fs: any;
|
|
3
|
+
type ParamRow = {
|
|
4
|
+
name: string;
|
|
5
|
+
typeStr: string;
|
|
6
|
+
optional: boolean;
|
|
7
|
+
description: string;
|
|
8
|
+
example?: string;
|
|
9
|
+
acceptsValues?: string[];
|
|
10
|
+
};
|
|
11
|
+
type ParseParamsCallInfo = {
|
|
12
|
+
filePath: string;
|
|
13
|
+
typeInfo: string;
|
|
14
|
+
typeInfoTable?: ParamRow[];
|
|
15
|
+
defaultParams: Record<string, any>;
|
|
16
|
+
line: number;
|
|
17
|
+
};
|
|
18
|
+
declare function getSourceFilesFromEntry(entryFile: string): string[];
|
|
19
|
+
type JSDocParamInfo = {
|
|
20
|
+
description: string;
|
|
21
|
+
example: string;
|
|
22
|
+
password?: boolean;
|
|
23
|
+
};
|
|
24
|
+
declare function parseJSDocInner(inner: string): JSDocParamInfo;
|
|
25
|
+
declare function getJSDocFromLeadingTrivia(text: string, fullStart: number, start: number): string;
|
|
26
|
+
declare function getJSDocParamInfo(ts: any, decl: any): JSDocParamInfo;
|
|
27
|
+
declare function getGenericTypeDisplay(checker: any, type: any, seen?: Set<number>): string;
|
|
28
|
+
declare function getAcceptableValues(checker: any, type: any, seen?: Set<number>): string[];
|
|
29
|
+
declare function expandTypeToParamRows(ts: any, checker: any, typeNode: any, sourceCode: string): ParamRow[] | null;
|
|
30
|
+
declare function isNumericValue(s: string): boolean;
|
|
31
|
+
declare function resolveDefaultValue(ts: any, checker: any, initializer: any, sourceCode: string, depth?: number): string;
|
|
32
|
+
declare function formatParamsTable(rows: ParamRow[], defaultParams: Record<string, any>): string;
|
|
33
|
+
declare function analyzeParseParamsInFile(sourceFile: string, options?: {
|
|
34
|
+
checker?: any;
|
|
35
|
+
program?: any;
|
|
36
|
+
ts?: any;
|
|
37
|
+
}): ParseParamsCallInfo[];
|
|
38
|
+
declare const parseParamsCache: Map<string, ParseParamsCallInfo[]>;
|
|
39
|
+
declare function getParseParamsFromCode(entryFile: string): ParseParamsCallInfo[];
|
|
40
|
+
declare function formatParseParamsForDocs(calls: ParseParamsCallInfo[], projectRoot?: string): string;
|
|
41
|
+
declare function analyzeParseParams(entryFile: string): string;
|
|
42
|
+
declare function analyzeParseParamsData(entryFile: string): ParseParamsCallInfo[];
|
|
43
|
+
declare function clearParseParamsCache(): void;
|
|
44
|
+
declare function clearParseParamsCacheEntry(entryFile: string): void;
|