1
1
module . exports = ( api , options , rootOptions ) => {
2
2
const fs = require ( 'fs' )
3
3
const rimraf = require ( 'rimraf' )
4
+ const replace = require ( 'replace-in-file' ) ;
5
+ const path = require ( 'path' ) ;
6
+
7
+ console . log ( 'adding to package.json' ) ;
4
8
5
9
api . extendPackage ( {
10
+ nativescript : {
11
+ 'id' : 'org.nativescript.application' ,
12
+ 'tns-ios' : {
13
+ 'version' : '4.2.0'
14
+ } ,
15
+ 'tns-android' : {
16
+ 'version' : '4.2.0'
17
+ }
18
+ } ,
6
19
scripts : {
7
- 'watch:android' : 'vue-cli-service tns --android' ,
8
- 'watch:ios' : 'vue-cli-service tns --ios' ,
20
+ "serve:web" : "vue-cli-service serve --mode development.web" ,
21
+ "serve:android" : "vue-cli-service tns:dev --mode development.android" ,
22
+ "serve:ios" : "vue-cli-service tns:dev --mode development.ios" ,
23
+ "build:web" : "vue-cli-service build --mode production.web" ,
24
+ "build:android" : "vue-cli-service tns:prod --mode production.android" ,
25
+ "build:ios" : "vue-cli-service tns:prod --mode production.ios" ,
9
26
} ,
10
27
dependencies : {
11
- 'nativescript-vue' : '^1.3.1'
28
+ 'nativescript-vue' : '^2.0.2' ,
29
+ 'tns-core-modules' : '^4.2.1' ,
12
30
} ,
13
31
devDependencies : {
14
- 'nativescript-vue-loader' : '1.0.0' ,
15
- 'nativescript-vue-template-compiler' : '^1.3.1' ,
16
- 'tns-core-modules' : '^4.0.0'
32
+ '@babel/core' : '^7.1.2' ,
33
+ '@babel/preset-env' : '^7.1.0' ,
34
+ '@babel/types' : '^7.1.3' ,
35
+ 'babel-loader' : '^8.0.4' ,
36
+ 'babel-traverse' : '^6.26.0' ,
37
+ 'clean-webpack-plugin' : '^0.1.19' ,
38
+ 'copy-webpack-plugin' : '^4.5.4' ,
39
+ 'nativescript-dev-webpack' : '^0.17.0' ,
40
+ 'nativescript-vue-template-compiler' : '^2.0.2' ,
41
+ 'nativescript-worker-loader' : '~0.9.1' ,
42
+ 'replace-in-file' : '^3.4.2' ,
43
+ "string-replace-loader" : "^2.1.1" ,
17
44
}
18
45
} )
19
46
47
+ console . log ( 'deleting from package.json' ) ;
48
+
49
+
20
50
api . extendPackage ( pkg => {
21
- delete pkg . dependencies [ 'vue' ]
22
- delete pkg . devDependencies [ 'vue-template-compiler' ]
23
- delete pkg . browserslist
24
- delete pkg . scripts [ 'serve' ]
51
+ // delete pkg.dependencies['vue']
52
+ delete pkg . devDependencies [
53
+ // 'vue-template-compiler',
54
+ 'babel-core'
55
+ ]
56
+ // delete pkg.browserslist
57
+ delete pkg . scripts [ 'serve' ] ,
58
+ delete pkg . scripts [ 'build' ]
59
+
25
60
} )
26
61
62
+ console . log ( 'doing template rendering' ) ;
63
+
27
64
api . render ( './templates/simple' , {
28
65
applicationName : api . generator . pkg . name ,
29
66
applicationVersion : api . generator . pkg . version ,
@@ -34,11 +71,85 @@ module.exports = (api, options, rootOptions) => {
34
71
historyMode : options . historyMode || false ,
35
72
} )
36
73
37
- // delete the "public" directory
74
+ console . log ( 'onCreateComplete' ) ;
75
+
76
+ // delete the 'public' directory
38
77
api . onCreateComplete ( ( ) => {
39
- const publicPath = api . resolve ( 'public' )
40
- if ( fs . existsSync ( publicPath ) ) {
41
- rimraf . sync ( publicPath )
78
+ const newline = process . platform === 'win32' ? '\r\n' : '\n' ;
79
+ // // // const publicPath = api.resolve('public')
80
+ const webpackConfigFile = api . resolve ( './webpack.config.js' )
81
+ const main = api . resolve ( 'src/main.js' ) ;
82
+ const gitignorePath = api . resolve ( '.gitignore' )
83
+
84
+ // // // if(fs.existsSync(publicPath)) {
85
+ // // // rimraf.sync(publicPath)
86
+ // // // }
87
+
88
+ // remove any webpack.config.js file that might already be there
89
+ if ( fs . existsSync ( webpackConfigFile ) ) {
90
+ fs . unlink ( webpackConfigFile , ( err ) => {
91
+ if ( err ) throw err ;
92
+ } ) ; }
93
+
94
+ // delete main.js
95
+ if ( fs . existsSync ( main ) ) {
96
+ fs . unlink ( main , ( err ) => {
97
+ if ( err ) throw err ;
98
+ } ) ;
99
+ }
100
+
101
+ // setup string replacement options for babel.config.js file
102
+ if ( fs . existsSync ( './babel.config.js' ) ) {
103
+ const replaceOptions = {
104
+ files : './babel.config.js' ,
105
+ from : ' \'@vue/app\'' ,
106
+ to : ' process.env.VUE_PLATFORM === \'web\' ? \'@vue/app\' : {}, ' + newline + ' [\'@babel/env\', { targets: { esmodules: true } }]' ,
107
+ }
108
+ replace ( replaceOptions , ( error , changes ) => {
109
+ if ( error ) {
110
+ return console . error ( 'Error occurred:' , error ) ;
111
+ }
112
+ } )
42
113
}
114
+
115
+ // write out environmental files
116
+ const developmentAndroid = 'NODE_ENV=development' + newline + 'VUE_PLATFORM=android' + newline + 'VUE_APP_MODE=native' ;
117
+ const developmentIOS = 'NODE_ENV=development' + newline + 'VUE_PLATFORM=ios' + newline + 'VUE_APP_MODE=native' ;
118
+ const developmentWeb = 'NODE_ENV=development' + newline + 'VUE_PLATFORM=web' + newline + 'VUE_APP_MODE=web' ;
119
+ const productionAndroid = 'NODE_ENV=production' + newline + 'VUE_PLATFORM=android' + newline + 'VUE_APP_MODE=native' ;
120
+ const productionIOS = 'NODE_ENV=production' + newline + 'VUE_PLATFORM=ios' + newline + 'VUE_APP_MODE=native' ;
121
+ const productionWeb = 'NODE_ENV=production' + newline + 'VUE_PLATFORM=web' + newline + 'VUE_APP_MODE=web' ;
122
+
123
+ fs . writeFileSync ( './.env.development.android' , developmentAndroid , { encoding : 'utf8' } )
124
+ fs . writeFileSync ( './.env.development.ios' , developmentIOS , { encoding : 'utf8' } )
125
+ fs . writeFileSync ( './.env.development.web' , developmentWeb , { encoding : 'utf8' } )
126
+ fs . writeFileSync ( './.env.production.android' , productionAndroid , { encoding : 'utf8' } )
127
+ fs . writeFileSync ( './.env.production.ios' , productionIOS , { encoding : 'utf8' } )
128
+ fs . writeFileSync ( './.env.production.web' , productionWeb , { encoding : 'utf8' } )
129
+
130
+
131
+ // write nsconfig.json
132
+ const nsconfig = {
133
+ 'appPath' : 'src' ,
134
+ 'appResourcesPath' : 'src/App_Resources'
135
+ }
136
+ fs . writeFileSync ( './nsconfig.json' , JSON . stringify ( nsconfig , null , 2 ) , { encoding : 'utf8' } ) ;
137
+
138
+ // write .gitignore additions
139
+ let gitignoreContent
140
+
141
+ if ( fs . existsSync ( gitignorePath ) ) {
142
+ gitignoreContent = fs . readFileSync ( gitignorePath , { encoding : 'utf8' } )
143
+ } else {
144
+ gitignoreContent = ''
145
+ }
146
+
147
+ const gitignoreAdditions = newline + '# NativeScript application' + newline + 'hooks' + newline + 'platforms'
148
+ if ( gitignoreContent . indexOf ( gitignoreAdditions ) === - 1 ) {
149
+ gitignoreContent += gitignoreAdditions
150
+
151
+ fs . writeFileSync ( gitignorePath , gitignoreContent , { encoding : 'utf8' } )
152
+ }
153
+
43
154
} )
44
155
}
0 commit comments