Skip to content

Disable single-page livesync updates #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ bin/dist
node_modules
tags
src/nativescript-angular/**/*.js
!src/nativescript-angular/postinstall.js
!src/nativescript-angular/hooks/**/*.js
.baseDir.ts
.tscache
.nvm
Expand Down
20 changes: 20 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var fs = require("fs");
var path = require("path");
var shelljs = require("shelljs");

Expand All @@ -10,6 +11,7 @@ module.exports = function(grunt) {

var outDir = "bin/dist/modules";
var moduleOutDir = path.join(outDir, "nativescript-angular");
var moduleOutPackageJson = path.join(moduleOutDir, "package.json");
var packageName = "nativescript-angular-" + require("./package.json").version + ".tgz";

grunt.initConfig({
Expand Down Expand Up @@ -39,6 +41,15 @@ module.exports = function(grunt) {
src: 'package.json',
dest: moduleOutDir
},
hookScripts: {
cwd: 'src/nativescript-angular',
expand: true,
src: [
'postinstall.js',
'hooks/**/*.js'
],
dest: moduleOutDir
},
npmReadme: {
expand: true,
src: 'README.md',
Expand Down Expand Up @@ -103,9 +114,18 @@ module.exports = function(grunt) {
grunt.registerTask("build", [
"ts:build",
"copy:packageJson",
"copy:hookScripts",
"add-post-install-script",
"package"
]);

grunt.registerTask("add-post-install-script", function() {
var packageJson = JSON.parse(fs.readFileSync(moduleOutPackageJson, "utf-8"));
packageJson.scripts = packageJson.scripts || {};
packageJson.scripts.postinstall = "node postinstall.js";
fs.writeFileSync(moduleOutPackageJson, JSON.stringify(packageJson, null, " "));
});

grunt.registerTask("updateTests", ["all", "shell:updateTests"]);

grunt.registerTask("default", ["all"]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-angular",
"version": "0.0.42",
"version": "0.0.43",
"description": "",
"homepage": "http://www.telerik.com",
"bugs": "http://www.telerik.com",
Expand Down
3 changes: 3 additions & 0 deletions src/nativescript-angular/hooks/before-livesync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function ($usbLiveSyncService) {
$usbLiveSyncService.forceExecuteFullSync = true;
};
33 changes: 33 additions & 0 deletions src/nativescript-angular/hooks/hook-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";
var fs = require("fs");
var path = require("path");
function findProjectDir() {
var candidateDir = path.join(__dirname, "..");
while (true) {
var oldCandidateDir = candidateDir;
candidateDir = path.dirname(candidateDir);
if (path.basename(candidateDir) === 'node_modules') {
continue;
}
var packageJsonFile = path.join(candidateDir, 'package.json');
if (fs.existsSync(packageJsonFile)) {
return candidateDir;
}
if (oldCandidateDir === candidateDir) {
return;
}
}
}
exports.findProjectDir = findProjectDir;
function getHooksDir() {
return path.join(findProjectDir(), 'hooks');
}
exports.getHooksDir = getHooksDir;
function gerBeforeLivesyncHookDir() {
return path.join(getHooksDir(), "before-livesync");
}
exports.gerBeforeLivesyncHookDir = gerBeforeLivesyncHookDir;
function getHookFilePath() {
return path.join(gerBeforeLivesyncHookDir(), "nativescript-restart-on-sync-plugin.js");
}
exports.getHookFilePath = getHookFilePath;
16 changes: 16 additions & 0 deletions src/nativescript-angular/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var fs = require("fs");
var os = require("os");
var hookHelper = require("./hooks/hook-helper");
var projectDir = hookHelper.findProjectDir();
if (projectDir) {
var hooksDir = hookHelper.getHooksDir(),
beforeLivesyncHookDir = hookHelper.gerBeforeLivesyncHookDir(),
content = 'module.exports = require("nativescript-restart-on-sync-plugin/hooks/before-livesync");';
if (!fs.existsSync(hooksDir)) {
fs.mkdirSync(hooksDir);
}
if (!fs.existsSync(beforeLivesyncHookDir)) {
fs.mkdirSync(beforeLivesyncHookDir);
}
fs.writeFileSync(hookHelper.getHookFilePath(), content + os.EOL);
}