Skip to content

Commit cb055ae

Browse files
Merge pull request #1174 from NativeScript/vladimirov/ignore-ts-on-build
Do not copy .ts and .js.map files in real app
2 parents 4787484 + 50764bf commit cb055ae

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lib/services/platform-service.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ import * as shell from "shelljs";
66
import * as constants from "../constants";
77
import * as helpers from "../common/helpers";
88
import * as semver from "semver";
9+
import * as minimatch from "minimatch";
10+
import Future = require("fibers/future");
911

1012
export class PlatformService implements IPlatformService {
1113
private static TNS_MODULES_FOLDER_NAME = "tns_modules";
14+
private static EXCLUDE_FILES_PATTERN = [
15+
"**/*.js.map",
16+
"**/*.ts"
17+
];
1218

1319
constructor(private $devicesService: Mobile.IDevicesService,
1420
private $errors: IErrors,
@@ -174,22 +180,26 @@ export class PlatformService implements IPlatformService {
174180
.value();
175181

176182
// Copy all files from app dir, but make sure to exclude tns_modules
177-
let sourceFiles = this.$fs.readDirectory(appSourceDirectoryPath).wait();
183+
let sourceFiles = this.$fs.enumerateFilesInDirectorySync(appSourceDirectoryPath);
178184

179185
if (this.$options.release) {
180186
sourceFiles = sourceFiles.filter(source => source !== 'tests');
181187
}
182188

183-
let hasTnsModulesInAppFolder = _.contains(sourceFiles, constants.TNS_MODULES_FOLDER_NAME);
189+
let hasTnsModulesInAppFolder = this.$fs.exists(path.join(appSourceDirectoryPath, constants.TNS_MODULES_FOLDER_NAME)).wait();
184190
if(hasTnsModulesInAppFolder && this.$projectData.dependencies && this.$projectData.dependencies[constants.TNS_CORE_MODULES_NAME]) {
185191
this.$logger.warn("You have tns_modules dir in your app folder and tns-core-modules in your package.json file. Tns_modules dir in your app folder will not be used and you can safely remove it.");
186-
sourceFiles.filter(source => source !== constants.TNS_MODULES_FOLDER_NAME)
187-
.map(source => path.join(appSourceDirectoryPath, source))
188-
.forEach(source => shell.cp("-Rf", source, appDestinationDirectoryPath));
189-
} else {
190-
shell.cp("-Rf", path.join(appSourceDirectoryPath, "*"), appDestinationDirectoryPath);
192+
sourceFiles = sourceFiles.filter(source => !minimatch(source, `**/${constants.TNS_MODULES_FOLDER_NAME}/**`, {nocase: true}));
191193
}
192194

195+
// Remove .ts and .js.map files
196+
PlatformService.EXCLUDE_FILES_PATTERN.forEach(pattern => sourceFiles = sourceFiles.filter(file => !minimatch(file, pattern, {nocase: true})));
197+
let copyFileFutures = sourceFiles.map(source => {
198+
let destinationFile = path.join(appDestinationDirectoryPath, path.relative(appSourceDirectoryPath, source));
199+
return this.$fs.copyFile(source, destinationFile);
200+
});
201+
Future.wait(copyFileFutures);
202+
193203
// Copy App_Resources to project root folder
194204
this.$fs.ensureDirectoryExists(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait()).wait(); // Should be deleted
195205
let appResourcesDirectoryPath = path.join(appDestinationDirectoryPath, constants.APP_RESOURCES_FOLDER_NAME);

test/npm-support.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function preparePlatform(testInjector: IInjector): IFuture<void> {
161161

162162
describe("Npm support tests", () => {
163163
let testInjector: IInjector, projectFolder: string, appDestinationFolderPath: string;
164-
before(() => {
164+
beforeEach(() => {
165165
let projectSetup = setupProject().wait();
166166
testInjector = projectSetup.testInjector;
167167
projectFolder = projectSetup.projectFolder;

0 commit comments

Comments
 (0)