Skip to content

Commit

Permalink
support for custom source details
Browse files Browse the repository at this point in the history
  • Loading branch information
skarim committed Sep 5, 2024
1 parent 1858f90 commit 031893c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ npx @flisk/analyze-tracking /path/to/project [options]

Optional arguments:
- `-o, --output <output_file>`: Name of the output file (default: `tracking-schema.yaml`)
- `-c, --customFunction <output_file>`: Name of your custom tracking function
- `-c, --customFunction <function_name>`: Name of your custom tracking function
- `-u, --repositoryUrl <git_url>`: URL to your repository
- `-h, --commitHash <commit_sha>`: Latest commit hash
- `-t, --commitTimestamp <iso_timestamp>`: Timestamp of latest commit

Note: Custom Functions only support the following format:
```js
Expand Down
32 changes: 30 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,41 @@ const optionDefinitions = [
alias: 'c',
type: String,
},
{
name: 'repositoryUrl',
alias: 'u',
type: String,
},
{
name: 'commitHash',
alias: 'h',
type: String,
},
{
name: 'commitTimestamp',
alias: 't',
type: String,
},
]
const options = commandLineArgs(optionDefinitions);
const { targetDir, output, customFunction } = options;
const {
targetDir,
output,
customFunction,
repositoryUrl,
commitHash,
commitTimestamp,
} = options;

const customSourceDetails = {
repositoryUrl,
commitHash,
commitTimestamp,
};

if (!targetDir) {
console.error('Please provide the path to the repository.');
process.exit(1);
}

run(path.resolve(targetDir), output, customFunction);
run(path.resolve(targetDir), output, customFunction, customSourceDetails);
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flisk/analyze-tracking",
"version": "0.2.5",
"version": "0.2.6",
"description": "Analyzes tracking code in a project and generates data schemas",
"main": "src/index.js",
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const { analyzeDirectory } = require('./analyze');
const { getRepoDetails } = require('./repoDetails');
const { generateYamlSchema } = require('./yamlGenerator');

async function run(targetDir, outputPath, customFunction) {
async function run(targetDir, outputPath, customFunction, customSourceDetails) {
const events = analyzeDirectory(targetDir, customFunction);
const repoDetails = await getRepoDetails(targetDir);
const repoDetails = await getRepoDetails(targetDir, customSourceDetails);
generateYamlSchema(events, repoDetails, outputPath);
}

Expand Down
7 changes: 6 additions & 1 deletion src/repoDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function toISODateString(date) {
+ pad(date.getUTCSeconds())+'Z';
}

async function getRepoDetails(targetDir) {
async function getRepoDetails(targetDir, customSourceDetails) {
const repoUrl = await getRepositoryUrl(targetDir);
const commitHash = await getCommitHash(targetDir);
const commitEpochTime = await getCommitTimestamp(targetDir, commitHash);
Expand All @@ -67,6 +67,11 @@ async function getRepoDetails(targetDir) {
if (!!repoUrl) repoDetails.repository = repoUrl;
if (!!commitHash) repoDetails.commit = commitHash;
repoDetails.timestamp = commitTimestamp;

if (!!customSourceDetails?.repositoryUrl) repoDetails.repository = customSourceDetails.repositoryUrl;
if (!!customSourceDetails?.commitHash) repoDetails.commit = customSourceDetails.commitHash;
if (!!customSourceDetails?.commitTimestamp) repoDetails.timestamp = customSourceDetails.commitTimestamp;

return repoDetails;
}

Expand Down

0 comments on commit 031893c

Please sign in to comment.