@akylas/nativescript-cli 8.7.2 → 8.8.2
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/test-deps-versions-generated.json +1 -1
- package/docs/man_pages/project/configuration/native/native-add-java.md +32 -0
- package/docs/man_pages/project/configuration/native/native-add-kotlin.md +34 -0
- package/docs/man_pages/project/configuration/native/native-add-objective-c.md +34 -0
- package/docs/man_pages/project/configuration/native/native-add-swift.md +32 -0
- package/docs/man_pages/project/configuration/native/native-add.md +31 -0
- package/docs/man_pages/project/configuration/native/native.md +31 -0
- package/lib/.d.ts +2 -0
- package/lib/bootstrap.js +8 -0
- package/lib/commands/embedding/embed.js +91 -0
- package/lib/commands/native-add.js +300 -0
- package/lib/commands/plugin/build-plugin.js +3 -9
- package/lib/commands/prepare.js +9 -0
- package/lib/commands/typings.js +1 -1
- package/lib/common/mobile/android/android-virtual-device-service.js +4 -1
- package/lib/common/mobile/android/logcat-helper.js +15 -6
- package/lib/common/mobile/emulator-helper.js +1 -0
- package/lib/common/utils.js +8 -1
- package/lib/controllers/migrate-controller.js +6 -6
- package/lib/controllers/platform-controller.js +4 -0
- package/lib/controllers/prepare-controller.js +61 -14
- package/lib/data/build-data.js +2 -0
- package/lib/data/prepare-data.js +1 -0
- package/lib/declarations.d.ts +14 -3
- package/lib/definitions/android-plugin-migrator.d.ts +1 -0
- package/lib/definitions/platform.d.ts +1 -0
- package/lib/definitions/prepare.d.ts +3 -0
- package/lib/definitions/project.d.ts +5 -0
- package/lib/helpers/platform-command-helper.js +10 -1
- package/lib/options.js +9 -2
- package/lib/project-data.js +4 -1
- package/lib/providers/project-files-provider.js +1 -1
- package/lib/services/android/gradle-build-args-service.js +4 -3
- package/lib/services/android/gradle-command-service.js +5 -1
- package/lib/services/android-plugin-build-service.js +34 -22
- package/lib/services/android-project-service.js +20 -23
- package/lib/services/assets-generation/assets-generation-service.js +5 -1
- package/lib/services/cocoapods-service.js +9 -3
- package/lib/services/files-hash-service.js +3 -2
- package/lib/services/ios-project-service.js +50 -17
- package/lib/services/livesync/android-device-livesync-sockets-service.js +3 -4
- package/lib/services/livesync/android-livesync-service.js +2 -2
- package/lib/services/livesync/ios-livesync-service.js +2 -2
- package/lib/services/livesync/platform-livesync-service-base.js +4 -3
- package/lib/services/log-source-map-service.js +3 -2
- package/lib/services/platform/add-platform-service.js +7 -2
- package/lib/services/platform/prepare-native-platform-service.js +6 -3
- package/lib/services/platform-environment-requirements.js +3 -1
- package/lib/services/plugins-service.js +7 -1
- package/lib/services/project-changes-service.js +8 -1
- package/lib/services/project-config-service.js +1 -1
- package/lib/services/project-data-service.js +15 -21
- package/lib/services/webpack/webpack-compiler-service.js +14 -6
- package/lib/services/xcproj-service.js +12 -0
- package/package.json +3 -3
- package/vendor/aab-tool/README.txt +1 -1
- package/vendor/aab-tool/bundletool.jar +0 -0
- package/vendor/gradle-app/app/build.gradle +12 -4
- package/vendor/gradle-plugin/build.gradle +12 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"@jsdevtools/coverage-istanbul-loader":"3.0.5","karma":"6.4.
|
|
1
|
+
{"@jsdevtools/coverage-istanbul-loader":"3.0.5","karma":"6.4.4","karma-coverage":"2.2.1","karma-nativescript-launcher":"0.4.0","mocha":"10.7.3","karma-mocha":"2.0.1","karma-chai":"0.1.0","karma-jasmine":"4.0.2","karma-qunit":"4.2.1","@types/karma-chai":"0.1.7","@types/mocha":"10.0.9","@types/jasmine":"5.1.4","@types/qunit":"2.19.10","nyc":"17.1.0"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<% if (isJekyll) { %>---
|
|
2
|
+
title: ns native add java
|
|
3
|
+
position: 2
|
|
4
|
+
---<% } %>
|
|
5
|
+
|
|
6
|
+
# ns native add java
|
|
7
|
+
|
|
8
|
+
### Description
|
|
9
|
+
|
|
10
|
+
Adds a newly generated Java file, which includes a class with the specified name, placing it in the appropriate directory.
|
|
11
|
+
|
|
12
|
+
### Commands
|
|
13
|
+
|
|
14
|
+
Usage | Synopsis
|
|
15
|
+
------|-------
|
|
16
|
+
Java | `$ ns native add java <Java class name>`
|
|
17
|
+
|
|
18
|
+
### Arguments
|
|
19
|
+
|
|
20
|
+
* `<Java class name>` is the fully qualified name of the `Class` to create, e.g. `org.nativescript.SomeClass`
|
|
21
|
+
|
|
22
|
+
<% if(isHtml) { %>
|
|
23
|
+
|
|
24
|
+
### Related Commands
|
|
25
|
+
|
|
26
|
+
Command | Description
|
|
27
|
+
----------|----------
|
|
28
|
+
[native add swift](native-add-swift.html) | Generates and adds a Swift file containing a class of the given name.
|
|
29
|
+
[native add objective-c](native-add-objective-c.html) | Generates and adds Objective-C files containing an interface of the given name.
|
|
30
|
+
[native add java](native-add-java.html) | Generates and adds a Java file containing a class of the given name.
|
|
31
|
+
[native add kotlin](native-add-kotlin.html) | Generates and adds a Kotlin file containing a class of the given name.
|
|
32
|
+
<% } %>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<% if (isJekyll) { %>---
|
|
2
|
+
title: ns native add kotlin
|
|
3
|
+
position: 3
|
|
4
|
+
---<% } %>
|
|
5
|
+
|
|
6
|
+
# ns native add kotlin
|
|
7
|
+
|
|
8
|
+
### Description
|
|
9
|
+
|
|
10
|
+
Adds a newly generated Kotlin file, which includes a class with the specified name, placing it in the appropriate directory.
|
|
11
|
+
|
|
12
|
+
Kotlin usage requires that the `useKotlin` property is set in `gradle.properties`, the command will set this to `true`.
|
|
13
|
+
|
|
14
|
+
### Commands
|
|
15
|
+
|
|
16
|
+
Usage | Synopsis
|
|
17
|
+
------|-------
|
|
18
|
+
Kotlin | `$ ns native add kotlin <Kotlin class name>`
|
|
19
|
+
|
|
20
|
+
### Arguments
|
|
21
|
+
|
|
22
|
+
* `<Kotlin class name>` is the fully qualified name of the `Class` to create, e.g. `org.nativescript.SomeClass`
|
|
23
|
+
|
|
24
|
+
<% if(isHtml) { %>
|
|
25
|
+
|
|
26
|
+
### Related Commands
|
|
27
|
+
|
|
28
|
+
Command | Description
|
|
29
|
+
----------|----------
|
|
30
|
+
[native add swift](native-add-swift.html) | Generates and adds a Swift file containing a class of the given name.
|
|
31
|
+
[native add objective-c](native-add-objective-c.html) | Generates and adds Objective-C files containing an interface of the given name.
|
|
32
|
+
[native add java](native-add-java.html) | Generates and adds a Java file containing a class of the given name.
|
|
33
|
+
[native add kotlin](native-add-kotlin.html) | Generates and adds a Kotlin file containing a class of the given name.
|
|
34
|
+
<% } %>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<% if (isJekyll) { %>---
|
|
2
|
+
title: ns native add objective-c
|
|
3
|
+
position: 4
|
|
4
|
+
---<% } %>
|
|
5
|
+
|
|
6
|
+
# ns native add objective-c
|
|
7
|
+
|
|
8
|
+
### Description
|
|
9
|
+
|
|
10
|
+
Adds newly generated Objective-C files, which include an interface with the specified name, placing them in the appropriate directory.
|
|
11
|
+
|
|
12
|
+
Objective-C usage requires that the `module.modulemap` is modified to include the header file, the command will set this entry.
|
|
13
|
+
|
|
14
|
+
### Commands
|
|
15
|
+
|
|
16
|
+
Usage | Synopsis
|
|
17
|
+
------|-------
|
|
18
|
+
Objective-C | `$ ns native add objective-c <Objective-C interface name>`
|
|
19
|
+
|
|
20
|
+
### Arguments
|
|
21
|
+
|
|
22
|
+
* `<Objective-C interface name>` is the name of the `interface` to create, e.g. `SomeInterface`
|
|
23
|
+
|
|
24
|
+
<% if(isHtml) { %>
|
|
25
|
+
|
|
26
|
+
### Related Commands
|
|
27
|
+
|
|
28
|
+
Command | Description
|
|
29
|
+
----------|----------
|
|
30
|
+
[native add swift](native-add-swift.html) | Generates and adds a Swift file containing a class of the given name.
|
|
31
|
+
[native add objective-c](native-add-objective-c.html) | Generates and adds Objective-C files containing an interface of the given name.
|
|
32
|
+
[native add java](native-add-java.html) | Generates and adds a Java file containing a class of the given name.
|
|
33
|
+
[native add kotlin](native-add-kotlin.html) | Generates and adds a Kotlin file containing a class of the given name.
|
|
34
|
+
<% } %>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<% if (isJekyll) { %>---
|
|
2
|
+
title: ns native add swift
|
|
3
|
+
position: 5
|
|
4
|
+
---<% } %>
|
|
5
|
+
|
|
6
|
+
# ns native add swift
|
|
7
|
+
|
|
8
|
+
### Description
|
|
9
|
+
|
|
10
|
+
Adds a newly generated Swift file, which includes a class with the specified name, placing it in the appropriate directory.
|
|
11
|
+
|
|
12
|
+
### Commands
|
|
13
|
+
|
|
14
|
+
Usage | Synopsis
|
|
15
|
+
------|-------
|
|
16
|
+
Swift | `$ ns native add swift <Swift class name>`
|
|
17
|
+
|
|
18
|
+
### Arguments
|
|
19
|
+
|
|
20
|
+
* `<Swift class name>` is the name of the `Class` to create, e.g. `SomeClass`
|
|
21
|
+
|
|
22
|
+
<% if(isHtml) { %>
|
|
23
|
+
|
|
24
|
+
### Related Commands
|
|
25
|
+
|
|
26
|
+
Command | Description
|
|
27
|
+
----------|----------
|
|
28
|
+
[native add swift](native-add-swift.html) | Generates and adds a Swift file containing a class of the given name.
|
|
29
|
+
[native add objective-c](native-add-objective-c.html) | Generates and adds Objective-C files containing an interface of the given name.
|
|
30
|
+
[native add java](native-add-java.html) | Generates and adds a Java file containing a class of the given name.
|
|
31
|
+
[native add kotlin](native-add-kotlin.html) | Generates and adds a Kotlin file containing a class of the given name.
|
|
32
|
+
<% } %>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<% if (isJekyll) { %>---
|
|
2
|
+
title: ns native add
|
|
3
|
+
position: 1
|
|
4
|
+
---<% } %>
|
|
5
|
+
|
|
6
|
+
# ns native add
|
|
7
|
+
|
|
8
|
+
### Description
|
|
9
|
+
|
|
10
|
+
Commands to add native files to the application placing them in the correct directory.
|
|
11
|
+
|
|
12
|
+
### Commands
|
|
13
|
+
|
|
14
|
+
Usage | Synopsis
|
|
15
|
+
------|-------
|
|
16
|
+
Swift | `$ ns native add swift <Swift class name>`
|
|
17
|
+
Objective-C | `$ ns native add objective-c <Objective-C interface name>`
|
|
18
|
+
Java | `$ ns native add java <Java class name>`
|
|
19
|
+
Kotlin | `$ ns native add kotlin <Kotlin class name>`
|
|
20
|
+
|
|
21
|
+
<% if(isHtml) { %>
|
|
22
|
+
|
|
23
|
+
### Related Commands
|
|
24
|
+
|
|
25
|
+
Command | Description
|
|
26
|
+
----------|----------
|
|
27
|
+
[native add swift](native-add-swift.html) | Generates and adds a Swift file containing a class of the given name.
|
|
28
|
+
[native add objective-c](native-add-objective-c.html) | Generates and adds Objective-C files containing an interface of the given name.
|
|
29
|
+
[native add java](native-add-java.html) | Generates and adds a Java file containing a class of the given name.
|
|
30
|
+
[native add kotlin](native-add-kotlin.html) | Generates and adds a Kotlin file containing a class of the given name.
|
|
31
|
+
<% } %>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<% if (isJekyll) { %>---
|
|
2
|
+
title: ns native
|
|
3
|
+
position: 1
|
|
4
|
+
---<% } %>
|
|
5
|
+
|
|
6
|
+
# ns native
|
|
7
|
+
|
|
8
|
+
### Description
|
|
9
|
+
|
|
10
|
+
Commands to add native files to the application placing them in the correct directory.
|
|
11
|
+
|
|
12
|
+
### Commands
|
|
13
|
+
|
|
14
|
+
Usage | Synopsis
|
|
15
|
+
------|-------
|
|
16
|
+
Swift | `$ ns native add swift <Swift class name>`
|
|
17
|
+
Objective-C | `$ ns native add objective-c <Objective-C interface name>`
|
|
18
|
+
Java | `$ ns native add java <Java class name>`
|
|
19
|
+
Kotlin | `$ ns native add kotlin <Kotlin class name>`
|
|
20
|
+
|
|
21
|
+
<% if(isHtml) { %>
|
|
22
|
+
|
|
23
|
+
### Related Commands
|
|
24
|
+
|
|
25
|
+
Command | Description
|
|
26
|
+
----------|----------
|
|
27
|
+
[native add swift](native-add-swift.html) | Generates and adds a Swift file containing a class of the given name.
|
|
28
|
+
[native add objective-c](native-add-objective-c.html) | Generates and adds Objective-C files containing an interface of the given name.
|
|
29
|
+
[native add java](native-add-java.html) | Generates and adds a Java file containing a class of the given name.
|
|
30
|
+
[native add kotlin](native-add-kotlin.html) | Generates and adds a Kotlin file containing a class of the given name.
|
|
31
|
+
<% } %>
|
package/lib/.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
/// <reference path="commands/create-project.ts" />
|
|
16
16
|
/// <reference path="commands/debug.ts" />
|
|
17
17
|
/// <reference path="commands/deploy.ts" />
|
|
18
|
+
/// <reference path="commands/embedding/embed.ts" />
|
|
18
19
|
/// <reference path="commands/extensibility/install-extension.ts" />
|
|
19
20
|
/// <reference path="commands/extensibility/list-extensions.ts" />
|
|
20
21
|
/// <reference path="commands/extensibility/uninstall-extension.ts" />
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
/// <reference path="commands/install.ts" />
|
|
27
28
|
/// <reference path="commands/list-platforms.ts" />
|
|
28
29
|
/// <reference path="commands/migrate.ts" />
|
|
30
|
+
/// <reference path="commands/native-add.ts" />
|
|
29
31
|
/// <reference path="commands/platform-clean.ts" />
|
|
30
32
|
/// <reference path="commands/plugin/add-plugin.ts" />
|
|
31
33
|
/// <reference path="commands/plugin/build-plugin.ts" />
|
package/lib/bootstrap.js
CHANGED
|
@@ -93,6 +93,7 @@ yok_1.injector.requireCommand("build|android", "./commands/build");
|
|
|
93
93
|
yok_1.injector.requireCommand("build|vision", "./commands/build");
|
|
94
94
|
yok_1.injector.requireCommand("build|visionos", "./commands/build");
|
|
95
95
|
yok_1.injector.requireCommand("deploy", "./commands/deploy");
|
|
96
|
+
yok_1.injector.requireCommand("embed", "./commands/embedding/embed");
|
|
96
97
|
yok_1.injector.require("testExecutionService", "./services/test-execution-service");
|
|
97
98
|
yok_1.injector.requireCommand("dev-test|android", "./commands/test");
|
|
98
99
|
yok_1.injector.requireCommand("dev-test|ios", "./commands/test");
|
|
@@ -200,4 +201,11 @@ yok_1.injector.require("sharedEventBus", "./shared-event-bus");
|
|
|
200
201
|
yok_1.injector.require("keyCommandHelper", "./helpers/key-command-helper");
|
|
201
202
|
yok_1.injector.requireCommand("start", "./commands/start");
|
|
202
203
|
yok_1.injector.require("startService", "./services/start-service");
|
|
204
|
+
yok_1.injector.requireCommand([
|
|
205
|
+
"native|add",
|
|
206
|
+
"native|add|java",
|
|
207
|
+
"native|add|kotlin",
|
|
208
|
+
"native|add|swift",
|
|
209
|
+
"native|add|objective-c",
|
|
210
|
+
], "./commands/native-add");
|
|
203
211
|
require("./key-commands/bootstrap");
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EmbedCommand = void 0;
|
|
13
|
+
const yok_1 = require("../../common/yok");
|
|
14
|
+
const prepare_1 = require("../prepare");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const color_1 = require("../../color");
|
|
17
|
+
class EmbedCommand extends prepare_1.PrepareCommand {
|
|
18
|
+
constructor($options, $prepareController, $platformValidationService, $projectData, $platformCommandParameter, $platformsDataService, $prepareDataService, $migrateController, $logger, $fs, $projectConfigService) {
|
|
19
|
+
super($options, $prepareController, $platformValidationService, $projectData, $platformCommandParameter, $platformsDataService, $prepareDataService, $migrateController);
|
|
20
|
+
this.$options = $options;
|
|
21
|
+
this.$prepareController = $prepareController;
|
|
22
|
+
this.$platformValidationService = $platformValidationService;
|
|
23
|
+
this.$projectData = $projectData;
|
|
24
|
+
this.$platformCommandParameter = $platformCommandParameter;
|
|
25
|
+
this.$platformsDataService = $platformsDataService;
|
|
26
|
+
this.$prepareDataService = $prepareDataService;
|
|
27
|
+
this.$migrateController = $migrateController;
|
|
28
|
+
this.$logger = $logger;
|
|
29
|
+
this.$fs = $fs;
|
|
30
|
+
this.$projectConfigService = $projectConfigService;
|
|
31
|
+
}
|
|
32
|
+
resolveHostProjectPath(hostProjectPath) {
|
|
33
|
+
if (hostProjectPath.charAt(0) === ".") {
|
|
34
|
+
const projectDir = this.$projectData.projectDir;
|
|
35
|
+
return (0, path_1.resolve)(projectDir, hostProjectPath);
|
|
36
|
+
}
|
|
37
|
+
return (0, path_1.resolve)(hostProjectPath);
|
|
38
|
+
}
|
|
39
|
+
execute(args) {
|
|
40
|
+
const _super = Object.create(null, {
|
|
41
|
+
execute: { get: () => super.execute }
|
|
42
|
+
});
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const hostProjectPath = args[1];
|
|
45
|
+
const resolvedHostProjectPath = this.resolveHostProjectPath(hostProjectPath);
|
|
46
|
+
if (!this.$fs.exists(resolvedHostProjectPath)) {
|
|
47
|
+
this.$logger.error(`The host project path ${color_1.color.yellow(hostProjectPath)} (resolved to: ${color_1.color.yellow.dim(resolvedHostProjectPath)}) does not exist.`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.$options["hostProjectPath"] = resolvedHostProjectPath;
|
|
51
|
+
if (args.length > 2) {
|
|
52
|
+
this.$options["hostProjectModuleName"] = args[2];
|
|
53
|
+
}
|
|
54
|
+
return _super.execute.call(this, args);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
canExecute(args) {
|
|
58
|
+
const _super = Object.create(null, {
|
|
59
|
+
canExecute: { get: () => super.canExecute }
|
|
60
|
+
});
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const canSuperExecute = yield _super.canExecute.call(this, args);
|
|
63
|
+
if (!canSuperExecute) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const platform = args[0].toLowerCase();
|
|
67
|
+
if (!args[1]) {
|
|
68
|
+
const hostProjectPath = this.getEmbedConfigForKey("hostProjectPath", platform);
|
|
69
|
+
if (hostProjectPath) {
|
|
70
|
+
args[1] = hostProjectPath;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!args[2]) {
|
|
74
|
+
const hostProjectModuleName = this.getEmbedConfigForKey("hostProjectModuleName", platform);
|
|
75
|
+
if (hostProjectModuleName) {
|
|
76
|
+
args[2] = hostProjectModuleName;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
console.log(args);
|
|
80
|
+
if (args.length < 2) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
getEmbedConfigForKey(key, platform) {
|
|
87
|
+
return this.$projectConfigService.getValue(`embed.${platform}.${key}`, this.$projectConfigService.getValue(`embed.${key}`));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.EmbedCommand = EmbedCommand;
|
|
91
|
+
yok_1.injector.registerCommand("embed", EmbedCommand);
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NativeAddSwiftCommand = exports.NativeAddObjectiveCCommand = exports.NativeAddKotlinCommand = exports.NativeAddJavaCommand = exports.NativeAddAndroidCommand = exports.NativeAddSingleCommand = exports.NativeAddCommand = void 0;
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const path = require("path");
|
|
15
|
+
const yok_1 = require("../common/yok");
|
|
16
|
+
const utils_1 = require("../common/utils");
|
|
17
|
+
const os_1 = require("os");
|
|
18
|
+
class NativeAddCommand {
|
|
19
|
+
constructor($projectData, $logger, $errors) {
|
|
20
|
+
this.$projectData = $projectData;
|
|
21
|
+
this.$logger = $logger;
|
|
22
|
+
this.$errors = $errors;
|
|
23
|
+
this.allowedParameters = [];
|
|
24
|
+
this.$projectData.initializeProjectData();
|
|
25
|
+
}
|
|
26
|
+
execute(args) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
this.failWithUsage();
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
failWithUsage() {
|
|
33
|
+
this.$errors.failWithHelp("Usage: ns native add [swift|objective-c|java|kotlin] [class name]");
|
|
34
|
+
}
|
|
35
|
+
canExecute(args) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
this.failWithUsage();
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
getIosSourcePathBase() {
|
|
42
|
+
const resources = this.$projectData.getAppResourcesDirectoryPath();
|
|
43
|
+
return path.join(resources, "iOS", "src");
|
|
44
|
+
}
|
|
45
|
+
getAndroidSourcePathBase() {
|
|
46
|
+
const resources = this.$projectData.getAppResourcesDirectoryPath();
|
|
47
|
+
return path.join(resources, "Android", "src", "main", "java");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.NativeAddCommand = NativeAddCommand;
|
|
51
|
+
class NativeAddSingleCommand extends NativeAddCommand {
|
|
52
|
+
constructor($projectData, $logger, $errors) {
|
|
53
|
+
super($projectData, $logger, $errors);
|
|
54
|
+
}
|
|
55
|
+
canExecute(args) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
if (!args || args.length !== 1) {
|
|
58
|
+
this.failWithUsage();
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.NativeAddSingleCommand = NativeAddSingleCommand;
|
|
65
|
+
class NativeAddAndroidCommand extends NativeAddSingleCommand {
|
|
66
|
+
constructor($projectData, $logger, $errors) {
|
|
67
|
+
super($projectData, $logger, $errors);
|
|
68
|
+
}
|
|
69
|
+
getPackageName(className) {
|
|
70
|
+
const lastDotIndex = className.lastIndexOf(".");
|
|
71
|
+
if (lastDotIndex !== -1) {
|
|
72
|
+
return className.substring(0, lastDotIndex);
|
|
73
|
+
}
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
getClassSimpleName(className) {
|
|
77
|
+
const lastDotIndex = className.lastIndexOf(".");
|
|
78
|
+
if (lastDotIndex !== -1) {
|
|
79
|
+
return className.substring(lastDotIndex + 1);
|
|
80
|
+
}
|
|
81
|
+
return className;
|
|
82
|
+
}
|
|
83
|
+
generateJavaClassContent(packageName, classSimpleName) {
|
|
84
|
+
return ((packageName.length > 0 ? `package ${packageName};` : "") +
|
|
85
|
+
`
|
|
86
|
+
import android.util.Log;
|
|
87
|
+
|
|
88
|
+
public class ${classSimpleName} {
|
|
89
|
+
public void logMessage() {
|
|
90
|
+
Log.d("JS", "Hello from ${classSimpleName}!");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
`);
|
|
94
|
+
}
|
|
95
|
+
generateKotlinClassContent(packageName, classSimpleName) {
|
|
96
|
+
return ((packageName.length > 0 ? `package ${packageName};` : "") +
|
|
97
|
+
`
|
|
98
|
+
|
|
99
|
+
import android.util.Log
|
|
100
|
+
|
|
101
|
+
class ${classSimpleName} {
|
|
102
|
+
fun logMessage() {
|
|
103
|
+
Log.d("JS", "Hello from ${classSimpleName}!")
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
`);
|
|
107
|
+
}
|
|
108
|
+
doJavaKotlin(className, extension) {
|
|
109
|
+
const fileExt = extension == "java" ? extension : "kt";
|
|
110
|
+
const packageName = this.getPackageName(className);
|
|
111
|
+
const classSimpleName = this.getClassSimpleName(className);
|
|
112
|
+
const packagePath = path.join(this.getAndroidSourcePathBase(), ...packageName.split("."));
|
|
113
|
+
const filePath = path.join(packagePath, `${classSimpleName}.${fileExt}`);
|
|
114
|
+
if (fs.existsSync(filePath)) {
|
|
115
|
+
this.$errors.failWithHelp(`${extension} file '${filePath}' already exists.`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (extension == "kotlin" && !this.checkAndUpdateGradleProperties()) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const fileContent = extension == "java"
|
|
122
|
+
? this.generateJavaClassContent(packageName, classSimpleName)
|
|
123
|
+
: this.generateKotlinClassContent(packageName, classSimpleName);
|
|
124
|
+
fs.mkdirSync(packagePath, { recursive: true });
|
|
125
|
+
fs.writeFileSync(filePath, fileContent);
|
|
126
|
+
this.$logger.info(`${(0, utils_1.capitalizeFirstLetter)(extension)} file '${filePath}' generated successfully.`);
|
|
127
|
+
}
|
|
128
|
+
checkAndUpdateGradleProperties() {
|
|
129
|
+
const resources = this.$projectData.getAppResourcesDirectoryPath();
|
|
130
|
+
const filePath = path.join(resources, "Android", "gradle.properties");
|
|
131
|
+
if (fs.existsSync(filePath)) {
|
|
132
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
133
|
+
const propertyRegex = /^useKotlin\s*=\s*(true|false)$/m;
|
|
134
|
+
const match = propertyRegex.exec(fileContent);
|
|
135
|
+
if (match) {
|
|
136
|
+
const useKotlin = match[1];
|
|
137
|
+
if (useKotlin === "false") {
|
|
138
|
+
this.$errors.failWithHelp("The useKotlin property is set to false. Stopping processing. Kotlin must be enabled in gradle.properties to use.");
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if (useKotlin === "true") {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
fs.appendFileSync(filePath, `${os_1.EOL}useKotlin=true${os_1.EOL}`);
|
|
147
|
+
this.$logger.info('Added "useKotlin=true" property to gradle.properties.');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
fs.writeFileSync(filePath, `useKotlin=true${os_1.EOL}`);
|
|
152
|
+
this.$logger.info('Created gradle.properties with "useKotlin=true" property.');
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.NativeAddAndroidCommand = NativeAddAndroidCommand;
|
|
158
|
+
class NativeAddJavaCommand extends NativeAddAndroidCommand {
|
|
159
|
+
constructor($projectData, $logger, $errors) {
|
|
160
|
+
super($projectData, $logger, $errors);
|
|
161
|
+
}
|
|
162
|
+
execute(args) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
this.doJavaKotlin(args[0], "java");
|
|
165
|
+
return Promise.resolve();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.NativeAddJavaCommand = NativeAddJavaCommand;
|
|
170
|
+
class NativeAddKotlinCommand extends NativeAddAndroidCommand {
|
|
171
|
+
constructor($projectData, $logger, $errors) {
|
|
172
|
+
super($projectData, $logger, $errors);
|
|
173
|
+
}
|
|
174
|
+
execute(args) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
this.doJavaKotlin(args[0], "kotlin");
|
|
177
|
+
return Promise.resolve();
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.NativeAddKotlinCommand = NativeAddKotlinCommand;
|
|
182
|
+
class NativeAddObjectiveCCommand extends NativeAddSingleCommand {
|
|
183
|
+
constructor($projectData, $logger, $errors) {
|
|
184
|
+
super($projectData, $logger, $errors);
|
|
185
|
+
}
|
|
186
|
+
execute(args) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
this.doObjectiveC(args[0]);
|
|
189
|
+
return Promise.resolve();
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
doObjectiveC(className) {
|
|
193
|
+
const iosSourceBase = this.getIosSourcePathBase();
|
|
194
|
+
const classFilePath = path.join(iosSourceBase, `${className}.m`);
|
|
195
|
+
const headerFilePath = path.join(iosSourceBase, `${className}.h`);
|
|
196
|
+
if (this.generateObjectiveCFiles(className, classFilePath, headerFilePath)) {
|
|
197
|
+
this.generateOrUpdateModuleMap(`${className}.h`, path.join(iosSourceBase, "module.modulemap"));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
generateOrUpdateModuleMap(headerFileName, moduleMapPath) {
|
|
201
|
+
const moduleName = "LocalModule";
|
|
202
|
+
const headerPath = headerFileName;
|
|
203
|
+
let moduleMapContent = "";
|
|
204
|
+
if (fs.existsSync(moduleMapPath)) {
|
|
205
|
+
moduleMapContent = fs.readFileSync(moduleMapPath, "utf8");
|
|
206
|
+
}
|
|
207
|
+
const headerDeclaration = `header "${headerPath}"`;
|
|
208
|
+
if (moduleMapContent.includes(`module ${moduleName}`)) {
|
|
209
|
+
if (moduleMapContent.includes(headerDeclaration)) {
|
|
210
|
+
this.$logger.warn(`Header '${headerFileName}' is already added to the module map.`);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const updatedModuleMapContent = moduleMapContent.replace(new RegExp(`module ${moduleName} {\\s*([^}]*)\\s*}`, "s"), `module ${moduleName} {${os_1.EOL} $1${os_1.EOL} ${headerDeclaration}${os_1.EOL}}`);
|
|
214
|
+
fs.writeFileSync(moduleMapPath, updatedModuleMapContent);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const moduleDeclaration = `module ${moduleName} {${os_1.EOL} ${headerDeclaration}${os_1.EOL} export *${os_1.EOL}}`;
|
|
218
|
+
moduleMapContent += `${os_1.EOL}${os_1.EOL}${moduleDeclaration}`;
|
|
219
|
+
fs.writeFileSync(moduleMapPath, moduleMapContent);
|
|
220
|
+
}
|
|
221
|
+
this.$logger.info(`Module map '${moduleMapPath}' has been updated with the header '${headerFileName}'.`);
|
|
222
|
+
}
|
|
223
|
+
generateObjectiveCFiles(className, classFilePath, interfaceFilePath) {
|
|
224
|
+
if (fs.existsSync(classFilePath)) {
|
|
225
|
+
this.$errors.failWithHelp(`Error: File '${classFilePath}' already exists.`);
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
if (fs.existsSync(interfaceFilePath)) {
|
|
229
|
+
this.$errors.failWithHelp(`Error: File '${interfaceFilePath}' already exists.`);
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const interfaceContent = `#import <Foundation/Foundation.h>
|
|
233
|
+
|
|
234
|
+
@interface ${className} : NSObject
|
|
235
|
+
|
|
236
|
+
- (void)logMessage;
|
|
237
|
+
|
|
238
|
+
@end
|
|
239
|
+
`;
|
|
240
|
+
const classContent = `#import "${className}.h"
|
|
241
|
+
|
|
242
|
+
@implementation ${className}
|
|
243
|
+
|
|
244
|
+
- (void)logMessage {
|
|
245
|
+
NSLog(@"Hello from ${className} class!");
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@end
|
|
249
|
+
`;
|
|
250
|
+
fs.writeFileSync(classFilePath, classContent);
|
|
251
|
+
this.$logger.trace(`Objective-C class file '${classFilePath}' generated successfully.`);
|
|
252
|
+
fs.writeFileSync(interfaceFilePath, interfaceContent);
|
|
253
|
+
this.$logger.trace(`Objective-C interface file '${interfaceFilePath}' generated successfully.`);
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
exports.NativeAddObjectiveCCommand = NativeAddObjectiveCCommand;
|
|
258
|
+
class NativeAddSwiftCommand extends NativeAddSingleCommand {
|
|
259
|
+
constructor($projectData, $logger, $errors) {
|
|
260
|
+
super($projectData, $logger, $errors);
|
|
261
|
+
}
|
|
262
|
+
execute(args) {
|
|
263
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
264
|
+
this.doSwift(args[0]);
|
|
265
|
+
return Promise.resolve();
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
doSwift(className) {
|
|
269
|
+
const iosSourceBase = this.getIosSourcePathBase();
|
|
270
|
+
const swiftFilePath = path.join(iosSourceBase, `${className}.swift`);
|
|
271
|
+
this.generateSwiftFile(className, swiftFilePath);
|
|
272
|
+
}
|
|
273
|
+
generateSwiftFile(className, filePath) {
|
|
274
|
+
const directory = path.dirname(filePath);
|
|
275
|
+
if (!fs.existsSync(directory)) {
|
|
276
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
277
|
+
this.$logger.trace(`Created directory: '${directory}'.`);
|
|
278
|
+
}
|
|
279
|
+
if (fs.existsSync(filePath)) {
|
|
280
|
+
this.$errors.failWithHelp(`Error: File '${filePath}' already exists.`);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const content = `import Foundation;
|
|
284
|
+
import os;
|
|
285
|
+
|
|
286
|
+
@objc class ${className}: NSObject {
|
|
287
|
+
@objc func logMessage() {
|
|
288
|
+
os_log("Hello from ${className} class!")
|
|
289
|
+
}
|
|
290
|
+
}`;
|
|
291
|
+
fs.writeFileSync(filePath, content);
|
|
292
|
+
this.$logger.info(`Swift file '${filePath}' generated successfully.`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
exports.NativeAddSwiftCommand = NativeAddSwiftCommand;
|
|
296
|
+
yok_1.injector.registerCommand(["native|add"], NativeAddCommand);
|
|
297
|
+
yok_1.injector.registerCommand(["native|add|java"], NativeAddJavaCommand);
|
|
298
|
+
yok_1.injector.registerCommand(["native|add|kotlin"], NativeAddKotlinCommand);
|
|
299
|
+
yok_1.injector.registerCommand(["native|add|swift"], NativeAddSwiftCommand);
|
|
300
|
+
yok_1.injector.registerCommand(["native|add|objective-c"], NativeAddObjectiveCCommand);
|
|
@@ -38,15 +38,9 @@ class BuildPluginCommand {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
const tempAndroidProject = yield this.$tempService.mkdirSync("android-project");
|
|
41
|
-
const gradleArgs = (this.$projectData.nsConfig.android.gradleArgs || [].concat(this.$options.gradleArgs || [])
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
gradleArgs,
|
|
45
|
-
aarOutputDir: platformsAndroidPath,
|
|
46
|
-
platformsAndroidDirPath: platformsAndroidPath,
|
|
47
|
-
pluginName: pluginName,
|
|
48
|
-
tempPluginDirPath: tempAndroidProject,
|
|
49
|
-
};
|
|
41
|
+
const gradleArgs = (this.$projectData.nsConfig.android.gradleArgs || []).concat(this.$options.gradleArgs || []);
|
|
42
|
+
const pluginOptions = (this.$projectData.nsConfig.android.plugins || {})[pluginName] || {};
|
|
43
|
+
const options = Object.assign({ gradlePath: this.$options.gradlePath, gradleArgs, aarOutputDir: platformsAndroidPath, platformsAndroidDirPath: platformsAndroidPath, pluginName: pluginName, tempPluginDirPath: tempAndroidProject }, pluginOptions);
|
|
50
44
|
const androidPluginBuildResult = yield this.$androidPluginBuildService.buildAar(options);
|
|
51
45
|
if (androidPluginBuildResult) {
|
|
52
46
|
this.$logger.info(`${pluginName} successfully built aar at ${platformsAndroidPath}.${os_1.EOL}Temporary Android project can be found at ${tempAndroidProject}.`);
|