@flisk/analyze-tracking 0.2.5 → 0.2.7
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 +4 -1
- package/bin/cli.js +30 -2
- package/package.json +1 -1
- package/src/analyze/helpers.js +4 -3
- package/src/index.js +2 -2
- package/src/repoDetails.js +6 -1
package/README.md
CHANGED
|
@@ -12,7 +12,10 @@ npx @flisk/analyze-tracking /path/to/project [options]
|
|
|
12
12
|
|
|
13
13
|
Optional arguments:
|
|
14
14
|
- `-o, --output <output_file>`: Name of the output file (default: `tracking-schema.yaml`)
|
|
15
|
-
- `-c, --customFunction <
|
|
15
|
+
- `-c, --customFunction <function_name>`: Name of your custom tracking function
|
|
16
|
+
- `-u, --repositoryUrl <git_url>`: URL to your repository
|
|
17
|
+
- `-h, --commitHash <commit_sha>`: Latest commit hash
|
|
18
|
+
- `-t, --commitTimestamp <iso_timestamp>`: Timestamp of latest commit
|
|
16
19
|
|
|
17
20
|
Note: Custom Functions only support the following format:
|
|
18
21
|
```js
|
package/bin/cli.js
CHANGED
|
@@ -22,13 +22,41 @@ const optionDefinitions = [
|
|
|
22
22
|
alias: 'c',
|
|
23
23
|
type: String,
|
|
24
24
|
},
|
|
25
|
+
{
|
|
26
|
+
name: 'repositoryUrl',
|
|
27
|
+
alias: 'u',
|
|
28
|
+
type: String,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'commitHash',
|
|
32
|
+
alias: 'h',
|
|
33
|
+
type: String,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'commitTimestamp',
|
|
37
|
+
alias: 't',
|
|
38
|
+
type: String,
|
|
39
|
+
},
|
|
25
40
|
]
|
|
26
41
|
const options = commandLineArgs(optionDefinitions);
|
|
27
|
-
const {
|
|
42
|
+
const {
|
|
43
|
+
targetDir,
|
|
44
|
+
output,
|
|
45
|
+
customFunction,
|
|
46
|
+
repositoryUrl,
|
|
47
|
+
commitHash,
|
|
48
|
+
commitTimestamp,
|
|
49
|
+
} = options;
|
|
50
|
+
|
|
51
|
+
const customSourceDetails = {
|
|
52
|
+
repositoryUrl,
|
|
53
|
+
commitHash,
|
|
54
|
+
commitTimestamp,
|
|
55
|
+
};
|
|
28
56
|
|
|
29
57
|
if (!targetDir) {
|
|
30
58
|
console.error('Please provide the path to the repository.');
|
|
31
59
|
process.exit(1);
|
|
32
60
|
}
|
|
33
61
|
|
|
34
|
-
run(path.resolve(targetDir), output, customFunction);
|
|
62
|
+
run(path.resolve(targetDir), output, customFunction, customSourceDetails);
|
package/package.json
CHANGED
package/src/analyze/helpers.js
CHANGED
|
@@ -139,8 +139,9 @@ function extractJsProperties(node) {
|
|
|
139
139
|
function extractTsProperties(checker, node) {
|
|
140
140
|
const properties = {};
|
|
141
141
|
|
|
142
|
-
node.properties
|
|
143
|
-
const key = prop.name ? prop.name.text : prop.key.text || prop.key.value;
|
|
142
|
+
for (const prop of node.properties) {
|
|
143
|
+
const key = !!prop.name ? prop.name.text : (!!prop.key ? (prop.key.text || prop.key.value) : undefined);
|
|
144
|
+
if (!key) continue;
|
|
144
145
|
let valueType = 'any';
|
|
145
146
|
|
|
146
147
|
if (ts.isShorthandPropertyAssignment(prop)) {
|
|
@@ -195,7 +196,7 @@ function extractTsProperties(checker, node) {
|
|
|
195
196
|
valueType = checker.typeToString(checker.getTypeFromTypeNode(prop.type)) || 'any';
|
|
196
197
|
properties[key] = { type: valueType };
|
|
197
198
|
}
|
|
198
|
-
}
|
|
199
|
+
}
|
|
199
200
|
|
|
200
201
|
return properties;
|
|
201
202
|
}
|
package/src/index.js
CHANGED
|
@@ -2,9 +2,9 @@ const { analyzeDirectory } = require('./analyze');
|
|
|
2
2
|
const { getRepoDetails } = require('./repoDetails');
|
|
3
3
|
const { generateYamlSchema } = require('./yamlGenerator');
|
|
4
4
|
|
|
5
|
-
async function run(targetDir, outputPath, customFunction) {
|
|
5
|
+
async function run(targetDir, outputPath, customFunction, customSourceDetails) {
|
|
6
6
|
const events = analyzeDirectory(targetDir, customFunction);
|
|
7
|
-
const repoDetails = await getRepoDetails(targetDir);
|
|
7
|
+
const repoDetails = await getRepoDetails(targetDir, customSourceDetails);
|
|
8
8
|
generateYamlSchema(events, repoDetails, outputPath);
|
|
9
9
|
}
|
|
10
10
|
|
package/src/repoDetails.js
CHANGED
|
@@ -57,7 +57,7 @@ function toISODateString(date) {
|
|
|
57
57
|
+ pad(date.getUTCSeconds())+'Z';
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
async function getRepoDetails(targetDir) {
|
|
60
|
+
async function getRepoDetails(targetDir, customSourceDetails) {
|
|
61
61
|
const repoUrl = await getRepositoryUrl(targetDir);
|
|
62
62
|
const commitHash = await getCommitHash(targetDir);
|
|
63
63
|
const commitEpochTime = await getCommitTimestamp(targetDir, commitHash);
|
|
@@ -67,6 +67,11 @@ async function getRepoDetails(targetDir) {
|
|
|
67
67
|
if (!!repoUrl) repoDetails.repository = repoUrl;
|
|
68
68
|
if (!!commitHash) repoDetails.commit = commitHash;
|
|
69
69
|
repoDetails.timestamp = commitTimestamp;
|
|
70
|
+
|
|
71
|
+
if (!!customSourceDetails?.repositoryUrl) repoDetails.repository = customSourceDetails.repositoryUrl;
|
|
72
|
+
if (!!customSourceDetails?.commitHash) repoDetails.commit = customSourceDetails.commitHash;
|
|
73
|
+
if (!!customSourceDetails?.commitTimestamp) repoDetails.timestamp = customSourceDetails.commitTimestamp;
|
|
74
|
+
|
|
70
75
|
return repoDetails;
|
|
71
76
|
}
|
|
72
77
|
|