Skip to content

Commit

Permalink
Merge pull request #10218 from keymanapp/chore/developer/10162-honor-…
Browse files Browse the repository at this point in the history
…prompt-to-upgrade-in-kmc

chore(developer): honor prompt to upgrade in kmc
  • Loading branch information
mcdurdin authored Jan 2, 2024
2 parents edc9507 + 3d250fe commit ee6814c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion developer/src/common/web/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { validateMITLicense } from './src/validate-mit-license.js';
export { KeymanSentry } from './src/KeymanSentry.js';
export { getOption, loadOptions } from './src/options.js';
export { getOption, loadOptions, clearOptions } from './src/options.js';
15 changes: 14 additions & 1 deletion developer/src/common/web/utils/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ export interface KeymanDeveloperOptions {
"automatically report usage"?: boolean;
"toolbar visible"?: boolean;
"active project"?: string;
"prompt to upgrade projects"?: boolean;
};

type KeymanDeveloperOption = keyof KeymanDeveloperOptions;

// Default has no options set, and unit tests will use the defaults (won't call
// `loadOptions()`)
let options: KeymanDeveloperOptions = {};

// We only load the options from disk once on first use
let options: KeymanDeveloperOptions = null;
let optionsLoaded = false;

export async function loadOptions(): Promise<KeymanDeveloperOptions> {
Expand Down Expand Up @@ -74,9 +78,18 @@ export async function loadOptions(): Promise<KeymanDeveloperOptions> {
// low level.
options = {};
}
optionsLoaded = true;
return options;
}

export function getOption<T extends KeymanDeveloperOption>(valueName: T, defaultValue: KeymanDeveloperOptions[T]): KeymanDeveloperOptions[T] {
return options[valueName] ?? defaultValue;
}

/**
* unit tests will clear options before running, for consistency
*/
export function clearOptions() {
options = {};
optionsLoaded = true;
}
5 changes: 4 additions & 1 deletion developer/src/kmc/src/commands/buildClasses/BuildProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { buildActivities, buildKeyboardInfoActivity, buildModelInfoActivity } fr
import { InfrastructureMessages } from '../../messages/infrastructureMessages.js';
import { loadProject } from '../../util/projectLoader.js';
import { ExtendedCompilerOptions } from 'src/util/extendedCompilerOptions.js';
import { getOption } from '@keymanapp/developer-utils';

export class BuildProject extends BuildActivity {
public get name(): string { return 'Project'; }
Expand Down Expand Up @@ -43,7 +44,9 @@ class ProjectBuilder {

// Give a hint if the project is v1.0
if(this.project.options.version != '2.0') {
this.callbacks.reportMessage(InfrastructureMessages.Hint_ProjectIsVersion10());
if(getOption("prompt to upgrade projects", true)) {
this.callbacks.reportMessage(InfrastructureMessages.Hint_ProjectIsVersion10());
}
}

// Go through the various file types and build them
Expand Down
6 changes: 5 additions & 1 deletion developer/src/kmc/test/test-build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
import { clearOptions } from '@keymanapp/developer-utils';
import { assert } from 'chai';
import 'mocha';
import { BuildProject } from '../src/commands/buildClasses/BuildProject.js';
Expand All @@ -13,7 +14,10 @@ interface CompilerWarningsAsErrorsTruthTable {
};

describe('compilerWarningsAsErrors', function () {
beforeEach(() => callbacks.clear());
beforeEach(() => {
callbacks.clear();
clearOptions();
});

// The CLI option should override the project setting

Expand Down
4 changes: 4 additions & 0 deletions developer/src/kmc/test/test-infrastructureMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import { NodeCompilerCallbacks } from '../src/util/NodeCompilerCallbacks.js';
import { CompilerErrorNamespace, CompilerEvent } from '@keymanapp/common-types';
import { unitTestEndpoints } from '../src/commands/build.js';
import { KmnCompilerMessages } from '@keymanapp/kmc-kmn';
import { clearOptions } from '@keymanapp/developer-utils';

describe('InfrastructureMessages', function () {

beforeEach(clearOptions);

it('should have a valid InfrastructureMessages object', function() {
return verifyCompilerMessagesObject(InfrastructureMessages, CompilerErrorNamespace.Infrastructure);
});
Expand Down
2 changes: 2 additions & 0 deletions developer/src/kmc/test/test-project-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import 'mocha';
import { BuildProject } from '../src/commands/buildClasses/BuildProject.js';
import { makePathToFixture } from './helpers/index.js';
import { InfrastructureMessages } from '../src/messages/infrastructureMessages.js';
import { clearOptions } from '@keymanapp/developer-utils';

const callbacks = new TestCompilerCallbacks();

describe('BuildProject', function () {
it('should build a keyboard project', async function() {
clearOptions();
const builder = new BuildProject();
const path = makePathToFixture('relative_paths', 'k_000___null_keyboard.kpj');
let result = await builder.build(path, null, callbacks, {
Expand Down

0 comments on commit ee6814c

Please sign in to comment.