Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 0893b28

Browse files
authored
refactor: remove old update scripts (#475)
1 parent 0eab4af commit 0893b28

File tree

1 file changed

+0
-87
lines changed

1 file changed

+0
-87
lines changed

Diff for: projectFilesManager.js

-87
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,6 @@ const fs = require("fs");
33

44
const { isTypeScript, isAngular } = require("./projectHelpers");
55

6-
const FRAME_MATCH = /(\s*)(require\("ui\/frame"\);)(\s*)(require\("ui\/frame\/activity"\);)/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 = /(exports = [^]+?)\s*return ({[^]+target:\s*nativescriptTarget[^]+?};)/;
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-
336
function addProjectFiles(projectDir, appDir) {
347
const projectTemplates = getProjectTemplates(projectDir);
358
Object.keys(projectTemplates).forEach(function(templateName) {
@@ -122,65 +95,6 @@ function getFullTemplatesPath(projectDir, templates) {
12295
return updatedTemplates;
12396
}
12497

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(/StyleUrlResolvePlugin/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-
18498
function getFullPath(projectDir, filePath) {
18599
return path.resolve(projectDir, filePath);
186100
}
@@ -194,6 +108,5 @@ module.exports = {
194108
addProjectFiles,
195109
removeProjectFiles,
196110
forceUpdateProjectFiles,
197-
editExistingProjectFiles,
198111
};
199112

0 commit comments

Comments
 (0)