Skip to content

Commit 9951485

Browse files
committed
fix: demo build for some plugins depending on ../src typings
1 parent bff4998 commit 9951485

1 file changed

Lines changed: 32 additions & 18 deletions

File tree

lib/github.service.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ export namespace GithubService {
2323
const demoDir = _getDemoDir(path.join(testDirectory, projectName), plugin);
2424
result.demoDirectory = demoDir;
2525

26+
if (plugin.badges.androidVersion || plugin.badges.iosVersion) {
27+
await _prepareDemoProject(demoDir, plugin.name);
28+
}
29+
2630
if (plugin.badges.androidVersion) {
27-
result.android = !!(await _buildProject(demoDir, plugin.name, 'android'));
31+
result.android = !!(await _buildProject(demoDir, 'android'));
2832
hasPlatform = true;
2933
}
3034

3135
if (plugin.badges.iosVersion) {
32-
result.ios = !!(await _buildProject(demoDir, plugin.name, 'ios'));
36+
result.ios = !!(await _buildProject(demoDir, 'ios'));
3337
hasPlatform = true;
3438
}
3539

@@ -56,39 +60,49 @@ export namespace GithubService {
5660
return name;
5761
}
5862

59-
async function _buildProject(cwd: string, name: string, platform: string) {
63+
async function _prepareDemoProject(cwd: string, name: string) {
6064
// TODO: run 'tns update' / detect and build webpack
61-
Logger.debug(`building project in ${cwd} for ${platform} ...`);
65+
Logger.debug(`preparing project in ${cwd}...`);
66+
67+
// replace plugin version in package.json with latest(*)
6268
const pkgFilePath = path.join(cwd, 'package.json');
6369
let pkgFile: any;
6470
try {
6571
const pkgFileStr = readFileSync(pkgFilePath, 'utf8');
6672
pkgFile = JSON.parse(pkgFileStr);
6773
} catch (e) {
6874
Logger.error(e.message || e);
69-
return false;
75+
return;
7076
}
7177

72-
if (!pkgFile) {
73-
return false;
74-
}
78+
if (pkgFile) {
79+
if (pkgFile.dependencies && pkgFile.dependencies[name]) {
80+
pkgFile.dependencies[name] = '*';
81+
}
7582

76-
if (pkgFile.dependencies && pkgFile.dependencies[name]) {
77-
pkgFile.dependencies[name] = '*';
78-
}
83+
if (pkgFile.devDependencies && pkgFile.devDependencies[name]) {
84+
pkgFile.devDependencies[name] = '*';
85+
}
7986

80-
if (pkgFile.devDependencies && pkgFile.devDependencies[name]) {
81-
pkgFile.devDependencies[name] = '*';
87+
try {
88+
writeFileSync(pkgFilePath, JSON.stringify(pkgFile, null, 4), 'utf8');
89+
} catch (e) {
90+
Logger.error(e.message || e);
91+
return;
92+
}
8293
}
8394

84-
try {
85-
writeFileSync(pkgFilePath, JSON.stringify(pkgFile, null, 4), 'utf8');
86-
} catch (e) {
87-
Logger.error(e.message || e);
88-
return false;
95+
const srcDir = path.join(cwd, '..', 'src');
96+
if (existsSync(srcDir)) {
97+
// npm i from source directory so references can be used
98+
await execPromise(srcDir, 'npm i');
8999
}
90100

91101
await execPromise(cwd, 'npm i');
102+
}
103+
104+
async function _buildProject(cwd: string, platform: string) {
105+
Logger.debug(`building project in ${cwd} for ${platform}...`);
92106
const result = await execPromise(cwd, `tns build ${platform}`);
93107
return result;
94108
}

0 commit comments

Comments
 (0)