Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(developer): add --for-publishing to kmc 🎺 #9717

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions developer/src/kmc-keyboard-info/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export interface KeyboardInfoSources {

/** Last modification date for files in the project folder 'YYYY-MM-DDThh:mm:ssZ' */
lastCommitDate?: string;

/** Return an error if project does not meet requirements of keyboards repository */
forPublishing: boolean;
};

export class KeyboardInfoCompiler {
Expand Down Expand Up @@ -121,15 +124,23 @@ export class KeyboardInfoCompiler {

// License

if(!kmpJsonData.options?.licenseFile) {
this.callbacks.reportMessage(KeyboardInfoCompilerMessages.Error_NoLicenseFound());
return null;
}
if(sources.forPublishing) {
// We will only verify the license if asked to do so, so that all keyboard
// projects can be built even if license is not present. Keyboards
// repository will always verify license
if(!kmpJsonData.options?.licenseFile) {
this.callbacks.reportMessage(KeyboardInfoCompilerMessages.Error_NoLicenseFound());
return null;
}

if(!this.isLicenseMIT(this.callbacks.resolveFilename(sources.kpsFilename, kmpJsonData.options.licenseFile))) {
return null;
if(!this.isLicenseMIT(this.callbacks.resolveFilename(sources.kpsFilename, kmpJsonData.options.licenseFile))) {
return null;
}
}

// Even if license is not verified, we set the .keyboard_info license to
// 'mit' to meet the schema requirements. The .keyboard_info file is only
// used by the keyboards repository, so this is a fair assumption to make.
keyboard_info.license = 'mit';

// isRTL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('keyboard-info-compiler', function () {
sourcePath: 'release/k/khmer_angkor',
kpsFilename,
jsFilename: jsFilename,
forPublishing: true,
});
} catch(e) {
callbacks.printMessages();
Expand Down
3 changes: 3 additions & 0 deletions developer/src/kmc-model-info/src/model-info-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class ModelInfoSources {

/** Last modification date for files in the project folder 'YYYY-MM-DDThh:mm:ssZ' */
lastCommitDate?: string;

/** Return an error if project does not meet requirements of lexical-models repository */
forPublishing: boolean;
};
/* c8 ignore stop */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('model-info-compiler', function () {
modelFileName,
sourcePath: 'release/sil/sil.cmo.bw',
kpsFilename,
forPublishing: true,
});
if(data == null) {
callbacks.printMessages();
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmc-model-info/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"rootDir": "src/",
"paths": {
"@keymanapp/common-types": ["../../../common/web/types/src/main"],
"@keymanapp/developer-utils": ["../developer/web/utils/index"],
"@keymanapp/developer-utils": ["../common/web/utils/index"],
}
},
"include": [
Expand Down
8 changes: 5 additions & 3 deletions developer/src/kmc/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import { expandFileLists } from '../util/fileLists.js';
import { isProject } from '../util/projectLoader.js';
import { buildTestData } from './buildTestData/index.js';
import { buildWindowsPackageInstaller } from './buildWindowsPackageInstaller/index.js';
//import { buildWindowsPackageInstaller } from './buildWindowsPackageInstaller/index.js';
import { ExtendedCompilerOptions } from 'src/util/extendedCompilerOptions.js';


function commandOptionsToCompilerOptions(options: any): CompilerOptions {
function commandOptionsToCompilerOptions(options: any): ExtendedCompilerOptions {
// We don't want to rename command line options to match the precise
// properties that we have in CompilerOptions, but nor do we want to rename
// CompilerOptions properties...
Expand All @@ -29,6 +28,8 @@ function commandOptionsToCompilerOptions(options: any): CompilerOptions {
saveDebug: options.debug,
compilerWarningsAsErrors: options.compilerWarningsAsErrors,
warnDeprecatedCode: options.warnDeprecatedCode,
// ExtendedOptions
forPublishing: options.forPublishing,
}
}

Expand All @@ -50,6 +51,7 @@ export function declareBuild(program: Command) {

buildCommand.command('file [infile...]', {isDefault: true})
.description(`Compile one or more source files or projects ('file' subcommand is default).`)
.option('--for-publishing', 'Verify that project meets @keymanapp repository requirements')
.addHelpText('after', `
Supported file types:
* folder: Keyman project in folder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import * as fs from 'fs';
import { BuildActivity } from './BuildActivity.js';
import { CompilerCallbacks, CompilerOptions, KeymanDeveloperProject, KeymanFileTypes } from '@keymanapp/common-types';
import { CompilerCallbacks, KeymanDeveloperProject, KeymanFileTypes } from '@keymanapp/common-types';
import { KeyboardInfoCompiler } from '@keymanapp/kmc-keyboard-info';
import { loadProject } from '../../util/projectLoader.js';
import { InfrastructureMessages } from '../../messages/infrastructureMessages.js';
import { calculateSourcePath } from '../../util/calculateSourcePath.js';
import { getLastGitCommitDate } from '../../util/getLastGitCommitDate.js';
import { ExtendedCompilerOptions } from 'src/util/extendedCompilerOptions.js';

export class BuildKeyboardInfo extends BuildActivity {
public get name(): string { return 'Keyboard metadata'; }
public get sourceExtension(): KeymanFileTypes.Source { return KeymanFileTypes.Source.Project; }
public get compiledExtension(): KeymanFileTypes.Binary { return KeymanFileTypes.Binary.KeyboardInfo; }
public get description(): string { return 'Build a keyboard metadata file'; }
public async build(infile: string, callbacks: CompilerCallbacks, options: CompilerOptions): Promise<boolean> {
public async build(infile: string, callbacks: CompilerCallbacks, options: ExtendedCompilerOptions): Promise<boolean> {
if(!KeymanFileTypes.filenameIs(infile, KeymanFileTypes.Source.Project)) {
// Even if the project file does not exist, we use its name as our reference
// in order to avoid ambiguity
Expand Down Expand Up @@ -41,7 +42,8 @@ export class BuildKeyboardInfo extends BuildActivity {
kpsFilename: project.resolveInputFilePath(kps),
jsFilename: fs.existsSync(jsFilename) ? jsFilename : undefined,
sourcePath: calculateSourcePath(infile),
lastCommitDate
lastCommitDate,
forPublishing: !!options.forPublishing,
});

if(data == null) {
Expand Down
8 changes: 5 additions & 3 deletions developer/src/kmc/src/commands/buildClasses/BuildModelInfo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as fs from 'fs';
import { BuildActivity } from './BuildActivity.js';
import { CompilerCallbacks, CompilerOptions, KeymanFileTypes } from '@keymanapp/common-types';
import { CompilerCallbacks, KeymanFileTypes } from '@keymanapp/common-types';
import { ModelInfoCompiler } from '@keymanapp/kmc-model-info';
import { KmpCompiler } from '@keymanapp/kmc-package';
import { loadProject } from '../../util/projectLoader.js';
import { InfrastructureMessages } from '../../messages/infrastructureMessages.js';
import { calculateSourcePath } from '../../util/calculateSourcePath.js';
import { getLastGitCommitDate } from '../../util/getLastGitCommitDate.js';
import { ExtendedCompilerOptions } from 'src/util/extendedCompilerOptions.js';

export class BuildModelInfo extends BuildActivity {
public get name(): string { return 'Lexical model metadata'; }
Expand All @@ -24,7 +25,7 @@ export class BuildModelInfo extends BuildActivity {
* @param options
* @returns
*/
public async build(infile: string, callbacks: CompilerCallbacks, options: CompilerOptions): Promise<boolean> {
public async build(infile: string, callbacks: CompilerCallbacks, options: ExtendedCompilerOptions): Promise<boolean> {
if(!KeymanFileTypes.filenameIs(infile, KeymanFileTypes.Source.Project)) {
// Even if the project file does not exist, we use its name as our reference
// in order to avoid ambiguity
Expand Down Expand Up @@ -65,7 +66,8 @@ export class BuildModelInfo extends BuildActivity {
modelFileName: project.resolveOutputFilePath(model, KeymanFileTypes.Source.Model, KeymanFileTypes.Binary.Model),
kmpFileName: project.resolveOutputFilePath(kps, KeymanFileTypes.Source.Package, KeymanFileTypes.Binary.Package),
kpsFilename: project.resolveInputFilePath(kps),
lastCommitDate
lastCommitDate,
forPublishing: !!options.forPublishing,
});

if(data == null) {
Expand Down
11 changes: 6 additions & 5 deletions developer/src/kmc/src/commands/buildClasses/BuildProject.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as path from 'path';
import * as fs from 'fs';
import { CompilerCallbacks, CompilerFileCallbacks, CompilerOptions, KeymanDeveloperProject, KeymanDeveloperProjectFile, KeymanFileTypes } from '@keymanapp/common-types';
import { CompilerCallbacks, CompilerFileCallbacks, KeymanDeveloperProject, KeymanDeveloperProjectFile, KeymanFileTypes } from '@keymanapp/common-types';
import { BuildActivity } from './BuildActivity.js';
import { buildActivities, buildKeyboardInfoActivity, buildModelInfoActivity } from './buildActivities.js';
import { InfrastructureMessages } from '../../messages/infrastructureMessages.js';
import { loadProject } from '../../util/projectLoader.js';
import { ExtendedCompilerOptions } from 'src/util/extendedCompilerOptions.js';

export class BuildProject extends BuildActivity {
public get name(): string { return 'Project'; }
public get sourceExtension(): KeymanFileTypes.Source { return KeymanFileTypes.Source.Project; }
public get compiledExtension(): KeymanFileTypes.Binary { return null; }
public get description(): string { return 'Build a keyboard or lexical model project'; }
public async build(infile: string, callbacks: CompilerCallbacks, options: CompilerOptions): Promise<boolean> {
public async build(infile: string, callbacks: CompilerCallbacks, options: ExtendedCompilerOptions): Promise<boolean> {
let builder = new ProjectBuilder(infile, callbacks, options);
return builder.run();
}
Expand All @@ -20,10 +21,10 @@ export class BuildProject extends BuildActivity {
class ProjectBuilder {
callbacks: CompilerCallbacks;
infile: string;
options: CompilerOptions;
options: ExtendedCompilerOptions;
project: KeymanDeveloperProject;

constructor(infile: string, callbacks: CompilerCallbacks, options: CompilerOptions) {
constructor(infile: string, callbacks: CompilerCallbacks, options: ExtendedCompilerOptions) {
this.infile = path.resolve(infile);
this.callbacks = new CompilerFileCallbacks(infile, options, callbacks);
this.options = options;
Expand Down Expand Up @@ -53,7 +54,7 @@ class ProjectBuilder {
}

// Build project metadata
if(!this.project.options.skipMetadataFiles) {
if(this.options.forPublishing || !this.project.options.skipMetadataFiles) {
if(!await (this.buildProjectTargets(
this.project.isKeyboardProject()
? buildKeyboardInfoActivity
Expand Down
10 changes: 10 additions & 0 deletions developer/src/kmc/src/util/extendedCompilerOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CompilerOptions } from '@keymanapp/common-types';

export interface ExtendedCompilerOptions extends CompilerOptions {
/**
* Verify that the project meets the requirements of the keymanapp/keyboards
* or keymanapp/lexical-models repository, e.g. verify that project license is
* MIT
*/
forPublishing?: boolean;
};