CodeTags is a powerful feature within this VS Code extension that dynamically parses a header file (maestro.h) to inject useful variables like build versions, timestamps, and more into your code. This helps streamline the process of keeping metadata up-to-date by automating the insertion of values such as the current date, build number, and random hexadecimal values.
CodeTags scans for a specific header file (maestro.h) in your project, evaluates any directives it contains, and injects the corresponding values. This feature is especially useful for embedding dynamically generated metadata (e.g., dates, version numbers) into your codebase, eliminating the need for manual updates.
- Dynamic Metadata Insertion: Automatically generates and updates code variables like year, month, build number, and more.
- JavaScript-based Evaluation: Uses JavaScript expressions to calculate values, providing flexibility and precision.
- Environment and Workspace Integration: Easily references environment variables and workspace-specific paths.
Here’s an example of what a maestro.h file might look like when using CodeTags:
#pragma once
// OTX_Extension_print(#define PROJECTNAME = '${workspaceFolderBasename}')
#define PROJECTNAME = 'OTX-HelloWorld'
// OTX_Extension_print(#define ONETHINX_PACK_LOC = '${env:ONETHINX_PACK_LOC}')
#define ONETHINX_PACK_LOC = '/Applications/OTX-Maestro'
// OTX_Extension_eval("#define buildyear " + new Date().getFullYear() % 100)
#define buildyear 24
// OTX_Extension_eval("#define buildmonth " + (new Date().getMonth() + 1))
#define buildmonth 10
// OTX_Extension_eval("#define buildday " + new Date().getDate())
#define buildday 8
// OTX_Extension_eval("#define buildhour " + new Date().getHours())
#define buildhour 22
// OTX_Extension_eval("#define buildminute " + new Date().getMinutes())
#define buildminute 35
// OTX_Extension_eval("#define buildsecond " + new Date().getSeconds())
#define buildsecond 57
// OTX_Extension_eval( "#define buildNr " + (${nextLineValue}+1) )
#define buildNr 52
// OTX_Extension_eval( "#define random 0x" + (Math.floor(Math.random() * 0x100000000)).toString(16).padStart(8, '0').toUpperCase(); )
#define random 0xF3DF2754In this file, CodeTags automatically evaluates and updates the variables based on JavaScript expressions, such as inserting the current year, month, day, or a randomly generated hexadecimal value.
- Create
maestro.h: In your workspace, create a file namedmaestro.hin thesourcefolder where you can add variable definitions that need to be dynamically updated by CodeTags. - Add Directives: Use
OTX_Extension_printfor static values like environment variables or workspace-specific names, andOTX_Extension_evalfor dynamic JavaScript-based values. - Automatic Parsing: When you use your extension, CodeTags will parse the
maestro.hfile, evaluate the expressions, and insert the appropriate values in place of the directives.
OTX_Extension_print: Injects static values or metadata such as workspace folder names or environment variables.
Example:
// OTX_Extension_print(#define PROJECTNAME = '${workspaceFolderBasename}')
#define PROJECTNAME = 'OTX-HelloWorld'
OTX_Extension_eval: Evaluates JavaScript expressions and inserts dynamic values into the code.
Example:
// OTX_Extension_eval("#define year " + new Date().getFullYear() % 100)
#define year 24
- Version Control: Automatically increment build numbers using
buildNrwithout manual intervention. - Timestamps: Add current date and time in your header file for documentation or version tracking.
- Randomization: Generate random values, like a unique session ID, using the random hexadecimal functionality.
No additional configuration is required to start using CodeTags. Just ensure that a maestro.h file is present in your project root, and the extension will handle the rest.