nativescript 9.1.2 → 9.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/config.json +1 -1
- package/config/test-deps-versions-generated.json +1 -1
- package/docs/man_pages/project/testing/build-android.md +2 -1
- package/docs/man_pages/project/testing/build-ios.md +2 -1
- package/docs/man_pages/project/testing/compiled-report.md +43 -0
- package/docs/man_pages/project/testing/compiled-verify.md +46 -0
- package/docs/man_pages/project/testing/run-android.md +2 -1
- package/docs/man_pages/project/testing/run-ios.md +2 -1
- package/lib/bootstrap.js +4 -0
- package/lib/commands/compiled-report.d.ts +40 -0
- package/lib/commands/compiled-report.js +153 -0
- package/lib/commands/compiled-verify.d.ts +16 -0
- package/lib/commands/compiled-verify.js +53 -0
- package/lib/common/services/hooks-service.js +7 -18
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +5 -4
- package/lib/controllers/build-controller.d.ts +4 -1
- package/lib/controllers/build-controller.js +25 -5
- package/lib/controllers/prepare-controller.d.ts +3 -1
- package/lib/controllers/prepare-controller.js +10 -1
- package/lib/data/prepare-data.d.ts +1 -0
- package/lib/data/prepare-data.js +1 -0
- package/lib/declarations.d.ts +1 -0
- package/lib/definitions/prepare.d.ts +5 -0
- package/lib/definitions/project.d.ts +32 -0
- package/lib/helpers/livesync-command-helper.js +2 -3
- package/lib/options.js +4 -0
- package/lib/services/compiled-release-service.d.ts +44 -0
- package/lib/services/compiled-release-service.js +357 -0
- package/lib/services/compiled-report-service.d.ts +89 -0
- package/lib/services/compiled-report-service.js +688 -0
- package/package.json +4 -4
|
@@ -7,8 +7,9 @@ const events_1 = require("events");
|
|
|
7
7
|
const helpers_1 = require("../common/helpers");
|
|
8
8
|
const yok_1 = require("../common/yok");
|
|
9
9
|
const perf_hooks_1 = require("perf_hooks");
|
|
10
|
+
const path = require("path");
|
|
10
11
|
class BuildController extends events_1.EventEmitter {
|
|
11
|
-
constructor($analyticsService, $buildArtifactsService, $buildInfoFileService, $fs, $logger, $injector, $mobileHelper, $projectDataService, $projectChangesService, $prepareController) {
|
|
12
|
+
constructor($analyticsService, $buildArtifactsService, $buildInfoFileService, $fs, $logger, $injector, $mobileHelper, $projectDataService, $projectChangesService, $prepareController, $compiledReleaseService) {
|
|
12
13
|
super();
|
|
13
14
|
this.$analyticsService = $analyticsService;
|
|
14
15
|
this.$buildArtifactsService = $buildArtifactsService;
|
|
@@ -20,6 +21,7 @@ class BuildController extends events_1.EventEmitter {
|
|
|
20
21
|
this.$projectDataService = $projectDataService;
|
|
21
22
|
this.$projectChangesService = $projectChangesService;
|
|
22
23
|
this.$prepareController = $prepareController;
|
|
24
|
+
this.$compiledReleaseService = $compiledReleaseService;
|
|
23
25
|
}
|
|
24
26
|
get $platformsDataService() {
|
|
25
27
|
return this.$injector.resolve("platformsDataService");
|
|
@@ -48,6 +50,19 @@ class BuildController extends events_1.EventEmitter {
|
|
|
48
50
|
? constants.BuildStates.Clean
|
|
49
51
|
: constants.BuildStates.Incremental}`,
|
|
50
52
|
});
|
|
53
|
+
if (this.$compiledReleaseService.isCompiledRelease(buildData)) {
|
|
54
|
+
const packageFile = await this.$compiledReleaseService.build(platformData, projectData, buildData);
|
|
55
|
+
this.logBuildTime(startTime);
|
|
56
|
+
if (buildData.copyTo) {
|
|
57
|
+
const target = path.resolve(buildData.copyTo);
|
|
58
|
+
this.$fs.copyFile(packageFile, target);
|
|
59
|
+
this.$logger.info(`Copied file '${packageFile}' to '${target}'.`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.$logger.info(`The build result is located at: ${packageFile}`);
|
|
63
|
+
}
|
|
64
|
+
return packageFile;
|
|
65
|
+
}
|
|
51
66
|
if (buildData.clean) {
|
|
52
67
|
await platformData.platformProjectService.cleanProject(platformData.projectRoot);
|
|
53
68
|
}
|
|
@@ -60,10 +75,7 @@ class BuildController extends events_1.EventEmitter {
|
|
|
60
75
|
await (0, helpers_1.attachAwaitDetach)(constants.BUILD_OUTPUT_EVENT_NAME, platformData.platformProjectService, handler, platformData.platformProjectService.buildProject(platformData.projectRoot, projectData, buildData));
|
|
61
76
|
const buildInfoFileDir = platformData.getBuildOutputPath(buildData);
|
|
62
77
|
this.$buildInfoFileService.saveLocalBuildInfo(platformData, buildInfoFileDir);
|
|
63
|
-
|
|
64
|
-
const buildTime = (endTime - startTime) / 1000;
|
|
65
|
-
this.$logger.info("Project successfully built.");
|
|
66
|
-
this.$logger.info(`Build time: ${buildTime.toFixed(3)} s.`);
|
|
78
|
+
this.logBuildTime(startTime);
|
|
67
79
|
const result = await this.$buildArtifactsService.getLatestAppPackagePath(platformData, buildData);
|
|
68
80
|
if (buildData.copyTo) {
|
|
69
81
|
this.$buildArtifactsService.copyLatestAppPackage(buildData.copyTo, platformData, buildData);
|
|
@@ -73,6 +85,11 @@ class BuildController extends events_1.EventEmitter {
|
|
|
73
85
|
}
|
|
74
86
|
return result;
|
|
75
87
|
}
|
|
88
|
+
logBuildTime(startTime) {
|
|
89
|
+
const buildTime = (perf_hooks_1.performance.now() - startTime) / 1000;
|
|
90
|
+
this.$logger.info("Project successfully built.");
|
|
91
|
+
this.$logger.info(`Build time: ${buildTime.toFixed(3)} s.`);
|
|
92
|
+
}
|
|
76
93
|
async buildIfNeeded(buildData) {
|
|
77
94
|
let result = null;
|
|
78
95
|
const shouldBuildPlatform = await this.shouldBuild(buildData);
|
|
@@ -82,6 +99,9 @@ class BuildController extends events_1.EventEmitter {
|
|
|
82
99
|
return result;
|
|
83
100
|
}
|
|
84
101
|
async shouldBuild(buildData) {
|
|
102
|
+
if (this.$compiledReleaseService.isCompiledRelease(buildData)) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
85
105
|
const projectData = this.$projectDataService.getProjectData(buildData.projectDir);
|
|
86
106
|
const platformData = this.$platformsDataService.getPlatformData(buildData.platform, projectData);
|
|
87
107
|
const outputPath = buildData.outputPath || platformData.getBuildOutputPath(buildData);
|
|
@@ -4,6 +4,7 @@ import { IOptions, IWatchIgnoreListService } from "../declarations";
|
|
|
4
4
|
import { INodeModulesDependenciesBuilder, IPlatformController, IPlatformData, IPlatformsDataService } from "../definitions/platform";
|
|
5
5
|
import { IPluginsService } from "../definitions/plugins";
|
|
6
6
|
import { IProjectConfigService, IProjectData, IProjectDataService, IProjectService } from "../definitions/project";
|
|
7
|
+
import { CompiledReleaseService } from "../services/compiled-release-service";
|
|
7
8
|
export declare class PrepareController extends EventEmitter implements IPrepareController {
|
|
8
9
|
private $platformController;
|
|
9
10
|
$hooksService: IHooksService;
|
|
@@ -23,12 +24,13 @@ export declare class PrepareController extends EventEmitter implements IPrepareC
|
|
|
23
24
|
private $markingModeService;
|
|
24
25
|
private $projectConfigService;
|
|
25
26
|
private $projectService;
|
|
27
|
+
private $compiledReleaseService;
|
|
26
28
|
private watchersData;
|
|
27
29
|
private isInitialPrepareReady;
|
|
28
30
|
private persistedData;
|
|
29
31
|
private webpackCompilerHandler;
|
|
30
32
|
private pausedFileWatch;
|
|
31
|
-
constructor($platformController: IPlatformController, $hooksService: IHooksService, $fs: IFileSystem, $logger: ILogger, $options: IOptions, $mobileHelper: Mobile.IMobileHelper, $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder, $platformsDataService: IPlatformsDataService, $pluginsService: IPluginsService, $prepareNativePlatformService: IPrepareNativePlatformService, $projectChangesService: IProjectChangesService, $projectDataService: IProjectDataService, $bundlerCompilerService: IBundlerCompilerService, $watchIgnoreListService: IWatchIgnoreListService, $analyticsService: IAnalyticsService, $markingModeService: IMarkingModeService, $projectConfigService: IProjectConfigService, $projectService: IProjectService);
|
|
33
|
+
constructor($platformController: IPlatformController, $hooksService: IHooksService, $fs: IFileSystem, $logger: ILogger, $options: IOptions, $mobileHelper: Mobile.IMobileHelper, $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder, $platformsDataService: IPlatformsDataService, $pluginsService: IPluginsService, $prepareNativePlatformService: IPrepareNativePlatformService, $projectChangesService: IProjectChangesService, $projectDataService: IProjectDataService, $bundlerCompilerService: IBundlerCompilerService, $watchIgnoreListService: IWatchIgnoreListService, $analyticsService: IAnalyticsService, $markingModeService: IMarkingModeService, $projectConfigService: IProjectConfigService, $projectService: IProjectService, $compiledReleaseService: CompiledReleaseService);
|
|
32
34
|
prepare(prepareData: IPrepareData): Promise<IPrepareResultData>;
|
|
33
35
|
stopWatchers(projectDir: string, platform: string): Promise<void>;
|
|
34
36
|
private prepareCore;
|
|
@@ -17,7 +17,7 @@ const yok_1 = require("../common/yok");
|
|
|
17
17
|
const constants_1 = require("../constants");
|
|
18
18
|
const resolve_package_path_1 = require("@rigor789/resolve-package-path");
|
|
19
19
|
class PrepareController extends events_1.EventEmitter {
|
|
20
|
-
constructor($platformController, $hooksService, $fs, $logger, $options, $mobileHelper, $nodeModulesDependenciesBuilder, $platformsDataService, $pluginsService, $prepareNativePlatformService, $projectChangesService, $projectDataService, $bundlerCompilerService, $watchIgnoreListService, $analyticsService, $markingModeService, $projectConfigService, $projectService) {
|
|
20
|
+
constructor($platformController, $hooksService, $fs, $logger, $options, $mobileHelper, $nodeModulesDependenciesBuilder, $platformsDataService, $pluginsService, $prepareNativePlatformService, $projectChangesService, $projectDataService, $bundlerCompilerService, $watchIgnoreListService, $analyticsService, $markingModeService, $projectConfigService, $projectService, $compiledReleaseService) {
|
|
21
21
|
super();
|
|
22
22
|
this.$platformController = $platformController;
|
|
23
23
|
this.$hooksService = $hooksService;
|
|
@@ -37,6 +37,7 @@ class PrepareController extends events_1.EventEmitter {
|
|
|
37
37
|
this.$markingModeService = $markingModeService;
|
|
38
38
|
this.$projectConfigService = $projectConfigService;
|
|
39
39
|
this.$projectService = $projectService;
|
|
40
|
+
this.$compiledReleaseService = $compiledReleaseService;
|
|
40
41
|
this.watchersData = {};
|
|
41
42
|
this.isInitialPrepareReady = false;
|
|
42
43
|
this.persistedData = [];
|
|
@@ -74,6 +75,14 @@ class PrepareController extends events_1.EventEmitter {
|
|
|
74
75
|
}
|
|
75
76
|
async prepareCore(prepareData, projectData) {
|
|
76
77
|
await this.$projectService.ensureAppResourcesExist(projectData.projectDir);
|
|
78
|
+
if (this.$compiledReleaseService.isCompiledRelease(prepareData)) {
|
|
79
|
+
await this.$compiledReleaseService.prepare(this.$platformsDataService.getPlatformData(prepareData.platform, projectData), projectData);
|
|
80
|
+
this.$logger.info(`Project successfully prepared (${prepareData.platform.toLowerCase()}, compiled)`);
|
|
81
|
+
return {
|
|
82
|
+
hasNativeChanges: true,
|
|
83
|
+
platform: prepareData.platform.toLowerCase(),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
77
86
|
await this.$platformController.addPlatformIfNeeded(prepareData, projectData);
|
|
78
87
|
await this.trackRuntimeVersion(prepareData.platform, projectData);
|
|
79
88
|
this.$logger.info("Preparing project...");
|
package/lib/data/prepare-data.js
CHANGED
package/lib/declarations.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ import { IProjectData } from "./project";
|
|
|
6
6
|
declare global {
|
|
7
7
|
interface IPrepareData extends IControllerDataBase {
|
|
8
8
|
release: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Compile a release build to native code with no JavaScript runtime.
|
|
11
|
+
* Unset defers to `release.compiled` in nativescript.config.
|
|
12
|
+
*/
|
|
13
|
+
compiled?: boolean;
|
|
9
14
|
hmr: boolean;
|
|
10
15
|
env: any;
|
|
11
16
|
watch?: boolean;
|
|
@@ -99,8 +99,39 @@ interface IProjectService {
|
|
|
99
99
|
ensureAppResourcesExist(projectDir: string): Promise<void>;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Release builds compiled to native code by `@nativescript/compiler`, and the
|
|
104
|
+
* compiler's options.
|
|
105
|
+
*/
|
|
106
|
+
interface INsConfigRelease {
|
|
107
|
+
/**
|
|
108
|
+
* Release builds compile the app to native code instead of bundling it for
|
|
109
|
+
* the JavaScript runtime. `--compiled` / `--no-compiled` override it per command.
|
|
110
|
+
*/
|
|
111
|
+
compiled?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Packages the compiled build replaces with a module of the app's, as
|
|
114
|
+
* `'package': 'path'`.
|
|
115
|
+
*/
|
|
116
|
+
pluginReplacements?: Record<string, string>;
|
|
117
|
+
/**
|
|
118
|
+
* Checkouts of plugins' TypeScript source, as `'package': 'path'`, used
|
|
119
|
+
* instead of fetching the published revision.
|
|
120
|
+
*/
|
|
121
|
+
pluginSources?: Record<string, string>;
|
|
122
|
+
/**
|
|
123
|
+
* Build despite properties core declares that the compiled build does not
|
|
124
|
+
* apply, with a warning for each.
|
|
125
|
+
*/
|
|
126
|
+
allowUnimplementedProperties?: boolean;
|
|
127
|
+
}
|
|
128
|
+
|
|
102
129
|
interface INsConfigPlaform {
|
|
103
130
|
id?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Merged over the top-level `release` for this platform; object options merge by key.
|
|
133
|
+
*/
|
|
134
|
+
release?: INsConfigRelease;
|
|
104
135
|
}
|
|
105
136
|
|
|
106
137
|
interface IOSSPMPackageBase {
|
|
@@ -201,6 +232,7 @@ interface INsConfig {
|
|
|
201
232
|
webpackConfigPath?: string;
|
|
202
233
|
bundlerConfigPath?: string;
|
|
203
234
|
bundler?: BundlerType;
|
|
235
|
+
release?: INsConfigRelease;
|
|
204
236
|
ios?: INsConfigIOS;
|
|
205
237
|
android?: INsConfigAndroid;
|
|
206
238
|
visionos?: INSConfigVisionOS;
|
|
@@ -181,14 +181,13 @@ class LiveSyncCommandHelper {
|
|
|
181
181
|
sdk: this.$options.sdk,
|
|
182
182
|
});
|
|
183
183
|
await this.$deployController.deploy({ deviceDescriptors });
|
|
184
|
-
|
|
185
|
-
const device = this.$devicesService.getDeviceByIdentifier(deviceDescriptor.identifier);
|
|
184
|
+
await this.$devicesService.execute(async (device) => {
|
|
186
185
|
await device.applicationManager.startApplication({
|
|
187
186
|
appId: this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()],
|
|
188
187
|
projectName: this.$projectData.projectName,
|
|
189
188
|
projectDir: this.$projectData.projectDir,
|
|
190
189
|
});
|
|
191
|
-
}
|
|
190
|
+
}, (device) => _.some(deviceDescriptors, (deviceDescriptor) => deviceDescriptor.identifier === device.deviceInfo.identifier));
|
|
192
191
|
}
|
|
193
192
|
async stop() {
|
|
194
193
|
const devices = await this.getDeviceInstances();
|
package/lib/options.js
CHANGED
|
@@ -174,6 +174,7 @@ class Options {
|
|
|
174
174
|
alias: "r",
|
|
175
175
|
hasSensitiveValue: false,
|
|
176
176
|
},
|
|
177
|
+
compiled: { type: enums_1.OptionType.Boolean, hasSensitiveValue: false },
|
|
177
178
|
markingMode: { type: enums_1.OptionType.Boolean, hasSensitiveValue: false },
|
|
178
179
|
var: { type: enums_1.OptionType.Object, hasSensitiveValue: true },
|
|
179
180
|
default: { type: enums_1.OptionType.Boolean, hasSensitiveValue: false },
|
|
@@ -392,6 +393,9 @@ class Options {
|
|
|
392
393
|
if (this.argv.simulator) {
|
|
393
394
|
this.argv.emulator = this.argv.simulator;
|
|
394
395
|
}
|
|
396
|
+
if (this.argv.compiled) {
|
|
397
|
+
this.argv.release = true;
|
|
398
|
+
}
|
|
395
399
|
this.argv.bundle = "webpack";
|
|
396
400
|
this.adjustDashedOptions();
|
|
397
401
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IChildProcess, IErrors, IFileSystem, IHooksService } from "../common/declarations";
|
|
2
|
+
import { IPlatformData } from "../definitions/platform";
|
|
3
|
+
import { IProjectData, IProjectDataService } from "../definitions/project";
|
|
4
|
+
import { IAndroidBuildData, IBuildData, IiOSBuildData } from "../definitions/build";
|
|
5
|
+
import { IGradleCommandService } from "../definitions/gradle";
|
|
6
|
+
import { IOSProvisionService } from "./ios-provision-service";
|
|
7
|
+
import { CompiledReportService } from "./compiled-report-service";
|
|
8
|
+
export interface ICompiledReleaseOptions {
|
|
9
|
+
projectDir: string;
|
|
10
|
+
platform: string;
|
|
11
|
+
release?: boolean;
|
|
12
|
+
compiled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class CompiledReleaseService {
|
|
15
|
+
private $childProcess;
|
|
16
|
+
private $compiledReportService;
|
|
17
|
+
private $errors;
|
|
18
|
+
private $exportOptionsPlistService;
|
|
19
|
+
private $fs;
|
|
20
|
+
private $gradleCommandService;
|
|
21
|
+
$hooksService: IHooksService;
|
|
22
|
+
private $iOSProvisionService;
|
|
23
|
+
private $logger;
|
|
24
|
+
private $mobileHelper;
|
|
25
|
+
private $projectDataService;
|
|
26
|
+
private $xcodebuildCommandService;
|
|
27
|
+
constructor($childProcess: IChildProcess, $compiledReportService: CompiledReportService, $errors: IErrors, $exportOptionsPlistService: IExportOptionsPlistService, $fs: IFileSystem, $gradleCommandService: IGradleCommandService, $hooksService: IHooksService, $iOSProvisionService: IOSProvisionService, $logger: ILogger, $mobileHelper: Mobile.IMobileHelper, $projectDataService: IProjectDataService, $xcodebuildCommandService: IXcodebuildCommandService);
|
|
28
|
+
isCompiledRelease(options: ICompiledReleaseOptions): boolean;
|
|
29
|
+
private getProjectRoot;
|
|
30
|
+
prepare(platformData: IPlatformData, projectData: IProjectData): Promise<void>;
|
|
31
|
+
private captureOutput;
|
|
32
|
+
private compileWithXcodebuild;
|
|
33
|
+
build(platformData: IPlatformData, projectData: IProjectData, buildData: IBuildData): Promise<string>;
|
|
34
|
+
buildIOSProject(projectRoot: string, projectData: IProjectData, buildData: IiOSBuildData): Promise<string>;
|
|
35
|
+
buildAndroidProject(projectRoot: string, projectData: IProjectData, buildData: IAndroidBuildData): Promise<string>;
|
|
36
|
+
private getCompilerPath;
|
|
37
|
+
getCompilerBin(projectData: IProjectData, name: string): string;
|
|
38
|
+
private getPackageDir;
|
|
39
|
+
private buildIOS;
|
|
40
|
+
private createProvisionExportOptions;
|
|
41
|
+
private packageUnsignedIpa;
|
|
42
|
+
private printKotlinErrorsInSource;
|
|
43
|
+
private buildAndroid;
|
|
44
|
+
}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CompiledReleaseService = void 0;
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const resolve_package_path_1 = require("@rigor789/resolve-package-path");
|
|
12
|
+
const constants_1 = require("../constants");
|
|
13
|
+
const yok_1 = require("../common/yok");
|
|
14
|
+
const helpers_1 = require("../common/helpers");
|
|
15
|
+
class CompiledReleaseService {
|
|
16
|
+
constructor($childProcess, $compiledReportService, $errors, $exportOptionsPlistService, $fs, $gradleCommandService, $hooksService, $iOSProvisionService, $logger, $mobileHelper, $projectDataService, $xcodebuildCommandService) {
|
|
17
|
+
this.$childProcess = $childProcess;
|
|
18
|
+
this.$compiledReportService = $compiledReportService;
|
|
19
|
+
this.$errors = $errors;
|
|
20
|
+
this.$exportOptionsPlistService = $exportOptionsPlistService;
|
|
21
|
+
this.$fs = $fs;
|
|
22
|
+
this.$gradleCommandService = $gradleCommandService;
|
|
23
|
+
this.$hooksService = $hooksService;
|
|
24
|
+
this.$iOSProvisionService = $iOSProvisionService;
|
|
25
|
+
this.$logger = $logger;
|
|
26
|
+
this.$mobileHelper = $mobileHelper;
|
|
27
|
+
this.$projectDataService = $projectDataService;
|
|
28
|
+
this.$xcodebuildCommandService = $xcodebuildCommandService;
|
|
29
|
+
}
|
|
30
|
+
isCompiledRelease(options) {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
if (!options.release) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (typeof options.compiled === "boolean") {
|
|
36
|
+
return options.compiled;
|
|
37
|
+
}
|
|
38
|
+
const nsConfig = this.$projectDataService.getProjectData(options.projectDir).nsConfig;
|
|
39
|
+
const platformConfig = nsConfig === null || nsConfig === void 0 ? void 0 : nsConfig[options.platform.toLowerCase()];
|
|
40
|
+
return !!((_b = (_a = platformConfig === null || platformConfig === void 0 ? void 0 : platformConfig.release) === null || _a === void 0 ? void 0 : _a.compiled) !== null && _b !== void 0 ? _b : (_c = nsConfig === null || nsConfig === void 0 ? void 0 : nsConfig.release) === null || _c === void 0 ? void 0 : _c.compiled);
|
|
41
|
+
}
|
|
42
|
+
getProjectRoot(projectData, platform) {
|
|
43
|
+
return path.join(projectData.platformsDir, "compiled", platform.toLowerCase());
|
|
44
|
+
}
|
|
45
|
+
async prepare(platformData, projectData) {
|
|
46
|
+
const platform = platformData.platformNameLowerCase;
|
|
47
|
+
if (!this.$mobileHelper.isiOSPlatform(platform) &&
|
|
48
|
+
!this.$mobileHelper.isAndroidPlatform(platform)) {
|
|
49
|
+
this.$errors.fail(`A compiled release build is available for iOS and Android, not ${platformData.normalizedPlatformName}.`);
|
|
50
|
+
}
|
|
51
|
+
const args = [
|
|
52
|
+
this.getCompilerPath(projectData),
|
|
53
|
+
projectData.projectDir,
|
|
54
|
+
"--platform",
|
|
55
|
+
platform,
|
|
56
|
+
"--out",
|
|
57
|
+
this.getProjectRoot(projectData, platform),
|
|
58
|
+
"--name",
|
|
59
|
+
projectData.projectName,
|
|
60
|
+
"--bundle",
|
|
61
|
+
projectData.projectIdentifiers[platform],
|
|
62
|
+
];
|
|
63
|
+
this.$compiledReportService.clearDraft(projectData, platform);
|
|
64
|
+
this.$logger.info(`Compiling the app to native code (${platform})...`);
|
|
65
|
+
const eventName = "compiledReleaseCompilerOutput";
|
|
66
|
+
const capture = this.captureOutput(eventName);
|
|
67
|
+
let result;
|
|
68
|
+
try {
|
|
69
|
+
result = await this.$childProcess.spawnFromEvent(process.execPath, args, "close", { cwd: projectData.projectDir, stdio: ["inherit", "inherit", "pipe"] }, { throwError: false, emitOptions: { eventName } });
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
capture.stop();
|
|
73
|
+
}
|
|
74
|
+
if (result.exitCode !== 0) {
|
|
75
|
+
const hint = this.$compiledReportService.saveDraft(projectData, platform, "compile-refused", capture.output.join(""));
|
|
76
|
+
this.$errors.fail(`The compile to native code failed (exit code ${result.exitCode}).${hint ? `\n${hint}` : ""}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
captureOutput(eventName) {
|
|
80
|
+
const output = [];
|
|
81
|
+
const onOutput = ({ data, pipe }) => {
|
|
82
|
+
output.push(data.toString());
|
|
83
|
+
(pipe === "stderr" ? process.stderr : process.stdout).write(data);
|
|
84
|
+
};
|
|
85
|
+
this.$childProcess.on(eventName, onOutput);
|
|
86
|
+
return {
|
|
87
|
+
output,
|
|
88
|
+
stop: () => this.$childProcess.removeListener(eventName, onOutput),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async compileWithXcodebuild(projectData, args, options) {
|
|
92
|
+
const eventName = "compiledReleaseXcodebuildOutput";
|
|
93
|
+
const capture = this.captureOutput(eventName);
|
|
94
|
+
let result;
|
|
95
|
+
try {
|
|
96
|
+
result = await this.$xcodebuildCommandService.executeCommand(args, {
|
|
97
|
+
...options,
|
|
98
|
+
stdio: "pipe",
|
|
99
|
+
spawnOptions: { throwError: false, emitOptions: { eventName } },
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
capture.stop();
|
|
104
|
+
}
|
|
105
|
+
if (result.exitCode !== 0) {
|
|
106
|
+
const hint = this.$compiledReportService.saveDraft(projectData, "ios", "native-compile", capture.output.join(""));
|
|
107
|
+
this.$errors.fail(`xcodebuild failed with exit code ${result.exitCode}.${hint ? `\n${hint}` : ""}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async build(platformData, projectData, buildData) {
|
|
111
|
+
if (buildData.clean) {
|
|
112
|
+
const projectRoot = this.getProjectRoot(projectData, platformData.platformNameLowerCase);
|
|
113
|
+
this.$fs.deleteDirectory(path.join(projectRoot, "DerivedData"));
|
|
114
|
+
this.$fs.deleteDirectory(path.join(projectRoot, "build"));
|
|
115
|
+
}
|
|
116
|
+
const platform = platformData.platformNameLowerCase;
|
|
117
|
+
const projectRoot = this.getProjectRoot(projectData, platform);
|
|
118
|
+
const packageFile = this.$mobileHelper.isAndroidPlatform(platform)
|
|
119
|
+
? await this.buildAndroidProject(projectRoot, projectData, buildData)
|
|
120
|
+
: await this.buildIOSProject(projectRoot, projectData, buildData);
|
|
121
|
+
if (!this.$fs.exists(packageFile)) {
|
|
122
|
+
this.$errors.fail(`The compiled release build finished without producing ${packageFile}.`);
|
|
123
|
+
}
|
|
124
|
+
return packageFile;
|
|
125
|
+
}
|
|
126
|
+
async buildIOSProject(projectRoot, projectData, buildData) {
|
|
127
|
+
return this.buildIOS(projectData, buildData);
|
|
128
|
+
}
|
|
129
|
+
async buildAndroidProject(projectRoot, projectData, buildData) {
|
|
130
|
+
return this.buildAndroid(projectData, buildData);
|
|
131
|
+
}
|
|
132
|
+
getCompilerPath(projectData) {
|
|
133
|
+
return this.getCompilerBin(projectData, "ns-native");
|
|
134
|
+
}
|
|
135
|
+
getCompilerBin(projectData, name) {
|
|
136
|
+
const packageDir = this.getPackageDir(projectData);
|
|
137
|
+
const { bin } = this.$fs.readJson(path.join(packageDir, "package.json"));
|
|
138
|
+
if (!(bin === null || bin === void 0 ? void 0 : bin[name])) {
|
|
139
|
+
this.$errors.fail(`The project's ${constants_1.COMPILER_PACKAGE_NAME} has no ${name}: update it.`);
|
|
140
|
+
}
|
|
141
|
+
return path.join(packageDir, bin[name]);
|
|
142
|
+
}
|
|
143
|
+
getPackageDir(projectData) {
|
|
144
|
+
const packageDir = (0, resolve_package_path_1.resolvePackagePath)(constants_1.COMPILER_PACKAGE_NAME, {
|
|
145
|
+
paths: [projectData.projectDir],
|
|
146
|
+
});
|
|
147
|
+
if (!packageDir) {
|
|
148
|
+
this.$errors.fail(`A compiled release build needs ${constants_1.COMPILER_PACKAGE_NAME} in the project. ` +
|
|
149
|
+
`Install it with 'npm install --save-dev ${constants_1.COMPILER_PACKAGE_NAME}', ` +
|
|
150
|
+
`or build on the JavaScript runtime with --no-compiled.`);
|
|
151
|
+
}
|
|
152
|
+
return packageDir;
|
|
153
|
+
}
|
|
154
|
+
async buildIOS(projectData, buildData) {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
const projectRoot = this.getProjectRoot(projectData, "ios");
|
|
157
|
+
const name = projectData.projectName;
|
|
158
|
+
const integrated = path.join(projectRoot, "ns-native-project.json");
|
|
159
|
+
const generated = this.$fs.exists(integrated)
|
|
160
|
+
? this.$fs.readJson(integrated)
|
|
161
|
+
: null;
|
|
162
|
+
const workspace = (_a = generated === null || generated === void 0 ? void 0 : generated.workspace) !== null && _a !== void 0 ? _a : null;
|
|
163
|
+
if (!generated) {
|
|
164
|
+
try {
|
|
165
|
+
await this.$childProcess.spawnFromEvent("xcodegen", ["generate", "--quiet"], "close", { cwd: projectRoot, stdio: "inherit" });
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
this.$errors.fail(err.code === "ENOENT"
|
|
169
|
+
? "The native iOS build generates its Xcode project with XcodeGen. Install it with 'brew install xcodegen'."
|
|
170
|
+
: err.message);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const projectArgs = [
|
|
174
|
+
...(workspace
|
|
175
|
+
? ["-workspace", workspace]
|
|
176
|
+
: ["-project", (_b = generated === null || generated === void 0 ? void 0 : generated.project) !== null && _b !== void 0 ? _b : `${name}.xcodeproj`]),
|
|
177
|
+
"-scheme",
|
|
178
|
+
name,
|
|
179
|
+
"-configuration",
|
|
180
|
+
"Release",
|
|
181
|
+
"-derivedDataPath",
|
|
182
|
+
"DerivedData",
|
|
183
|
+
"-quiet",
|
|
184
|
+
];
|
|
185
|
+
if (!buildData.buildForDevice && !buildData.buildForAppStore) {
|
|
186
|
+
await this.compileWithXcodebuild(projectData, [
|
|
187
|
+
...projectArgs,
|
|
188
|
+
"-destination",
|
|
189
|
+
"generic/platform=iOS Simulator",
|
|
190
|
+
"ARCHS=$(NATIVE_ARCH_ACTUAL)",
|
|
191
|
+
"build",
|
|
192
|
+
], { cwd: projectRoot, message: "Xcode build (compiled release)..." });
|
|
193
|
+
return path.join(projectRoot, "DerivedData", "Build", "Products", "Release-iphonesimulator", `${name}.app`);
|
|
194
|
+
}
|
|
195
|
+
const outputDir = path.join(projectRoot, "build");
|
|
196
|
+
const archivePath = path.join(outputDir, `${name}.xcarchive`);
|
|
197
|
+
const automaticSigning = buildData.teamId && !buildData.provision
|
|
198
|
+
? [
|
|
199
|
+
"CODE_SIGNING_ALLOWED=YES",
|
|
200
|
+
"CODE_SIGN_STYLE=Automatic",
|
|
201
|
+
`DEVELOPMENT_TEAM=${buildData.teamId}`,
|
|
202
|
+
"-allowProvisioningUpdates",
|
|
203
|
+
]
|
|
204
|
+
: ["CODE_SIGNING_ALLOWED=NO"];
|
|
205
|
+
this.$fs.deleteDirectory(archivePath);
|
|
206
|
+
await this.compileWithXcodebuild(projectData, [
|
|
207
|
+
...projectArgs,
|
|
208
|
+
"-destination",
|
|
209
|
+
"generic/platform=iOS",
|
|
210
|
+
"-archivePath",
|
|
211
|
+
archivePath,
|
|
212
|
+
"archive",
|
|
213
|
+
...automaticSigning,
|
|
214
|
+
], { cwd: projectRoot, message: "Xcode archive (compiled release)..." });
|
|
215
|
+
if (!buildData.teamId && !buildData.provision) {
|
|
216
|
+
this.$logger.warn(`The archive is unsigned: pass --team-id <team> or --provision <profile> to sign it and export an .ipa that installs on a device. ` +
|
|
217
|
+
`The unsigned .ipa is for re-signing elsewhere.`);
|
|
218
|
+
return this.packageUnsignedIpa(archivePath, outputDir, name);
|
|
219
|
+
}
|
|
220
|
+
const exportOptions = buildData.provision
|
|
221
|
+
? await this.createProvisionExportOptions(projectData, buildData.provision, outputDir)
|
|
222
|
+
: buildData.buildForAppStore
|
|
223
|
+
? await this.$exportOptionsPlistService.createDistributionExportOptionsPlist(archivePath, projectData, buildData)
|
|
224
|
+
: await this.$exportOptionsPlistService.createDevelopmentExportOptionsPlist(archivePath, projectData, buildData);
|
|
225
|
+
await this.$xcodebuildCommandService.executeCommand([
|
|
226
|
+
"-exportArchive",
|
|
227
|
+
"-archivePath",
|
|
228
|
+
archivePath,
|
|
229
|
+
"-exportPath",
|
|
230
|
+
exportOptions.exportFileDir,
|
|
231
|
+
"-exportOptionsPlist",
|
|
232
|
+
exportOptions.exportOptionsPlistFilePath,
|
|
233
|
+
...(buildData.provision ? [] : ["-allowProvisioningUpdates"]),
|
|
234
|
+
], { cwd: projectRoot, message: "Exporting the .ipa..." });
|
|
235
|
+
return exportOptions.exportFilePath;
|
|
236
|
+
}
|
|
237
|
+
async createProvisionExportOptions(projectData, provision, outputDir) {
|
|
238
|
+
const bundleId = projectData.projectIdentifiers.ios;
|
|
239
|
+
const profile = await this.$iOSProvisionService.pick(provision, bundleId);
|
|
240
|
+
if (!profile) {
|
|
241
|
+
this.$errors.fail(`Failed to find mobile provision with UUID or Name: ${provision}`);
|
|
242
|
+
}
|
|
243
|
+
const method = {
|
|
244
|
+
Development: "development",
|
|
245
|
+
AdHoc: "ad-hoc",
|
|
246
|
+
Distribution: "app-store",
|
|
247
|
+
Enterprise: "enterprise",
|
|
248
|
+
}[profile.Type];
|
|
249
|
+
const exportOptionsPlistFilePath = path.join(outputDir, "ExportOptions.plist");
|
|
250
|
+
this.$fs.writeFile(exportOptionsPlistFilePath, `<?xml version="1.0" encoding="UTF-8"?>
|
|
251
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
252
|
+
<plist version="1.0">
|
|
253
|
+
<dict>
|
|
254
|
+
<key>method</key>
|
|
255
|
+
<string>${method}</string>
|
|
256
|
+
<key>signingStyle</key>
|
|
257
|
+
<string>manual</string>
|
|
258
|
+
<key>teamID</key>
|
|
259
|
+
<string>${profile.TeamIdentifier[0]}</string>
|
|
260
|
+
<key>provisioningProfiles</key>
|
|
261
|
+
<dict>
|
|
262
|
+
<key>${bundleId}</key>
|
|
263
|
+
<string>${profile.UUID}</string>
|
|
264
|
+
</dict>
|
|
265
|
+
</dict>
|
|
266
|
+
</plist>
|
|
267
|
+
`);
|
|
268
|
+
return {
|
|
269
|
+
exportFileDir: outputDir,
|
|
270
|
+
exportFilePath: path.join(outputDir, `${projectData.projectName}.ipa`),
|
|
271
|
+
exportOptionsPlistFilePath,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
async packageUnsignedIpa(archivePath, outputDir, name) {
|
|
275
|
+
const payloadDir = path.join(outputDir, "Payload");
|
|
276
|
+
const ipaPath = path.join(outputDir, `${name}.ipa`);
|
|
277
|
+
this.$fs.deleteDirectory(payloadDir);
|
|
278
|
+
this.$fs.deleteFile(ipaPath);
|
|
279
|
+
this.$fs.ensureDirectoryExists(payloadDir);
|
|
280
|
+
await this.$childProcess.spawnFromEvent("cp", [
|
|
281
|
+
"-R",
|
|
282
|
+
path.join(archivePath, "Products", "Applications", `${name}.app`),
|
|
283
|
+
payloadDir,
|
|
284
|
+
], "close");
|
|
285
|
+
await this.$childProcess.spawnFromEvent("zip", ["-qr", "-y", ipaPath, "Payload"], "close", { cwd: outputDir });
|
|
286
|
+
this.$fs.deleteDirectory(payloadDir);
|
|
287
|
+
return ipaPath;
|
|
288
|
+
}
|
|
289
|
+
async printKotlinErrorsInSource(projectData, projectRoot, log) {
|
|
290
|
+
const errors = log.split("\n").filter((line) => /^e: /.test(line));
|
|
291
|
+
if (!errors.length || !this.$fs.exists(path.join(projectRoot, "source-lines.json"))) {
|
|
292
|
+
return [];
|
|
293
|
+
}
|
|
294
|
+
const logFile = path.join(projectRoot, "build", "compile-errors.log");
|
|
295
|
+
this.$fs.writeFile(logFile, errors.join("\n") + "\n");
|
|
296
|
+
try {
|
|
297
|
+
const result = await this.$childProcess.spawnFromEvent(process.execPath, [this.getCompilerBin(projectData, "ns-native-retrace"), "--build-log", projectRoot, logFile], "close", { cwd: projectData.projectDir }, { throwError: false });
|
|
298
|
+
const mapped = result.stdout.split("\n").filter((line, k) => line && line !== errors[k]);
|
|
299
|
+
if (mapped.length) {
|
|
300
|
+
this.$logger.error(`Kotlin errors in your source:\n${mapped.join("\n")}`);
|
|
301
|
+
}
|
|
302
|
+
return mapped;
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
this.$logger.trace(`Mapping Kotlin errors to source lines failed: ${err.message}`);
|
|
306
|
+
return [];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async buildAndroid(projectData, buildData) {
|
|
310
|
+
var _a;
|
|
311
|
+
const projectRoot = this.getProjectRoot(projectData, "android");
|
|
312
|
+
const args = [
|
|
313
|
+
"-p",
|
|
314
|
+
projectRoot,
|
|
315
|
+
buildData.androidBundle ? ":bundleRelease" : ":assembleRelease",
|
|
316
|
+
"--quiet",
|
|
317
|
+
];
|
|
318
|
+
if (buildData.keyStorePath) {
|
|
319
|
+
args.push(`-Pandroid.injected.signing.store.file=${path.resolve(buildData.keyStorePath)}`, `-Pandroid.injected.signing.store.password=${buildData.keyStorePassword}`, `-Pandroid.injected.signing.key.alias=${buildData.keyStoreAlias}`, `-Pandroid.injected.signing.key.password=${buildData.keyStoreAliasPassword}`);
|
|
320
|
+
}
|
|
321
|
+
const eventName = "compiledReleaseGradleOutput";
|
|
322
|
+
const capture = this.captureOutput(eventName);
|
|
323
|
+
try {
|
|
324
|
+
await this.$gradleCommandService.executeCommand(args, {
|
|
325
|
+
cwd: projectRoot,
|
|
326
|
+
message: "Gradle build (compiled release)...",
|
|
327
|
+
gradlePath: (_a = buildData.gradlePath) !== null && _a !== void 0 ? _a : path.join(this.getPackageDir(projectData), "kit-android", "gradlew"),
|
|
328
|
+
stdio: "pipe",
|
|
329
|
+
spawnOptions: { throwError: true, emitOptions: { eventName } },
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
catch (err) {
|
|
333
|
+
const log = capture.output.join("");
|
|
334
|
+
const mapped = await this.printKotlinErrorsInSource(projectData, projectRoot, log);
|
|
335
|
+
const hint = this.$compiledReportService.saveDraft(projectData, "android", "native-compile", [...mapped, log].join("\n"));
|
|
336
|
+
if (hint) {
|
|
337
|
+
err.message = `${err.message}\n${hint}`;
|
|
338
|
+
}
|
|
339
|
+
throw err;
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
capture.stop();
|
|
343
|
+
}
|
|
344
|
+
const outputName = projectData.projectName;
|
|
345
|
+
return buildData.androidBundle
|
|
346
|
+
? path.join(projectRoot, "build", "outputs", "bundle", "release", `${outputName}-release.aab`)
|
|
347
|
+
: path.join(projectRoot, "build", "outputs", "apk", "release", `${outputName}-release.apk`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
exports.CompiledReleaseService = CompiledReleaseService;
|
|
351
|
+
__decorate([
|
|
352
|
+
(0, helpers_1.hook)("buildIOS")
|
|
353
|
+
], CompiledReleaseService.prototype, "buildIOSProject", null);
|
|
354
|
+
__decorate([
|
|
355
|
+
(0, helpers_1.hook)("buildAndroid")
|
|
356
|
+
], CompiledReleaseService.prototype, "buildAndroidProject", null);
|
|
357
|
+
yok_1.injector.register("compiledReleaseService", CompiledReleaseService);
|