|
1 | 1 | import { join, resolve } from 'path'; |
2 | | -import { existsSync, readFileSync } from 'fs'; |
| 2 | +import { existsSync, readFileSync, readdirSync } from 'fs'; |
3 | 3 | import { FsUtility, sanitizePath, log } from '@contentstack/cli-utilities'; |
4 | 4 | import { ConfigType, ContentTypeStruct, CtConstructorParam, ModuleConstructorParam } from '../types'; |
5 | 5 | import { keys, values } from 'lodash'; |
@@ -46,10 +46,25 @@ export default class ModuleDataReader { |
46 | 46 | break; |
47 | 47 | case 'assets': { |
48 | 48 | log.debug(`Counting assets`, this.config.auditContext); |
49 | | - const assetsPath = join(this.folderPath, 'assets'); |
50 | | - log.debug(`Assets path: ${assetsPath}`, this.config.auditContext); |
51 | | - count = (await this.readEntryAssetsModule(assetsPath, 'assets')) || 0; |
52 | | - log.debug(`Assets count: ${count}`, this.config.auditContext); |
| 49 | + const spacesDir = join(this.folderPath, 'spaces'); |
| 50 | + if (existsSync(spacesDir)) { |
| 51 | + log.debug(`Multi-space structure detected at: ${spacesDir}`, this.config.auditContext); |
| 52 | + const spaceDirs = readdirSync(spacesDir, { withFileTypes: true }).filter( |
| 53 | + (entry) => entry.isDirectory() && existsSync(join(spacesDir, entry.name, 'assets')), |
| 54 | + ); |
| 55 | + for (const spaceDir of spaceDirs) { |
| 56 | + const spaceAssetsPath = join(spacesDir, spaceDir.name, 'assets'); |
| 57 | + log.debug(`Counting assets in space: ${spaceDir.name} at ${spaceAssetsPath}`, this.config.auditContext); |
| 58 | + const spaceCount = (await this.readEntryAssetsModule(spaceAssetsPath, 'assets')) || 0; |
| 59 | + log.debug(`Space ${spaceDir.name} asset count: ${spaceCount}`, this.config.auditContext); |
| 60 | + count += spaceCount; |
| 61 | + } |
| 62 | + } else { |
| 63 | + const assetsPath = join(this.folderPath, 'assets'); |
| 64 | + log.debug(`Flat structure detected, assets path: ${assetsPath}`, this.config.auditContext); |
| 65 | + count = (await this.readEntryAssetsModule(assetsPath, 'assets')) || 0; |
| 66 | + } |
| 67 | + log.debug(`Total assets count: ${count}`, this.config.auditContext); |
53 | 68 | break; |
54 | 69 | } |
55 | 70 | case 'entries': |
|
0 commit comments