MCPcopy
hub / github.com/activepieces/activepieces / findNewPieces

Function findNewPieces

tools/scripts/utils/piece-script-utils.ts:94–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

92};
93
94export async function findNewPieces(): Promise<PieceMetadata[]> {
95 const changedDistPaths = getChangedPiecesDistPaths()
96 const paths = changedDistPaths ?? await findAllDistPaths()
97
98 console.info(`[findNewPieces] scanning ${paths.length} dist paths${changedDistPaths ? ' (scoped to changed)' : ' (all)'}`)
99
100 const changedPieces: PieceMetadata[] = []
101
102 // Adding batches because of memory limit when we have a lot of pieces
103 const batchSize = 75
104 for (let i = 0; i < paths.length; i += batchSize) {
105 const batch = paths.slice(i, i + batchSize)
106 const batchResults = await Promise.all(batch.map(async (folderPath) => {
107 const packageJson = await readPackageJson(folderPath);
108 if (NON_PIECES_PACKAGES.includes(packageJson.name)) {
109 return null;
110 }
111 const exists = await pieceMetadataExists(packageJson.name, packageJson.version)
112 if (!exists) {
113 try {
114 return loadPieceFromFolder(folderPath);
115 } catch (ex) {
116 return null;
117 }
118 }
119 return null;
120 }))
121
122 const validResults = batchResults.filter((piece): piece is PieceMetadata => piece !== null)
123 changedPieces.push(...validResults)
124 }
125
126 return changedPieces;
127}
128
129function getChangedPiecesDistPaths(): string[] | null {
130 const changedPieces = process.env['CHANGED_PIECES']

Callers 1

mainFunction · 0.90

Calls 6

readPackageJsonFunction · 0.90
findAllDistPathsFunction · 0.85
pieceMetadataExistsFunction · 0.85
infoMethod · 0.80
loadPieceFromFolderFunction · 0.70

Tested by

no test coverage detected