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" ) ;
4
3
const { EOL } = require ( "os" ) ;
4
+
5
5
const hook = require ( "nativescript-hook" ) ( __dirname ) ;
6
6
7
7
const PROJECT_DATA_GETTERS = {
8
8
appPath : "getAppDirectoryRelativePath" ,
9
9
appResourcesPath : "getAppResourcesRelativeDirectoryPath" ,
10
10
} ;
11
11
12
- const APP_DIR = "app" ;
13
- const ANDROID_PROJECT_PATH = "platforms/android" ;
14
-
15
12
const isTypeScript = ( { projectDir, packageJson } = { } ) => {
16
13
packageJson = packageJson || getPackageJson ( projectDir ) ;
17
14
@@ -33,42 +30,19 @@ const isAngular = ({ projectDir, packageJson } = {}) => {
33
30
34
31
const isSass = ( { projectDir, packageJson } = { } ) => {
35
32
packageJson = packageJson || getPackageJson ( projectDir ) ;
33
+ const SASS_PLUGIN_NAME = "nativescript-dev-sass" ;
36
34
37
35
return (
38
36
packageJson . dependencies &&
39
- packageJson . dependencies . hasOwnProperty ( "nativescript-dev-sass" )
37
+ packageJson . dependencies . hasOwnProperty ( SASS_PLUGIN_NAME )
40
38
) || (
41
- packageJson . devDependencies &&
42
- packageJson . devDependencies . hasOwnProperty ( "nativescript-dev-sass" )
43
- ) ;
39
+ packageJson . devDependencies &&
40
+ packageJson . devDependencies . hasOwnProperty ( SASS_PLUGIN_NAME )
41
+ ) ;
44
42
} ;
45
43
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
-
70
44
const getWebpackConfig = ( projectDir , env , configPath = "webpack.config.js" ) => {
71
- const configAbsolutePath = path . resolve ( projectDir , configPath ) ;
45
+ const configAbsolutePath = resolve ( projectDir , configPath ) ;
72
46
let config ;
73
47
74
48
try {
@@ -92,59 +66,16 @@ const getWebpackConfig = (projectDir, env, configPath = "webpack.config.js") =>
92
66
93
67
const getPackageJson = projectDir => {
94
68
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" ) ) ;
105
70
} ;
106
71
107
72
const writePackageJson = ( content , projectDir ) => {
108
73
const packageJsonPath = getPackageJsonPath ( projectDir ) ;
109
- fs . writeFileSync ( packageJsonPath , JSON . stringify ( content , null , 2 ) )
74
+ writeFileSync ( packageJsonPath , JSON . stringify ( content , null , 2 ) )
110
75
}
111
76
const getProjectDir = hook . findProjectDir ;
112
77
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" ) ;
148
79
149
80
const isAndroid = platform => / a n d r o i d / i. test ( platform ) ;
150
81
const isIos = platform => / i o s / i. test ( platform ) ;
@@ -173,12 +104,8 @@ function safeGet(object, property, ...args) {
173
104
}
174
105
175
106
module . exports = {
176
- APP_DIR ,
177
107
getAppPathFromProjectData,
178
108
getAppResourcesPathFromProjectData,
179
- getAndroidProjectPath,
180
- getAndroidRuntimeVersion,
181
- getAndroidV8Version,
182
109
getPackageJson,
183
110
getProjectDir,
184
111
getWebpackConfig,
@@ -187,7 +114,5 @@ module.exports = {
187
114
isAngular,
188
115
isSass,
189
116
isTypeScript,
190
- resolveAndroidAppPath,
191
- resolveAndroidConfigurationsPath,
192
117
writePackageJson,
193
118
} ;
0 commit comments