Skip to content

Commit 3d928c8

Browse files
committed
update git service to build demo for ios as well
1 parent 41af418 commit 3d928c8

4 files changed

Lines changed: 25 additions & 24 deletions

File tree

lib/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface ResultsInterface {
99
name: string;
1010
webpack: any;
1111
webpackTime: number;
12-
demosBuild: boolean;
12+
demos: any;
1313
demoTime: number;
1414
}
1515

@@ -62,7 +62,7 @@ export async function run() {
6262
name: plugin.name,
6363
webpack: resultWP,
6464
webpackTime: Math.round((midDate - startDate) / 1000),
65-
demosBuild: !!resultD,
65+
demos: resultD,
6666
demoTime: Math.round((endDate - midDate) / 1000)
6767
});
6868
Logger.log(JSON.stringify(results[results.length - 1]));

lib/execPromise.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function execPromise(cwd: string, command: string, returnOutput = false)
4242
}
4343

4444
export function dirNameFromPluginName(name: string): string {
45-
let dirName = 'test' + name;
45+
let dirName = name;
4646
// remove / and other invalid chars from plugin name
4747
dirName = sanitize(dirName);
4848
// NativeScript max project name length

lib/github.service.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,41 @@ const testDirectory = 'testGit';
99
export 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}`);

lib/project.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44
import * as rimraf from 'rimraf';
55
import { ncp } from 'ncp';
66
import { Logger } from './log.service';
7-
import { execPromise, dirNameFromPluginName } from './execPromise';
7+
import { execPromise } from './execPromise';
88

99
const testDirectory = 'test';
1010
const testProject = 'baseTS';

0 commit comments

Comments
 (0)