Skip to content

Commit b9b57a1

Browse files
Fail if --bundle is specified but no bundler (#3246)
* Fail if --bundle is specified but no bundler * Make bundle option string * Document --bundle option * Change default * Update submodule ref
1 parent cc835bd commit b9b57a1

18 files changed

+68
-24
lines changed

docs/man_pages/project/testing/build-android.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ build android
33

44
Usage | Synopsis
55
---|---
6-
General | `$ tns build android [--compileSdk <API Level>] [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings] [--copy-to <File Path>]`
6+
General | `$ tns build android [--compileSdk <API Level>] [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings] [--copy-to <File Path>] [--bundle [<value>] [--env.*]]`
77

88
Builds the project for Android and produces an APK that you can manually deploy on device or in the native emulator.
99

@@ -15,6 +15,8 @@ Builds the project for Android and produces an APK that you can manually deploy
1515
* `--key-store-alias` - Provides the alias for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1616
* `--key-store-alias-password` - Provides the password for the alias specified with `--key-store-alias-password`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1717
* `--copy-to` - Specifies the file path where the built `.apk` will be copied. If it points to a non-existent directory, it will be created. If the specified value is directory, the original file name will be used.
18+
* `--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`.
19+
* `--env.*` - Specifies additional flags that the bundler may process. May be passed multiple times. For example: `--env.uglify --env.snapshot`.
1820

1921
### Attributes
2022
`<API Level>` is a valid Android API level. For example: 22, 23.<% if(isHtml) { %> For a complete list of the Android API levels and their corresponding Android versions, click [here](http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#platform).<% } %>

docs/man_pages/project/testing/build-ios.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ build ios
33

44
Usage | Synopsis
55
---|---
6-
General | `$ tns build ios [--for-device] [--release] [--copy-to <File Path>] [--provision [<UUID/name>]]`
6+
General | `$ tns build ios [--for-device] [--release] [--copy-to <File Path>] [--provision [<UUID/name>]] [--bundle [<value>] [--env.*]]`
77

88
Builds the project for iOS and produces an `APP` or `IPA` that you can manually deploy in the iOS Simulator or on device, respectively.
99

@@ -17,6 +17,8 @@ Builds the project for iOS and produces an `APP` or `IPA` that you can manually
1717
* `--copy-to` - Specifies the file path where the built `.ipa` will be copied. If it points to a non-existent directory, it will be created. If the specified value is directory, the original file name will be used.
1818
* `--team-id` - If used without parameter, lists all team names and ids. If used with team name or id, it will switch to automatic signing mode and configure the .xcodeproj file of your app. In this case .xcconfig should not contain any provisioning/team id flags. This team id will be further used for codesigning the app. For Xcode 9.0+, xcodebuild will be allowed to update and modify automatically managed provisioning profiles.
1919
* `--provision` - If used without parameter, lists all eligible provisioning profiles. If used with UUID or name of your provisioning profile, it will switch to manual signing mode and configure the .xcodeproj file of your app. In this case xcconfig should not contain any provisioning/team id flags. This provisioning profile will be further used for codesigning the app.
20+
* `--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`.
21+
* `--env.*` - Specifies additional flags that the bundler may process. May be passed multiple times. For example: `--env.uglify --env.snapshot`.
2022
<% } %>
2123
<% if(isHtml) { %>
2224
### Command Limitations

docs/man_pages/project/testing/run-android.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ run android
33

44
Usage | Synopsis
55
---|---
6-
Run on all connected devices and running emulators | `$ tns run android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
7-
Run on a selected connected device or running emulator. Will start emulator with specified `Device Identifier`, if not already running. | `$ tns run android --device <Device ID> [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
8-
Start a default emulator if none are running, or run application on all connected emulators. | `$ tns run android --emulator [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
6+
Run on all connected devices and running emulators | `$ tns run android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
7+
Run on a selected connected device or running emulator. Will start emulator with specified `Device Identifier`, if not already running. | `$ tns run android --device <Device ID> [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
8+
Start a default emulator if none are running, or run application on all connected emulators. | `$ tns run android --emulator [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
99

1010
Runs your project on a connected Android device or in a native Android emulator, if configured. This is shorthand for prepare, build and deploy. While your app is running, prints the output from the application in the console and watches for changes in your code. Once a change is detected, it synchronizes the change with all selected devices and restarts/refreshes the application.
1111

@@ -20,6 +20,8 @@ Runs your project on a connected Android device or in a native Android emulator,
2020
* `--key-store-password` - Provides the password for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
2121
* `--key-store-alias` - Provides the alias for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
2222
* `--key-store-alias-password` - Provides the password for the alias specified with `--key-store-alias-password`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
23+
* `--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`.
24+
* `--env.*` - Specifies additional flags that the bundler may process. May be passed multiple times. For example: `--env.uglify --env.snapshot`.
2325

2426
### Attributes
2527
* `<Device ID>` is the index or `Device Identifier` of the target device as listed by `$ tns device android --available-devices`

docs/man_pages/project/testing/run-ios.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ run ios
33

44
Usage | Synopsis
55
---|---
6-
Run on all connected devices | `$ tns run ios [--release] [--justlaunch]`
7-
Run on a selected connected device. Will start simulator with specified `Device Identifier`, if not already running. | `$ tns run ios [--device <Device ID>] [--release] [--justlaunch]`
8-
Start an emulator and run the app inside it | `$ tns run ios --emulator [--release]`
6+
Run on all connected devices | `$ tns run ios [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
7+
Run on a selected connected device. Will start simulator with specified `Device Identifier`, if not already running. | `$ tns run ios [--device <Device ID>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
8+
Start an emulator and run the app inside it | `$ tns run ios --emulator [--release] [--bundle [<value>] [--env.*]]`
99

1010
Runs your project on a connected iOS device or in the iOS Simulator, if configured. This is shorthand for prepare, build and deploy. While your app is running, prints the output from the application in the console and watches for changes in your code. Once a change is detected, it synchronizes the change with all selected devices and restarts/refreshes the application.
1111

@@ -20,6 +20,8 @@ Runs your project on a connected iOS device or in the iOS Simulator, if configur
2020
* `--clean` - If set, forces rebuilding the native application.
2121
* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command.
2222
* `--release` - If set, produces a release build. Otherwise, produces a debug build.
23+
* `--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`.
24+
* `--env.*` - Specifies additional flags that the bundler may process. May be passed multiple times. For example: `--env.uglify --env.snapshot`.
2325

2426
### Attributes
2527
* `<Device ID>` is the index or `Device Identifier` of the target device as listed by `$ tns device ios --available-devices`

lib/commands/appstore-upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class PublishIOS implements ICommand {
5656
if (!ipaFilePath) {
5757
const platform = this.$devicePlatformsConstants.iOS;
5858
// No .ipa path provided, build .ipa on out own.
59-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
59+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
6060
const platformInfo: IPreparePlatformInfo = {
6161
platform,
6262
appFilesUpdaterOptions,

lib/commands/base-bundler.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export abstract class BundleBase {
2+
private bundlersMap: IStringDictionary = {
3+
webpack: "nativescript-dev-webpack"
4+
};
5+
6+
constructor(protected $projectData: IProjectData,
7+
protected $errors: IErrors,
8+
protected $options: IOptions) {
9+
this.$projectData.initializeProjectData();
10+
}
11+
12+
protected validateBundling(): void {
13+
if (this.$options.bundle) {
14+
const bundlePluginName = this.bundlersMap[this.$options.bundle];
15+
if (!bundlePluginName || (!this.$projectData.devDependencies[bundlePluginName] && !this.$projectData.dependencies[bundlePluginName])) {
16+
this.$errors.fail("Passing --bundle requires a bundling plugin. No bundling plugin found or the specified bundling plugin is invalid.");
17+
}
18+
}
19+
}
20+
}

lib/commands/build.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
2+
import { BundleBase } from "./base-bundler";
23

3-
export class BuildCommandBase {
4+
export class BuildCommandBase extends BundleBase {
45
constructor(protected $options: IOptions,
56
protected $errors: IErrors,
67
protected $projectData: IProjectData,
78
protected $platformsData: IPlatformsData,
89
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
910
protected $platformService: IPlatformService) {
11+
super($projectData, $errors, $options);
1012
this.$projectData.initializeProjectData();
1113
}
1214

1315
public async executeCore(args: string[]): Promise<void> {
1416
const platform = args[0].toLowerCase();
15-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
17+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
1618
const platformInfo: IPreparePlatformInfo = {
1719
platform,
1820
appFilesUpdaterOptions,
@@ -47,6 +49,8 @@ export class BuildCommandBase {
4749
if (!this.$platformService.isPlatformSupportedForOS(platform, this.$projectData)) {
4850
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
4951
}
52+
53+
super.validateBundling();
5054
}
5155
}
5256

lib/commands/clean-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class CleanAppCommandBase implements ICommand {
1414
}
1515

1616
public async execute(args: string[]): Promise<void> {
17-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
17+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
1818
return this.$platformService.cleanDestinationApp(this.platform.toLowerCase(), appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options);
1919
}
2020

lib/commands/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class DeployOnDeviceCommand implements ICommand {
1414
}
1515

1616
public async execute(args: string[]): Promise<void> {
17-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
17+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
1818
const deployOptions: IDeployPlatformOptions = {
1919
clean: this.$options.clean,
2020
device: this.$options.device,

lib/commands/prepare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class PrepareCommand implements ICommand {
1010
}
1111

1212
public async execute(args: string[]): Promise<void> {
13-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
13+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
1414
const platformInfo: IPreparePlatformInfo = {
1515
platform: args[0],
1616
appFilesUpdaterOptions,

0 commit comments

Comments
 (0)