-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathprepare-native-platform-service.ts
73 lines (57 loc) · 2.91 KB
/
prepare-native-platform-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { hook } from "../../common/helpers";
import { performanceLog } from "../../common/decorators";
import { NativePlatformStatus } from "../../constants";
export class PrepareNativePlatformService implements IPrepareNativePlatformService {
constructor(
public $hooksService: IHooksService,
private $nodeModulesBuilder: INodeModulesBuilder,
private $projectChangesService: IProjectChangesService,
) { }
@performanceLog()
@hook('prepareNativeApp')
public async prepareNativePlatform(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<boolean> {
const { nativePrepare, release } = prepareData;
const changesInfo = await this.$projectChangesService.checkForChanges(platformData, projectData, prepareData);
if (nativePrepare && nativePrepare.skipNativePrepare) {
return changesInfo.hasChanges;
}
const hasNativeModulesChange = !changesInfo || changesInfo.nativeChanged;
const hasConfigChange = !changesInfo || changesInfo.configChanged;
const hasChangesRequirePrepare = !changesInfo || changesInfo.changesRequirePrepare;
const hasChanges = hasNativeModulesChange || hasConfigChange || hasChangesRequirePrepare;
if (changesInfo.hasChanges) {
await this.cleanProject(platformData, { release });
}
platformData.platformProjectService.prepareAppResources(projectData);
if (hasChangesRequirePrepare) {
await platformData.platformProjectService.prepareProject(projectData, prepareData);
}
if (hasNativeModulesChange) {
await this.$nodeModulesBuilder.prepareNodeModules({platformData, projectData});
}
if (hasNativeModulesChange || hasConfigChange) {
await platformData.platformProjectService.processConfigurationFilesFromAppResources(projectData, { release });
await platformData.platformProjectService.handleNativeDependenciesChange(projectData, { release });
}
platformData.platformProjectService.interpolateConfigurationFile(projectData);
await this.$projectChangesService.setNativePlatformStatus(platformData, projectData, { nativePlatformStatus: NativePlatformStatus.alreadyPrepared });
return hasChanges;
}
private async cleanProject(platformData: IPlatformData, options: { release: boolean }): Promise<void> {
// android build artifacts need to be cleaned up
// when switching between debug, release and webpack builds
if (platformData.platformNameLowerCase !== "android") {
return;
}
const previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platformData);
if (!previousPrepareInfo || previousPrepareInfo.nativePlatformStatus !== NativePlatformStatus.alreadyPrepared) {
return;
}
const { release: previousWasRelease } = previousPrepareInfo;
const { release: currentIsRelease } = options;
if (previousWasRelease !== currentIsRelease) {
await platformData.platformProjectService.cleanProject(platformData.projectRoot);
}
}
}
$injector.register("prepareNativePlatformService", PrepareNativePlatformService);