diff --git a/.gitignore b/.gitignore index 647ae502f..151331646 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/gruntfile.js b/gruntfile.js index 41354c143..fef1d30a7 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -1,3 +1,4 @@ +var fs = require("fs"); var path = require("path"); var shelljs = require("shelljs"); @@ -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({ @@ -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', @@ -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"]); diff --git a/package.json b/package.json index f0d8f4c31..7d8a4759d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/nativescript-angular/hooks/before-livesync.js b/src/nativescript-angular/hooks/before-livesync.js new file mode 100644 index 000000000..2c8247a66 --- /dev/null +++ b/src/nativescript-angular/hooks/before-livesync.js @@ -0,0 +1,3 @@ +module.exports = function ($usbLiveSyncService) { + $usbLiveSyncService.forceExecuteFullSync = true; +}; diff --git a/src/nativescript-angular/hooks/hook-helper.js b/src/nativescript-angular/hooks/hook-helper.js new file mode 100644 index 000000000..a49cf1d9b --- /dev/null +++ b/src/nativescript-angular/hooks/hook-helper.js @@ -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; diff --git a/src/nativescript-angular/postinstall.js b/src/nativescript-angular/postinstall.js new file mode 100644 index 000000000..37d58837e --- /dev/null +++ b/src/nativescript-angular/postinstall.js @@ -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); +}