Browse Source

refactor(admin-ui): Set UI version without requiring package.json

Michael Bromley 5 years ago
parent
commit
71d7e1310e

+ 8 - 7
packages/admin-ui/package.json

@@ -4,16 +4,16 @@
   "license": "MIT",
   "scripts": {
     "ng": "ng",
-    "start": "ng serve",
-    "build": "yarn reset-extensions && ng build --prod && yarn build:compiler",
-    "build:library": "node build-public-api.js && ng build vendure-admin-lib",
+    "start": "node scripts/set-version.js && ng serve",
+    "build": "yarn reset-extensions && ng build --prod",
+    "build:library": "node scripts/set-version.js && node scripts/build-public-api.js && ng build vendure-admin-lib --prod",
     "watch": "ng build --watch=true",
     "build:compiler": "tsc -p tsconfig.compiler.json",
     "test": "ng test --watch=false --browsers=ChromeHeadlessCI --progress=false",
     "lint": "tslint --fix",
     "reset-extensions": "rimraf ./src/app/extensions/modules && rimraf ./src/app/extensions/*.generated && rimraf ./src/app/extensions/*.temp",
     "extract-translations": "ngx-translate-extract --input ./src --output ./src/i18n-messages/en.json --clean --sort --format namespaced-json --format-indentation \"  \" -m _",
-    "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
+    "ngcc": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
   },
   "publishConfig": {
     "access": "public"
@@ -37,10 +37,11 @@
     "@angular/platform-browser": "^9.0.2",
     "@angular/platform-browser-dynamic": "^9.0.2",
     "@angular/router": "^9.0.2",
+    "@vendure/common": "^0.9.0",
     "@biesbjerg/ngx-translate-extract-marker": "^1.0.0",
-    "@clr/angular": "^3.0.0-rc.1",
-    "@clr/core": "^3.0.0-rc.1",
-    "@clr/icons": "^3.0.0-rc.1",
+    "@clr/angular": "^3.0.0",
+    "@clr/core": "^3.0.0",
+    "@clr/icons": "^3.0.0",
     "@clr/ui": "^3.0.0-rc.1",
     "@ng-select/ng-select": "^3.7.2",
     "@ngx-translate/core": "^11.0.1",

+ 1 - 1
packages/admin-ui/build-public-api.js → packages/admin-ui/scripts/build-public-api.js

@@ -7,7 +7,7 @@ const path = require('path');
 
 console.log('Generating public api...');
 const SOURCES_DIR = path.join(__dirname, 'src/app');
-const APP_SOURCE_FILE_PATTERN = /\.(pipe|service|component|module|routes|directive|guard)\.ts$/;
+const APP_SOURCE_FILE_PATTERN = /\.(pipe|service|component|module|routes|directive|guard|config)\.ts$/;
 const files = [];
 const publicApiFilePath = path.join(__dirname, 'src');
 forMatchingFiles(SOURCES_DIR, APP_SOURCE_FILE_PATTERN, filename => {

+ 17 - 0
packages/admin-ui/scripts/set-version.js

@@ -0,0 +1,17 @@
+const path = require('path');
+const fs = require('fs');
+const appVersion = require('../package.json').version;
+
+const versionFilePath = path.join(__dirname + '/../src/environments/version.ts');
+
+const src = `export const ADMIN_UI_VERSION = '${appVersion}';
+`;
+
+// ensure version module pulls value from package.json
+fs.writeFile(versionFilePath, src, { flat: 'w' }, function(err) {
+    if (err) {
+        return console.log(err);
+    }
+
+    console.log(`Updating application version ${appVersion}`);
+});

+ 2 - 2
packages/admin-ui/src/environments/environment.prod.ts

@@ -1,7 +1,7 @@
-import { getVersion } from './get-version';
+import { ADMIN_UI_VERSION } from './version';
 
 declare function require(path: string): any;
 export const environment = {
     production: true,
-    version: getVersion(),
+    version: ADMIN_UI_VERSION,
 };

+ 2 - 2
packages/admin-ui/src/environments/environment.ts

@@ -1,13 +1,13 @@
 // This file can be replaced during build by using the `fileReplacements` array.
 // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
 // The list of file replacements can be found in `angular.json`.
-import { getVersion } from './get-version';
+import { ADMIN_UI_VERSION } from './version';
 
 declare function require(path: string): any;
 
 export const environment = {
     production: false,
-    version: getVersion(),
+    version: ADMIN_UI_VERSION + '-dev',
 };
 
 /*

+ 0 - 16
packages/admin-ui/src/environments/get-version.ts

@@ -1,16 +0,0 @@
-export function getVersion(): string {
-    let version: string | undefined;
-    try {
-        version = require('../../../core/package.json').version;
-    } catch (e) {
-        /**/
-    }
-    if (!version) {
-        try {
-            version = require('../../../../core/package.json').version;
-        } catch (e) {
-            /**/
-        }
-    }
-    return version || 'unknown';
-}

+ 1 - 0
packages/admin-ui/src/environments/version.ts

@@ -0,0 +1 @@
+export const ADMIN_UI_VERSION = '0.9.0';