diff --git a/bin/nativescript.cmd b/bin/nativescript.cmd new file mode 100644 index 0000000000..9074113019 --- /dev/null +++ b/bin/nativescript.cmd @@ -0,0 +1 @@ +@node %~dp0\nativescript.js %* \ No newline at end of file diff --git a/bin/nativescript.js b/bin/nativescript.js index f44316be67..cc776ff51d 100644 --- a/bin/nativescript.js +++ b/bin/nativescript.js @@ -1,3 +1,4 @@ #!/usr/bin/env node +"use strict"; require("../lib/nativescript-cli.js"); \ No newline at end of file diff --git a/lib/bootstrap.ts b/lib/bootstrap.ts index 4b9a8dc63a..7472b9916f 100644 --- a/lib/bootstrap.ts +++ b/lib/bootstrap.ts @@ -23,6 +23,7 @@ $injector.requireCommand("run", "./commands/run"); $injector.requireCommand("prepare", "./commands/prepare"); $injector.requireCommand("build", "./commands/build"); $injector.requireCommand("deploy", "./commands/deploy"); +$injector.requireCommand("dev-post-install", "./commands/post-install"); $injector.require("npm", "./node-package-manager"); $injector.require("config", "./config"); diff --git a/lib/commands/post-install.ts b/lib/commands/post-install.ts new file mode 100644 index 0000000000..beca45e7d8 --- /dev/null +++ b/lib/commands/post-install.ts @@ -0,0 +1,86 @@ +/// +"use strict"; +import osenv = require("osenv"); +import path = require("path"); + +export class PostInstallCommand implements ICommand { + private static CALL_PROFILE_SCRIPT = + "if [ -f ~/.profile ]; then\n" + + " . ~/.profile\n" + + "fi\n"; + + constructor(private $fs: IFileSystem, + private $childProcess: IChildProcess, + private $logger: ILogger) { } + + public disableAnalytics = true; + + public execute(args: string[]): IFuture { + return (() => { + var scriptsOk = true; + + try { + this.updateShellScript(".profile").wait(); + this.updateShellScript(".bashrc").wait(); + + this.updateBashProfile().wait(); + + // zsh - http://www.acm.uiuc.edu/workshops/zsh/startup_files.html + this.updateShellScript(".zshrc").wait(); + } catch(err) { + this.$logger.out("Failed to update all shell start-up scripts. Auto-completion may not work. " + err); + scriptsOk = false; + } + + if(scriptsOk) { + this.$logger.out("Restart your shell to enable command auto-completion."); + } + }).future()(); + } + + private updateShellScript(fileName: string): IFuture { + return (() => { + var filePath = this.getHomePath(fileName); + + var doUpdate = true; + if (this.$fs.exists(filePath).wait()) { + var contents = this.$fs.readText(filePath).wait(); + if (contents.match(/nativescript\s+completion\s+--\s+/) || contents.match(/tns\s+completion\s+--\s+/)) { + doUpdate = false; + } + } + + if(doUpdate) { + this.updateShellScriptCore(filePath).wait(); + } + + }).future()(); + } + + private updateShellScriptCore(filePath: string): IFuture { + return (() => { + this.$childProcess.exec("nativescript completion >> " + filePath).wait(); + this.$childProcess.exec("tns completion >> " + filePath).wait(); + }).future()(); + } + + private getHomePath(fileName: string): string { + return path.join(osenv.home(), fileName); + } + + private updateBashProfile(): IFuture { + return (() => { + var bashProfileFileName = this.getHomePath(".bash_profile"); + if (this.$fs.exists(bashProfileFileName).wait()) { + var contens = this.$fs.readText(bashProfileFileName).wait(); + if (contens.indexOf(PostInstallCommand.CALL_PROFILE_SCRIPT) < 0) { + this.updateShellScript(".bash_profile"); + } + } else { + this.$fs.writeFile(bashProfileFileName, PostInstallCommand.CALL_PROFILE_SCRIPT).wait(); + this.updateShellScriptCore(bashProfileFileName).wait(); + } + }).future()(); + } +} +$injector.registerCommand("dev-post-install", PostInstallCommand); \ No newline at end of file diff --git a/lib/common b/lib/common index 3902e1ada7..4b954b1fc2 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 3902e1ada7a3fe34298a76658144a85329aaddf7 +Subproject commit 4b954b1fc20d184863613d7d4fc2585dfb9dc910 diff --git a/lib/config.ts b/lib/config.ts index 8f4fd3613f..0883d1f95f 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -6,6 +6,7 @@ import util = require("util"); export class StaticConfig implements IStaticConfig { public PROJECT_FILE_NAME = ".tnsproject"; public CLIENT_NAME = "nativescript"; + public CLIENT_NAME_ALIAS = "tns"; public ANALYTICS_API_KEY = "5752dabccfc54c4ab82aea9626b7338e"; public TRACK_FEATURE_USAGE_SETTING_NAME = "TrackFeatureUsage"; public ANALYTICS_INSTALLATION_ID_SETTING_NAME = "AnalyticsInstallationID"; diff --git a/lib/nativescript-cli.ts b/lib/nativescript-cli.ts index 996df98837..3c1533963f 100644 --- a/lib/nativescript-cli.ts +++ b/lib/nativescript-cli.ts @@ -21,3 +21,4 @@ $injector.register("config", { var dispatcher = $injector.resolve("dispatcher"); dispatcher.runMainFiber(); + diff --git a/package.json b/package.json index b272f5d8e1..8a84a5c707 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ }, "main": "./lib/nativescript-cli.js", "scripts": { - "test": "node_modules\\.bin\\_mocha --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 15000 test/" + "test": "node_modules\\.bin\\_mocha --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 15000 test/", + "postinstall": "node postinstall.js" }, "repository": { "type": "git", diff --git a/postinstall.js b/postinstall.js new file mode 100644 index 0000000000..96085cd75e --- /dev/null +++ b/postinstall.js @@ -0,0 +1,3 @@ + +var child_process = require("child_process"); +child_process.exec('node bin/nativescript.js dev-post-install'); \ No newline at end of file