1- const path = require ( "path" ) ;
2- const fs = require ( "fs" ) ;
3- const semver = require ( "semver" ) ;
1+ const { resolve } = require ( "path" ) ;
2+ const { readFileSync, writeFileSync } = require ( "fs" ) ;
43const { EOL } = require ( "os" ) ;
4+
55const hook = require ( "nativescript-hook" ) ( __dirname ) ;
66
77const PROJECT_DATA_GETTERS = {
88 appPath : "getAppDirectoryRelativePath" ,
99 appResourcesPath : "getAppResourcesRelativeDirectoryPath" ,
1010} ;
1111
12- const APP_DIR = "app" ;
13- const ANDROID_PROJECT_PATH = "platforms/android" ;
14-
1512const isTypeScript = ( { projectDir, packageJson } = { } ) => {
1613 packageJson = packageJson || getPackageJson ( projectDir ) ;
1714
@@ -33,42 +30,19 @@ const isAngular = ({ projectDir, packageJson } = {}) => {
3330
3431const isSass = ( { projectDir, packageJson } = { } ) => {
3532 packageJson = packageJson || getPackageJson ( projectDir ) ;
33+ const SASS_PLUGIN_NAME = "nativescript-dev-sass" ;
3634
3735 return (
3836 packageJson . dependencies &&
39- packageJson . dependencies . hasOwnProperty ( "nativescript-dev-sass" )
37+ packageJson . dependencies . hasOwnProperty ( SASS_PLUGIN_NAME )
4038 ) || (
41- packageJson . devDependencies &&
42- packageJson . devDependencies . hasOwnProperty ( "nativescript-dev-sass" )
43- ) ;
39+ packageJson . devDependencies &&
40+ packageJson . devDependencies . hasOwnProperty ( SASS_PLUGIN_NAME )
41+ ) ;
4442} ;
4543
46- const getAndroidRuntimeVersion = ( projectDir ) => {
47- try {
48- const projectPackageJSON = getPackageJson ( projectDir ) ;
49-
50- const version = projectPackageJSON [ "nativescript" ] [ "tns-android" ] [ "version" ] ;
51- return version && toReleaseVersion ( version ) ;
52- } catch ( e ) {
53- return null ;
54- }
55- }
56-
57- const getAndroidV8Version = ( projectDir ) => {
58- try {
59- const androidSettingsJSON = getAndroidSettingsJson ( projectDir ) ;
60- if ( androidSettingsJSON != null ) {
61- return androidSettingsJSON . v8Version ;
62- } else {
63- return null ;
64- }
65- } catch ( e ) {
66- return null ;
67- }
68- }
69-
7044const getWebpackConfig = ( projectDir , env , configPath = "webpack.config.js" ) => {
71- const configAbsolutePath = path . resolve ( projectDir , configPath ) ;
45+ const configAbsolutePath = resolve ( projectDir , configPath ) ;
7246 let config ;
7347
7448 try {
@@ -92,59 +66,16 @@ const getWebpackConfig = (projectDir, env, configPath = "webpack.config.js") =>
9266
9367const getPackageJson = projectDir => {
9468 const packageJsonPath = getPackageJsonPath ( projectDir ) ;
95- return JSON . parse ( fs . readFileSync ( packageJsonPath , "utf8" ) ) ;
96- } ;
97-
98- const getAndroidSettingsJson = projectDir => {
99- const androidSettingsJsonPath = path . resolve ( projectDir , ANDROID_PROJECT_PATH , "settings.json" ) ;
100- if ( fs . existsSync ( androidSettingsJsonPath ) ) {
101- return JSON . parse ( fs . readFileSync ( androidSettingsJsonPath , "utf8" ) ) ;
102- } else {
103- return null ;
104- }
69+ return JSON . parse ( readFileSync ( packageJsonPath , "utf8" ) ) ;
10570} ;
10671
10772const writePackageJson = ( content , projectDir ) => {
10873 const packageJsonPath = getPackageJsonPath ( projectDir ) ;
109- fs . writeFileSync ( packageJsonPath , JSON . stringify ( content , null , 2 ) )
74+ writeFileSync ( packageJsonPath , JSON . stringify ( content , null , 2 ) )
11075}
11176const getProjectDir = hook . findProjectDir ;
11277
113- const toReleaseVersion = version =>
114- version . replace ( / - .* / , "" ) ;
115-
116- const getAndroidProjectPath = ( { androidPackageVersion, projectRoot} ) => {
117- if ( projectRoot ) {
118- androidPackageVersion = getAndroidRuntimeVersion ( projectRoot ) ;
119- }
120-
121- return semver . lt ( androidPackageVersion , "3.4.0" ) ?
122- ANDROID_PROJECT_PATH :
123- path . join ( ANDROID_PROJECT_PATH , APP_DIR ) ;
124- } ;
125-
126-
127- const resolveAndroidAppPath = projectDir => {
128- const RESOURCES_PATH = "src/main/assets/app" ;
129- const androidPackageVersion = getAndroidRuntimeVersion ( projectDir ) ;
130- const androidProjectPath = getAndroidProjectPath ( { androidPackageVersion} ) ;
131-
132- return path . join ( projectDir , androidProjectPath , RESOURCES_PATH ) ;
133- } ;
134-
135- const resolveAndroidConfigurationsPath = projectDir => {
136- const CONFIGURATIONS_DIR = "configurations" ;
137- const androidPackageVersion = getAndroidRuntimeVersion ( projectDir ) ;
138- const androidProjectPath = getAndroidProjectPath ( { androidPackageVersion} ) ;
139-
140- const configurationsPath = semver . lt ( androidPackageVersion , "3.3.0" ) ?
141- path . join ( androidProjectPath , CONFIGURATIONS_DIR ) :
142- path . join ( androidProjectPath , "build" , CONFIGURATIONS_DIR ) ;
143-
144- return path . join ( projectDir , configurationsPath ) ;
145- } ;
146-
147- const getPackageJsonPath = projectDir => path . resolve ( projectDir , "package.json" ) ;
78+ const getPackageJsonPath = projectDir => resolve ( projectDir , "package.json" ) ;
14879
14980const isAndroid = platform => / a n d r o i d / i. test ( platform ) ;
15081const isIos = platform => / i o s / i. test ( platform ) ;
@@ -173,12 +104,8 @@ function safeGet(object, property, ...args) {
173104}
174105
175106module . exports = {
176- APP_DIR ,
177107 getAppPathFromProjectData,
178108 getAppResourcesPathFromProjectData,
179- getAndroidProjectPath,
180- getAndroidRuntimeVersion,
181- getAndroidV8Version,
182109 getPackageJson,
183110 getProjectDir,
184111 getWebpackConfig,
@@ -187,7 +114,5 @@ module.exports = {
187114 isAngular,
188115 isSass,
189116 isTypeScript,
190- resolveAndroidAppPath,
191- resolveAndroidConfigurationsPath,
192117 writePackageJson,
193118} ;
0 commit comments