Skip to content

Commit 26854cf

Browse files
committed
Fixed node-sass in compiled apps problem
The after-prepare step now auto removes the node-sass directory from the tns_modules folder in compiled app packages (Fixes #3)
1 parent fd976a7 commit 26854cf

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.4.1
2+
3+
- Updated after-prepare step to remove node-sass directory from compiled app packages (https://github.com/toddanglin/nativescript-dev-sass/issues/3)
4+
15
## v0.4.0
26

37
- Added demo project to Git repo

lib/after-prepare.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ var path = require('path');
33
var glob = require('glob');
44
var Promise = require('bluebird');
55

6+
// Clean-up files from compiled app packages
67
module.exports = function ($logger, $projectData, $usbLiveSyncService) {
78
// delete all scss files from compiled sources
89
var platformsData = $injector.resolve('platformsData');
910
return Promise.each(platformsData.platformsNames, function (platform) {
11+
// Remove node_sass directory from compiled output
12+
var nodeSassPath = path.join(platformsData.getPlatformData(platform).appDestinationDirectoryPath, 'app/tns_modules/node-sass/');
13+
deleteFolderRecursive(nodeSassPath);
14+
1015
// Find and remove unnecessary SCSS files from iOS and Android app packages
1116
var sassFilesPath = path.join(platformsData.getPlatformData(platform).appDestinationDirectoryPath, 'app/**/*.scss');
1217
var sassFiles = glob.sync(sassFilesPath).filter(function (filePath) {
@@ -19,4 +24,19 @@ module.exports = function ($logger, $projectData, $usbLiveSyncService) {
1924
return fs.unlinkSync(sassFile);
2025
});
2126
});
22-
}
27+
}
28+
29+
// Utility to delete non-empty folder recursively
30+
var deleteFolderRecursive = function(filepath) {
31+
if( fs.existsSync(filepath)) {
32+
fs.readdirSync(filepath).forEach(function(file,index){
33+
var curPath = path.join(filepath, file);
34+
if(fs.lstatSync(curPath).isDirectory()) { // recurse
35+
deleteFolderRecursive(curPath);
36+
} else { // delete file
37+
fs.unlinkSync(curPath);
38+
}
39+
});
40+
return fs.rmdirSync(filepath);
41+
}
42+
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-dev-sass",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "SASS CSS pre-processor for NativeScript projects.",
55
"scripts": {
66
"test": "exit 0",

0 commit comments

Comments
 (0)