1
1
import { AndroidPluginBuildService } from "../../lib/services/android-plugin-build-service" ;
2
- import { Yok } from "../../lib/common/yok" ;
3
2
import { assert } from "chai" ;
3
+ import { INCLUDE_GRADLE_NAME } from "../../lib/constants" ;
4
+ import { getShortPluginName } from "../../lib/common/helpers" ;
4
5
import * as FsLib from "../../lib/common/file-system" ;
5
6
import * as path from "path" ;
6
- import { HostInfo } from "../../lib/common/host-info" ;
7
- import { Logger } from "../../lib/common/logger" ;
8
- import * as ErrorsLib from "../../lib/common/errors" ;
9
- import temp = require( "temp" ) ;
10
- import { INCLUDE_GRADLE_NAME } from "../../lib/constants" ;
11
7
import * as stubs from "../stubs" ;
12
- import { DevicePlatformsConstants } from "../../lib/common/mobile/device-platforms-constants" ;
13
- import { getShortPluginName } from "../../lib/common/helpers" ;
8
+ import temp = require( "temp" ) ;
14
9
15
10
temp . track ( ) ;
16
11
17
- describe . only ( 'androidPluginBuildService' , ( ) => {
12
+ describe ( 'androidPluginBuildService' , ( ) => {
18
13
const pluginName = 'my-plugin' ;
19
14
const shortPluginName = getShortPluginName ( pluginName ) ;
20
15
let spawnFromEventCalled = false ;
@@ -40,7 +35,7 @@ describe.only('androidPluginBuildService', () => {
40
35
tempFolder = temp . mkdirSync ( "androidPluginBuildService-temp" ) ;
41
36
pluginFolder = temp . mkdirSync ( "androidPluginBuildService-plugin" ) ;
42
37
setupDI ( options ) ;
43
- setupPluginFolders ( options . addManifest , options . addResFolder , options . addAssetsFolder , options . addLegacyIncludeGradle ) ;
38
+ setupPluginFolders ( options ) ;
44
39
45
40
return {
46
41
platformsAndroidDirPath : pluginFolder ,
@@ -58,7 +53,7 @@ describe.only('androidPluginBuildService', () => {
58
53
projectRuntimeGradleVersion ?: string ,
59
54
projectRuntimeGradleAndroidVersion ?: string ,
60
55
} ) : void {
61
- const testInjector : IInjector = new Yok ( ) ;
56
+ const testInjector : IInjector = new stubs . InjectorStub ( ) ;
62
57
testInjector . register ( "fs" , FsLib . FileSystem ) ;
63
58
testInjector . register ( "childProcess" , {
64
59
spawnFromEvent : async ( command : string ) : Promise < ISpawnResult > => {
@@ -69,31 +64,11 @@ describe.only('androidPluginBuildService', () => {
69
64
return null ;
70
65
}
71
66
} ) ;
72
- testInjector . register ( "hostInfo" , HostInfo ) ;
73
- testInjector . register ( "androidToolsInfo" , {
74
- getToolsInfo : ( ) => {
75
- return { } ;
76
- } ,
77
- validateInfo : ( ) => {
78
- return true ;
79
- }
80
- } ) ;
81
- testInjector . register ( "logger" , Logger ) ;
82
- testInjector . register ( "errors" , ErrorsLib . Errors ) ;
83
- testInjector . register ( "options" , { } ) ;
84
- testInjector . register ( "config" , { } ) ;
85
- testInjector . register ( "staticConfig" , { } ) ;
86
- testInjector . register ( "hooksService" , {
87
- executeBeforeHooks : async ( commandName : string , hookArguments ?: IDictionary < any > ) : Promise < void > => undefined ,
88
- executeAfterHooks : async ( commandName : string , hookArguments ?: IDictionary < any > ) : Promise < void > => undefined
89
- } ) ;
90
- testInjector . register ( 'projectDataService' , stubs . ProjectDataService ) ;
91
67
testInjector . register ( 'platformService' , {
92
68
getCurrentPlatformVersion : ( platform : string , projectData : IProjectData ) : string => {
93
69
return options . addProjectRuntime ? "1.0.0" : null ;
94
70
}
95
71
} ) ;
96
- testInjector . register ( 'devicePlatformsConstants' , DevicePlatformsConstants ) ;
97
72
testInjector . register ( 'npm' , setupNpm ( options ) ) ;
98
73
99
74
fs = testInjector . resolve ( "fs" ) ;
@@ -132,27 +107,12 @@ describe.only('androidPluginBuildService', () => {
132
107
} ;
133
108
}
134
109
135
- function setUpIncludeGradle ( ) {
136
- const validIncludeGradleContent = `android {
137
- productFlavors {
138
- "nativescript-pro-ui" {
139
- dimension "nativescript-pro-ui"
140
- }
141
- }
142
- }
143
-
144
- def supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "23.3.0"
145
-
146
- dependencies {
147
- compile "com.android.support:appcompat-v7:$supportVersion"
148
- compile "com.android.support:recyclerview-v7:$supportVersion"
149
- compile "com.android.support:design:$supportVersion"
150
- }` ;
151
-
152
- fs . writeFile ( path . join ( pluginFolder , INCLUDE_GRADLE_NAME ) , validIncludeGradleContent ) ;
153
- }
154
-
155
- function setupPluginFolders ( manifestFile : boolean , resFolder : boolean , assetsFolder : boolean , addLegacyIncludeGradle : boolean ) {
110
+ function setupPluginFolders ( options : {
111
+ addManifest ?: boolean ,
112
+ addResFolder ?: boolean ,
113
+ addAssetsFolder ?: boolean ,
114
+ addLegacyIncludeGradle ?: boolean
115
+ } ) {
156
116
const validAndroidManifestContent = `<?xml version="1.0" encoding="UTF-8"?>
157
117
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
158
118
</manifest>` ;
@@ -162,25 +122,40 @@ dependencies {
162
122
name="string_name"
163
123
>text_string</string>
164
124
</resources>` ;
125
+ const validIncludeGradleContent = `android {
126
+ productFlavors {
127
+ "nativescript-pro-ui" {
128
+ dimension "nativescript-pro-ui"
129
+ }
130
+ }
131
+ }
132
+
133
+ def supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "23.3.0"
134
+
135
+ dependencies {
136
+ compile "com.android.support:appcompat-v7:$supportVersion"
137
+ compile "com.android.support:recyclerview-v7:$supportVersion"
138
+ compile "com.android.support:design:$supportVersion"
139
+ }` ;
165
140
166
- if ( manifestFile ) {
141
+ if ( options . addManifest ) {
167
142
fs . writeFile ( path . join ( pluginFolder , "AndroidManifest.xml" ) , validAndroidManifestContent ) ;
168
143
}
169
144
170
- if ( resFolder ) {
145
+ if ( options . addResFolder ) {
171
146
const valuesFolder = path . join ( pluginFolder , "res" , "values" ) ;
172
147
fs . createDirectory ( valuesFolder ) ;
173
148
fs . writeFile ( path . join ( valuesFolder , "strings.xml" ) , validStringsXmlContent ) ;
174
149
}
175
150
176
- if ( assetsFolder ) {
151
+ if ( options . addAssetsFolder ) {
177
152
const imagesFolder = path . join ( pluginFolder , "assets" , "images" ) ;
178
153
fs . createDirectory ( imagesFolder ) ;
179
154
fs . writeFile ( path . join ( imagesFolder , "myicon.png" ) , "123" ) ;
180
155
}
181
156
182
- if ( addLegacyIncludeGradle ) {
183
- setUpIncludeGradle ( ) ;
157
+ if ( options . addLegacyIncludeGradle ) {
158
+ fs . writeFile ( path . join ( pluginFolder , INCLUDE_GRADLE_NAME ) , validIncludeGradleContent ) ;
184
159
}
185
160
}
186
161
0 commit comments