Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert today's date and version number at compile time using typescript

I would like to have a (custom) version-number and the compilation-date in javascript files which have been compiled from typescript.

Is there a way to define variables or evaluate date-functions at compile time in TypeScript?

@COMPANY = "myCompanyName";
@VERSION = "2.3.4.5"
// copyright © 2015 - {year(@TODAY)} @COMPANY
//
// version: {@VERSION} 
// release: {@TODAY}`

I expect output in .js file like this:

// copyright © 2015 - 2019 MyCompanyName
//
// version: 2.3.4.5 
// release: 2019-09-16 10:00:00
like image 618
Jan Setzer Avatar asked Nov 07 '22 13:11

Jan Setzer


1 Answers

Although the line is not as well defined, TypeScript is not a build system; it doesn't support any processing like that.

You're better suited using anything else as part of your build process. There are many alternatives; the best one depends on your build workflow.

If you're using Babel (a common complementary build tool for TS projects), you could find that something that suit your needs like babel-plugin-add-header-comment or create one yourself.

You could also use the compiler library instead of the command line to create your files, doing any transformations you wanted.

Or you could create a separate step, after your build process, that does some string/regex replacement on output files - either via JS or via a bash script.

like image 108
zeh Avatar answered Nov 15 '22 12:11

zeh