1dc51e206SEvan Baconimport path from 'path';
2dc51e206SEvan Bacon
3*8a424bebSJames Ideimport { exportAppAsync } from './exportApp';
4*8a424bebSJames Ideimport { Options } from './resolveOptions';
5dc51e206SEvan Baconimport * as Log from '../log';
6d8009c4bSEvan Baconimport { FileNotifier } from '../utils/FileNotifier';
7dc51e206SEvan Baconimport { ensureDirectoryAsync, removeAsync } from '../utils/dir';
8dc51e206SEvan Bacon
9dc51e206SEvan Baconexport async function exportAsync(projectRoot: string, options: Options) {
10dc51e206SEvan Bacon  // Ensure the output directory is created
11dc51e206SEvan Bacon  const outputPath = path.resolve(projectRoot, options.outputDir);
12dc51e206SEvan Bacon  // Delete the output directory if it exists
13dc51e206SEvan Bacon  await removeAsync(outputPath);
14dc51e206SEvan Bacon  // Create the output directory
15dc51e206SEvan Bacon  await ensureDirectoryAsync(outputPath);
16dc51e206SEvan Bacon
17dc51e206SEvan Bacon  // Export the app
18dc51e206SEvan Bacon  await exportAppAsync(projectRoot, options);
19dc51e206SEvan Bacon
20d8009c4bSEvan Bacon  // Stop any file watchers to prevent the CLI from hanging.
21d8009c4bSEvan Bacon  FileNotifier.stopAll();
22d8009c4bSEvan Bacon
23dc51e206SEvan Bacon  // Final notes
24dc51e206SEvan Bacon  Log.log(`Export was successful. Your exported files can be found in ${options.outputDir}`);
25dc51e206SEvan Bacon}
26