Skip to content

Commit 8f47987

Browse files
committed
feat: add snapshot,aot, uglify support
- change test project from TS to NG template - refactor code to support more build tests - overal 50% more time per plugin due to snapshot builds
1 parent 4c1556c commit 8f47987

3 files changed

Lines changed: 70 additions & 31 deletions

File tree

lib/checker.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ import { Logger } from './log.service';
66

77
interface ResultsInterface {
88
name: string;
9-
webpack: any;
10-
webpackTime: number;
11-
build: any;
12-
buildTime: number;
9+
webpack?: any;
10+
webpackTime?: number;
11+
build?: any;
12+
buildTime?: number;
13+
snapshot?: any;
14+
snapshotTime?: number;
15+
aot?: any;
16+
aotTime?: number;
17+
uglify?: any;
18+
uglifyTime?: number;
1319
}
1420

1521
class OutputModel {
@@ -53,20 +59,25 @@ export async function run() {
5359

5460
// Test if the plugin builds when added to an app
5561
await ProjectService.prepareProject(plugin);
56-
const startDate = new Date().getTime();
57-
const resultWP = await ProjectService.testWebpack(plugin);
58-
const midDate = new Date().getTime();
59-
const resultB = await ProjectService.testBuild(plugin);
60-
const endDate = new Date().getTime();
62+
const actions = ['testWebpack', 'testBuild', 'testSnapshot']; // removed for speed , 'testUglify', 'testAot'];
63+
const result: ResultsInterface = {
64+
name: plugin.name
65+
};
66+
67+
for (let index = 0; index < actions.length; index++) {
68+
const action = actions[index];
69+
const startDate = new Date().getTime();
70+
const actionResult = await ProjectService[action](plugin);
71+
const endDate = new Date().getTime();
72+
const resultName = action.replace('test', '').toLowerCase();
73+
result[resultName] = actionResult;
74+
result[resultName + 'Time'] = Math.round((endDate - startDate) / 1000);
75+
}
76+
6177
await ProjectService.cleanProject();
62-
results.push({
63-
name: plugin.name,
64-
webpack: resultWP,
65-
webpackTime: Math.round((midDate - startDate) / 1000),
66-
build: resultB,
67-
buildTime: Math.round((endDate - midDate) / 1000)
68-
});
69-
Logger.log(JSON.stringify(results[results.length - 1]));
78+
results.push(result);
79+
Logger.log(JSON.stringify(results[results.length - 1], null, 4));
80+
Logger.log('---------------------------------------------------------------------------');
7081
}
7182

7283
output.data = results;

lib/project.service.ts

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Logger } from './log.service';
77
import { execPromise } from './execPromise';
88

99
const testDirectory = 'test';
10-
const testProject = 'baseTS';
10+
const testProject = 'baseNG';
1111
const testProjectOriginalSuffix = '_original';
1212

1313
export namespace ProjectService {
@@ -47,6 +47,18 @@ export namespace ProjectService {
4747
return await testPlugin(plugin, '--bundle');
4848
}
4949

50+
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');
52+
}
53+
54+
export async function testUglify(plugin: MarketplaceService.PluginModel) {
55+
return await testPlugin(plugin, '--bundle --env.uglify');
56+
}
57+
58+
export async function testAot(plugin: MarketplaceService.PluginModel) {
59+
return await testPlugin(plugin, '--bundle --env.aot');
60+
}
61+
5062
export async function testBuild(plugin: MarketplaceService.PluginModel) {
5163
return await testPlugin(plugin, '');
5264
}
@@ -103,18 +115,35 @@ export namespace ProjectService {
103115

104116
function _modifyProject(appRoot: string, plugin: MarketplaceService.PluginModel) {
105117
const name = plugin.name;
106-
const mainTsPath = path.join(appRoot, 'app', 'main-view-model.ts');
107-
let mainTs = readFileSync(mainTsPath, 'utf8');
108-
if (plugin.badges.typings) {
109-
mainTs = `import * as testPlugin from '${name}';\n` + mainTs;
110-
} else {
111-
mainTs = `const testPlugin = require('${name}');\n` + mainTs;
118+
119+
try {
120+
const packagePath = path.join(appRoot, 'app', 'package.json');
121+
let packageJson = readFileSync(packagePath, 'utf8');
122+
packageJson = packageJson.replace('"android": {', `"android": {\n"requireModules": ["${name}"],`);
123+
if (packageJson.indexOf(name) === -1) {
124+
throw new Error('package.json content has changed! Plugin test script needs to be updated.');
125+
}
126+
writeFileSync(packagePath, packageJson, 'utf8');
127+
} catch (e) {
128+
Logger.error('error while updating package.json in app folder! ' + (e && e.message));
112129
}
113-
mainTs = mainTs.replace('public onTap() {', 'public onTap() {\nfor (let testExport in testPlugin) {console.log(testExport);}\n');
114-
if (mainTs.indexOf('testExport') === -1) {
115-
throw new Error('Template content has changed! Plugin test script needs to be updated.');
130+
131+
try {
132+
const mainTsPath = path.join(appRoot, 'app', 'home', 'home.component.ts');
133+
let mainTs = readFileSync(mainTsPath, 'utf8');
134+
if (plugin.badges.typings) {
135+
mainTs = `import * as testPlugin from '${name}';\n` + mainTs;
136+
} else {
137+
mainTs = `const testPlugin = require('${name}');\n` + mainTs;
138+
}
139+
mainTs = mainTs.replace('constructor() {', 'constructor() {\nfor (let testExport in testPlugin) {console.log(testExport);}\n');
140+
if (mainTs.indexOf('console.log(testExport)') === -1) {
141+
throw new Error('Template component content has changed! Plugin test script needs to be updated.');
142+
}
143+
writeFileSync(mainTsPath, mainTs, 'utf8');
144+
} catch (e) {
145+
Logger.error('error while updating main-view-model.ts in app folder! ' + (e && e.message));
116146
}
117-
writeFileSync(mainTsPath, mainTs, 'utf8');
118147
}
119148

120149
async function _copyTestProject(name: string) {
@@ -142,8 +171,7 @@ export namespace ProjectService {
142171
async function _createProject(name: string) {
143172
Logger.debug(`creating project ${name} ...`);
144173
const baseProjectDir = path.join(testDirectory, name);
145-
await execPromise(testDirectory, `tns create ${name} --tsc`);
146-
await execPromise(baseProjectDir, 'npm i --save-dev nativescript-dev-webpack');
174+
await execPromise(testDirectory, `tns create ${name} --template tns-template-blank-ng`);
147175
await execPromise(baseProjectDir, 'npm i');
148176
await execPromise(baseProjectDir, 'tns platform add android');
149177
await execPromise(baseProjectDir, 'tns platform add ios');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"tslib": "~1.9.2"
1717
},
1818
"devDependencies": {
19-
"@types/node": "^10.3.3",
19+
"@types/node": "^10.1.4",
2020
"nativescript": "*",
2121
"typescript": "^2.9.2"
2222
}

0 commit comments

Comments
 (0)