-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeManifest.ts
24 lines (20 loc) · 912 Bytes
/
writeManifest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import * as path from 'path';
import * as fs from 'fs';
import * as yaml from 'js-yaml';
import { MANIFEST_FILENAME } from './constants';
import { DependencyHashes } from './hashDependencies';
const fsPromises = fs.promises;
export type DependenciesForManifest = Record<string, string>;
export const hashesToRecord = (dependencyHashes: DependencyHashes): DependenciesForManifest => {
const hashesRecord: DependenciesForManifest = {};
for (const hash of dependencyHashes) {
hashesRecord[hash.dependencyPath] = hash.hash;
}
return hashesRecord;
};
export const writeManifest = async (dirpath: string, targetOutput: string, dependencyHashes: DependencyHashes): Promise<void> => {
const yamlManifest = yaml.safeDump({
dependencies: hashesToRecord(dependencyHashes),
});
await fsPromises.writeFile(path.join(dirpath, targetOutput, MANIFEST_FILENAME), yamlManifest);
};