(location: string, log: (...args: any[]) => void)
| 30 | } |
| 31 | |
| 32 | export async function buildManifestFromLocation(location: string, log: (...args: any[]) => void): Promise<string> { |
| 33 | let directory: string; |
| 34 | let projectManifestEntry: string; |
| 35 | // lstatSync will throw if location not exist |
| 36 | if (lstatSync(location).isDirectory()) { |
| 37 | directory = location; |
| 38 | projectManifestEntry = path.join(directory, DEFAULT_TS_MANIFEST); |
| 39 | } else if (lstatSync(location).isFile()) { |
| 40 | directory = path.dirname(location); |
| 41 | projectManifestEntry = location; |
| 42 | } else { |
| 43 | throw new Error('Argument `location` is not a valid directory or file'); |
| 44 | } |
| 45 | |
| 46 | // We compile from TypeScript every time, even if the current YAML file exists, to ensure that the YAML file remains up-to-date with the latest changes |
| 47 | try { |
| 48 | //we could have a multichain yaml with ts projects inside it |
| 49 | const projectYamlPath = projectManifestEntry.endsWith('.ts') |
| 50 | ? await generateManifestFromTs(projectManifestEntry) |
| 51 | : projectManifestEntry; |
| 52 | |
| 53 | if (isMultichain(projectYamlPath)) { |
| 54 | const tsManifests = getTsManifestsFromMultichain(projectYamlPath); |
| 55 | await Promise.all(tsManifests.map((manifest) => generateManifestFromTs(manifest))); |
| 56 | replaceTsReferencesInMultichain(projectYamlPath); |
| 57 | } |
| 58 | } catch (e: any) { |
| 59 | console.log(e); |
| 60 | throw new Error(`Failed to generate manifest from typescript ${projectManifestEntry}, ${e.message}`); |
| 61 | } |
| 62 | return directory; |
| 63 | } |
| 64 | |
| 65 | export async function buildTsManifest(location: string, log: (...args: any[]) => void): Promise<void> { |
| 66 | const tsManifest = getTsManifest(location); |
no test coverage detected