Merge pull request #13200 from keymanapp/chore/developer/13127-info-logs-for-kmc-copy-and-generate

chore(developer): add INFO messages for `kmc copy` and `kmc generate`
This commit is contained in:
Marc Durdin 2025-02-14 10:13:07 +07:00 • committed by GitHub
commit f3abae39f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 74 additions and 14 deletions

View file

@ -25,11 +25,7 @@ export class CopierMessages {
o.e ?? 'unknown error'
);
static INFO_CopyingProject = SevInfo | 0x0002;
static Info_CopyingProject = (o:{type: string, id: string}) => m(
this.INFO_CopyingProject,
`Copying project of type ${def(o.type)} with id ${def(o.id)}`
);
// unused 0x0002 (was INFO_CopyingProject, now in InfrastructureMessages)
static ERROR_CannotCreateFolder = SevError | 0x0003;
static Error_CannotCreateFolder = (o:{folderName:string, e: any}) => CompilerMessageSpecWithException(

View file

@ -7,7 +7,7 @@
import { CompilerErrorNamespace, CompilerErrorSeverity, CompilerMessageSpec as m, CompilerMessageDef as def, CompilerMessageSpecWithException } from "@keymanapp/developer-utils";
const Namespace = CompilerErrorNamespace.Generator;
const SevInfo = CompilerErrorSeverity.Info | Namespace;
// const SevInfo = CompilerErrorSeverity.Info | Namespace;
// const SevHint = CompilerErrorSeverity.Hint | Namespace;
const SevWarn = CompilerErrorSeverity.Warn | Namespace;
const SevError = CompilerErrorSeverity.Error | Namespace;
@ -23,11 +23,7 @@ export class GeneratorMessages {
o.e ?? 'unknown error',
);
static INFO_GeneratingProject = SevInfo | 0x0002;
static Info_GeneratingProject = (o:{type: string, id: string}) => m(
this.INFO_GeneratingProject,
`Generating project of type ${def(o.type)} with id ${def(o.id)}`
);
// unused 0x0002 (was INFO_GeneratingProject, now in InfrastructureMessages)
static ERROR_CannotCreateFolder = SevError | 0x0003;
static Error_CannotCreateFolder = (o:{folderName:string, e: any}) => CompilerMessageSpecWithException(

View file

@ -79,6 +79,18 @@ async function doCopy(callbacks: NodeCompilerCallbacks, sources: string | string
return false;
}
const dest = options.outPath;
callbacks.reportMessage(InfrastructureMessages.Info_CopyingProject({source, dest}));
const result = runCopier(callbacks, source, options);
if(result) {
callbacks.reportMessage(InfrastructureMessages.Info_ProjectCopiedSuccessfully({source, dest}));
} else {
callbacks.reportMessage(InfrastructureMessages.Info_ProjectNotCopiedSuccessfully({source, dest}));
}
return result;
}
async function runCopier(callbacks: NodeCompilerCallbacks, source: string, options: CopierOptions) {
const copier = new KeymanProjectCopier();
try {
if(!await copier.init(callbacks, options)) {

View file

@ -113,9 +113,16 @@ async function generate(generator: KeymanCompiler, ids: string | string[], comma
}
const options = commanderOptionsToGeneratorOptions(id, commanderOptions);
const outPath = options.outPath;
const callbacks = new NodeCompilerCallbacks(options);
if(!await doGenerate(callbacks, generator, options)) {
callbacks.reportMessage(InfrastructureMessages.Info_GeneratingProject({id, outPath}));
const result = await doGenerate(callbacks, generator, options);
if(result) {
callbacks.reportMessage(InfrastructureMessages.Info_ProjectGeneratedSuccessfully({id}));
} else {
callbacks.reportMessage(InfrastructureMessages.Info_ProjectNotGeneratedSuccessfully({id}));
return await exitProcess(1);
}
}

View file

@ -158,5 +158,48 @@ export class InfrastructureMessages {
this.ERROR_CopyRequiresOutPath,
`The copy command requires the --out-path, -o parameter`
);
}
// For this message, we override the filename with the passed-in file. A bit of a hack but does the job
static INFO_CopyingProject = SevInfo | 0x0023;
static Info_CopyingProject = (o:{source:string,dest:string}) => ({filename:o.source, ...m(
this.INFO_CopyingProject,
`Copying project '${def(o.source)}' to '${def(o.dest)}'`,
)});
// For this message, we override the filename with the passed-in file. A bit of a hack but does the job
static INFO_ProjectCopiedSuccessfully = SevInfo | 0x0024;
static Info_ProjectCopiedSuccessfully = (o:{source:string, dest:string}) => ({filename:o.source, ...m(
this.INFO_ProjectCopiedSuccessfully,
`'${def(o.source)}' copied to '${def(o.dest)}' successfully.`,
)});
// For this message, we override the filename with the passed-in file. A bit of a hack but does the job
static INFO_ProjectNotCopiedSuccessfully = SevInfo | 0x0025;
static Info_ProjectNotCopiedSuccessfully = (o:{source:string, dest:string}) => ({filename:o.source, ...m(
this.INFO_ProjectNotCopiedSuccessfully,
`Failed to copy '${def(o.source)}' to '${def(o.dest)}'.`,
)});
// For this message, we override the filename with the passed-in file. A bit of a hack but does the job
static INFO_GeneratingProject = SevInfo | 0x0026;
static Info_GeneratingProject = (o:{id:string, outPath: string}) => ({filename:o.id, ...m(
this.INFO_GeneratingProject,
`Generating new project '${def(o.id)}' in '${def(o.outPath)}'.`,
)});
// For this message, we override the filename with the passed-in file. A bit of a hack but does the job
static INFO_ProjectGeneratedSuccessfully = SevInfo | 0x0027;
static Info_ProjectGeneratedSuccessfully = (o:{id:string}) => ({filename:o.id, ...m(
this.INFO_ProjectGeneratedSuccessfully,
`New project '${def(o.id)}' generated successfully.`,
)});
// For this message, we override the filename with the passed-in file. A bit of a hack but does the job
static INFO_ProjectNotGeneratedSuccessfully = SevInfo | 0x0028;
static Info_ProjectNotGeneratedSuccessfully = (o:{id:string}) => ({filename:o.id, ...m(
this.INFO_ProjectNotGeneratedSuccessfully,
`Failed to generate new project '${def(o.id)}'.`,
)});
}

View file

@ -242,12 +242,18 @@ export class NodeCompilerCallbacks implements CompilerCallbacks {
messageSpecialColor(event: CompilerEvent) {
switch(event.code) {
case InfrastructureMessages.INFO_BuildingFile:
case InfrastructureMessages.INFO_CopyingProject:
case InfrastructureMessages.INFO_GeneratingProject:
return color.whiteBright;
case InfrastructureMessages.INFO_FileNotBuiltSuccessfully:
case InfrastructureMessages.INFO_ProjectNotBuiltSuccessfully:
case InfrastructureMessages.INFO_ProjectNotCopiedSuccessfully:
case InfrastructureMessages.INFO_ProjectNotGeneratedSuccessfully:
return color.red;
case InfrastructureMessages.INFO_FileBuiltSuccessfully:
case InfrastructureMessages.INFO_ProjectBuiltSuccessfully:
case InfrastructureMessages.INFO_ProjectCopiedSuccessfully:
case InfrastructureMessages.INFO_ProjectGeneratedSuccessfully:
return color.green;
}
return null;