@@ -7,7 +7,7 @@ import { Logger } from './log.service';
77import { execPromise } from './execPromise' ;
88
99const testDirectory = 'test' ;
10- const testProject = 'baseTS ' ;
10+ const testProject = 'baseNG ' ;
1111const testProjectOriginalSuffix = '_original' ;
1212
1313export 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' ) ;
0 commit comments