mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-03 06:07:41 +00:00
Merge pull request #16478 from keymanapp/chore/developer/server-remove-environment-version-duplication
chore(developer): remove duplicated versioning information from Server
This commit is contained in:
commit
dd40dfcfbd
7 changed files with 42 additions and 125 deletions
|
|
@ -4,11 +4,6 @@
|
|||
* Environmental variables and paths
|
||||
*/
|
||||
import path from 'node:path';
|
||||
import { extractVersionData } from './version-data.js';
|
||||
// TODO: environment should be just KEYMAN_VERSION
|
||||
|
||||
import KEYMAN_VERSION from "@keymanapp/keyman-version";
|
||||
export const environment = extractVersionData(KEYMAN_VERSION.VERSION_WITH_TAG);
|
||||
|
||||
/**
|
||||
* @returns base path for the running server -- where index.js is stored
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
import { KeymanUrls } from '@keymanapp/developer-utils';
|
||||
/*
|
||||
* Keyman is copyright (C) SIL Global. MIT License.
|
||||
*
|
||||
* API: return list of packages under testing and urls for installing in mobile
|
||||
* apps
|
||||
*/
|
||||
import * as express from 'express';
|
||||
import { KeymanUrls } from '@keymanapp/developer-utils';
|
||||
import KEYMAN_VERSION from '@keymanapp/keyman-version';
|
||||
import { data } from "../../data.js";
|
||||
import { environment } from '../../environment.js';
|
||||
|
||||
export default function handleIncPackagesJson (req: express.Request, res: express.Response) {
|
||||
const packages = Object.keys(data.packages).map(id => { return { id: id, filename: id+'.kmp', name: data.packages[id].name} });
|
||||
res.send({
|
||||
packages: packages,
|
||||
urls: {
|
||||
installLinkAndroid: KeymanUrls.KeymanDeveloper_KeymanForAndroidDownload(environment.versionRelease),
|
||||
installLinkIos: KeymanUrls.KeymanDeveloper_KeymanForIosDownload(environment.versionRelease),
|
||||
installLinkAndroid: KeymanUrls.KeymanDeveloper_KeymanForAndroidDownload(KEYMAN_VERSION.VERSION_RELEASE),
|
||||
installLinkIos: KeymanUrls.KeymanDeveloper_KeymanForIosDownload(KEYMAN_VERSION.VERSION_RELEASE),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
/*
|
||||
* Keyman is copyright (C) SIL Global. MIT License.
|
||||
*
|
||||
* Keyman Developer Server main program
|
||||
*/
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import chalk from 'chalk';
|
||||
import express from 'express';
|
||||
import multer from 'multer';
|
||||
import * as ws from 'ws';
|
||||
import KEYMAN_VERSION from '@keymanapp/keyman-version';
|
||||
import { KeymanSentry } from './KeymanSentry.js';
|
||||
import { standardPaths } from './standardPaths.js';
|
||||
import { environment } from './environment.js';
|
||||
import setupRoutes from './routes.js';
|
||||
import { shutdown } from './shutdown.js';
|
||||
import { initTray } from './tray.js';
|
||||
|
|
@ -23,7 +28,7 @@ const options = {
|
|||
// set of options if an error occurs.
|
||||
await loadOptions();
|
||||
|
||||
console.log(`Starting Keyman Developer Server ${environment.versionWithTag}, listening on port ${getOption('web host port')}.`);
|
||||
console.log(`Starting Keyman Developer Server ${KEYMAN_VERSION.VERSION_WITH_TAG}, listening on port ${getOption('web host port')}.`);
|
||||
|
||||
KeymanSentry.init();
|
||||
try {
|
||||
|
|
@ -74,7 +79,7 @@ export async function run() {
|
|||
|
||||
/* Setup routes */
|
||||
|
||||
setupRoutes(app, upload, wsServer, environment);
|
||||
setupRoutes(app, upload, wsServer);
|
||||
|
||||
/* Start the web server */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
import * as express from 'express';
|
||||
import * as ws from 'ws';
|
||||
import * as multer from 'multer';
|
||||
import KEYMAN_VERSION from '@keymanapp/keyman-version';
|
||||
import handleIncKeyboardsJs from './handlers/inc/keyboards-js.js';
|
||||
import { data, DebugFont, DebugKeyboard, DebugModel, DebugObject, DebugPackage, isValidId } from './data.js';
|
||||
import apiGet from './handlers/api/debugobject/get.js';
|
||||
|
|
@ -16,23 +17,20 @@ import apiUnregister from './handlers/api/debugobject/unregister.js';
|
|||
import handleIncPackagesJson from './handlers/inc/packages-json.js';
|
||||
import apiPackageRegister from './handlers/api/package/register.js';
|
||||
import handleIncKeyboardsCss from './handlers/inc/keyboards-css.js';
|
||||
import { Environment } from './version-data.js';
|
||||
import { standardPaths } from './standardPaths.js';
|
||||
import chalk from 'chalk';
|
||||
import { shutdown } from './shutdown.js';
|
||||
import { getOption } from './options.js';
|
||||
import { serverSitePath } from './environment.js';
|
||||
|
||||
export default function setupRoutes(app: express.Express, upload: multer.Multer, wsServer: ws.WebSocketServer, environment: Environment ) {
|
||||
export default function setupRoutes(app: express.Express, upload: multer.Multer, wsServer: ws.WebSocketServer ) {
|
||||
|
||||
/* Middleware - JSON and logging */
|
||||
|
||||
app.use(express.json()); // for parsing application/json
|
||||
|
||||
app.use(function (req, _res, next) {
|
||||
// if(environment.environment == 'local') {
|
||||
console.log(req.method + ' ' + req.path);
|
||||
// }
|
||||
console.log(req.method + ' ' + req.path);
|
||||
next();
|
||||
});
|
||||
|
||||
|
|
@ -99,7 +97,7 @@ export default function setupRoutes(app: express.Express, upload: multer.Multer,
|
|||
app.get('/inc/packages.json', handleIncPackagesJson);
|
||||
|
||||
app.get('/api-public/version', (req,res,next)=>{
|
||||
res.json({version: environment.versionWithTag, isApiAvailable: isLocalhost(req)});
|
||||
res.json({version: KEYMAN_VERSION.VERSION_WITH_TAG, isApiAvailable: isLocalhost(req)});
|
||||
next();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
Version information from builder-basic.inc.sh:
|
||||
|
||||
# KEYMAN_VERSION: Full current build version, e.g. "14.0.1"
|
||||
# [KEYMAN_VERSION_WIN: Full current build version for Windows, e.g. "14.0.1.0"]
|
||||
# KEYMAN_VERSION_RELEASE: Current release version, e.g. "14.0"
|
||||
# KEYMAN_VERSION_MAJOR: Major version, e.g. "14"
|
||||
# KEYMAN_VERSION_MINOR: Minor version, e.g. "0"
|
||||
# KEYMAN_VERSION_PATCH: Patch version, e.g. "1"
|
||||
# KEYMAN_TIER: Current tier, one of "alpha", "beta" or "stable"
|
||||
# KEYMAN_VERSION_TAG: Tier + Pull Request + Location of build [-alpha|-beta][-test[-1234]][-local]
|
||||
# KEYMAN_VERSION_WITH_TAG: e.g. "14.0.1-alpha-test-1234" or "14.0.5-beta-local" or "14.0.1-alpha-test"
|
||||
# [KEYMAN_ROOT: fully resolved root path of Keyman repository]
|
||||
# KEYMAN_VERSION_ENVIRONMENT: One of: local, test, alpha, beta, stable
|
||||
# KEYMAN_VERSION_GIT_TAG: Git tag for the release, "release@$KEYMAN_VERSION_WITH_TAG", e.g. "release@14.0.1-alpha-test-1234"
|
||||
*/
|
||||
|
||||
export interface Environment {
|
||||
version: string;
|
||||
versionRelease: string;
|
||||
versionMajor: string;
|
||||
versionMinor: string;
|
||||
versionPatch: string;
|
||||
tier: string;
|
||||
versionTag: string;
|
||||
versionWithTag: string;
|
||||
versionEnvironment: string;
|
||||
versionGitTag: string;
|
||||
// Pull Request Data
|
||||
pr: string;
|
||||
}
|
||||
|
||||
export function extractVersionData(version: string): Environment {
|
||||
const versionData = /^(\d+)\.(\d+)\.(\d+)((?:-(alpha|beta))?(?:-(test|local))?(?:-(\d+))?)$/.exec(version);
|
||||
if(!versionData) return null;
|
||||
|
||||
return {
|
||||
version: `${versionData[1]}.${versionData[2]}.${versionData[3]}`,
|
||||
versionRelease: `${versionData[1]}.${versionData[2]}`,
|
||||
versionMajor: versionData[1],
|
||||
versionMinor: versionData[2],
|
||||
versionPatch: versionData[3],
|
||||
tier: versionData[5] || 'stable',
|
||||
versionTag: versionData[4],
|
||||
versionWithTag: version,
|
||||
versionEnvironment: versionData[6] || versionData[5] || 'stable',
|
||||
versionGitTag: 'release@'+version,
|
||||
|
||||
pr: versionData[7] || ''
|
||||
};
|
||||
};
|
||||
|
||||
20
developer/src/server/test/environment.tests.ts
Normal file
20
developer/src/server/test/environment.tests.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Keyman is copyright (C) SIL Global. MIT License.
|
||||
*/
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import {assert} from 'chai';
|
||||
import 'mocha';
|
||||
import { serverBasePath, serverSitePath } from '../src/environment.js';
|
||||
|
||||
describe('serverBasePath', function() {
|
||||
it('should find index.js in the base path', function() {
|
||||
assert.isTrue(fs.existsSync(path.join(serverBasePath(), 'index.js')));
|
||||
});
|
||||
});
|
||||
|
||||
describe('serverSitePath', function() {
|
||||
it('should find index.html in the base path', function() {
|
||||
assert.isTrue(fs.existsSync(path.join(serverSitePath(), 'index.html')));
|
||||
});
|
||||
});
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
import {assert} from 'chai';
|
||||
import 'mocha';
|
||||
import { extractVersionData } from '../src/version-data.js';
|
||||
|
||||
describe('extractVersionData', function() {
|
||||
it('should parse version strings', function() {
|
||||
let v = extractVersionData('14.0.283');
|
||||
assert.equal(v.version, '14.0.283');
|
||||
assert.equal(v.versionRelease, '14.0');
|
||||
assert.equal(v.versionMajor, '14');
|
||||
assert.equal(v.versionMinor, '0');
|
||||
assert.equal(v.versionPatch, '283');
|
||||
assert.equal(v.tier, 'stable');
|
||||
assert.equal(v.versionTag, '');
|
||||
assert.equal(v.versionWithTag, '14.0.283');
|
||||
assert.equal(v.versionEnvironment, 'stable');
|
||||
assert.equal(v.pr, '');
|
||||
|
||||
v = extractVersionData('14.0.283-beta');
|
||||
assert.equal(v.version, '14.0.283');
|
||||
assert.equal(v.versionRelease, '14.0');
|
||||
assert.equal(v.versionMajor, '14');
|
||||
assert.equal(v.versionMinor, '0');
|
||||
assert.equal(v.versionPatch, '283');
|
||||
assert.equal(v.tier, 'beta');
|
||||
assert.equal(v.versionTag, '-beta');
|
||||
assert.equal(v.versionWithTag, '14.0.283-beta');
|
||||
assert.equal(v.versionEnvironment, 'beta');
|
||||
assert.equal(v.pr, '');
|
||||
|
||||
v = extractVersionData('14.0.283-alpha-local');
|
||||
assert.equal(v.version, '14.0.283');
|
||||
assert.equal(v.versionRelease, '14.0');
|
||||
assert.equal(v.versionMajor, '14');
|
||||
assert.equal(v.versionMinor, '0');
|
||||
assert.equal(v.versionPatch, '283');
|
||||
assert.equal(v.tier, 'alpha');
|
||||
assert.equal(v.versionTag, '-alpha-local');
|
||||
assert.equal(v.versionWithTag, '14.0.283-alpha-local');
|
||||
assert.equal(v.versionEnvironment, 'local');
|
||||
assert.equal(v.pr, '');
|
||||
|
||||
v = extractVersionData('14.0.283-alpha-test-1234');
|
||||
assert.equal(v.version, '14.0.283');
|
||||
assert.equal(v.versionRelease, '14.0');
|
||||
assert.equal(v.versionMajor, '14');
|
||||
assert.equal(v.versionMinor, '0');
|
||||
assert.equal(v.versionPatch, '283');
|
||||
assert.equal(v.tier, 'alpha');
|
||||
assert.equal(v.versionTag, '-alpha-test-1234');
|
||||
assert.equal(v.versionWithTag, '14.0.283-alpha-test-1234');
|
||||
assert.equal(v.versionEnvironment, 'test');
|
||||
assert.equal(v.pr, '1234');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue