@@ -3,33 +3,6 @@ const fs = require("fs");
3
3
4
4
const { isTypeScript, isAngular } = require ( "./projectHelpers" ) ;
5
5
6
- const FRAME_MATCH = / ( \s * ) ( r e q u i r e \( " u i \/ f r a m e " \) ; ) ( \s * ) ( r e q u i r e \( " u i \/ f r a m e \/ a c t i v i t y " \) ; ) / g;
7
- const SCOPED_FRAME = `if (!global["__snapshot"]) {
8
- // In case snapshot generation is enabled these modules will get into the bundle
9
- // but will not be required/evaluated.
10
- // The snapshot webpack plugin will add them to the tns-java-classes.js bundle file.
11
- // This way, they will be evaluated on app start as early as possible.
12
- $1 $2$3 $4
13
- }` ;
14
-
15
- const CONFIG_MATCH = / ( e x p o r t s = [ ^ ] + ?) \s * r e t u r n ( { [ ^ ] + t a r g e t : \s * n a t i v e s c r i p t T a r g e t [ ^ ] + ?} ; ) / ;
16
- const CONFIG_REPLACE = `$1
17
-
18
- const config = $2
19
-
20
- if (env.snapshot) {
21
- plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
22
- chunk: "vendor",
23
- projectRoot: __dirname,
24
- webpackConfig: config,
25
- targetArchs: ["arm", "arm64", "ia32"],
26
- tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
27
- useLibs: false
28
- }));
29
- }
30
-
31
- return config;` ;
32
-
33
6
function addProjectFiles ( projectDir , appDir ) {
34
7
const projectTemplates = getProjectTemplates ( projectDir ) ;
35
8
Object . keys ( projectTemplates ) . forEach ( function ( templateName ) {
@@ -122,65 +95,6 @@ function getFullTemplatesPath(projectDir, templates) {
122
95
return updatedTemplates ;
123
96
}
124
97
125
- function editExistingProjectFiles ( projectDir ) {
126
- const webpackConfigPath = getFullPath ( projectDir , "webpack.config.js" ) ;
127
- const webpackCommonPath = getFullPath ( projectDir , "webpack.common.js" ) ;
128
-
129
- const configChangeFunctions = [
130
- replaceStyleUrlResolvePlugin ,
131
- addSnapshotPlugin ,
132
- ] ;
133
-
134
- editFileContent ( webpackConfigPath , ...configChangeFunctions ) ;
135
- editFileContent ( webpackCommonPath , ...configChangeFunctions ) ;
136
-
137
- const extension = isAngular ( { projectDir} ) ? "ts" : "js" ;
138
- const vendorAndroidPath = getFullPath (
139
- projectDir ,
140
- `app/vendor-platform.android.${ extension } `
141
- ) ;
142
-
143
- editFileContent ( vendorAndroidPath , addSnapshotToVendor ) ;
144
- }
145
-
146
- function editFileContent ( path , ...funcs ) {
147
- if ( ! fs . existsSync ( path ) ) {
148
- return ;
149
- }
150
-
151
- let content = fs . readFileSync ( path , "utf8" ) ;
152
- funcs . forEach ( fn => content = fn ( content ) ) ;
153
-
154
- fs . writeFileSync ( path , content , "utf8" ) ;
155
- }
156
-
157
- function replaceStyleUrlResolvePlugin ( config ) {
158
- if ( config . indexOf ( "StyleUrlResolvePlugin" ) === - 1 ) {
159
- return config ;
160
- }
161
-
162
- console . info ( "Replacing deprecated StyleUrlsResolvePlugin with UrlResolvePlugin..." ) ;
163
- return config . replace ( / S t y l e U r l R e s o l v e P l u g i n / g, "UrlResolvePlugin" ) ;
164
- }
165
-
166
- function addSnapshotPlugin ( config ) {
167
- if ( config . indexOf ( "NativeScriptSnapshotPlugin" ) > - 1 ) {
168
- return config ;
169
- }
170
-
171
- console . info ( "Adding NativeScriptSnapshotPlugin configuration..." ) ;
172
- return config . replace ( CONFIG_MATCH , CONFIG_REPLACE ) ;
173
- }
174
-
175
- function addSnapshotToVendor ( content ) {
176
- if ( content . indexOf ( "__snapshot" ) > - 1 ) {
177
- return content ;
178
- }
179
-
180
- console . info ( "Adding __snapshot configuration to app/vendor-platform.android ..." ) ;
181
- return content . replace ( FRAME_MATCH , SCOPED_FRAME ) ;
182
- }
183
-
184
98
function getFullPath ( projectDir , filePath ) {
185
99
return path . resolve ( projectDir , filePath ) ;
186
100
}
@@ -194,6 +108,5 @@ module.exports = {
194
108
addProjectFiles,
195
109
removeProjectFiles,
196
110
forceUpdateProjectFiles,
197
- editExistingProjectFiles,
198
111
} ;
199
112
0 commit comments