Charles Lyding 64c9a0512e refactor(@angular/cli): convert VERSION property from require to file read
Much like the framework packages, the VERSION property will eventually be set via build-time stamping but the necessary build infrastructure is not yet in place. Until then, the global require usage has been replaced with a file read and JSON parse which provides the equivalent required behavior.
2021-08-25 11:40:51 +01:00

31 lines
872 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { readFileSync } from 'fs';
import { resolve } from 'path';
// Same structure as used in framework packages
export class Version {
public readonly major: string;
public readonly minor: string;
public readonly patch: string;
constructor(public readonly full: string) {
this.major = full.split('.')[0];
this.minor = full.split('.')[1];
this.patch = full.split('.').slice(2).join('.');
}
}
// TODO: Convert this to use build-time version stamping once implemented in the build system
export const VERSION = new Version(
(
JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf-8')) as { version: string }
).version,
);