Skip to content

Commit

Permalink
fix(export): allow importing "versions" and interface in one line
Browse files Browse the repository at this point in the history
Better TypeScript import of 'versions: TsAppVersion' variable. Full backward compatible: no changes
needed on environment files. This change lets you import "versions" as
standard TypeScript module as is done on environment.ts files. This allow you to remove
double import statements for component.ts file and to keep the files cleaner.
  • Loading branch information
dzoccarato authored and saitho committed Apr 3, 2020
1 parent 286943d commit 66d0296
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ You'll be able to import the values just like any other package, if you want use
```
import versions from '../_versions';
```
or you can import also TsAppVersion and use direclty in your template, like in app.component.ts example file
or you can import also TsAppVersion and use directly in your template, like in app.component.ts example file
```
import { TsAppVersion } from 'src/_versions.ts';
import versions from 'src/_versions.ts';
import { TsAppVersion, versions } from 'src/_versions.ts';
@Component({
selector: 'app-root',
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let src = `export interface TsAppVersion {
gitCommitDate?: string;
gitTag?: string;
};
const obj: TsAppVersion = {
export const versions: TsAppVersion = {
version: '${appVersion}',
name: '${appName}',
versionDate: '${new Date().toISOString()}',
Expand Down Expand Up @@ -133,7 +133,7 @@ if (enableGit) {
}

src += `};
export default obj;
export default versions;
`;

console.log('[TsAppVersion] ' + colors.green('Writing version module to ') + colors.yellow(versionFile));
Expand Down
3 changes: 1 addition & 2 deletions example/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Component } from '@angular/core';
import { environment } from "../environments/environment";

import { TsAppVersion } from 'src/_versions';
import versions from 'src/_versions';
import { TsAppVersion, versions } from 'src/_versions';

@Component({
selector: 'app-root',
Expand Down
20 changes: 10 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ describe('appversion', function() {
expect(fileContents).to.contains('gitCommitHash?: string;');
expect(fileContents).to.contains('gitCommitDate?: string;');
expect(fileContents).to.contains('gitTag?: string;');
expect(fileContents).to.contains('};\nconst obj: TsAppVersion = {'); // interface end + obj start
expect(fileContents).to.contains('};\nexport const versions: TsAppVersion = {'); // interface end + obj start

// data test
expect(fileContents).to.contains('version: \'1.0.0\',');
expect(fileContents).to.contains('name: \'test\',');
expect(fileContents).to.contains('description: \'test description\',');
expect(fileContents).to.contains('};\nexport default obj;\n'); // export default obj + file close
expect(fileContents).to.contains('};\nexport default versions;\n'); // export default obj + file close
expect(fileContents).not.to.contains('versionLong = \'1.0.0-');

done();
Expand Down Expand Up @@ -109,14 +109,14 @@ describe('appversion', function() {
expect(fileContents).to.contains('gitCommitHash?: string;');
expect(fileContents).to.contains('gitCommitDate?: string;');
expect(fileContents).to.contains('gitTag?: string;');
expect(fileContents).to.contains('};\nconst obj: TsAppVersion = {'); // interface end + obj start
expect(fileContents).to.contains('};\nexport const versions: TsAppVersion = {'); // interface end + obj start

// data test
expect(fileContents).to.contains('version: \'1.0.0\',');
expect(fileContents).to.contains('name: \'test\',');
expect(fileContents).to.contains('description: \'test description\',');
expect(fileContents).to.contains('versionLong: \'1.0.0-');
expect(fileContents).to.contains('};\nexport default obj;\n'); // export default obj + file close
expect(fileContents).to.contains('};\nexport default versions;\n'); // export default obj + file close
expect(fileContents).to.not.contains('versionLong: \'1.0.0-\'');

done();
Expand Down Expand Up @@ -153,14 +153,14 @@ describe('appversion', function() {
expect(fileContents).to.contains('gitCommitHash?: string;');
expect(fileContents).to.contains('gitCommitDate?: string;');
expect(fileContents).to.contains('gitTag?: string;');
expect(fileContents).to.contains('};\nconst obj: TsAppVersion = {'); // interface end + obj start
expect(fileContents).to.contains('};\nexport const versions: TsAppVersion = {'); // interface end + obj start

// data test
expect(fileContents).to.contains('version: \'1.0.0\',');
expect(fileContents).to.contains('name: \'test\',');
expect(fileContents).to.contains('versionLong: \'1.0.0-');
expect(fileContents).to.not.contains('versionLong: \'1.0.0-\'');
expect(fileContents).to.contains('};\nexport default obj;\n'); // export default obj + file close
expect(fileContents).to.contains('};\nexport default versions;\n'); // export default obj + file close
expect(fileContents).to.not.contains('description: \'');

done();
Expand Down Expand Up @@ -196,14 +196,14 @@ describe('appversion', function() {
expect(fileContents).to.contains('gitCommitHash?: string;');
expect(fileContents).to.contains('gitCommitDate?: string;');
expect(fileContents).to.contains('gitTag?: string;');
expect(fileContents).to.contains('};\nconst obj: TsAppVersion = {'); // interface end + obj start
expect(fileContents).to.contains('};\nexport const versions: TsAppVersion = {'); // interface end + obj start

// data test
expect(fileContents).to.contains('version: \'1.0.0\',');
expect(fileContents).to.contains('name: \'test\',');
expect(fileContents).to.contains('description: \'test description\',');
expect(fileContents).to.contains('versionLong: \'1.0.0-');
expect(fileContents).to.contains('};\nexport default obj;\n'); // export default obj + file close
expect(fileContents).to.contains('};\nexport default versions;\n'); // export default obj + file close
expect(fileContents).to.not.contains('versionLong: \'1.0.0-\'');

done();
Expand Down Expand Up @@ -241,14 +241,14 @@ describe('appversion', function() {
expect(fileContents).to.contains('gitCommitHash?: string;');
expect(fileContents).to.contains('gitCommitDate?: string;');
expect(fileContents).to.contains('gitTag?: string;');
expect(fileContents).to.contains('};\nconst obj: TsAppVersion = {'); // interface end + obj start
expect(fileContents).to.contains('};\nexport const versions: TsAppVersion = {'); // interface end + obj start

// data test
expect(fileContents).to.contains('version: \'1.0.0\'');
expect(fileContents).to.contains('name: \'test\'');
expect(fileContents).to.contains('description: \'test description\'');
expect(fileContents).to.contains('versionLong: \'1.0.0-');
expect(fileContents).to.contains('};\nexport default obj;\n'); // export default obj + file close
expect(fileContents).to.contains('};\nexport default versions;\n'); // export default obj + file close

expect(fileContents).to.not.contains('versionLong: \'1.0.0-\'');

Expand Down

0 comments on commit 66d0296

Please sign in to comment.