File tree Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,12 @@ export interface NativeScriptConfig {
196
196
shared ?: boolean ;
197
197
previewAppSchema ?: string ;
198
198
overridePods ?: string ;
199
+ /**
200
+ * Custom platform project name.
201
+ * By default, the platforms/{platform}/{name} is based on the basename of the project directory.
202
+ * You can override that to use a name of your choice by setting this.
203
+ */
204
+ projectName ?: string ;
199
205
/**
200
206
* Custom webpack config path
201
207
* The default is `webpack.config.js` in the root however you can use a custom name and place elsewhere.
Original file line number Diff line number Diff line change 1
1
import { env } from '../../src/' ;
2
- import { addPlatform , getEntryPath } from '../../src/helpers/platform' ;
2
+ import {
3
+ addPlatform ,
4
+ getEntryPath ,
5
+ getDistPath ,
6
+ } from '../../src/helpers/platform' ;
3
7
4
8
import { getValue } from '../../src/helpers/config' ;
5
9
@@ -47,3 +51,34 @@ describe('getEntryPath', () => {
47
51
expect ( res ) . toEqual ( '__jest__/src/app.js' ) ;
48
52
} ) ;
49
53
} ) ;
54
+
55
+ describe ( 'getDistPath' , ( ) => {
56
+ it ( 'is generated from working directory when no projectName setting in nativescript.config.ts' , ( ) => {
57
+ env . ios = true ;
58
+
59
+ const distPath = getDistPath ( ) ;
60
+
61
+ expect ( distPath ) . toEqual ( 'platforms/ios/jest/app' ) ;
62
+ env . ios = false ;
63
+ } ) ;
64
+
65
+ it ( 'is generated using projectName value from nativescript.config.ts when set' , ( ) => {
66
+ env . ios = true ;
67
+
68
+ // mock getValue
69
+ const getValueMock = getValue as jest . Mock ;
70
+ const getValueMockImpl = getValueMock . getMockImplementation ( ) ;
71
+
72
+ getValueMock . mockImplementation ( ( key ) => {
73
+ if ( key === 'projectName' ) {
74
+ return 'projectNameSpecified' ;
75
+ }
76
+ } ) ;
77
+
78
+ const distPath = getDistPath ( ) ;
79
+
80
+ expect ( distPath ) . toEqual ( 'platforms/ios/projectNameSpecified/app' ) ;
81
+
82
+ getValueMock . mockImplementation ( getValueMockImpl ) ;
83
+ } ) ;
84
+ } ) ;
Original file line number Diff line number Diff line change @@ -3,14 +3,17 @@ import { basename } from "path";
3
3
import { INativeScriptPlatform } from "../helpers/platform" ;
4
4
import { getProjectRootPath } from "../helpers/project" ;
5
5
import { env } from '../' ;
6
+ import { getValue } from '../helpers/config' ;
6
7
7
8
function sanitizeName ( appName : string ) : string {
8
9
return appName . split ( "" ) . filter ( ( c ) =>
9
10
/ [ a - z A - Z 0 - 9 ] / . test ( c )
10
11
) . join ( "" ) ;
11
12
}
12
13
function getDistPath ( ) {
13
- const appName = sanitizeName ( basename ( getProjectRootPath ( ) ) ) ;
14
+ // try projectName from nativescript.config.ts, if not set, use original method
15
+ const appName = getValue ( 'projectName' ) ?? sanitizeName ( basename ( getProjectRootPath ( ) ) ) ;
16
+
14
17
return `${ env . buildPath ?? "platforms" } /ios/${ appName } /app` ;
15
18
}
16
19
You can’t perform that action at this time.
0 commit comments