@@ -9,27 +9,41 @@ const testDirectory = 'testGit';
99export namespace GithubService {
1010
1111 export async function testPlugin ( plugin : MarketplaceService . PluginModel ) {
12+ const result = { android : false , ios : false , demoDirectory : '' } ;
13+ let hasPlatform = false ;
1214 if ( ! plugin || ! plugin . badges || ! plugin . badges . demos ) {
1315 Logger . error ( 'plugin has no demos badge' ) ;
14- return false ;
16+ return result ;
1517 }
1618
1719 try {
1820 await _checkTestDirectory ( ) ;
1921 const projectName = dirNameFromPluginName ( plugin . name ) ;
2022 await _cloneProject ( plugin . repositoryUrl , projectName ) ;
21- const platform = _getPlatform ( plugin ) ;
2223 const demoDir = _getDemoDir ( path . join ( testDirectory , projectName ) , plugin ) ;
23- if ( platform ) {
24- const result = await _buildProject ( demoDir , platform ) ;
25- return result ;
26- } else {
24+ result . demoDirectory = demoDir ;
25+
26+ // if there is a plugin build script, execute it
27+ await execPromise ( name , `npm run build.plugin --if-present` ) ;
28+
29+ if ( plugin . badges . androidVersion ) {
30+ result . android = ! ! ( await _buildProject ( demoDir , 'android' ) ) ;
31+ hasPlatform = true ;
32+ }
33+
34+ if ( plugin . badges . iosVersion ) {
35+ result . ios = ! ! ( await _buildProject ( demoDir , 'ios' ) ) ;
36+ hasPlatform = true ;
37+ }
38+
39+ if ( ! hasPlatform ) {
2740 Logger . error ( 'plugin has no platform' ) ;
2841 }
2942 } catch ( errExec ) {
3043 Logger . error ( JSON . stringify ( errExec ) ) ;
3144 }
32- return false ;
45+
46+ return result ;
3347 }
3448
3549 function _getDemoDir ( name : string , plugin : MarketplaceService . PluginModel ) {
@@ -48,24 +62,11 @@ export namespace GithubService {
4862 async function _buildProject ( name : string , platform : string ) {
4963 // TODO: run 'tns update' / detect and build webpack
5064 Logger . debug ( `building project in ${ name } for ${ platform } ...` ) ;
51- // let pkgFile: any;
52- // const pkgFileStr = readFileSync(path.join(name, 'package.json'), 'utf8');
53- // pkgFile = JSON.parse(pkgFileStr);
54- // if (!pkgFile) return false;
55-
56- // if there is a plugin build script, execute it
57- await execPromise ( name , `npm run build.plugin --if-present` ) ;
58-
5965 await execPromise ( name , 'npm i' ) ;
6066 const result = await execPromise ( name , `tns build ${ platform } ` ) ;
6167 return result ;
6268 }
6369
64- function _getPlatform ( plugin : MarketplaceService . PluginModel ) : string {
65- const platform = plugin . badges && plugin . badges . androidVersion ? 'android' : plugin . badges && plugin . badges . iosVersion ? 'ios' : '' ;
66- return platform ;
67- }
68-
6970 async function _cloneProject ( repositoryUrl : string , name : string ) {
7071 Logger . debug ( `cloning into ${ name } ...` ) ;
7172 await execPromise ( testDirectory , `git clone ${ repositoryUrl } ${ name } ` ) ;
0 commit comments