-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ns typings dummy commands * feat: ns typings (wip) * feat: ns typings * chore: cleanup * revert: package-lock.json
- Loading branch information
1 parent
8f8dd83
commit 4703cef
Showing
6 changed files
with
193 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<% if (isJekyll) { %>--- | ||
title: ns typings | ||
position: 25 | ||
---<% } %> | ||
|
||
# ns typings | ||
|
||
### Description | ||
|
||
Generate iOS & Android typings by default (respecting platform support, so no ios typings generated on windows/linux machines) | ||
|
||
### Commands | ||
|
||
Usage | Synopsis | ||
---|--- | ||
Generate typings to Android | `$ ns typings android [--jar <Jar1> --jar <Jar2>] [--aar <Aar1>] [--copy-to <Path>]` | ||
Generate typings to iOS | `$ ns typings ios [--filter <Filter>] [--copy-to <Path>]` | ||
|
||
### Options | ||
|
||
* `--jar` - Path to jar file to generate typings for (Supports multiple by passing them individually) (Android only) | ||
* `--aar` - Path to aar file to generate typings for (Currently unsupported) (Android only) | ||
* `--filter` - Regex to filter typings (Currently unsupported) (iOS only) | ||
|
||
* `--copy-to` - Copy generated typings to the specified folder | ||
|
||
<% if((isConsole && isMacOS) || isHtml) { %>### Arguments | ||
`<Platform>` is the target mobile platform for which you want to generate typings. You can set the following target platforms: | ||
* `android` - Generate typings for android. | ||
* `ios` - Generate typings for iOS. | ||
|
||
|
||
|
||
### Related Commands | ||
|
||
Command | Description | ||
----------|---------- | ||
[appstore](../../publishing/appstore.html) | Lists applications registered in iTunes Connect. | ||
[appstore upload](../../publishing/appstore-upload.html) | Uploads project to iTunes Connect. | ||
[build android](build-android.html) | Builds the project for Android and produces an APK that you can manually deploy on device or in the native emulator. | ||
[build ios](build-ios.html) | Builds the project for iOS and produces an APP or IPA that you can manually deploy in the iOS Simulator or on device, respectively. | ||
[build](build.html) | Builds the project for the selected target platform and produces an application package that you can manually deploy on device or in the native emulator. | ||
[debug android](debug-android.html) | Debugs your project on a connected Android device or in a native emulator. | ||
[debug ios](debug-ios.html) | Debugs your project on a connected iOS device or in a native emulator. | ||
[debug](debug.html) | Debugs your project on a connected device or in a native emulator. | ||
[deploy](deploy.html) | Builds and deploys the project to a connected physical or virtual device. | ||
[run android](run-android.html) | Runs your project on a connected Android device or in a native Android emulator, if configured. | ||
[run ios](run-ios.html) | Runs your project on a connected iOS device or in the iOS Simulator, if configured. | ||
[test init](test-init.html) | Configures your project for unit testing with a selected framework. | ||
[test android](test-android.html) | Runs the tests in your project on Android devices or native emulators. | ||
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator. | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { IOptions } from "../declarations"; | ||
import { IChildProcess, IFileSystem } from "../common/declarations"; | ||
import { ICommand, ICommandParameter } from "../common/definitions/commands"; | ||
import { injector } from "../common/yok"; | ||
import { IProjectData } from "../definitions/project"; | ||
import * as path from "path"; | ||
|
||
export class TypingsCommand implements ICommand { | ||
public allowedParameters: ICommandParameter[] = []; | ||
constructor( | ||
private $logger: ILogger, | ||
private $options: IOptions, | ||
private $fs: IFileSystem, | ||
private $projectData: IProjectData, | ||
private $mobileHelper: Mobile.IMobileHelper, | ||
private $childProcess: IChildProcess | ||
) {} | ||
|
||
public async execute(args: string[]): Promise<void> { | ||
const platform = args[0]; | ||
|
||
if (this.$mobileHelper.isAndroidPlatform(platform)) { | ||
await this.handleAndroidTypings(); | ||
} | ||
|
||
if (this.$mobileHelper.isiOSPlatform(platform)) { | ||
await this.handleiOSTypings(); | ||
} | ||
let typingsFolder = "./typings"; | ||
if (this.$options.copyTo) { | ||
this.$fs.copyFile( | ||
path.resolve(this.$projectData.projectDir, "typings"), | ||
this.$options.copyTo | ||
); | ||
typingsFolder = this.$options.copyTo; | ||
} | ||
this.$logger.info( | ||
"Typing have been generated in the following directory:", | ||
typingsFolder | ||
); | ||
} | ||
|
||
public async canExecute(args: string[]): Promise<boolean> { | ||
const platform = args[0]; | ||
this.$mobileHelper.validatePlatformName(platform); | ||
return true; | ||
} | ||
|
||
private async handleAndroidTypings() { | ||
if (this.$options.aar) { | ||
return this.$logger.warn(`Open the .aar archive | ||
Extract the classes.jar and any dependencies it may have inside libs/ | ||
Rename classes.jar if necessary | ||
ns typings android --jar classes.jar --jar dependency-of-classes-jar.jar | ||
`); | ||
} else if (!this.$options.jar) { | ||
return this.$logger.warn( | ||
"No .jar file specified. Please specify a .jar file with --jar <Jar>." | ||
); | ||
} | ||
|
||
this.$fs.ensureDirectoryExists( | ||
path.resolve(this.$projectData.projectDir, "typings", "android") | ||
); | ||
|
||
const dtsGeneratorPath = path.resolve( | ||
this.$projectData.projectDir, | ||
"platforms", | ||
"android", | ||
"build-tools", | ||
"dts-generator.jar" | ||
); | ||
if (!this.$fs.exists(dtsGeneratorPath)) { | ||
this.$logger.warn("No platforms folder found, preparing project now..."); | ||
await this.$childProcess.spawnFromEvent( | ||
"ns", | ||
["prepare", "android"], | ||
"exit", | ||
{ stdio: "inherit" } | ||
); | ||
} | ||
|
||
if (this.$options.jar) { | ||
const jars: string[] = | ||
typeof this.$options.jar === "string" | ||
? [this.$options.jar] | ||
: this.$options.jar; | ||
await this.$childProcess.spawnFromEvent( | ||
"java", | ||
[ | ||
"-jar", | ||
dtsGeneratorPath, | ||
"-input", | ||
...jars, | ||
"-output", | ||
path.resolve(this.$projectData.projectDir, "typings", "android"), | ||
], | ||
"exit", | ||
{ stdio: "inherit" } | ||
); | ||
} | ||
} | ||
|
||
private async handleiOSTypings() { | ||
if (this.$options.filter !== undefined) { | ||
this.$logger.warn("--filter flag is not supported yet."); | ||
} | ||
|
||
this.$fs.ensureDirectoryExists( | ||
path.resolve(this.$projectData.projectDir, "typings", "ios") | ||
); | ||
|
||
await this.$childProcess.spawnFromEvent("ns", ["build", "ios"], "exit", { | ||
env: { | ||
...process.env, | ||
TNS_TYPESCRIPT_DECLARATIONS_PATH: path.resolve( | ||
this.$projectData.projectDir, | ||
"typings", | ||
"ios" | ||
), | ||
}, | ||
stdio: "inherit", | ||
}); | ||
} | ||
} | ||
|
||
injector.registerCommand("typings", TypingsCommand); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters