( rootDir: string, sinceRef?: string )
| 20 | } |
| 21 | |
| 22 | export default async function getChangesets( |
| 23 | rootDir: string, |
| 24 | sinceRef?: string |
| 25 | ): Promise<Array<NewChangeset>> { |
| 26 | let changesetBase = path.join(rootDir, ".changeset"); |
| 27 | let contents: string[]; |
| 28 | try { |
| 29 | contents = await fs.readdir(changesetBase); |
| 30 | } catch (err) { |
| 31 | if ((err as any).code === "ENOENT") { |
| 32 | throw new Error("There is no .changeset directory in this project"); |
| 33 | } |
| 34 | throw err; |
| 35 | } |
| 36 | |
| 37 | if (sinceRef !== undefined) { |
| 38 | contents = await filterChangesetsSinceRef( |
| 39 | contents, |
| 40 | changesetBase, |
| 41 | sinceRef |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | let oldChangesetsPromise = getOldChangesetsAndWarn(changesetBase, contents); |
| 46 | |
| 47 | let changesets = contents.filter( |
| 48 | (file) => |
| 49 | !file.startsWith(".") && |
| 50 | file.endsWith(".md") && |
| 51 | !/^README\.md$/i.test(file) |
| 52 | ); |
| 53 | |
| 54 | const changesetContents = changesets.map(async (file) => { |
| 55 | const changeset = await fs.readFile( |
| 56 | path.join(changesetBase, file), |
| 57 | "utf-8" |
| 58 | ); |
| 59 | |
| 60 | return { ...parse(changeset), id: file.replace(".md", "") }; |
| 61 | }); |
| 62 | return [ |
| 63 | ...(await oldChangesetsPromise), |
| 64 | ...(await Promise.all(changesetContents)), |
| 65 | ]; |
| 66 | } |
no test coverage detected