Skip to content

Commit 582150f

Browse files
authored
Merge pull request #1 from NativeScript/lini/cloud-build
Lini/cloud build
2 parents e0efe78 + e3dd312 commit 582150f

3 files changed

Lines changed: 59 additions & 22 deletions

File tree

lib/checker.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MarketplaceService } from './marketplace.service';
22
import { ProjectService } from './project.service';
3-
import { writeFileSync } from 'fs';
3+
import { writeFileSync, unlinkSync, existsSync } from 'fs';
44
import { execPromise } from './execPromise';
55
import { Logger } from './log.service';
66

@@ -34,8 +34,22 @@ async function _setup(out: OutputModel) {
3434
out.tnsVersion = tnsVersion.trim();
3535
out.nodeVersion = process.version;
3636
out.npmVersion = npmVersion.trim();
37-
38-
await ProjectService.setup();
37+
const args = process.argv;
38+
const user = args.length > 4 ? args[4] : '';
39+
const pass = args.length > 5 ? args[5] : '';
40+
const cloudEnabled = !!(user && pass);
41+
if (cloudEnabled) {
42+
await execPromise('.', 'tns extension install nativescript-cloud');
43+
await execPromise('.', 'tns accept eula');
44+
await execPromise('.', 'tns config apply test --apiVersion test');
45+
await execPromise('.', `tns dev-login ${user} ${pass}`);
46+
// setup android signing
47+
if (existsSync('debug.p12')) {
48+
unlinkSync('debug.p12');
49+
}
50+
await execPromise('.', 'echo android | keytool -importkeystore -srckeystore ~/.android/debug.keystore -destkeystore debug.p12 -srcstoretype JKS -deststoretype PKCS12 -deststorepass android -srcalias androiddebugkey -destalias androiddebugkey');
51+
}
52+
await ProjectService.setup(cloudEnabled);
3953
}
4054

4155
export async function run() {

lib/execPromise.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function execPromise(cwd: string, command: string, returnOutput = false)
3333
});
3434
cp.stderr.on('data', function (data) {
3535
if (!hasError) {
36-
Logger.error(`error while executing ${command}:`);
36+
Logger.error(`plugin-verifier error output for ${command}:`);
3737
hasError = true;
3838
}
3939
Logger.error(data.toString());

lib/project.service.ts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ const testProject = 'baseNG';
1111
const testProjectOriginalSuffix = '_original';
1212

1313
export namespace ProjectService {
14-
15-
export async function setup() {
14+
export let cloudEnabled = false;
15+
export async function setup(cloud: boolean) {
16+
cloudEnabled = cloud;
1617
if (existsSync(testDirectory)) {
1718
await _removeDirectory(testDirectory);
1819
}
@@ -44,41 +45,56 @@ export namespace ProjectService {
4445
}
4546

4647
export async function testWebpack(plugin: MarketplaceService.PluginModel) {
47-
return await testPlugin(plugin, '--bundle');
48+
return await testPlugin(plugin, {
49+
android: '--bundle',
50+
ios: '--bundle'
51+
});
4852
}
4953

5054
export async function testSnapshot(plugin: MarketplaceService.PluginModel) {
51-
return await testPlugin(plugin, '--bundle --release --env.snapshot --key-store-path ~/.android/debug.keystore --key-store-password android --key-store-alias androiddebugkey --key-store-alias-password android');
55+
const signKeystore = cloudEnabled ? '../../debug.p12' : '~/.android/debug.keystore';
56+
return await testPlugin(plugin, {
57+
android: `--bundle --release --env.snapshot --key-store-path ${signKeystore} --key-store-password android --key-store-alias androiddebugkey --key-store-alias-password android`
58+
});
5259
}
5360

5461
export async function testUglify(plugin: MarketplaceService.PluginModel) {
55-
return await testPlugin(plugin, '--bundle --env.uglify');
62+
return await testPlugin(plugin, {
63+
android: '--bundle --env.uglify',
64+
ios: '--bundle --env.uglify'
65+
});
5666
}
5767

5868
export async function testAot(plugin: MarketplaceService.PluginModel) {
59-
return await testPlugin(plugin, '--bundle --env.aot');
69+
return await testPlugin(plugin, {
70+
android: '--bundle --env.aot',
71+
ios: '--bundle --env.aot'
72+
});
6073
}
6174

6275
export async function testBuild(plugin: MarketplaceService.PluginModel) {
63-
return await testPlugin(plugin, '');
76+
return await testPlugin(plugin, {
77+
android: ' ',
78+
ios: ' '
79+
});
6480
}
6581

66-
async function testPlugin(plugin: MarketplaceService.PluginModel, options: string) {
82+
async function testPlugin(plugin: MarketplaceService.PluginModel, options: { android?: string, ios?: string }) {
6783
const result = { android: false, ios: false };
6884
let skipBuild = false;
6985
try {
7086
skipBuild = !plugin.badges.androidVersion && plugin.badges.iosVersion;
71-
if (!skipBuild) {
72-
result.android = !!(await _buildProject(testProject, 'android', options));
87+
if (!skipBuild && options.android) {
88+
result.android = !!(await _buildProject(testProject, 'android', options.android));
7389
} else {
74-
Logger.error('Skipping android build! Plugin only has ios support.');
90+
Logger.error('Skipping android build! Plugin only has ios support or no options supplied.');
7591
}
7692

7793
skipBuild = !plugin.badges.iosVersion && plugin.badges.androidVersion;
78-
if (!skipBuild) {
79-
result.ios = !!(await _buildProject(testProject, 'ios', options));
94+
if (!skipBuild && options.ios) {
95+
result.ios = !!(await _buildProject(testProject, 'ios', options.ios));
8096
} else {
81-
Logger.error('Skipping ios build! Plugin only has android support.');
97+
Logger.error('Skipping ios build! Plugin only has android support or no options supplied.');
8298
}
8399
} catch (errExec) {
84100
Logger.error(JSON.stringify(errExec));
@@ -89,7 +105,11 @@ export namespace ProjectService {
89105
async function _buildProject(projectName: string, platform: string, options: string) {
90106
Logger.debug(`building project for ${platform} ...`);
91107
const cwd = path.join(testDirectory, projectName);
92-
const result = await execPromise(cwd, `tns build ${platform} ${options}`);
108+
if (platform === 'ios' && cloudEnabled) {
109+
options += ' --provision /tns-official/CodeSign/ios/Icenium_QA_Development.mobileprovision --certificate /tns-official/CodeSign/ios/iPhone\\ Developer\\ Dragon\\ Telerikov\\ \\(GNKAEXW8YQ\\).p12 --certificatePassword 1';
110+
}
111+
const command = cloudEnabled ? `tns cloud build ${platform} --accountId 1 ${options}` : `tns build ${platform} ${options}`;
112+
const result = await execPromise(cwd, command);
93113
return result;
94114
}
95115

@@ -162,9 +182,12 @@ export namespace ProjectService {
162182

163183
async function _renameTestProject() {
164184
return new Promise((resolve, reject) => {
165-
rename(path.join(testDirectory, testProject), path.join(testDirectory, testProject + testProjectOriginalSuffix), err => {
166-
return err ? reject(err) : resolve();
167-
});
185+
setTimeout(() => {
186+
rename(path.join(testDirectory, testProject), path.join(testDirectory, testProject + testProjectOriginalSuffix), err => {
187+
return err ? reject(err) : resolve();
188+
});
189+
}, 2000);
190+
168191
});
169192
}
170193

0 commit comments

Comments
 (0)