Skip to content

Commit a57d0b6

Browse files
committed
Updated to work with {N} 3.0.0-rc
Also works in {N} 2.4.x and earlier. Not compatible with 2.5.x
1 parent d387a0b commit a57d0b6

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

lib/after-prepare.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,41 @@ var glob = require('glob');
44
var Promise = require('bluebird');
55

66
// Clean-up files from compiled app packages
7-
module.exports = function ($logger, $projectData, $usbLiveSyncService) {
7+
module.exports = function (logger, platformsData, projectData, hookArgs) {
88
// delete all scss files from compiled sources
9-
var platformsData = $injector.resolve('platformsData');
10-
return Promise.each(platformsData.platformsNames, function (platform) {
9+
10+
// Don't include .SCSS files in LiveSync -- only sync CSS files
11+
if (hookArgs.filesToSync !== undefined) {
12+
hookArgs.filesToSync.forEach(function (file, index) {
13+
if (file.indexOf(".scss") !== -1) {
14+
// Remove the .SCSS file from LiveSync operation
15+
hookArgs.filesToSync.splice(index, 1);
16+
}
17+
});
18+
}
19+
20+
var platformData = platformsData.getPlatformData(hookArgs.platform.toLowerCase());
21+
22+
return new Promise(function(resolve, reject) {
1123
// Remove node_sass directory from compiled output
12-
var nodeSassPath = path.join(platformsData.getPlatformData(platform).appDestinationDirectoryPath, 'app/tns_modules/node-sass/');
24+
var nodeSassPath = path.join(platformData.appDestinationDirectoryPath, 'app/tns_modules/node-sass/');
1325
deleteFolderRecursive(nodeSassPath);
1426

1527
// Find and remove unnecessary SCSS files from iOS and Android app packages
16-
var sassFilesPath = path.join(platformsData.getPlatformData(platform).appDestinationDirectoryPath, 'app/**/*.scss');
28+
var sassFilesPath = path.join(platformData.appDestinationDirectoryPath, 'app/**/*.scss');
1729
var sassFiles = glob.sync(sassFilesPath).filter(function (filePath) {
1830
var path = filePath;
1931
var parts = path.split('/');
2032
var filename = parts[parts.length - 1];
2133
return path.indexOf("App_Resources") === -1;
2234
});
23-
return Promise.each(sassFiles, function (sassFile) {
35+
36+
Promise.each(sassFiles, function (sassFile) {
2437
return fs.unlinkSync(sassFile);
38+
})
39+
.then(function() {
40+
console.log("All SASS source files removed from app package");
41+
resolve();
2542
});
2643
});
2744
}
@@ -39,4 +56,4 @@ var deleteFolderRecursive = function(filepath) {
3956
});
4057
return fs.rmdirSync(filepath);
4158
}
42-
};
59+
};

lib/before-prepare.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
var converter = require('./converter');
22

3-
module.exports = function ($logger, $projectData, $usbLiveSyncService) {
4-
return converter.convert($logger, $projectData.projectDir);
3+
module.exports = function (logger, platformsData, projectData, hookArgs) {
4+
// Do not run converter during LiveSync if there are no SCSS files being processed
5+
var runProcessor = false;
6+
if (hookArgs.filesToSync !== undefined) {
7+
hookArgs.filesToSync.forEach(function (file) {
8+
if (file.indexOf(".scss") !== -1) {
9+
runProcessor = true;
10+
}
11+
});
12+
} else {
13+
// Not a LiveSync operation; always run converter
14+
runProcessor = true;
15+
}
16+
17+
if (runProcessor) {
18+
console.log("Converting SCSS to CSS...");
19+
return converter.convert(logger, projectData.projectDir);
20+
}
521
}

0 commit comments

Comments
 (0)