Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function readAssetJsonAsync(
projectDir: string
): Promise<{ assetJson: JsonFile; assetInfo: AssetOptimizationState }> {
const dirPath = join(projectDir, '.expo-shared');
ensureDirSync(dirPath);
const assetJson = new JsonFile(join(dirPath, 'assets.json'));
if (!fileExists(assetJson.file)) {
console.log();
console.log(
chalk.magenta(
`\u203A Creating ${chalk.bold('.expo-shared/assets.json')} in the project's root directory.`
)
);
console.log(
chalk.magenta`\u203A This file is autogenerated and should not be edited directly.`
);
console.log(
chalk.magenta`\u203A You should commit this to git so that asset state is shared between collaborators.`
);
console.log();
await assetJson.writeAsync({});
}
export async function isProjectOptimized(
projectDir: string,
options: OptimizationOptions
): Promise {
if (!fileExists(join(projectDir, '.expo-shared/assets.json'))) {
return false;
}
const { selectedFiles } = await getAssetFilesAsync(projectDir, options);
const { assetInfo } = await readAssetJsonAsync(projectDir);
for (const file of selectedFiles) {
const hash = calculateHash(file);
if (!assetInfo[hash]) {
return false;
}
}
return true;
}