diff --git a/bootstrap.py b/bootstrap.py index 5c97a2f8..c90ab38f 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -2,14 +2,10 @@ import os import os.path as op -from distutils import dir_util -import glob -import json import platform import sys import subprocess import shlex -import shutil SLUG = 'lettercraft' WINDOWS = (platform.system() == 'Windows') @@ -167,123 +163,6 @@ def make_create_db_command(psql_cmd): psql_cmd + ' -f ' + op.join('backend', 'create_db.sql'), ) -def merge_json(target, source): - for key, value in source.items(): - if value is None: - del target[key] - elif key in target and isinstance(target[key], dict) and \ - isinstance(source[key], dict): - merge_json(target[key], source[key]) - else: - target[key] = value - return target - - -def modify_angular_json(): - with open('frontend/angular.json', 'r') as file: - data = json.load(file) - try: - project = 'lettercraft'.replace('_', '-') - data['projects'][project]['architect']['test']['options']['karmaConfig'] = 'karma.conf.js' - for lang in 'en:english'.split(','): - [code, lang_name] = lang.split(':') - production = merge_json({}, data['projects'][project]['architect']['build']['configurations']['production']) - production['outputPath'] = f'dist/{code}' - production['i18nFile'] = f'locale/messages.{code}.xlf' - production['i18nFormat'] = 'xlf' - production['i18nLocale'] = code - production['i18nMissingTranslation'] = 'error' - data['projects'][project]['architect']['build']['configurations'][f'production-{code}'] = production - - serve = merge_json({}, data['projects'][project]['architect']['serve']['configurations']['production']) - serve['browserTarget'] += f'-{code}' - data['projects'][project]['architect']['serve']['configurations'][code] = serve - - data['projects'][project]['architect']['build']['options']['outputPath'] = \ - data['projects'][project]['architect']['build']['configurations']['production']['outputPath'] = 'dist' - except Exception as error: - print("Oh no! :( Maybe the format changed?") - print(json.dumps(data, indent=4)) - raise error - with open('frontend/angular.json', 'w') as file: - json.dump(data, file, indent=4) - - -def activate_frontend(): - framework = 'angular' - os.rename('package.angular.json', 'package.json') - - if framework == 'backbone': - os.rename('frontend.backbone', 'frontend') - shutil.move(op.join('frontend', 'proxy.json'), 'proxy.json') - override_package_json() - elif framework == 'angular': - project_name = 'lettercraft'.replace('_', '-') - Command( - 'Install dependencies', - ['yarn', 'install', '--ignore-scripts'] - )() - Command( - 'Creating project', - ['yarn', 'ng', 'new', project_name, '--prefix=lc', - '--skip-git=true', - '--skip-install=true', - '--package-manager=yarn', - '--style=scss', - '--routing=true'] - )() - dir_util.copy_tree('frontend.angular', project_name) - os.rename(project_name, 'frontend') - shutil.move(op.join('frontend', 'proxy.conf.json'), 'proxy.conf.json') - override_package_json() - Command( - 'Install frontend dependencies using Yarn', - ['yarn'], - cwd="frontend" - )() - # Remove editorconfig - os.remove(os.path.join('frontend', '.editorconfig')) - modify_angular_json() - Command( - 'ng add @angular/localize', - ['yarn', 'ng', 'add', '@angular/localize', '--skip-confirmation'], - cwd="frontend" - )() - Command( - 'Creating localizations', - ['yarn', 'i18n'], - cwd="frontend" - )() - for lang in 'en:english'.split(','): - [code, lang_name] = lang.split(':') - shutil.copyfile('frontend/locale/messages.xlf', f'frontend/locale/messages.{code}.xlf') - if '4200' != '4200': - Command( - 'Set frontend port', - ['yarn', 'ng', 'config', "projects.lettercraft.architect.serve.options.port", '4200'], - cwd="frontend" - )() - else: - print('Unknown framework angular specified!') - # remove other frameworks - for path in glob.glob("frontend.*"): - shutil.rmtree(path) - for path in glob.glob("package.*.json"): - os.remove(path) - - -def override_package_json(): - if os.path.isfile('frontend/package.overwrite.json'): - print('Overriding package.json') - with open('frontend/package.overwrite.json', 'r') as file: - overwrite = json.load(file) - with open('frontend/package.json', 'r') as file: - data = json.load(file) - with open('frontend/package.json', 'w') as file: - merge_json(data, overwrite) - json.dump(data, file, indent=4) - os.remove('frontend/package.overwrite.json') - install_pip_tools = Command( 'Install pip-tools', diff --git a/frontend/angular.json b/frontend/angular.json index 3ee9be5a..180d5b0f 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -62,26 +62,6 @@ "extractLicenses": false, "sourceMap": true, "namedChunks": true - }, - "production-en": { - "budgets": [ - { - "type": "initial", - "maximumWarning": "500kb", - "maximumError": "1mb" - }, - { - "type": "anyComponentStyle", - "maximumWarning": "2kb", - "maximumError": "4kb" - } - ], - "outputHashing": "all", - "outputPath": "dist/en", - "i18nFile": "locale/messages.en.xlf", - "i18nFormat": "xlf", - "i18nLocale": "en", - "i18nMissingTranslation": "error" } }, "defaultConfiguration": "production" @@ -94,19 +74,10 @@ }, "development": { "browserTarget": "lettercraft:build:development" - }, - "en": { - "browserTarget": "lettercraft:build:production-en" } }, "defaultConfiguration": "development" }, - "extract-i18n": { - "builder": "@angular-devkit/build-angular:extract-i18n", - "options": { - "browserTarget": "lettercraft:build" - } - }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { @@ -130,4 +101,4 @@ } } } -} \ No newline at end of file +} diff --git a/frontend/build/build-pre.js b/frontend/build/build-pre.js index e7324bac..a0f74e58 100644 --- a/frontend/build/build-pre.js +++ b/frontend/build/build-pre.js @@ -6,64 +6,15 @@ const { exec } = require('child_process'); console.log(colors.cyan('\nRunning pre-build tasks')); -async function getHash() { - return new Promise((resolve, reject) => { - exec('git rev-parse HEAD', (error, stdout, stderr) => { - if (error) { - reject(`error: ${error.message}`); - return; - } - if (stderr) { - reject(`stderr: ${stderr}`); - return; - } - - resolve(stdout.trim()); - }); - }); -} - -async function getRemoteUrl() { - return new Promise((resolve, reject) => { - exec('git config --get remote.origin.url', (error, stdout, stderr) => { - if (error) { - reject(`error: ${error.message}`); - return; - } - if (stderr) { - reject(`stderr: ${stderr}`); - return; - } - - // format is either: - // git@github.com:UUDigitalHumanitieslab/lettercraft.git - // or https://github.com/UUDigitalHumanitieslab/lettercraft.git - // or https://USERNAME:SECRET@github.com/UUDigitalHumanitieslab/lettercraft.git/ - - // remove https:// - let sourceUrl = stdout.replace(/^https?:\/\//, '').trim(); - // remove git@ or USERNAME:SECRET@ - sourceUrl = sourceUrl.replace(/^[^@]+@/, '').trim(); - // replace : with / - sourceUrl = sourceUrl.replace(':', '/'); - // remove .git/ - sourceUrl = sourceUrl.replace(/\.git\/?\n?$/, ''); - resolve('https://' + sourceUrl); - }); - }); -} - -Promise.all([getHash(), getRemoteUrl()]).then(([hash, remoteUrl]) => { - writeVersion(hash, remoteUrl); -}).catch((error) => { +try { + writeVersion(); +} catch { console.log(`${colors.red('Could not update version: ')} ${error}`); -}); +} -function writeVersion(hash, remoteUrl) { +function writeVersion() { const versionFilePath = path.join(__dirname + '/../src/environments/version.ts'); const src = `export const version = '${appVersion}'; -export const buildTime = '${new Date()}'; -export const sourceUrl = '${remoteUrl}/tree/${hash}'; `; // ensure version module pulls value from package.json @@ -74,6 +25,5 @@ export const sourceUrl = '${remoteUrl}/tree/${hash}'; console.log(colors.green(`Updating application version ${colors.yellow(appVersion)}`)); console.log(`${colors.green('Writing version module to ')}${colors.yellow(versionFilePath)}\n`); - console.log(src); }); } diff --git a/frontend/locale/messages.en.xlf b/frontend/locale/messages.en.xlf deleted file mode 100644 index 7f3dcd60..00000000 --- a/frontend/locale/messages.en.xlf +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - Lettercraft & Epistolary Performance in Medieval Europe - - src/app/footer/footer.component.html - 6 - - - - Source code (BSD 3-Clause License) - - src/app/footer/footer.component.html - 9,10 - - - - Version: - - src/app/footer/footer.component.html - 12 - - - - (source) - - src/app/footer/footer.component.html - 12 - - - - Centre for Digital Humanities, Utrecht University - - src/app/footer/footer.component.html - 18 - - - - Home - - src/app/home/home.component.html - 1 - - - - Lettercraft & Epistolary Performance in Medieval Europe - - src/app/menu/menu.component.html - 4,6 - - - - Home - - src/app/menu/menu.component.html - 19,21 - - - - - diff --git a/frontend/locale/messages.xlf b/frontend/locale/messages.xlf deleted file mode 100644 index 7f3dcd60..00000000 --- a/frontend/locale/messages.xlf +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - Lettercraft & Epistolary Performance in Medieval Europe - - src/app/footer/footer.component.html - 6 - - - - Source code (BSD 3-Clause License) - - src/app/footer/footer.component.html - 9,10 - - - - Version: - - src/app/footer/footer.component.html - 12 - - - - (source) - - src/app/footer/footer.component.html - 12 - - - - Centre for Digital Humanities, Utrecht University - - src/app/footer/footer.component.html - 18 - - - - Home - - src/app/home/home.component.html - 1 - - - - Lettercraft & Epistolary Performance in Medieval Europe - - src/app/menu/menu.component.html - 4,6 - - - - Home - - src/app/menu/menu.component.html - 19,21 - - - - - diff --git a/frontend/package.json b/frontend/package.json index b71b86e1..13c7e603 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,16 +4,14 @@ "start": "yarn serve", "build": "ng build --deploy-url='/static/'", "watch": "ng build --watch", - "test": "ng test --watch=true", + "test": "ng test --watch=false", "prebuild": "node ./build/build-pre.js", - "build:en": "ng build --deploy-url='/static/' --configuration=production-en", - "i18n": "ng extract-i18n --output-path locale", "preserve": "yarn prebuild", "serve": "ng serve --proxy-config ../proxy.conf.json", "serve:en": "ng serve --proxy-config ../proxy.conf.json --configuration=en", "stop": "lsof -t -i tcp:4200 | xargs kill -9 || echo \"not running\"", "pretest": "yarn prebuild", - "test-once": "ng test --watch=false" + "watch-test": "ng test --watch=true" }, "private": true, "dependencies": { @@ -31,19 +29,21 @@ "@ng-bootstrap/ng-bootstrap": "^15.0.0", "@ngrx/effects": "^16.0.0", "@ngrx/store": "^16.0.0", - "bootstrap": "^5.2.3", "@popperjs/core": "^2.11.6", + "bootstrap": "^5.2.3", "colors": "^1.4.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", + "underscore": "^1.13.6", "zone.js": "~0.13.3" }, "devDependencies": { "@angular-devkit/build-angular": "^16.2.10", "@angular/cli": "~16.2.10", "@angular/compiler-cli": "^16.2.12", - "@angular/localize": "16.2.12", + "@angular/localize": "^16.2.12", "@types/jasmine": "~4.3.0", + "@types/underscore": "^1.11.15", "jasmine-core": "~4.5.0", "karma": "~6.4.0", "karma-chrome-launcher": "~3.1.0", diff --git a/frontend/src/app/core/footer/footer.component.html b/frontend/src/app/core/footer/footer.component.html index 24daa0e6..e2e9a232 100644 --- a/frontend/src/app/core/footer/footer.component.html +++ b/frontend/src/app/core/footer/footer.component.html @@ -2,19 +2,13 @@
-

Lettercraft & Epistolary Performance in Medieval Europe

+

Lettercraft & Epistolary Performance in Medieval Europe

-

- - Source code - - (BSD 3-Clause License) -

+

Version: {{environment.version}}

- Version: - {{environment.version}} - (source) + Source code (BSD 3-Clause License)

@@ -22,7 +16,6 @@ href="https://cdh.uu.nl/centre-for-digital-humanities/research-software-lab/"> Centre for Digital Humanities, Utrecht University
diff --git a/frontend/src/app/core/footer/footer.component.ts b/frontend/src/app/core/footer/footer.component.ts index e3a5efa7..c70f5ac2 100644 --- a/frontend/src/app/core/footer/footer.component.ts +++ b/frontend/src/app/core/footer/footer.component.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; -import { environment } from '../../../environments/environment'; +import { environment } from '@env'; @Component({ selector: 'lc-footer', diff --git a/frontend/src/app/core/menu/menu.component.html b/frontend/src/app/core/menu/menu.component.html index 4c73c4ed..3f11634a 100644 --- a/frontend/src/app/core/menu/menu.component.html +++ b/frontend/src/app/core/menu/menu.component.html @@ -1,7 +1,7 @@