spiegel-keyman/developer/src/kmc/src/util/projectRunner.ts
Marc Durdin e67aed1606 refactor(common): move compiler-interfaces to @keymanapp/developer-utils
This should be the last step in the refactoring.

Fixes: #9665
2024-08-02 13:49:59 +07:00

30 lines
No EOL
1 KiB
TypeScript

import { KeymanFileTypes } from '@keymanapp/common-types';
import { CompilerCallbacks } from '@keymanapp/developer-utils';
import { isProject, loadProject } from './projectLoader.js';
async function runProject(callbacks: CompilerCallbacks, filename: string, callback: (filename:string)=>Promise<boolean>): Promise<boolean> {
const project = loadProject(filename, callbacks);
for(const file of project.files) {
if(KeymanFileTypes.filenameIs(file.filename, KeymanFileTypes.Source.Project)) {
// Don't accidentally recurse into projects
continue;
}
if(!await callback(project.resolveInputFilePath(file))) {
return false;
}
}
return true;
}
export async function runOnFiles(callbacks: CompilerCallbacks, filenames: string[], callback: (filename:string)=>Promise<boolean>): Promise<boolean> {
for(let filename of filenames) {
const result = isProject(filename) ?
await runProject(callbacks, filename, callback) :
await callback(filename);
if(!result) {
return false;
}
}
return true;
}