Skip to content

Commit bff4998

Browse files
committed
try to replace plugin version in demo with latest
1 parent 3af2425 commit bff4998

1 file changed

Lines changed: 36 additions & 10 deletions

File tree

lib/github.service.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MarketplaceService } from './marketplace.service';
2-
import { existsSync, mkdir, readFileSync } from 'fs';
2+
import { existsSync, mkdir, readFileSync, writeFileSync } from 'fs';
33
import * as path from 'path';
44
import * as rimraf from 'rimraf';
55
import { Logger } from './log.service';
@@ -23,16 +23,13 @@ export namespace GithubService {
2323
const demoDir = _getDemoDir(path.join(testDirectory, projectName), plugin);
2424
result.demoDirectory = demoDir;
2525

26-
// if there is a plugin build script, execute it
27-
await execPromise(demoDir, `npm run build.plugin --if-present`);
28-
2926
if (plugin.badges.androidVersion) {
30-
result.android = !!(await _buildProject(demoDir, 'android'));
27+
result.android = !!(await _buildProject(demoDir, plugin.name, 'android'));
3128
hasPlatform = true;
3229
}
3330

3431
if (plugin.badges.iosVersion) {
35-
result.ios = !!(await _buildProject(demoDir, 'ios'));
32+
result.ios = !!(await _buildProject(demoDir, plugin.name, 'ios'));
3633
hasPlatform = true;
3734
}
3835

@@ -59,11 +56,40 @@ export namespace GithubService {
5956
return name;
6057
}
6158

62-
async function _buildProject(name: string, platform: string) {
59+
async function _buildProject(cwd: string, name: string, platform: string) {
6360
// TODO: run 'tns update' / detect and build webpack
64-
Logger.debug(`building project in ${name} for ${platform} ...`);
65-
await execPromise(name, 'npm i');
66-
const result = await execPromise(name, `tns build ${platform}`);
61+
Logger.debug(`building project in ${cwd} for ${platform} ...`);
62+
const pkgFilePath = path.join(cwd, 'package.json');
63+
let pkgFile: any;
64+
try {
65+
const pkgFileStr = readFileSync(pkgFilePath, 'utf8');
66+
pkgFile = JSON.parse(pkgFileStr);
67+
} catch (e) {
68+
Logger.error(e.message || e);
69+
return false;
70+
}
71+
72+
if (!pkgFile) {
73+
return false;
74+
}
75+
76+
if (pkgFile.dependencies && pkgFile.dependencies[name]) {
77+
pkgFile.dependencies[name] = '*';
78+
}
79+
80+
if (pkgFile.devDependencies && pkgFile.devDependencies[name]) {
81+
pkgFile.devDependencies[name] = '*';
82+
}
83+
84+
try {
85+
writeFileSync(pkgFilePath, JSON.stringify(pkgFile, null, 4), 'utf8');
86+
} catch (e) {
87+
Logger.error(e.message || e);
88+
return false;
89+
}
90+
91+
await execPromise(cwd, 'npm i');
92+
const result = await execPromise(cwd, `tns build ${platform}`);
6793
return result;
6894
}
6995

0 commit comments

Comments
 (0)