11#!/usr/bin/env node
22
3- const { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } = require ( "fs" ) ;
3+ const {
4+ existsSync,
5+ mkdirSync,
6+ readdirSync,
7+ readFileSync,
8+ statSync,
9+ writeFileSync
10+ } = require ( "fs" ) ;
411const { basename, resolve } = require ( "path" ) ;
5-
6- const appRootPath = require ( 'app-root-path' ) . toString ( ) ;
712const childProcess = require ( "child_process" ) ;
13+ const appRootPath = require ( 'app-root-path' ) . toString ( ) ;
14+
15+ const sampleTestsFolder = "samples" ;
816const e2eTests = "e2e" ;
9- const e2eProjectFolderPath = resolve ( appRootPath , e2eTests ) ;
10- const e2ePluginFolderPath = resolve ( appRootPath , "node_modules" , "nativescript-dev-appium" , "e2e" ) ;
17+ const sampleTestsProjectFolderPath = resolve ( appRootPath , e2eTests ) ;
18+ const sampleTestsPluginFolderPath = resolve ( appRootPath , "node_modules" , "nativescript-dev-appium" , sampleTestsFolder ) ;
1119const packageJsonPath = resolve ( appRootPath , "package.json" ) ;
1220const packageJson = JSON . parse ( readFileSync ( packageJsonPath , "utf8" ) ) ;
21+
1322const isTypeScriptProject =
14- (
15- packageJson . dependencies &&
16- packageJson . dependencies . hasOwnProperty ( "typescript" )
17- ) || (
18- packageJson . devDependencies &&
19- packageJson . devDependencies . hasOwnProperty ( "typescript" )
20- ) ;
23+ ( packageJson . dependencies && packageJson . dependencies . hasOwnProperty ( "typescript" ) )
24+ || ( packageJson . devDependencies && packageJson . devDependencies . hasOwnProperty ( "typescript" ) ) ;
2125const isWin = / ^ w i n / . test ( process . platform ) ;
2226
23- function executeNpmInstall ( cwd ) {
27+ const executeNpmInstall = cwd => {
2428 let spawnArgs = [ ] ;
2529 let command = "" ;
2630 if ( isWin ) {
@@ -33,7 +37,7 @@ function executeNpmInstall(cwd) {
3337 childProcess . spawnSync ( command , spawnArgs , { cwd, stdio : "inherit" } ) ;
3438}
3539
36- function copy ( src , dest ) {
40+ const copy = ( src , dest ) => {
3741 if ( ! existsSync ( src ) ) {
3842 return Error ( "Source doesn't exist: " + src ) ;
3943 }
@@ -57,25 +61,24 @@ function copy(src, dest) {
5761 }
5862}
5963
60- function getDevDependencies ( ) {
64+ const getDevDependencies = ( ) => {
6165 // These are nativescript-dev-appium plugin's dependencies.
6266 // There is NO need to explicitly install them to the project.
6367 // const requiredDevDependencies = [
6468 // { name: "chai", version: "~4.1.1" },
6569 // { name: "chai-as-promised", version: "~7.1.1" },
66- // { name: "mocha", version: "~3.5 .0" },
70+ // { name: "mocha", version: "~5.2 .0" },
6771 // { name: "mocha-junit-reporter", version: "^1.13.0" },
68- // { name: "mocha-multi", version: "^0.11.0 " },
72+ // { name: "mocha-multi", version: "^1.0.1 " },
6973 // ];
7074
7175 // These are nativescript-dev-appium plugin's devDependencies.
7276 // There is need to explicitly install them to the project.
73- const typeScriptDevDependencies = [
74- //{ name: "tslib", version: "^1.7.1" },
75- { name : "@types/chai" , version : "~4.1.3" } ,
76- { name : "@types/mocha" , version : "~5.2.1" } ,
77- { name : "@types/node" , version : "^7.0.5" } ,
78- ] ;
77+ // const typeScriptDevDependencies = [
78+ // { name: "@types/chai", version: "~4.1.3" },
79+ // { name: "@types/mocha", version: "~5.2.1" },
80+ // { name: "@types/node", version: "^7.0.5" },
81+ // ];
7982
8083 // return isTypeScriptProject ?
8184 // [
@@ -84,10 +87,15 @@ function getDevDependencies() {
8487 // ] :
8588 // requiredDevDependencies;
8689
87- return typeScriptDevDependencies ;
90+ return ! isTypeScriptProject ? [ ] :
91+ [
92+ { name : "@types/chai" , version : "~4.1.3" } ,
93+ { name : "@types/mocha" , version : "~5.2.1" } ,
94+ { name : "@types/node" , version : "^7.0.5" } ,
95+ ] ;
8896}
8997
90- function configureDevDependencies ( packageJson ) {
98+ const configureDevDependencies = packageJson => {
9199 if ( ! packageJson . devDependencies ) {
92100 packageJson . devDependencies = { } ;
93101 }
@@ -100,13 +108,13 @@ function configureDevDependencies(packageJson) {
100108 if ( devDependenciesToInstall . length ) {
101109 console . info ( "Installing new devDependencies ..." ) ;
102110 // Execute `npm install` after everything else
103- setTimeout ( function ( ) {
111+ setTimeout ( function ( ) {
104112 executeNpmInstall ( appRootPath ) ;
105113 } , 300 ) ;
106114 }
107115}
108116
109- function updatePackageJsonDependencies ( packageJson , isTypeScriptProject ) {
117+ const updatePackageJsonDependencies = ( packageJson , isTypeScriptProject ) => {
110118 if ( ! packageJson . scripts ) {
111119 packageJson . scripts = { } ;
112120 }
@@ -126,14 +134,19 @@ function updatePackageJsonDependencies(packageJson, isTypeScriptProject) {
126134
127135if ( basename ( appRootPath ) !== "nativescript-dev-appium" ) {
128136 updatePackageJsonDependencies ( packageJson , isTypeScriptProject ) ;
129- if ( ! existsSync ( e2eProjectFolderPath ) ) {
130- mkdirSync ( e2eProjectFolderPath ) ;
137+ if ( ! existsSync ( sampleTestsProjectFolderPath ) ) {
138+ mkdirSync ( sampleTestsProjectFolderPath ) ;
131139 if ( isTypeScriptProject ) {
132- console . info ( "TypeScript project - adding sample config and test ..." ) ;
133- console . info ( "Copying " + e2ePluginFolderPath + " to " + e2eProjectFolderPath + " ..." ) ;
134- copy ( e2ePluginFolderPath , e2eProjectFolderPath ) ;
140+ console . info ( `TypeScript project - adding sample config and test ...` ) ;
141+ const tscSampleTestsPath = resolve ( sampleTestsPluginFolderPath , "e2e-tsc" )
142+ console . info ( `Copying ${ tscSampleTestsPath } to ${ sampleTestsProjectFolderPath } ...` ) ;
143+ copy ( tscSampleTestsPath , sampleTestsProjectFolderPath ) ;
135144 } else {
136- console . info ( "JavaScript project - not adding sample config and test ..." ) ;
145+ const jsSampleTestsPath = resolve ( sampleTestsPluginFolderPath , "e2e-js" )
146+ console . info ( "JavaScript project - adding sample config and test ..." ) ;
147+ console . info ( `Copying ${ jsSampleTestsPath } to ${ sampleTestsProjectFolderPath } ...` ) ;
148+ copy ( jsSampleTestsPath , sampleTestsProjectFolderPath ) ;
137149 }
138150 }
139- }
151+ }
152+
0 commit comments