Skip to content

Commit 9ad585f

Browse files
committed
refactor: remove the vendor.ts/js files
1 parent 2ec8083 commit 9ad585f

7 files changed

+32
-139
lines changed

installer.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ const dependencyManager = require("./dependencyManager");
44

55
function install() {
66
const projectDir = helpers.getProjectDir();
7-
const appPath = helpers.getAppPath();
87
const packageJson = helpers.getPackageJson(projectDir);
98

10-
projectFilesManager.addProjectFiles(projectDir, appPath);
9+
projectFilesManager.addProjectFiles(projectDir);
1110

1211
const postinstallOptions = dependencyManager.addProjectDeps(packageJson);
1312
packageJson.devDependencies = postinstallOptions.deps;
@@ -19,8 +18,7 @@ function install() {
1918

2019
function uninstall() {
2120
const projectDir = helpers.getProjectDir();
22-
const appPath = helpers.getAppPath();
23-
projectFilesManager.removeProjectFiles(projectDir, appPath);
21+
projectFilesManager.removeProjectFiles(projectDir);
2422

2523
console.log("NativeScript Webpack removed!");
2624
}

nsCliHelpers.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

projectFilesManager.js

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,26 @@ const fs = require("fs");
33

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

6-
function addProjectFiles(projectDir, appDir) {
6+
function addProjectFiles(projectDir) {
77
const projectTemplates = getProjectTemplates(projectDir);
88
Object.keys(projectTemplates).forEach(function(templateName) {
99
const templateDestination = projectTemplates[templateName];
1010
templateName = path.resolve(templateName);
1111
copyTemplate(templateName, templateDestination);
1212
});
13-
14-
const appTemplates = getAppTemplates(projectDir, appDir);
15-
Object.keys(appTemplates).forEach(function(templateName) {
16-
const templateDestination = appTemplates[templateName];
17-
copyTemplate(templateName, templateDestination)
18-
});
1913
}
2014

21-
function removeProjectFiles(projectDir, appDir) {
15+
function removeProjectFiles(projectDir) {
2216
const projectTemplates = getProjectTemplates(projectDir);
2317
Object.keys(projectTemplates).forEach(function(templateName) {
2418
const templateDestination = projectTemplates[templateName];
2519
deleteFile(templateDestination);
2620
});
27-
28-
const appTemplates = getAppTemplates(projectDir, appDir);
29-
Object.keys(appTemplates).forEach(function(templateName) {
30-
const templateDestination = appTemplates[templateName];
31-
deleteFile(templateDestination);
32-
});
3321
}
3422

35-
function forceUpdateProjectFiles(projectDir, appDir) {
36-
removeProjectFiles(projectDir, appDir);
37-
addProjectFiles(projectDir, appDir);
23+
function forceUpdateProjectFiles(projectDir) {
24+
removeProjectFiles(projectDir);
25+
addProjectFiles(projectDir);
3826
}
3927

4028
function compareProjectFiles(projectDir) {
@@ -69,31 +57,20 @@ function copyTemplate(templateName, destinationPath) {
6957
}
7058

7159
function getProjectTemplates(projectDir) {
72-
let templates = {}
60+
const templates = {}
61+
const CONFIG_NAME = "webpack.config.js";
7362

7463
if (isAngular({projectDir})) {
75-
templates["webpack.angular.js"] = "webpack.config.js";
64+
templates["webpack.angular.js"] = CONFIG_NAME;
7665
} else if (isTypeScript({projectDir})) {
77-
templates["webpack.typescript.js"] = "webpack.config.js";
66+
templates["webpack.typescript.js"] = CONFIG_NAME;
7867
} else {
79-
templates["webpack.javascript.js"] = "webpack.config.js";
68+
templates["webpack.javascript.js"] = CONFIG_NAME;
8069
}
8170

8271
return getFullTemplatesPath(projectDir, templates);
8372
}
8473

85-
function getAppTemplates(projectDir, appDir) {
86-
const templates = {};
87-
88-
if (isAngular({projectDir})) {
89-
templates["vendor.angular.ts"] = tsOrJs(projectDir, "vendor");
90-
} else {
91-
templates["vendor.nativescript.ts"] = tsOrJs(projectDir, "vendor");
92-
}
93-
94-
return getFullTemplatesPath(appDir, templates);
95-
}
96-
9774
function getFullTemplatesPath(projectDir, templates) {
9875
let updatedTemplates = {};
9976

@@ -111,15 +88,9 @@ function getFullPath(projectDir, filePath) {
11188
return path.resolve(projectDir, filePath);
11289
}
11390

114-
function tsOrJs(projectDir, name) {
115-
const extension = isTypeScript({projectDir}) ? "ts" : "js";
116-
return `${name}.${extension}`;
117-
}
118-
11991
module.exports = {
12092
addProjectFiles,
12193
removeProjectFiles,
12294
forceUpdateProjectFiles,
12395
compareProjectFiles,
12496
};
125-

projectHelpers.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ const semver = require("semver");
44
const { EOL } = require("os");
55
const hook = require("nativescript-hook")(__dirname);
66

7-
const {
8-
PROJECT_DATA_GETTERS,
9-
getProjectData,
10-
safeGet,
11-
} = require("./nsCliHelpers");
7+
const PROJECT_DATA_GETTERS = {
8+
appPath: "getAppDirectoryRelativePath",
9+
appResourcesPath: "getAppResourcesRelativeDirectoryPath",
10+
};
1211

1312
const APP_DIR = "app";
1413
const ANDROID_PROJECT_PATH = "platforms/android";
@@ -150,16 +149,6 @@ const getPackageJsonPath = projectDir => path.resolve(projectDir, "package.json"
150149
const isAndroid = platform => /android/i.test(platform);
151150
const isIos = platform => /ios/i.test(platform);
152151

153-
function getAppPath() {
154-
const projectDir = getProjectDir();
155-
const projectData = getProjectData(projectDir);
156-
const appDir = getAppPathFromProjectData(projectData) || APP_DIR;
157-
158-
const appPath = path.resolve(projectDir, appDir);
159-
160-
return appPath;
161-
}
162-
163152
function getAppPathFromProjectData(data) {
164153
return safeGet(data, PROJECT_DATA_GETTERS.appPath);
165154
}
@@ -168,9 +157,23 @@ function getAppResourcesPathFromProjectData(data) {
168157
return safeGet(data, PROJECT_DATA_GETTERS.appResourcesPath);
169158
}
170159

160+
function safeGet(object, property, ...args) {
161+
if (!object) {
162+
return;
163+
}
164+
165+
const value = object[property];
166+
if (!value) {
167+
return;
168+
}
169+
170+
return typeof value === "function" ?
171+
value.bind(object)(...args) :
172+
value;
173+
}
174+
171175
module.exports = {
172176
APP_DIR,
173-
getAppPath,
174177
getAppPathFromProjectData,
175178
getAppResourcesPathFromProjectData,
176179
getAndroidProjectPath,

templates/vendor.angular.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

templates/vendor.nativescript.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

verify/update.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const { spawn } = require("child_process");
22
const { resolve: pathResolve } = require("path");
33

44
const {
5-
getAppPath,
65
getPackageJson,
76
getProjectDir,
87
writePackageJson,
@@ -48,9 +47,7 @@ function updateDeps(projectDir) {
4847

4948
function updateConfigs(projectDir) {
5049
console.info("Updating configuration files...");
51-
52-
const appDir = getAppPath();
53-
forceUpdateProjectFiles(projectDir, appDir);
50+
forceUpdateProjectFiles(projectDir);
5451
}
5552

5653
function execute(command) {

0 commit comments

Comments
 (0)